wgblas 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +36 -54
- package/dist/wgblas.browser.js +779 -34
- package/index.d.mts +13 -0
- package/index.mjs +8 -0
- package/package.json +56 -3
- package/src/dasum/dasum.d.mts +2 -2
- package/src/dasum/dasum.mjs +6 -4
- package/src/idamax/idamax.d.mts +51 -0
- package/src/idamax/idamax.mjs +128 -0
- package/src/init.mjs +9 -1
- package/src/isamax/isamax.d.mts +1 -1
- package/src/sasum/sasum.d.mts +1 -1
- package/src/saxpy/saxpy.d.mts +1 -1
- package/src/scopy/scopy.d.mts +1 -1
- package/src/sdot/sdot.d.mts +1 -1
- package/src/sgemm/sgemm.d.mts +102 -0
- package/src/sgemm/sgemm.mjs +195 -0
- package/src/sgemmtr/sgemmtr.d.mts +104 -0
- package/src/sgemmtr/sgemmtr.mjs +203 -0
- package/src/sgemv/sgemv.d.mts +1 -38
- package/src/sgemv/sgemv.mjs +4 -0
- package/src/sger/sger.d.mts +1 -34
- package/src/sger/sger.mjs +2 -0
- package/src/shaders/block_transfer.wgsl +42 -0
- package/src/shaders/browser-shaders.mjs +26 -0
- package/src/shaders/dasum.wgsl +3 -2
- package/src/shaders/f64/dekker.wgsl +4 -85
- package/src/shaders/f64/utils/abs.wgsl +10 -0
- package/src/shaders/f64/utils/add.wgsl +77 -0
- package/src/shaders/f64/utils/equal.wgsl +7 -0
- package/src/shaders/f64/utils/greater.wgsl +12 -0
- package/src/shaders/f64/utils/multiply.wgsl +81 -0
- package/src/shaders/idamax.wgsl +96 -0
- package/src/shaders/reduction/argmaxF64.wgsl +50 -0
- package/src/shaders/reduction/sumF64.wgsl +2 -2
- package/src/shaders/sgemm_large.wgsl +117 -0
- package/src/shaders/sgemm_small.wgsl +112 -0
- package/src/shaders/sgemmtr_large.wgsl +117 -0
- package/src/shaders/sgemmtr_small.wgsl +110 -0
- package/src/shaders/symmetrize.wgsl +31 -0
- package/src/shaders/triangularize.wgsl +44 -0
- package/src/snrm2/snrm2.d.mts +1 -1
- package/src/srot/srot.d.mts +1 -1
- package/src/srotm/srotm.d.mts +1 -1
- package/src/sscal/sscal.d.mts +1 -1
- package/src/sswap/sswap.d.mts +1 -1
- package/src/ssymm/ssymm.d.mts +103 -0
- package/src/ssymm/ssymm.mjs +209 -0
- package/src/ssymv/ssymv.d.mts +1 -36
- package/src/ssymv/ssymv.mjs +2 -0
- package/src/ssyr/ssyr.d.mts +1 -30
- package/src/ssyr/ssyr.mjs +2 -0
- package/src/ssyr2/ssyr2.d.mts +1 -34
- package/src/ssyr2/ssyr2.mjs +2 -0
- package/src/ssyr2k/ssyr2k.d.mts +100 -0
- package/src/ssyr2k/ssyr2k.mjs +201 -0
- package/src/ssyrk/ssyrk.d.mts +90 -0
- package/src/ssyrk/ssyrk.mjs +176 -0
- package/src/strmm/strmm.d.mts +100 -0
- package/src/strmm/strmm.mjs +211 -0
- package/src/strmv/strmv.d.mts +1 -36
- package/src/strmv/strmv.mjs +2 -0
- package/src/strsm/strsm.d.mts +99 -0
- package/src/strsm/strsm.mjs +342 -0
- package/src/strsv/strsv.d.mts +1 -32
- package/src/strsv/strsv.mjs +2 -0
- package/src/util/buffer.mjs +4 -2
- package/src/util/compute.mjs +6 -3
- package/src/util/f64.mjs +3 -3
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import {
|
|
2
|
+
uploadBuffer,
|
|
3
|
+
createParamsBuffer,
|
|
4
|
+
createStorageBuffer,
|
|
5
|
+
stageReadback,
|
|
6
|
+
destroyBuffers,
|
|
7
|
+
} from "../util/buffer.mjs";
|
|
8
|
+
import { createBindGroup } from "../util/bindgroup.mjs";
|
|
9
|
+
import { beginTimedEncoder, encodePass, submit } from "../util/compute.mjs";
|
|
10
|
+
import { extractResult } from "../util/result.mjs";
|
|
11
|
+
import { resolveTimestamp, extractTimestamp } from "../util/benchmark.mjs";
|
|
12
|
+
import { getPipeline } from "../util/pipeline.mjs";
|
|
13
|
+
import { GpuMatrix } from "../classes/GpuMatrix.mjs";
|
|
14
|
+
|
|
15
|
+
const BM_SMALL = 32, BN_SMALL = 32; // sgemm_small.wgsl's block tile
|
|
16
|
+
const BM_LARGE = 64, BN_LARGE = 64; // sgemm_large.wgsl's block tile
|
|
17
|
+
const LARGE_TILE_WORKGROUP_THRESHOLD = 36; // same threshold sgemm/sgemmtr/ssyrk use
|
|
18
|
+
const SYM_WG = 8; // symmetrize.wgsl's @workgroup_size(8, 8)
|
|
19
|
+
|
|
20
|
+
// ssymm: C := alpha*A*B + beta*C (side='left') or alpha*B*A + beta*C
|
|
21
|
+
// (side='right'), A symmetric. No fused kernel — symmetrize then sgemm,
|
|
22
|
+
// both on one command encoder. See symmetrize.wgsl.
|
|
23
|
+
export async function ssymm(
|
|
24
|
+
device, side, uplo, m, n, alpha, A, lda, B, ldb, beta, C, ldc, layout = "row-major",
|
|
25
|
+
) {
|
|
26
|
+
const AIsGpu = A instanceof GpuMatrix;
|
|
27
|
+
const BIsGpu = B instanceof GpuMatrix;
|
|
28
|
+
const CIsGpu = C instanceof GpuMatrix;
|
|
29
|
+
|
|
30
|
+
if (!(device instanceof GPUDevice))
|
|
31
|
+
throw new Error("device must be a GPUDevice.");
|
|
32
|
+
if (side !== "left" && side !== "right")
|
|
33
|
+
throw new Error("side must be 'left' or 'right'.");
|
|
34
|
+
if (uplo !== "lower" && uplo !== "upper")
|
|
35
|
+
throw new Error("uplo must be 'lower' or 'upper'.");
|
|
36
|
+
if (layout !== "row-major" && layout !== "column-major")
|
|
37
|
+
throw new Error("layout must be 'row-major' or 'column-major'.");
|
|
38
|
+
if (typeof alpha !== "number")
|
|
39
|
+
throw new Error("alpha must be a number.");
|
|
40
|
+
if (Number.isNaN(alpha)) throw new Error("alpha must not be NaN.");
|
|
41
|
+
if (!Number.isFinite(alpha)) throw new Error("alpha must be finite.");
|
|
42
|
+
if (typeof beta !== "number")
|
|
43
|
+
throw new Error("beta must be a number.");
|
|
44
|
+
if (Number.isNaN(beta)) throw new Error("beta must not be NaN.");
|
|
45
|
+
if (!Number.isFinite(beta)) throw new Error("beta must be finite.");
|
|
46
|
+
if (
|
|
47
|
+
!Number.isInteger(m) || !Number.isInteger(n) ||
|
|
48
|
+
!Number.isInteger(lda) || !Number.isInteger(ldb) || !Number.isInteger(ldc)
|
|
49
|
+
)
|
|
50
|
+
throw new Error("m, n, lda, ldb, and ldc must be integers.");
|
|
51
|
+
if (!AIsGpu && !(A instanceof Float32Array))
|
|
52
|
+
throw new Error("A must be a Float32Array or GpuMatrix.");
|
|
53
|
+
if (!BIsGpu && !(B instanceof Float32Array))
|
|
54
|
+
throw new Error("B must be a Float32Array or GpuMatrix.");
|
|
55
|
+
if (!CIsGpu && !(C instanceof Float32Array))
|
|
56
|
+
throw new Error("C must be a Float32Array or GpuMatrix.");
|
|
57
|
+
if ((AIsGpu || BIsGpu) && !CIsGpu)
|
|
58
|
+
throw new Error("C must be a GpuMatrix when A or B is a GpuMatrix.");
|
|
59
|
+
if (CIsGpu && (!AIsGpu || !BIsGpu))
|
|
60
|
+
throw new Error("A and B must be GpuMatrix when C is a GpuMatrix.");
|
|
61
|
+
if (m < 0 || n < 0) throw new Error("m and n must be non-negative.");
|
|
62
|
+
if (m === 0 || n === 0) return CIsGpu ? {} : { C };
|
|
63
|
+
|
|
64
|
+
const effLayoutA = AIsGpu ? A.layout : layout;
|
|
65
|
+
const effLayoutB = BIsGpu ? B.layout : layout;
|
|
66
|
+
const effLayoutC = CIsGpu ? C.layout : layout;
|
|
67
|
+
|
|
68
|
+
// A: symmetric, order = m (side='left') or n (side='right').
|
|
69
|
+
const aOrder = side === "left" ? m : n;
|
|
70
|
+
if (lda < aOrder) throw new Error("lda must be >= " + (side === "left" ? "m" : "n") + ".");
|
|
71
|
+
if (AIsGpu) {
|
|
72
|
+
if (lda !== A.lda) throw new Error("lda must match A.lda when A is a GpuMatrix.");
|
|
73
|
+
if (A.rows < aOrder || A.cols < aOrder) throw new Error("A is too small for the given m/n and side.");
|
|
74
|
+
} else if (A.length < (aOrder - 1) * lda + aOrder) {
|
|
75
|
+
throw new Error("A does not have enough elements for the given dimensions and lda.");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// B: always m x n, no trans flag — same shape rule as sgemm's C.
|
|
79
|
+
const bOuter = effLayoutB === "column-major" ? n : m;
|
|
80
|
+
const bInner = effLayoutB === "column-major" ? m : n;
|
|
81
|
+
if (ldb < bInner)
|
|
82
|
+
throw new Error(`ldb must be >= ${effLayoutB === "column-major" ? "rows" : "cols"} of B as stored.`);
|
|
83
|
+
if (BIsGpu) {
|
|
84
|
+
if (ldb !== B.lda) throw new Error("ldb must match B.lda when B is a GpuMatrix.");
|
|
85
|
+
if (B.rows < m || B.cols < n) throw new Error("B is too small for the given m and n.");
|
|
86
|
+
} else if (B.length < (bOuter - 1) * ldb + bInner) {
|
|
87
|
+
throw new Error("B does not have enough elements for the given dimensions and ldb.");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// C: always m x n.
|
|
91
|
+
const cOuter = effLayoutC === "column-major" ? n : m;
|
|
92
|
+
const cInner = effLayoutC === "column-major" ? m : n;
|
|
93
|
+
if (ldc < cInner)
|
|
94
|
+
throw new Error(`ldc must be >= ${effLayoutC === "column-major" ? "rows" : "cols"} of C as stored.`);
|
|
95
|
+
if (CIsGpu) {
|
|
96
|
+
if (ldc !== C.lda) throw new Error("ldc must match C.lda when C is a GpuMatrix.");
|
|
97
|
+
if (C.rows < m || C.cols < n) throw new Error("C is too small for the given m and n.");
|
|
98
|
+
} else if (C.length < (cOuter - 1) * ldc + cInner) {
|
|
99
|
+
throw new Error("C does not have enough elements for the given dimensions and ldc.");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// A = A^T, so column-major storage is still A, but the populated
|
|
103
|
+
// triangle swaps — uplo flips (same reasoning ssyr/ssyrk use).
|
|
104
|
+
const uploEffA = effLayoutA === "column-major" ? (uplo === "lower" ? "upper" : "lower") : uplo;
|
|
105
|
+
|
|
106
|
+
const transB = effLayoutB === "column-major" ? "transpose" : "no-transpose";
|
|
107
|
+
const transDense = "no-transpose"; // Adense is always row-major
|
|
108
|
+
|
|
109
|
+
// X*Y (X=Adense,Y=B for side='left', swapped for 'right'). Column-major
|
|
110
|
+
// C: compute C^T instead (swap X/Y, flip trans, swap m_g/n_g) — sgemm's own trick.
|
|
111
|
+
let mg = m, ng = n;
|
|
112
|
+
const kg = aOrder;
|
|
113
|
+
let transX = side === "left" ? transDense : transB;
|
|
114
|
+
let transY = side === "left" ? transB : transDense;
|
|
115
|
+
const flip = (t) => (t === "no-transpose" ? "transpose" : "no-transpose");
|
|
116
|
+
let swapXY = side === "right"; // which JS buffer plays "X" vs "Y" below
|
|
117
|
+
if (effLayoutC === "column-major") {
|
|
118
|
+
[transX, transY] = [flip(transY), flip(transX)];
|
|
119
|
+
swapXY = !swapXY;
|
|
120
|
+
[mg, ng] = [ng, mg];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const ldDense = aOrder; // Adense is tightly packed, row-major
|
|
124
|
+
const largeWgX = Math.ceil(ng / BN_LARGE);
|
|
125
|
+
const largeWgY = Math.ceil(mg / BM_LARGE);
|
|
126
|
+
const useLargeTile = largeWgX * largeWgY >= LARGE_TILE_WORKGROUP_THRESHOLD;
|
|
127
|
+
const gemmPipeline = await getPipeline(device, useLargeTile ? "sgemm_large" : "sgemm_small");
|
|
128
|
+
const symPipeline = await getPipeline(device, "symmetrize");
|
|
129
|
+
const gemmWgCount = useLargeTile
|
|
130
|
+
? {
|
|
131
|
+
x: Math.min(largeWgX, device.limits.maxComputeWorkgroupsPerDimension),
|
|
132
|
+
y: Math.min(largeWgY, device.limits.maxComputeWorkgroupsPerDimension),
|
|
133
|
+
}
|
|
134
|
+
: {
|
|
135
|
+
x: Math.min(Math.ceil(ng / BN_SMALL), device.limits.maxComputeWorkgroupsPerDimension),
|
|
136
|
+
y: Math.min(Math.ceil(mg / BM_SMALL), device.limits.maxComputeWorkgroupsPerDimension),
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const ABuffer = AIsGpu ? A._buf : uploadBuffer(A, "ssymm-A", false);
|
|
140
|
+
const BBuffer = BIsGpu ? B._buf : uploadBuffer(B, "ssymm-B", false);
|
|
141
|
+
const CBuffer = CIsGpu ? C._buf : uploadBuffer(C, "ssymm-C", true);
|
|
142
|
+
const AdenseBuffer = createStorageBuffer(aOrder * ldDense * 4, "ssymm-Adense");
|
|
143
|
+
let symParams = null, gemmParams = null;
|
|
144
|
+
|
|
145
|
+
try {
|
|
146
|
+
symParams = createParamsBuffer(
|
|
147
|
+
[
|
|
148
|
+
{ value: aOrder, type: "u32" },
|
|
149
|
+
{ value: lda, type: "u32" },
|
|
150
|
+
{ value: ldDense, type: "u32" },
|
|
151
|
+
{ value: uploEffA === "upper" ? 1 : 0, type: "u32" },
|
|
152
|
+
],
|
|
153
|
+
"ssymm-sym-params",
|
|
154
|
+
);
|
|
155
|
+
const symBindGroup = createBindGroup(symPipeline.getBindGroupLayout(0), [ABuffer, AdenseBuffer, symParams]);
|
|
156
|
+
|
|
157
|
+
// X/Y buffers and their own ld, matching swapXY above.
|
|
158
|
+
const XBuffer = swapXY ? BBuffer : AdenseBuffer;
|
|
159
|
+
const ldX = swapXY ? ldb : ldDense;
|
|
160
|
+
const YBuffer = swapXY ? AdenseBuffer : BBuffer;
|
|
161
|
+
const ldY = swapXY ? ldDense : ldb;
|
|
162
|
+
|
|
163
|
+
gemmParams = createParamsBuffer(
|
|
164
|
+
[
|
|
165
|
+
{ value: mg, type: "u32" },
|
|
166
|
+
{ value: ng, type: "u32" },
|
|
167
|
+
{ value: kg, type: "u32" },
|
|
168
|
+
{ value: alpha, type: "f32" },
|
|
169
|
+
{ value: beta, type: "f32" },
|
|
170
|
+
{ value: ldX, type: "u32" },
|
|
171
|
+
{ value: ldY, type: "u32" },
|
|
172
|
+
{ value: ldc, type: "u32" },
|
|
173
|
+
{ value: transX === "transpose" ? 1 : 0, type: "u32" },
|
|
174
|
+
{ value: transY === "transpose" ? 1 : 0, type: "u32" },
|
|
175
|
+
],
|
|
176
|
+
"ssymm-gemm-params",
|
|
177
|
+
);
|
|
178
|
+
const gemmBindGroup = createBindGroup(gemmPipeline.getBindGroupLayout(0), [XBuffer, YBuffer, CBuffer, gemmParams]);
|
|
179
|
+
|
|
180
|
+
const { commandEncoder, querySet } = beginTimedEncoder();
|
|
181
|
+
const symDesc = querySet ? { timestampWrites: { querySet, beginningOfPassWriteIndex: 0 } } : undefined;
|
|
182
|
+
const gemmDesc = querySet ? { timestampWrites: { querySet, endOfPassWriteIndex: 1 } } : undefined;
|
|
183
|
+
encodePass(commandEncoder, symPipeline, symBindGroup, { x: Math.ceil(aOrder / SYM_WG), y: Math.ceil(aOrder / SYM_WG) }, symDesc);
|
|
184
|
+
encodePass(commandEncoder, gemmPipeline, gemmBindGroup, gemmWgCount, gemmDesc);
|
|
185
|
+
|
|
186
|
+
const ts = resolveTimestamp(commandEncoder, querySet);
|
|
187
|
+
const readBuffer = CIsGpu ? null : stageReadback(commandEncoder, CBuffer);
|
|
188
|
+
|
|
189
|
+
submit(commandEncoder);
|
|
190
|
+
|
|
191
|
+
const gpuTimeMs = await extractTimestamp(ts);
|
|
192
|
+
|
|
193
|
+
if (CIsGpu) {
|
|
194
|
+
if (gpuTimeMs !== undefined) return { gpuTimeMs };
|
|
195
|
+
return {};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const result = await extractResult(readBuffer, Float32Array);
|
|
199
|
+
if (gpuTimeMs !== undefined) return { C: result, gpuTimeMs };
|
|
200
|
+
return { C: result };
|
|
201
|
+
} finally {
|
|
202
|
+
if (!AIsGpu) destroyBuffers(ABuffer);
|
|
203
|
+
if (!BIsGpu) destroyBuffers(BBuffer);
|
|
204
|
+
if (!CIsGpu) destroyBuffers(CBuffer);
|
|
205
|
+
destroyBuffers(AdenseBuffer);
|
|
206
|
+
if (symParams) destroyBuffers(symParams);
|
|
207
|
+
if (gemmParams) destroyBuffers(gemmParams);
|
|
208
|
+
}
|
|
209
|
+
}
|
package/src/ssymv/ssymv.d.mts
CHANGED
|
@@ -44,41 +44,6 @@ export declare function ssymv(
|
|
|
44
44
|
layout?: 'row-major' | 'column-major',
|
|
45
45
|
): Promise<{ y: Float32Array; gpuTimeMs?: number }>;
|
|
46
46
|
|
|
47
|
-
/**
|
|
48
|
-
* Performs the symmetric matrix-vector operation y = alpha * A * x + beta * y
|
|
49
|
-
*
|
|
50
|
-
* A is kept GPU-resident; x and y are CPU Float32Arrays. `A`'s own `layout`
|
|
51
|
-
* (set at `GpuMatrix.from` time) determines the operation — there is no
|
|
52
|
-
* separate `layout` argument here.
|
|
53
|
-
*
|
|
54
|
-
* @param device - GPUDevice from `init()`
|
|
55
|
-
* @param uplo - `'lower'` to use the lower triangle, `'upper'` to use the upper triangle
|
|
56
|
-
* @param n - order of the matrix A
|
|
57
|
-
* @param alpha - scalar multiplier for A*x
|
|
58
|
-
* @param A - GpuMatrix, GPU-resident
|
|
59
|
-
* @param lda - leading dimension of A (must equal A.lda)
|
|
60
|
-
* @param x - Float32Array input vector
|
|
61
|
-
* @param incx - stride for x (must be a positive integer)
|
|
62
|
-
* @param beta - scalar multiplier for y
|
|
63
|
-
* @param y - Float32Array input/output vector
|
|
64
|
-
* @param incy - stride for y (must be a positive integer)
|
|
65
|
-
* @see <a href="https://github.com/manit2004/wgblas/blob/main/src/ssymv/ssymv.mjs#L15">Source code: ssymv.mjs (L15)</a>
|
|
66
|
-
* @category BLAS Level 2
|
|
67
|
-
*/
|
|
68
|
-
export declare function ssymv(
|
|
69
|
-
device: GPUDevice,
|
|
70
|
-
uplo: 'lower' | 'upper',
|
|
71
|
-
n: number,
|
|
72
|
-
alpha: number,
|
|
73
|
-
A: GpuMatrix,
|
|
74
|
-
lda: number,
|
|
75
|
-
x: Float32Array,
|
|
76
|
-
incx: number,
|
|
77
|
-
beta: number,
|
|
78
|
-
y: Float32Array,
|
|
79
|
-
incy: number,
|
|
80
|
-
): Promise<{ y: Float32Array; gpuTimeMs?: number }>;
|
|
81
|
-
|
|
82
47
|
/**
|
|
83
48
|
* Performs the symmetric matrix-vector operation y = alpha * A * x + beta * y
|
|
84
49
|
*
|
|
@@ -86,7 +51,7 @@ export declare function ssymv(
|
|
|
86
51
|
* `layout` (set at `GpuMatrix.from` time) determines the operation — there is
|
|
87
52
|
* no separate `layout` argument here.
|
|
88
53
|
*
|
|
89
|
-
* {@includeCode ../../examples/ssymv/
|
|
54
|
+
* {@includeCode ../../examples/ssymv/gpu.ssymv.js}
|
|
90
55
|
*
|
|
91
56
|
* @param device - GPUDevice from `init()`
|
|
92
57
|
* @param uplo - `'lower'` to use the lower triangle, `'upper'` to use the upper triangle
|
package/src/ssymv/ssymv.mjs
CHANGED
|
@@ -53,6 +53,8 @@ export async function ssymv(device, uplo, n, alpha, A, lda, x, incx, beta, y, in
|
|
|
53
53
|
);
|
|
54
54
|
if (xIsGpu && !AIsGpu)
|
|
55
55
|
throw new Error("A must be a GpuMatrix when x and y are GpuVectors.");
|
|
56
|
+
if (AIsGpu && !xIsGpu)
|
|
57
|
+
throw new Error("x and y must be GpuVectors when A is a GpuMatrix.");
|
|
56
58
|
if (xIsGpu && x._buf === y._buf)
|
|
57
59
|
throw new Error("x and y must not reference the same GPU buffer when both are GpuVectors.");
|
|
58
60
|
if (AIsGpu && lda !== A.lda)
|
package/src/ssyr/ssyr.d.mts
CHANGED
|
@@ -39,35 +39,6 @@ export declare function ssyr(
|
|
|
39
39
|
layout?: 'row-major' | 'column-major',
|
|
40
40
|
): Promise<{ A: Float32Array; gpuTimeMs?: number }>;
|
|
41
41
|
|
|
42
|
-
/**
|
|
43
|
-
* Performs the symmetric rank-1 update A = alpha * x * x^T + A
|
|
44
|
-
*
|
|
45
|
-
* A is kept GPU-resident; x is a CPU Float32Array. `A`'s own `layout` (set at
|
|
46
|
-
* `GpuMatrix.from` time) determines the operation — there is no separate
|
|
47
|
-
* `layout` argument here.
|
|
48
|
-
*
|
|
49
|
-
* @param device - GPUDevice from `init()`
|
|
50
|
-
* @param uplo - `'lower'` to use the lower triangle, `'upper'` to use the upper triangle
|
|
51
|
-
* @param n - order of the matrix A
|
|
52
|
-
* @param alpha - scalar multiplier for x*x^T
|
|
53
|
-
* @param x - Float32Array input vector
|
|
54
|
-
* @param incx - stride for x (must be a positive integer)
|
|
55
|
-
* @param A - GpuMatrix, GPU-resident
|
|
56
|
-
* @param lda - leading dimension of A (must equal A.lda)
|
|
57
|
-
* @see <a href="https://github.com/manit2004/wgblas/blob/main/src/ssyr/ssyr.mjs#L15">Source code: ssyr.mjs (L15)</a>
|
|
58
|
-
* @category BLAS Level 2
|
|
59
|
-
*/
|
|
60
|
-
export declare function ssyr(
|
|
61
|
-
device: GPUDevice,
|
|
62
|
-
uplo: 'lower' | 'upper',
|
|
63
|
-
n: number,
|
|
64
|
-
alpha: number,
|
|
65
|
-
x: Float32Array,
|
|
66
|
-
incx: number,
|
|
67
|
-
A: GpuMatrix,
|
|
68
|
-
lda: number,
|
|
69
|
-
): Promise<{ gpuTimeMs?: number }>;
|
|
70
|
-
|
|
71
42
|
/**
|
|
72
43
|
* Performs the symmetric rank-1 update A = alpha * x * x^T + A
|
|
73
44
|
*
|
|
@@ -75,7 +46,7 @@ export declare function ssyr(
|
|
|
75
46
|
* `GpuMatrix.from` time) determines the operation — there is no separate
|
|
76
47
|
* `layout` argument here.
|
|
77
48
|
*
|
|
78
|
-
* {@includeCode ../../examples/ssyr/
|
|
49
|
+
* {@includeCode ../../examples/ssyr/gpu.ssyr.js}
|
|
79
50
|
*
|
|
80
51
|
* @param device - GPUDevice from `init()`
|
|
81
52
|
* @param uplo - `'lower'` to use the lower triangle, `'upper'` to use the upper triangle
|
package/src/ssyr/ssyr.mjs
CHANGED
|
@@ -36,6 +36,8 @@ export async function ssyr(device, uplo, n, alpha, x, incx, A, lda, layout = "ro
|
|
|
36
36
|
throw new Error("x must be a Float32Array or GpuVector.");
|
|
37
37
|
if (xIsGpu && !AIsGpu)
|
|
38
38
|
throw new Error("A must be a GpuMatrix when x is a GpuVector.");
|
|
39
|
+
if (AIsGpu && !xIsGpu)
|
|
40
|
+
throw new Error("x must be a GpuVector when A is a GpuMatrix.");
|
|
39
41
|
if (AIsGpu && xIsGpu && A._buf === x._buf)
|
|
40
42
|
throw new Error("A and x must not reference the same GPU buffer.");
|
|
41
43
|
if (AIsGpu && lda !== A.lda)
|
package/src/ssyr2/ssyr2.d.mts
CHANGED
|
@@ -43,39 +43,6 @@ export declare function ssyr2(
|
|
|
43
43
|
layout?: 'row-major' | 'column-major',
|
|
44
44
|
): Promise<{ A: Float32Array; gpuTimeMs?: number }>;
|
|
45
45
|
|
|
46
|
-
/**
|
|
47
|
-
* Performs the symmetric rank-2 update A = alpha * x * y^T + alpha * y * x^T + A
|
|
48
|
-
*
|
|
49
|
-
* A is kept GPU-resident; x and y are CPU Float32Arrays. `A`'s own `layout`
|
|
50
|
-
* (set at `GpuMatrix.from` time) determines the operation — there is no
|
|
51
|
-
* separate `layout` argument here.
|
|
52
|
-
*
|
|
53
|
-
* @param device - GPUDevice from `init()`
|
|
54
|
-
* @param uplo - `'lower'` to use the lower triangle, `'upper'` to use the upper triangle
|
|
55
|
-
* @param n - order of the matrix A
|
|
56
|
-
* @param alpha - scalar multiplier for x*y^T + y*x^T
|
|
57
|
-
* @param x - Float32Array input vector
|
|
58
|
-
* @param incx - stride for x (must be a positive integer)
|
|
59
|
-
* @param y - Float32Array input vector
|
|
60
|
-
* @param incy - stride for y (must be a positive integer)
|
|
61
|
-
* @param A - GpuMatrix, row-major, GPU-resident, Float32-backed
|
|
62
|
-
* @param lda - leading dimension of A (must equal A.lda)
|
|
63
|
-
* @see <a href="https://github.com/manit2004/wgblas/blob/main/src/ssyr2/ssyr2.mjs#L15">Source code: ssyr2.mjs (L15)</a>
|
|
64
|
-
* @category BLAS Level 2
|
|
65
|
-
*/
|
|
66
|
-
export declare function ssyr2(
|
|
67
|
-
device: GPUDevice,
|
|
68
|
-
uplo: 'lower' | 'upper',
|
|
69
|
-
n: number,
|
|
70
|
-
alpha: number,
|
|
71
|
-
x: Float32Array,
|
|
72
|
-
incx: number,
|
|
73
|
-
y: Float32Array,
|
|
74
|
-
incy: number,
|
|
75
|
-
A: GpuMatrix,
|
|
76
|
-
lda: number,
|
|
77
|
-
): Promise<{ gpuTimeMs?: number }>;
|
|
78
|
-
|
|
79
46
|
/**
|
|
80
47
|
* Performs the symmetric rank-2 update A = alpha * x * y^T + alpha * y * x^T + A
|
|
81
48
|
*
|
|
@@ -83,7 +50,7 @@ export declare function ssyr2(
|
|
|
83
50
|
* `GpuMatrix.from` time) determines the operation — there is no separate
|
|
84
51
|
* `layout` argument here.
|
|
85
52
|
*
|
|
86
|
-
* {@includeCode ../../examples/ssyr2/
|
|
53
|
+
* {@includeCode ../../examples/ssyr2/gpu.ssyr2.js}
|
|
87
54
|
*
|
|
88
55
|
* @param device - GPUDevice from `init()`
|
|
89
56
|
* @param uplo - `'lower'` to use the lower triangle, `'upper'` to use the upper triangle
|
package/src/ssyr2/ssyr2.mjs
CHANGED
|
@@ -49,6 +49,8 @@ export async function ssyr2(device, uplo, n, alpha, x, incx, y, incy, A, lda, la
|
|
|
49
49
|
);
|
|
50
50
|
if (xIsGpu && !AIsGpu)
|
|
51
51
|
throw new Error("A must be a GpuMatrix when x and y are GpuVectors.");
|
|
52
|
+
if (AIsGpu && !xIsGpu)
|
|
53
|
+
throw new Error("x and y must be GpuVectors when A is a GpuMatrix.");
|
|
52
54
|
if (AIsGpu && xIsGpu && A._buf === x._buf)
|
|
53
55
|
throw new Error("A and x must not reference the same GPU buffer.");
|
|
54
56
|
if (AIsGpu && yIsGpu && A._buf === y._buf)
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { GpuMatrix } from "../classes/GpuMatrix.mjs";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Performs the symmetric rank-2k update
|
|
5
|
+
* C := uplo(alpha * op(A) * op(B)^T + alpha * op(B) * op(A)^T + beta * C) —
|
|
6
|
+
* only the triangle of C named by `uplo` is read or written (`'lower'`:
|
|
7
|
+
* `col <= row`, `'upper'`: `col >= row`). C is always n×n.
|
|
8
|
+
*
|
|
9
|
+
* - `trans='no-transpose'`: op(A) = A, op(B) = B (both n×k)
|
|
10
|
+
* - `trans='transpose'`: op(A) = A^T, op(B) = B^T (A, B stored k×n)
|
|
11
|
+
*
|
|
12
|
+
* No dedicated kernel — two passes of `sgemmtr`'s kernel
|
|
13
|
+
* (`sgemmtr_small.wgsl`/`sgemmtr_large.wgsl`) on one command encoder, the
|
|
14
|
+
* second accumulating with `beta=1` so C never leaves the GPU between them.
|
|
15
|
+
*
|
|
16
|
+
* {@includeCode ../../examples/ssyr2k/ssyr2k.js}
|
|
17
|
+
*
|
|
18
|
+
* **Browser (standalone HTML):**
|
|
19
|
+
* {@includeCode ../../examples/ssyr2k/web/ssyr2k.html}
|
|
20
|
+
*
|
|
21
|
+
* @param device - GPUDevice from `init()`
|
|
22
|
+
* @param uplo - `'lower'` to update only `col <= row`, `'upper'` for `col >= row`
|
|
23
|
+
* @param trans - `'no-transpose'` for A*B^T + B*A^T, `'transpose'` for A^T*B + B^T*A
|
|
24
|
+
* @param n - order of C (C is n×n); rows of op(A) and op(B)
|
|
25
|
+
* @param k - columns of op(A) and op(B) — the shared/contracted dimension
|
|
26
|
+
* @param alpha - scalar multiplier for both rank-k terms
|
|
27
|
+
* @param A - Float32Array, row-major or column-major (see `layout`)
|
|
28
|
+
* @param lda - leading dimension of A as stored
|
|
29
|
+
* @param B - Float32Array, row-major or column-major (see `layout`)
|
|
30
|
+
* @param ldb - leading dimension of B as stored
|
|
31
|
+
* @param beta - scalar multiplier for C
|
|
32
|
+
* @param C - Float32Array input/output matrix, row-major or column-major
|
|
33
|
+
* @param ldc - leading dimension of C as stored
|
|
34
|
+
* @param layout - storage layout shared by A/B/C when they're Float32Array
|
|
35
|
+
* (default: `'row-major'`) — same handling as `sgemmtr`; column-major C
|
|
36
|
+
* flips `uplo` internally so it still names the triangle you asked for
|
|
37
|
+
* @returns updated C as a Float32Array (only the requested triangle changed)
|
|
38
|
+
* @see <a href="https://github.com/manit2004/wgblas/blob/main/src/ssyr2k/ssyr2k.mjs#L20">Source code: ssyr2k.mjs (L20)</a>
|
|
39
|
+
* @category BLAS Level 3
|
|
40
|
+
*/
|
|
41
|
+
export declare function ssyr2k(
|
|
42
|
+
device: GPUDevice,
|
|
43
|
+
uplo: 'lower' | 'upper',
|
|
44
|
+
trans: 'no-transpose' | 'transpose',
|
|
45
|
+
n: number,
|
|
46
|
+
k: number,
|
|
47
|
+
alpha: number,
|
|
48
|
+
A: Float32Array,
|
|
49
|
+
lda: number,
|
|
50
|
+
B: Float32Array,
|
|
51
|
+
ldb: number,
|
|
52
|
+
beta: number,
|
|
53
|
+
C: Float32Array,
|
|
54
|
+
ldc: number,
|
|
55
|
+
layout?: 'row-major' | 'column-major',
|
|
56
|
+
): Promise<{ C: Float32Array; gpuTimeMs?: number }>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Performs the symmetric rank-2k update
|
|
60
|
+
* C := uplo(alpha * op(A) * op(B)^T + alpha * op(B) * op(A)^T + beta * C)
|
|
61
|
+
*
|
|
62
|
+
* A, B, and C are all kept GPU-resident. Each matrix's own `layout` (set at
|
|
63
|
+
* `GpuMatrix.from` time) determines the operation — there is no separate
|
|
64
|
+
* `layout` argument here. A and B must be GpuMatrix whenever C is, and vice
|
|
65
|
+
* versa — mixing a GpuMatrix with a plain Float32Array is not supported.
|
|
66
|
+
*
|
|
67
|
+
* {@includeCode ../../examples/ssyr2k/gpu.ssyr2k.js}
|
|
68
|
+
*
|
|
69
|
+
* @param device - GPUDevice from `init()`
|
|
70
|
+
* @param uplo - `'lower'` to update only `col <= row`, `'upper'` for `col >= row`
|
|
71
|
+
* @param trans - `'no-transpose'` for A*B^T + B*A^T, `'transpose'` for A^T*B + B^T*A
|
|
72
|
+
* @param n - order of C (C is n×n); rows of op(A) and op(B)
|
|
73
|
+
* @param k - columns of op(A) and op(B) — the shared/contracted dimension
|
|
74
|
+
* @param alpha - scalar multiplier for both rank-k terms
|
|
75
|
+
* @param A - GpuMatrix
|
|
76
|
+
* @param lda - leading dimension of A (must equal A.lda)
|
|
77
|
+
* @param B - GpuMatrix
|
|
78
|
+
* @param ldb - leading dimension of B (must equal B.lda)
|
|
79
|
+
* @param beta - scalar multiplier for C
|
|
80
|
+
* @param C - GpuMatrix (mutated in place; only the requested triangle changes)
|
|
81
|
+
* @param ldc - leading dimension of C (must equal C.lda)
|
|
82
|
+
* @returns no C — it stays GPU-resident; call `C.read()` yourself for a CPU readback (see the example)
|
|
83
|
+
* @see <a href="https://github.com/manit2004/wgblas/blob/main/src/ssyr2k/ssyr2k.mjs#L20">Source code: ssyr2k.mjs (L20)</a>
|
|
84
|
+
* @category BLAS Level 3
|
|
85
|
+
*/
|
|
86
|
+
export declare function ssyr2k(
|
|
87
|
+
device: GPUDevice,
|
|
88
|
+
uplo: 'lower' | 'upper',
|
|
89
|
+
trans: 'no-transpose' | 'transpose',
|
|
90
|
+
n: number,
|
|
91
|
+
k: number,
|
|
92
|
+
alpha: number,
|
|
93
|
+
A: GpuMatrix,
|
|
94
|
+
lda: number,
|
|
95
|
+
B: GpuMatrix,
|
|
96
|
+
ldb: number,
|
|
97
|
+
beta: number,
|
|
98
|
+
C: GpuMatrix,
|
|
99
|
+
ldc: number,
|
|
100
|
+
): Promise<{ gpuTimeMs?: number }>;
|