GPUDevice from init()
'lower' to use the lower triangle, 'upper' to use the upper triangle
'no-transpose' for A, 'transpose' for A^T
'unit' to treat the diagonal as all-ones (A's diagonal is not read), 'non-unit' to read it
order of the matrix A (number of rows and columns)
Float32Array, row-major or column-major (see layout), at least (n-1)*lda+n elements
leading dimension of A (>= n either way — A is square)
Float32Array input vector, length at least (n-1)*incx+1
stride for x (must be a positive integer)
Float32Array output vector, length at least (n-1)*incy+1
stride for y (must be a positive integer)
Optionallayout: "column-major" | "row-major"
storage layout of A (default: 'row-major'); column-major
flips both the stored triangle and the effective trans (op(A) stays
what you asked for either way)
Performs the triangular matrix-vector operation $$y \leftarrow \mathrm{op}(A) x$$
x and y are kept resident on the GPU. A must be a GpuMatrix; its own
layout (set at GpuMatrix.from time) determines the operation — there is
no separate layout argument here.
import { init, cleanup } from "wgblas";
import { strmv } from "wgblas/strmv";
import { GpuVector } from "wgblas/classes/GpuVector";
import { GpuMatrix } from "wgblas/classes/GpuMatrix";
const device = await init();
// Lower triangular; entries above the diagonal are ignored.
const n = 3;
const A = new Float32Array([2, 0, 0, 3, 4, 0, 5, 6, 8]);
const x = new Float32Array([1, 1, 1]);
const AGpu = GpuMatrix.from(A, n, n, n, "row-major");
const xGpu = GpuVector.from(x);
const yGpu = GpuVector.from(new Float32Array(n));
console.log("A (lower triangular) =");
console.table([A.slice(0, 3), A.slice(3, 6), A.slice(6, 9)]);
console.log("x =", x);
await strmv(
device,
"lower",
"no-transpose",
"non-unit",
n,
AGpu,
AGpu.lda,
xGpu,
1,
yGpu,
1,
);
console.log("y = A*x =", await yGpu.read()); // [2, 3+4, 5+6+8] = [2, 7, 19]
AGpu.destroy();
xGpu.destroy();
yGpu.destroy();
if (typeof process !== "undefined") cleanup();
GPUDevice from init()
'lower' to use the lower triangle, 'upper' to use the upper triangle
'no-transpose' for A, 'transpose' for A^T
'unit' to treat the diagonal as all-ones (A's diagonal is not read), 'non-unit' to read it
order of the matrix A
GpuMatrix, GPU-resident
leading dimension of A (must equal A.lda)
GpuVector input vector (not mutated)
stride for x (must be a positive integer)
GpuVector output vector (mutated in place)
stride for y (must be a positive integer)
Performs the triangular matrix-vector operation $$y \leftarrow \mathrm{op}(A) x$$
A is an n×n triangular matrix stored in row-major order. Only the triangle specified by
uplois referenced; the other triangle is not accessed.Browser (standalone HTML):