wgblas 2.2.1 → 2.3.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.
@@ -0,0 +1,213 @@
1
+ import {
2
+ uploadBuffer,
3
+ createParamsBuffer,
4
+ stageReadback,
5
+ destroyBuffers,
6
+ } from "../util/buffer.mjs";
7
+ import { createBindGroup } from "../util/bindgroup.mjs";
8
+ import { runComputePass, submit } from "../util/compute.mjs";
9
+ import { extractResult } from "../util/result.mjs";
10
+ import { extractTimestamp } from "../util/benchmark.mjs";
11
+ import { getPipeline } from "../util/pipeline.mjs";
12
+ import { GpuVector } from "../classes/GpuVector.mjs";
13
+ import { GpuMatrix } from "../classes/GpuMatrix.mjs";
14
+ import { splitDoubleDouble, mergeDoubleDouble } from "../util/f64.mjs";
15
+ import { requireGpuDevice, requireSameDevice } from "../util/device.mjs";
16
+
17
+ // dger: A := alpha * x * y^T + A, double-double (Dekker) f64 emulation of
18
+ // sger — x, y, A, and alpha are each split into an f32 (hi, lo) pair; WGSL
19
+ // has no f64 type.
20
+ export async function dger(
21
+ device,
22
+ m,
23
+ n,
24
+ alpha,
25
+ x,
26
+ incx,
27
+ y,
28
+ incy,
29
+ A,
30
+ lda,
31
+ layout = "row-major",
32
+ ) {
33
+ const AIsGpu = A instanceof GpuMatrix;
34
+
35
+ requireGpuDevice(device);
36
+ requireSameDevice(device, "dger", { A, x, y });
37
+ if (layout !== "row-major" && layout !== "column-major")
38
+ throw new Error("layout must be 'row-major' or 'column-major'.");
39
+ if (typeof alpha !== "number") 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 (
43
+ !Number.isInteger(m) ||
44
+ !Number.isInteger(n) ||
45
+ !Number.isInteger(incx) ||
46
+ !Number.isInteger(incy) ||
47
+ !Number.isInteger(lda)
48
+ )
49
+ throw new Error("m, n, incx, incy, and lda must be integers.");
50
+ if (incx <= 0 || incy <= 0)
51
+ throw new Error("incx and incy must be positive.");
52
+ if (!AIsGpu && !(A instanceof Float64Array))
53
+ throw new Error("A must be a Float64Array or GpuMatrix.");
54
+ if (AIsGpu && A.dtype !== Float64Array)
55
+ throw new Error("A must be a Float64Array-backed GpuMatrix.");
56
+ if (AIsGpu && lda !== A.lda)
57
+ throw new Error("lda must match A.lda when A is a GpuMatrix.");
58
+ // A.rows/A.cols are fixed regardless of layout — check against original m/n before the swap below.
59
+ if (AIsGpu && (A.rows < m || A.cols < n))
60
+ throw new Error("A is too small for the given m and n.");
61
+
62
+ // GpuMatrix's own layout wins over the argument; column-major A reinterpreted row-major is A^T, so swap x/y and m/n to reproduce it (transpose of a rank-1 update swaps its two vectors).
63
+ const effLayout = AIsGpu ? A.layout : layout;
64
+ if (effLayout === "column-major") {
65
+ [m, n] = [n, m];
66
+ [x, y] = [y, x];
67
+ [incx, incy] = [incy, incx];
68
+ }
69
+
70
+ const xIsGpu = x instanceof GpuVector;
71
+ const yIsGpu = y instanceof GpuVector;
72
+
73
+ if (lda < n) throw new Error("lda must be >= n.");
74
+ if (!xIsGpu && !(x instanceof Float64Array))
75
+ throw new Error("x must be a Float64Array or GpuVector.");
76
+ if (!yIsGpu && !(y instanceof Float64Array))
77
+ throw new Error("y must be a Float64Array or GpuVector.");
78
+ if (xIsGpu && x.dtype !== Float64Array)
79
+ throw new Error("x must be a Float64Array-backed GpuVector.");
80
+ if (yIsGpu && y.dtype !== Float64Array)
81
+ throw new Error("y must be a Float64Array-backed GpuVector.");
82
+ if (xIsGpu !== yIsGpu)
83
+ throw new Error(
84
+ "x and y must be the same type (both Float64Array or both GpuVector).",
85
+ );
86
+ if (xIsGpu && !AIsGpu)
87
+ throw new Error("A must be a GpuMatrix when x and y are GpuVectors.");
88
+ if (AIsGpu && !xIsGpu)
89
+ throw new Error("x and y must be GpuVectors when A is a GpuMatrix.");
90
+ if (AIsGpu && xIsGpu && A._buf === x._buf)
91
+ throw new Error("A and x must not reference the same GPU buffer.");
92
+ if (AIsGpu && yIsGpu && A._buf === y._buf)
93
+ throw new Error("A and y must not reference the same GPU buffer.");
94
+ if (m < 0 || n < 0) throw new Error("m and n must be non-negative.");
95
+ if (m === 0 || n === 0) return AIsGpu ? {} : { A };
96
+
97
+ if (!AIsGpu && A.length < (m - 1) * lda + n)
98
+ throw new Error(
99
+ "A does not have enough elements for the given m, n, and lda.",
100
+ );
101
+ if (x.length < (m - 1) * incx + 1)
102
+ throw new Error(
103
+ "x does not have enough elements for the given m and incx.",
104
+ );
105
+ if (y.length < (n - 1) * incy + 1)
106
+ throw new Error(
107
+ "y does not have enough elements for the given n and incy.",
108
+ );
109
+
110
+ const f64Deps = ["f64/dekker", "f64/utils/add", "f64/utils/multiply"];
111
+ const pipeline = await getPipeline(device, [...f64Deps, "dger"], "dger_main");
112
+
113
+ const { hi: alphaHi, lo: alphaLo } = splitDoubleDouble(
114
+ new Float64Array([alpha]),
115
+ );
116
+
117
+ let xHiBuffer = null;
118
+ let xLoBuffer = null;
119
+ let yHiBuffer = null;
120
+ let yLoBuffer = null;
121
+ let AHiBuffer = null;
122
+ let ALoBuffer = null;
123
+ let paramsBuffer = null;
124
+ let readHiBuffer = null;
125
+ let readLoBuffer = null;
126
+
127
+ try {
128
+ if (xIsGpu) {
129
+ xHiBuffer = x._buf;
130
+ xLoBuffer = x._loBuf;
131
+ yHiBuffer = y._buf;
132
+ yLoBuffer = y._loBuf;
133
+ AHiBuffer = A._buf;
134
+ ALoBuffer = A._loBuf;
135
+ } else {
136
+ const xSplit = splitDoubleDouble(x);
137
+ const ySplit = splitDoubleDouble(y);
138
+ const ASplit = splitDoubleDouble(A);
139
+ xHiBuffer = uploadBuffer(device, xSplit.hi, "dger-xHi", false);
140
+ xLoBuffer = uploadBuffer(device, xSplit.lo, "dger-xLo", false);
141
+ yHiBuffer = uploadBuffer(device, ySplit.hi, "dger-yHi", false);
142
+ yLoBuffer = uploadBuffer(device, ySplit.lo, "dger-yLo", false);
143
+ AHiBuffer = uploadBuffer(device, ASplit.hi, "dger-AHi", true);
144
+ ALoBuffer = uploadBuffer(device, ASplit.lo, "dger-ALo", true);
145
+ }
146
+ paramsBuffer = createParamsBuffer(
147
+ device,
148
+ [
149
+ { value: m, type: "u32" },
150
+ { value: n, type: "u32" },
151
+ { value: alphaHi[0], type: "f32" },
152
+ { value: alphaLo[0], type: "f32" },
153
+ { value: incx, type: "u32" },
154
+ { value: incy, type: "u32" },
155
+ { value: lda, type: "u32" },
156
+ ],
157
+ "dger-params",
158
+ );
159
+
160
+ const bindGroup = createBindGroup(device, pipeline.getBindGroupLayout(0), [
161
+ xHiBuffer,
162
+ xLoBuffer,
163
+ yHiBuffer,
164
+ yLoBuffer,
165
+ AHiBuffer,
166
+ ALoBuffer,
167
+ paramsBuffer,
168
+ ]);
169
+
170
+ // One workgroup per row of A; clamped to device limit — the shader's
171
+ // grid-stride loop handles remaining rows when m > dispatch count.
172
+ const wgCount = Math.min(m, device.limits.maxComputeWorkgroupsPerDimension);
173
+ const { commandEncoder, ts } = runComputePass(
174
+ device,
175
+ pipeline,
176
+ bindGroup,
177
+ wgCount,
178
+ );
179
+ readHiBuffer = AIsGpu
180
+ ? null
181
+ : stageReadback(device, commandEncoder, AHiBuffer);
182
+ readLoBuffer = AIsGpu
183
+ ? null
184
+ : stageReadback(device, commandEncoder, ALoBuffer);
185
+
186
+ submit(device, commandEncoder);
187
+
188
+ const gpuTimeMs = await extractTimestamp(ts);
189
+
190
+ if (AIsGpu) {
191
+ if (gpuTimeMs !== undefined) return { gpuTimeMs };
192
+ return {};
193
+ }
194
+
195
+ const hi = await extractResult(readHiBuffer, Float32Array);
196
+ readHiBuffer = null;
197
+ const lo = await extractResult(readLoBuffer, Float32Array);
198
+ readLoBuffer = null;
199
+ const result = mergeDoubleDouble(hi, lo);
200
+ if (gpuTimeMs !== undefined) return { A: result, gpuTimeMs };
201
+ return { A: result };
202
+ } finally {
203
+ if (!xIsGpu && xHiBuffer) destroyBuffers(xHiBuffer);
204
+ if (!xIsGpu && xLoBuffer) destroyBuffers(xLoBuffer);
205
+ if (!yIsGpu && yHiBuffer) destroyBuffers(yHiBuffer);
206
+ if (!yIsGpu && yLoBuffer) destroyBuffers(yLoBuffer);
207
+ if (!AIsGpu && AHiBuffer) destroyBuffers(AHiBuffer);
208
+ if (!AIsGpu && ALoBuffer) destroyBuffers(ALoBuffer);
209
+ if (paramsBuffer) destroyBuffers(paramsBuffer);
210
+ if (readHiBuffer) destroyBuffers(readHiBuffer);
211
+ if (readLoBuffer) destroyBuffers(readLoBuffer);
212
+ }
213
+ }
@@ -0,0 +1,84 @@
1
+ import { GpuVector } from "../classes/GpuVector.mjs";
2
+ import { GpuMatrix } from "../classes/GpuMatrix.mjs";
3
+
4
+ /**
5
+ * Performs the symmetric matrix-vector operation $$y \leftarrow \alpha A x + \beta y$$
6
+ * in double precision (double-double emulation — WGSL has no native f64 type).
7
+ *
8
+ * A is an n×n symmetric matrix stored in row-major order. Only the triangle
9
+ * specified by `uplo` is referenced; the other triangle is inferred by symmetry.
10
+ *
11
+ * {@includeCode ../../examples/dsymv/dsymv.js}
12
+ *
13
+ * **Browser (standalone HTML):**
14
+ * {@includeCode ../../examples/dsymv/web/dsymv.html}
15
+ *
16
+ * @param device - GPUDevice from `init()`
17
+ * @param uplo - `'lower'` to use the lower triangle, `'upper'` to use the upper triangle
18
+ * @param n - order of the matrix A (number of rows and columns)
19
+ * @param alpha - scalar multiplier for A*x
20
+ * @param A - Float64Array, row-major or column-major (see `layout`), at least (n-1)*lda+n elements
21
+ * @param lda - leading dimension of A (>= n either way — A is square)
22
+ * @param x - Float64Array input vector, length at least (n-1)*incx+1
23
+ * @param incx - stride for x (must be a positive integer)
24
+ * @param beta - scalar multiplier for y
25
+ * @param y - Float64Array input/output vector, length at least (n-1)*incy+1
26
+ * @param incy - stride for y (must be a positive integer)
27
+ * @param layout - storage layout of `A` (default: `'row-major'`); for a symmetric
28
+ * matrix, column-major storage just means the *other* triangle is the one
29
+ * physically referenced for a given `uplo`
30
+ * @see <a href="https://github.com/manit2004/wgblas/blob/main/src/dsymv/dsymv.mjs#L19">Source code: dsymv.mjs (L19)</a>
31
+ * @category BLAS Level 2
32
+ */
33
+ export declare function dsymv(
34
+ device: GPUDevice,
35
+ uplo: 'lower' | 'upper',
36
+ n: number,
37
+ alpha: number,
38
+ A: Float64Array,
39
+ lda: number,
40
+ x: Float64Array,
41
+ incx: number,
42
+ beta: number,
43
+ y: Float64Array,
44
+ incy: number,
45
+ layout?: 'row-major' | 'column-major',
46
+ ): Promise<{ y: Float64Array; gpuTimeMs?: number }>;
47
+
48
+ /**
49
+ * Performs the symmetric matrix-vector operation $$y \leftarrow \alpha A x + \beta y$$
50
+ * in double precision (double-double emulation).
51
+ *
52
+ * x and y are kept resident on the GPU. A must be a GpuMatrix (Float64Array-
53
+ * backed); its own `layout` (set at `GpuMatrix.from` time) determines the
54
+ * operation — there is no separate `layout` argument here.
55
+ *
56
+ * {@includeCode ../../examples/dsymv/gpu.dsymv.js}
57
+ *
58
+ * @param device - GPUDevice from `init()`
59
+ * @param uplo - `'lower'` to use the lower triangle, `'upper'` to use the upper triangle
60
+ * @param n - order of the matrix A
61
+ * @param alpha - scalar multiplier for A*x
62
+ * @param A - GpuMatrix (Float64Array-backed), GPU-resident
63
+ * @param lda - leading dimension of A (must equal A.lda)
64
+ * @param x - GpuVector input vector (Float64Array-backed, not mutated)
65
+ * @param incx - stride for x (must be a positive integer)
66
+ * @param beta - scalar multiplier for y
67
+ * @param y - GpuVector input/output vector (Float64Array-backed, mutated in place)
68
+ * @param incy - stride for y (must be a positive integer)
69
+ * @see <a href="https://github.com/manit2004/wgblas/blob/main/src/dsymv/dsymv.mjs#L19">Source code: dsymv.mjs (L19)</a>
70
+ * @category BLAS Level 2
71
+ */
72
+ export declare function dsymv(
73
+ device: GPUDevice,
74
+ uplo: 'lower' | 'upper',
75
+ n: number,
76
+ alpha: number,
77
+ A: GpuMatrix,
78
+ lda: number,
79
+ x: GpuVector,
80
+ incx: number,
81
+ beta: number,
82
+ y: GpuVector,
83
+ incy: number,
84
+ ): Promise<{ gpuTimeMs?: number }>;
@@ -0,0 +1,227 @@
1
+ import {
2
+ uploadBuffer,
3
+ createParamsBuffer,
4
+ stageReadback,
5
+ destroyBuffers,
6
+ } from "../util/buffer.mjs";
7
+ import { createBindGroup } from "../util/bindgroup.mjs";
8
+ import { runComputePass, submit } from "../util/compute.mjs";
9
+ import { extractResult } from "../util/result.mjs";
10
+ import { extractTimestamp } from "../util/benchmark.mjs";
11
+ import { getPipeline } from "../util/pipeline.mjs";
12
+ import { GpuVector } from "../classes/GpuVector.mjs";
13
+ import { GpuMatrix } from "../classes/GpuMatrix.mjs";
14
+ import { splitDoubleDouble, mergeDoubleDouble } from "../util/f64.mjs";
15
+ import { requireGpuDevice, requireSameDevice } from "../util/device.mjs";
16
+
17
+ // dsymv: y := alpha * A * x + beta * y, double-double (Dekker) f64 emulation
18
+ // of ssymv — A, x, y, alpha, and beta are each split into an f32 (hi, lo)
19
+ // pair; WGSL has no f64 type.
20
+ export async function dsymv(
21
+ device,
22
+ uplo,
23
+ n,
24
+ alpha,
25
+ A,
26
+ lda,
27
+ x,
28
+ incx,
29
+ beta,
30
+ y,
31
+ incy,
32
+ layout = "row-major",
33
+ ) {
34
+ const xIsGpu = x instanceof GpuVector;
35
+ const yIsGpu = y instanceof GpuVector;
36
+ const AIsGpu = A instanceof GpuMatrix;
37
+
38
+ requireGpuDevice(device);
39
+ requireSameDevice(device, "dsymv", { A, x, y });
40
+ if (uplo !== "lower" && uplo !== "upper")
41
+ throw new Error("uplo must be 'lower' or 'upper'.");
42
+ if (layout !== "row-major" && layout !== "column-major")
43
+ throw new Error("layout must be 'row-major' or 'column-major'.");
44
+ if (
45
+ !Number.isInteger(n) ||
46
+ !Number.isInteger(incx) ||
47
+ !Number.isInteger(incy) ||
48
+ !Number.isInteger(lda)
49
+ )
50
+ throw new Error("n, incx, incy, and lda must be integers.");
51
+ if (typeof alpha !== "number") throw new Error("alpha must be a number.");
52
+ if (Number.isNaN(alpha)) throw new Error("alpha must not be NaN.");
53
+ if (!Number.isFinite(alpha)) throw new Error("alpha must be finite.");
54
+ if (typeof beta !== "number") throw new Error("beta must be a number.");
55
+ if (Number.isNaN(beta)) throw new Error("beta must not be NaN.");
56
+ if (!Number.isFinite(beta)) throw new Error("beta must be finite.");
57
+ if (incx <= 0 || incy <= 0)
58
+ throw new Error("incx and incy must be positive.");
59
+ if (lda < n) throw new Error("lda must be >= n.");
60
+ if (!AIsGpu && !(A instanceof Float64Array))
61
+ throw new Error("A must be a Float64Array or GpuMatrix.");
62
+ if (AIsGpu && A.dtype !== Float64Array)
63
+ throw new Error("A must be a Float64Array-backed GpuMatrix.");
64
+ if (!xIsGpu && !(x instanceof Float64Array))
65
+ throw new Error("x must be a Float64Array or GpuVector.");
66
+ if (!yIsGpu && !(y instanceof Float64Array))
67
+ throw new Error("y must be a Float64Array or GpuVector.");
68
+ if (xIsGpu && x.dtype !== Float64Array)
69
+ throw new Error("x must be a Float64Array-backed GpuVector.");
70
+ if (yIsGpu && y.dtype !== Float64Array)
71
+ throw new Error("y must be a Float64Array-backed GpuVector.");
72
+ if (xIsGpu !== yIsGpu)
73
+ throw new Error(
74
+ "x and y must be the same type (both Float64Array or both GpuVector).",
75
+ );
76
+ if (xIsGpu && !AIsGpu)
77
+ throw new Error("A must be a GpuMatrix when x and y are GpuVectors.");
78
+ if (AIsGpu && !xIsGpu)
79
+ throw new Error("x and y must be GpuVectors when A is a GpuMatrix.");
80
+ if (xIsGpu && x._buf === y._buf)
81
+ throw new Error(
82
+ "x and y must not reference the same GPU buffer when both are GpuVectors.",
83
+ );
84
+ if (AIsGpu && yIsGpu && A._buf === y._buf)
85
+ throw new Error("A and y must not reference the same GPU buffer.");
86
+ if (AIsGpu && lda !== A.lda)
87
+ throw new Error("lda must match A.lda when A is a GpuMatrix.");
88
+ if (AIsGpu && (A.rows < n || A.cols < n))
89
+ throw new Error("A is too small for the given n.");
90
+ if (n < 0) throw new Error("n must be non-negative.");
91
+ if (n === 0) return yIsGpu ? {} : { y };
92
+
93
+ if (!AIsGpu && A.length < (n - 1) * lda + n)
94
+ throw new Error("A does not have enough elements for the given n and lda.");
95
+ if (x.length < (n - 1) * incx + 1)
96
+ throw new Error(
97
+ "x does not have enough elements for the given n and incx.",
98
+ );
99
+ if (y.length < (n - 1) * incy + 1)
100
+ throw new Error(
101
+ "y does not have enough elements for the given n and incy.",
102
+ );
103
+
104
+ // GpuMatrix's own layout wins over the argument; A is symmetric, so column-major A reinterpreted row-major just flips which triangle is stored — flip uplo to match.
105
+ const effLayout = AIsGpu ? A.layout : layout;
106
+ const isLower =
107
+ effLayout === "column-major" ? uplo === "upper" : uplo === "lower";
108
+
109
+ const f64Deps = ["f64/dekker", "f64/utils/add", "f64/utils/multiply"];
110
+ const pipeline = await getPipeline(
111
+ device,
112
+ [...f64Deps, "dsymv"],
113
+ "dsymv_main",
114
+ );
115
+
116
+ const { hi: alphaHi, lo: alphaLo } = splitDoubleDouble(
117
+ new Float64Array([alpha]),
118
+ );
119
+ const { hi: betaHi, lo: betaLo } = splitDoubleDouble(
120
+ new Float64Array([beta]),
121
+ );
122
+
123
+ let AHiBuffer = null;
124
+ let ALoBuffer = null;
125
+ let xHiBuffer = null;
126
+ let xLoBuffer = null;
127
+ let yHiBuffer = null;
128
+ let yLoBuffer = null;
129
+ let paramsBuffer = null;
130
+ let readHiBuffer = null;
131
+ let readLoBuffer = null;
132
+
133
+ try {
134
+ if (AIsGpu) {
135
+ AHiBuffer = A._buf;
136
+ ALoBuffer = A._loBuf;
137
+ } else {
138
+ const ASplit = splitDoubleDouble(A);
139
+ AHiBuffer = uploadBuffer(device, ASplit.hi, "dsymv-AHi", false);
140
+ ALoBuffer = uploadBuffer(device, ASplit.lo, "dsymv-ALo", false);
141
+ }
142
+ if (xIsGpu) {
143
+ xHiBuffer = x._buf;
144
+ xLoBuffer = x._loBuf;
145
+ } else {
146
+ const xSplit = splitDoubleDouble(x);
147
+ xHiBuffer = uploadBuffer(device, xSplit.hi, "dsymv-xHi", false);
148
+ xLoBuffer = uploadBuffer(device, xSplit.lo, "dsymv-xLo", false);
149
+ }
150
+ if (yIsGpu) {
151
+ yHiBuffer = y._buf;
152
+ yLoBuffer = y._loBuf;
153
+ } else {
154
+ const ySplit = splitDoubleDouble(y);
155
+ yHiBuffer = uploadBuffer(device, ySplit.hi, "dsymv-yHi", true);
156
+ yLoBuffer = uploadBuffer(device, ySplit.lo, "dsymv-yLo", true);
157
+ }
158
+ paramsBuffer = createParamsBuffer(
159
+ device,
160
+ [
161
+ { value: n, type: "u32" },
162
+ { value: alphaHi[0], type: "f32" },
163
+ { value: alphaLo[0], type: "f32" },
164
+ { value: betaHi[0], type: "f32" },
165
+ { value: betaLo[0], type: "f32" },
166
+ { value: incx, type: "u32" },
167
+ { value: incy, type: "u32" },
168
+ { value: lda, type: "u32" },
169
+ { value: isLower ? 0 : 1, type: "u32" },
170
+ ],
171
+ "dsymv-params",
172
+ );
173
+
174
+ const bindGroup = createBindGroup(device, pipeline.getBindGroupLayout(0), [
175
+ AHiBuffer,
176
+ ALoBuffer,
177
+ xHiBuffer,
178
+ xLoBuffer,
179
+ yHiBuffer,
180
+ yLoBuffer,
181
+ paramsBuffer,
182
+ ]);
183
+
184
+ // One workgroup per row of A; clamped to device limit — the shader's
185
+ // grid-stride loop handles remaining rows when n > dispatch count.
186
+ const wgCount = Math.min(n, device.limits.maxComputeWorkgroupsPerDimension);
187
+ const { commandEncoder, ts } = runComputePass(
188
+ device,
189
+ pipeline,
190
+ bindGroup,
191
+ wgCount,
192
+ );
193
+ readHiBuffer = yIsGpu
194
+ ? null
195
+ : stageReadback(device, commandEncoder, yHiBuffer);
196
+ readLoBuffer = yIsGpu
197
+ ? null
198
+ : stageReadback(device, commandEncoder, yLoBuffer);
199
+
200
+ submit(device, commandEncoder);
201
+
202
+ const gpuTimeMs = await extractTimestamp(ts);
203
+
204
+ if (yIsGpu) {
205
+ if (gpuTimeMs !== undefined) return { gpuTimeMs };
206
+ return {};
207
+ }
208
+
209
+ const hi = await extractResult(readHiBuffer, Float32Array);
210
+ readHiBuffer = null;
211
+ const lo = await extractResult(readLoBuffer, Float32Array);
212
+ readLoBuffer = null;
213
+ const result = mergeDoubleDouble(hi, lo);
214
+ if (gpuTimeMs !== undefined) return { y: result, gpuTimeMs };
215
+ return { y: result };
216
+ } finally {
217
+ if (!AIsGpu && AHiBuffer) destroyBuffers(AHiBuffer);
218
+ if (!AIsGpu && ALoBuffer) destroyBuffers(ALoBuffer);
219
+ if (!xIsGpu && xHiBuffer) destroyBuffers(xHiBuffer);
220
+ if (!xIsGpu && xLoBuffer) destroyBuffers(xLoBuffer);
221
+ if (!yIsGpu && yHiBuffer) destroyBuffers(yHiBuffer);
222
+ if (!yIsGpu && yLoBuffer) destroyBuffers(yLoBuffer);
223
+ if (paramsBuffer) destroyBuffers(paramsBuffer);
224
+ if (readHiBuffer) destroyBuffers(readHiBuffer);
225
+ if (readLoBuffer) destroyBuffers(readLoBuffer);
226
+ }
227
+ }
@@ -0,0 +1,73 @@
1
+ import { GpuVector } from "../classes/GpuVector.mjs";
2
+ import { GpuMatrix } from "../classes/GpuMatrix.mjs";
3
+
4
+ /**
5
+ * Performs the symmetric rank-1 update $$A \leftarrow \alpha x x^{T} + A$$ in
6
+ * double precision (double-double emulation — WGSL has no native f64 type).
7
+ *
8
+ * A is an n×n symmetric matrix stored in row-major order, updated in place.
9
+ * Only the triangle specified by `uplo` is referenced and updated; the other
10
+ * triangle is left untouched (implied by symmetry).
11
+ *
12
+ * {@includeCode ../../examples/dsyr/dsyr.js}
13
+ *
14
+ * **Browser (standalone HTML):**
15
+ * {@includeCode ../../examples/dsyr/web/dsyr.html}
16
+ *
17
+ * @param device - GPUDevice from `init()`
18
+ * @param uplo - `'lower'` to use the lower triangle, `'upper'` to use the upper triangle
19
+ * @param n - order of the matrix A (number of rows and columns)
20
+ * @param alpha - scalar multiplier for x*x^T
21
+ * @param x - Float64Array input vector, length at least (n-1)*incx+1
22
+ * @param incx - stride for x (must be a positive integer)
23
+ * @param A - Float64Array, row-major or column-major (see `layout`), at least (n-1)*lda+n elements
24
+ * @param lda - leading dimension of A (>= n either way — A is square)
25
+ * @param layout - storage layout of `A` (default: `'row-major'`); for a symmetric
26
+ * matrix, column-major storage just means the *other* triangle is the one
27
+ * physically referenced for a given `uplo`
28
+ * @see <a href="https://github.com/manit2004/wgblas/blob/main/src/dsyr/dsyr.mjs#L18">Source code: dsyr.mjs (L18)</a>
29
+ * @category BLAS Level 2
30
+ */
31
+ export declare function dsyr(
32
+ device: GPUDevice,
33
+ uplo: 'lower' | 'upper',
34
+ n: number,
35
+ alpha: number,
36
+ x: Float64Array,
37
+ incx: number,
38
+ A: Float64Array,
39
+ lda: number,
40
+ layout?: 'row-major' | 'column-major',
41
+ ): Promise<{ A: Float64Array; gpuTimeMs?: number }>;
42
+
43
+ /**
44
+ * Performs the symmetric rank-1 update $$A \leftarrow \alpha x x^{T} + A$$ in
45
+ * double precision (double-double emulation).
46
+ *
47
+ * x and A are both kept resident on the GPU. `A`'s own `layout` (set at
48
+ * `GpuMatrix.from` time) determines the operation — there is no separate
49
+ * `layout` argument here.
50
+ *
51
+ * {@includeCode ../../examples/dsyr/gpu.dsyr.js}
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*x^T
57
+ * @param x - GpuVector input vector (Float64Array-backed, not mutated)
58
+ * @param incx - stride for x (must be a positive integer)
59
+ * @param A - GpuMatrix (Float64Array-backed), mutated in place
60
+ * @param lda - leading dimension of A (must equal A.lda)
61
+ * @see <a href="https://github.com/manit2004/wgblas/blob/main/src/dsyr/dsyr.mjs#L18">Source code: dsyr.mjs (L18)</a>
62
+ * @category BLAS Level 2
63
+ */
64
+ export declare function dsyr(
65
+ device: GPUDevice,
66
+ uplo: 'lower' | 'upper',
67
+ n: number,
68
+ alpha: number,
69
+ x: GpuVector,
70
+ incx: number,
71
+ A: GpuMatrix,
72
+ lda: number,
73
+ ): Promise<{ gpuTimeMs?: number }>;