GPUDevice from init()
'left' to solve op(A)X=alphaB, 'right' to solve Xop(A)=alphaB
'lower' if only A's lower triangle is stored, 'upper' for upper
'no-transpose' for A, 'transpose' for A^T
'unit' to treat A's diagonal as all-ones (A's diagonal is not read), 'non-unit' to read it
rows of B
columns of B
scalar multiplier for B
Float64Array, triangular, row-major or column-major (see layout)
leading dimension of A as stored
Float64Array input/output matrix, overwritten with the solution, row-major or column-major
leading dimension of B as stored
Optionallayout: "row-major" | "column-major"
storage layout shared by A/B when they're Float64Array
(default: 'row-major') — column-major A is a genuine transpose (A isn't
symmetric like dsymm's), so both transA and uplo are adjusted
internally to compensate
the solution X, written into B, as a Float64Array
Solves the triangular matrix equation
$$\mathrm{op}(A) X = \alpha B \quad (\texttt{side='left'})$$
$$X \mathrm{op}(A) = \alpha B \quad (\texttt{side='right'})$$
in double precision, overwriting B in place with X.
A and B are both 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 both
be GpuMatrix or both be Float64Array — mixing is not supported.
import { init, cleanup } from "wgblas";
import { dtrsm } from "wgblas/dtrsm";
import { GpuMatrix } from "wgblas/classes/GpuMatrix";
const device = await init();
// Solves A*X = B in place, A lower triangular. With B the identity, B ends
// up holding A's inverse, to about 15 correct digits (double-double).
const n = 3;
const A = new Float64Array([3, 0, 0, 1, 3, 0, 1, 1, 3]);
const B = new Float64Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
const AGpu = GpuMatrix.from(A, n, n, n, "row-major");
const BGpu = GpuMatrix.from(B, n, n, n, "row-major");
console.log("A (lower triangular) =");
console.table([A.slice(0, 3), A.slice(3, 6), A.slice(6, 9)]);
await dtrsm(
device,
"left",
"lower",
"no-transpose",
"non-unit",
n,
n,
1,
AGpu,
AGpu.lda,
BGpu,
BGpu.lda,
);
const result = await BGpu.read();
console.log("X solving A*X = I, i.e. A's inverse =");
console.table([result.slice(0, 3), result.slice(3, 6), result.slice(6, 9)]);
AGpu.destroy();
BGpu.destroy();
if (typeof process !== "undefined") cleanup();
GPUDevice from init()
'left' to solve op(A)X=alphaB, 'right' to solve Xop(A)=alphaB
'lower' if only A's lower triangle is stored, 'upper' for upper
'no-transpose' for A, 'transpose' for A^T
'unit' to treat A's diagonal as all-ones (A's diagonal is not read), 'non-unit' to read it
rows of B
columns of B
scalar multiplier for B
GpuMatrix (Float64Array-backed), triangular
leading dimension of A (must equal A.lda)
GpuMatrix (Float64Array-backed), overwritten in place with the solution
leading dimension of B (must equal B.lda)
no B — it stays GPU-resident; call B.read() yourself for a CPU readback (see the example)
Solves the triangular matrix equation $$\mathrm{op}(A) X = \alpha B \quad (\texttt{side='left'})$$ $$X \mathrm{op}(A) = \alpha B \quad (\texttt{side='right'})$$ in double precision (double-double emulation — WGSL has no native f64 type), overwriting
Bwith the solutionX—Ais triangular, only itsuplotriangle stored;Bis a general m×n matrix.side='left':Ais m×m — solvesop(A)*X = alpha*Bside='right':Ais n×n — solvesX*op(A) = alpha*BBlocked over 64-row diagonal blocks, all in one compute pass: each block is solved by substitution in place on
B, thendgemm's kernel (dgemm_small.wgsl) applies the trailing update to the rows (columns, forside='right') still to solve. A single block (order <= 64) is one dispatch. A near-zero diagonal entry amplifies error, same as any triangular solve.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), and a result or intermediate past ±3.4e38 overflows to ±Infinity, where real f64 would stay finite.
Browser (standalone HTML):