GPUDevice from init()
'no-transpose' for A, 'transpose' for A^T
'no-transpose' for B, 'transpose' for B^T
rows of op(A) and C
columns of op(B) and C
columns of op(A), rows of op(B)
scalar multiplier for op(A)*op(B)
Float64Array, row-major or column-major (see layout)
leading dimension of A as stored
Float64Array, row-major or column-major (see layout)
leading dimension of B as stored
scalar multiplier for C
Float64Array input/output matrix, row-major or column-major
leading dimension of C as stored
Optionallayout: "row-major" | "column-major"
storage layout shared by A/B/C when they're Float64Array
(default: 'row-major'); column-major A/B flips the respective trans
flag internally, column-major C computes C^T = op(B)^T*op(A)^T instead
(same underlying bytes) — op(A)*op(B) stays what you asked for either way
updated C as a Float64Array
Performs the matrix-matrix operation $$C \leftarrow \alpha \mathrm{op}(A) \mathrm{op}(B) + \beta C$$ in double precision (double-double emulation).
A, B, and C are all kept GPU-resident (Float64Array-backed GpuMatrix).
Each matrix's own layout (set at GpuMatrix.from time) determines the
operation — there is no separate layout argument here. A and B must be
GpuMatrix whenever C is, and vice versa — mixing a GpuMatrix with a plain
Float64Array is not supported.
Range: double-double keeps its leading part in an f32, so it has ~48 bits of precision but f32's exponent range. A double beyond ±3.4e38 reads as ±Infinity and one below ~1.2e-38 in magnitude as 0 (f32 subnormals may flush too, depending on the GPU) — including elements of an output array the routine never touches (stride gaps, padding, an unreferenced triangle) — and a result or intermediate past ±3.4e38 overflows to ±Infinity, where real f64 would stay finite.
import { init, cleanup } from "wgblas";
import { dgemm } from "wgblas/dgemm";
import { GpuMatrix } from "wgblas/classes/GpuMatrix";
const device = await init();
// C = A*B with A 2x3 and B 3x2, so C is 2x2.
const m = 2,
n = 2,
k = 3;
const A = new Float64Array([1, 2, 3, 4, 5, 6]);
const B = new Float64Array([1, 0, 0, 1, 1, 1]);
const AGpu = GpuMatrix.from(A, m, k, k, "row-major");
const BGpu = GpuMatrix.from(B, k, n, n, "row-major");
const CGpu = GpuMatrix.from(new Float64Array(m * n), m, n, n, "row-major");
console.log("A =");
console.table([A.slice(0, 3), A.slice(3, 6)]);
await dgemm(
device,
"no-transpose",
"no-transpose",
m,
n,
k,
1,
AGpu,
AGpu.lda,
BGpu,
BGpu.lda,
0,
CGpu,
CGpu.lda,
);
const result = await CGpu.read();
console.log("C = A*B =");
console.table([result.slice(0, 2), result.slice(2, 4)]); // [[4,5],[10,11]]
AGpu.destroy();
BGpu.destroy();
CGpu.destroy();
if (typeof process !== "undefined") cleanup();
GPUDevice from init()
'no-transpose' for A, 'transpose' for A^T
'no-transpose' for B, 'transpose' for B^T
rows of op(A) and C
columns of op(B) and C
columns of op(A), rows of op(B)
scalar multiplier for op(A)*op(B)
GpuMatrix (Float64Array-backed)
leading dimension of A (must equal A.lda)
GpuMatrix (Float64Array-backed)
leading dimension of B (must equal B.lda)
scalar multiplier for C
GpuMatrix (Float64Array-backed, mutated in place)
leading dimension of C (must equal C.lda)
no C — it stays GPU-resident; call C.read() yourself for a CPU readback (see the example)
Performs the matrix-matrix operation $$C \leftarrow \alpha \mathrm{op}(A) \mathrm{op}(B) + \beta C$$ in double precision (double-double emulation — WGSL has no native f64 type).
transA/transB='no-transpose': op(A) = A (m×k), op(B) = B (k×n)transA/transB='transpose': op(A) = A^T, op(B) = B^TA, B, C are row-major or column-major (see
layout) — backed by one shared-memory-tiled, register-blocked kernel,dgemm_small.wgsl(BM=BN=32), at every size: unlikesgemm, the 64×64 large tile measured ~2x slower for double-double.Range: double-double keeps its leading part in an f32, so it has ~48 bits of precision but f32's exponent range. A double beyond ±3.4e38 reads as ±Infinity and one below ~1.2e-38 in magnitude as 0 (f32 subnormals may flush too, depending on the GPU) — including elements of an output array the routine never touches (stride gaps, padding, an unreferenced triangle) — and a result or intermediate past ±3.4e38 overflows to ±Infinity, where real f64 would stay finite.
Browser (standalone HTML):