Skip to content

WasmGPU.compute.kernels.gemmF32

Summary

gemmF32 computes row-major out = alpha * A * B + beta * out for f32 matrices.

Syntax

WasmGPU.compute.kernels.gemmF32(a: StorageBuffer, b: StorageBuffer, m: number, n: number, k: number, opts?: GemmF32Options): StorageBuffer

Parameters

Name Type Required Description
a StorageBuffer Yes Row-major f32 matrix with shape (m, k).
b StorageBuffer Yes Row-major f32 matrix with shape (k, n).
m number Yes Non-negative output row count.
n number Yes Non-negative output column count.
k number Yes Non-negative shared inner dimension.
opts GemmF32Options No Output, scale factors, encoder, label, and limit-validation controls.

Returns

StorageBuffer - Row-major f32 matrix with shape (m, n). A new output enables COPY_SRC; opts.out is returned when supplied.

Type Details

type GemmF32Options = {
    out?: StorageBuffer;
    alpha?: number; // default: 1
    beta?: number;  // default: 0
    encoder?: GPUCommandEncoder;
    label?: string;
    validateLimits?: boolean;
};

The operation computes out = alpha * A * B + beta * out. Each dimension must fit in u32, and each derived element count must be a safe integer that fits in u32. A supplied output needs m * n * 4 bytes and must differ from both inputs. When opts.encoder is supplied, commands are recorded but not submitted by this call.

Example

const wgpu = await WasmGPU.create(document.querySelector("canvas"));
const a = wgpu.compute.createStorageBuffer({ data: new Float32Array([1, 2, 3, 4]) });
const b = wgpu.compute.createStorageBuffer({ data: new Float32Array([5, 6, 7, 8]) });
const out = wgpu.compute.kernels.gemmF32(a, b, 2, 2, 2);
console.log(Array.from(await wgpu.compute.readback.readF32(out)));

See Also