GPUDevice from init()
'no-transpose' for A, 'transpose' for A^T
number of rows in A
number of columns in A
scalar multiplier for op(A)*x
Float32Array or GpuMatrix, row-major, at least (m-1)*lda+n elements
leading dimension of A (>= n)
Float32Array input vector
stride for x (must be a positive integer)
scalar multiplier for y
Float32Array input/output vector
stride for y (must be a positive integer)
Performs the matrix-vector operation y = alpha * op(A) * x + beta * y
A is kept GPU-resident; x and y are CPU Float32Arrays.
GPUDevice from init()
'no-transpose' for A, 'transpose' for A^T
number of rows in A
number of columns in A
scalar multiplier for op(A)*x
GpuMatrix, row-major, GPU-resident
leading dimension of A (must equal A.lda)
Float32Array input vector
stride for x (must be a positive integer)
scalar multiplier for y
Float32Array input/output vector
stride for y (must be a positive integer)
Performs the matrix-vector operation y = alpha * op(A) * x + beta * y
x and y are kept resident on the GPU. A must be a GpuMatrix.
import { init, cleanup } from "wgblas";
import { sgemv } from "wgblas/sgemv";
import { GpuVector } from "wgblas/classes/GpuVector";
import { GpuMatrix } from "wgblas/classes/GpuMatrix";
import { randomFloat32Array } from "wgblas/random";
const device = await init();
// 4×4 row-major matrix A, GPU-resident x and y
const m = 4, n = 4;
const alpha = 1.0, beta = 0.0;
const A = randomFloat32Array(m * n, -10, 10);
const x = randomFloat32Array(n, -10, 10);
const y = randomFloat32Array(m, -10, 10);
const AGpu = GpuMatrix.from(A, m, n);
const xGpu = GpuVector.from(x);
const yGpu = GpuVector.from(y);
console.log("A:", A);
console.log("x:", x);
// result stays GPU-resident
await sgemv(device, "no-transpose", m, n, alpha, AGpu, AGpu.lda, xGpu, 1, beta, yGpu, 1);
// single readback
const result = await yGpu.read();
console.log("y:", result);
AGpu.destroy();
xGpu.destroy();
yGpu.destroy();
if (typeof process !== "undefined") cleanup();
GPUDevice from init()
'no-transpose' for A, 'transpose' for A^T
number of rows in A
number of columns in A
scalar multiplier for op(A)*x
GpuMatrix, row-major
leading dimension of A (>= n)
GpuVector input vector (not mutated)
stride for x (must be a positive integer)
scalar multiplier for y
GpuVector input/output vector (mutated in place)
stride for y (must be a positive integer)
Performs the matrix-vector operation y = alpha * op(A) * x + beta * y
trans='no-transpose': op(A) = A, x is length n, y is length mtrans='transpose': op(A) = A^T, x is length m, y is length nA is an m×n matrix stored in row-major order.
ldais the leading dimension (number of floats between the start of consecutive rows — must be >= n).Browser (standalone HTML):