compute.kernels.mul¶
Summary¶
compute.kernels.mul multiplies corresponding elements at the broadcast shape. A vector can apply per-column weights to a matrix without expanding the vector into a separate matrix. For products that sum over an axis, use dot or matmul.
Syntax¶
mul(a: GPUndarray, b: GPUndarray, opts?: ElementwiseOptions): GPUndarray
const products = kernels.mul(a, b);
Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
a, b |
GPUndarray |
Yes | Packed or strided GPU arrays with the same f32, u32 or c64 dtype and broadcastable shapes. |
opts |
ElementwiseOptions |
No | Kernel output and dispatch settings. |
Returns¶
GPUndarray - Product in the broadcast shape and input dtype. Unsigned products wrap modulo 2 ** 32. Complex elements use complex multiplication. A matching C-contiguous input can be used as out.
Example¶
const wgpu = await WasmGPU.create(document.querySelector("canvas"));
const { ndarray: nd, kernels } = wgpu.compute;
const x = nd.fromArray("c64", [1], [1, 1], { residency: "gpu" });
const y = kernels.mul(x, x);
const cpu = await nd.toCPU(y);
console.log(cpu.get(0)); // [0, 2]
cpu.destroy();
y.destroy();
x.destroy();