wgblas 2.0.0 → 2.2.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/README.md +20 -18
- package/dist/wgblas.browser.js +2172 -1174
- package/index.d.mts +49 -44
- package/index.mjs +11 -0
- package/package.json +133 -63
- package/src/classes/Complex32.d.mts +43 -0
- package/src/classes/Complex32.mjs +82 -0
- package/src/classes/Complex64.d.mts +44 -0
- package/src/classes/Complex64.mjs +76 -0
- package/src/classes/GpuMatrix.d.mts +41 -41
- package/src/classes/GpuMatrix.mjs +126 -17
- package/src/classes/GpuVector.d.mts +36 -40
- package/src/classes/GpuVector.mjs +66 -11
- package/src/cscal/cscal.d.mts +47 -0
- package/src/cscal/cscal.mjs +98 -0
- package/src/dasum/dasum.d.mts +4 -4
- package/src/dasum/dasum.mjs +38 -20
- package/src/daxpy/daxpy.d.mts +56 -0
- package/src/daxpy/daxpy.mjs +150 -0
- package/src/dcopy/dcopy.d.mts +52 -0
- package/src/dcopy/dcopy.mjs +140 -0
- package/src/ddot/ddot.d.mts +62 -0
- package/src/ddot/ddot.mjs +184 -0
- package/src/devdocs.mjs +13 -0
- package/src/dnrm2/dnrm2.d.mts +50 -0
- package/src/dnrm2/dnrm2.mjs +189 -0
- package/src/drot/drot.d.mts +67 -0
- package/src/drot/drot.mjs +170 -0
- package/src/drotm/drotm.d.mts +67 -0
- package/src/drotm/drotm.mjs +171 -0
- package/src/dscal/dscal.d.mts +52 -0
- package/src/dscal/dscal.mjs +119 -0
- package/src/dswap/dswap.d.mts +57 -0
- package/src/dswap/dswap.mjs +155 -0
- package/src/idamax/idamax.d.mts +20 -2
- package/src/idamax/idamax.mjs +56 -24
- package/src/init.mjs +117 -56
- package/src/isamax/isamax.d.mts +20 -2
- package/src/isamax/isamax.mjs +21 -16
- package/src/random/random.d.mts +37 -39
- package/src/random/random.mjs +39 -7
- package/src/sasum/sasum.d.mts +2 -2
- package/src/sasum/sasum.mjs +20 -16
- package/src/saxpy/saxpy.d.mts +2 -2
- package/src/saxpy/saxpy.mjs +14 -11
- package/src/scopy/scopy.d.mts +2 -2
- package/src/scopy/scopy.mjs +13 -9
- package/src/sdot/sdot.d.mts +2 -2
- package/src/sdot/sdot.mjs +21 -17
- package/src/sgemm/sgemm.d.mts +2 -2
- package/src/sgemm/sgemm.mjs +109 -40
- package/src/sgemmtr/sgemmtr.d.mts +3 -2
- package/src/sgemmtr/sgemmtr.mjs +98 -40
- package/src/sgemv/sgemv.d.mts +2 -2
- package/src/sgemv/sgemv.mjs +69 -41
- package/src/sger/sger.d.mts +2 -2
- package/src/sger/sger.mjs +43 -19
- package/src/shaders/__test_pipeline_a.wgsl +3 -0
- package/src/shaders/__test_pipeline_b.wgsl +2 -0
- package/src/shaders/cscal.wgsl +33 -0
- package/src/shaders/daxpy.wgsl +66 -0
- package/src/shaders/dcopy.wgsl +34 -0
- package/src/shaders/ddot.wgsl +106 -0
- package/src/shaders/dnrm2.wgsl +167 -0
- package/src/shaders/drot.wgsl +81 -0
- package/src/shaders/drotm.wgsl +99 -0
- package/src/shaders/dscal.wgsl +60 -0
- package/src/shaders/dswap.wgsl +38 -0
- package/src/shaders/f64/utils/add.wgsl +6 -0
- package/src/shaders/f64/utils/divide.wgsl +45 -0
- package/src/shaders/f64/utils/multiply.wgsl +19 -10
- package/src/shaders/f64/utils/sqrt.wgsl +45 -0
- package/src/shaders/index.mjs +233 -14
- package/src/shaders/reduction/scaledSum.wgsl +65 -0
- package/src/shaders/reduction/scaledSumF64.wgsl +93 -0
- package/src/shaders/sgemm_large.wgsl +107 -18
- package/src/shaders/sgemm_small.wgsl +115 -15
- package/src/shaders/sgemmtr_large.wgsl +4 -1
- package/src/shaders/sgemmtr_small.wgsl +4 -1
- package/src/shaders/sgemv_n.wgsl +3 -1
- package/src/shaders/sgemv_t.wgsl +3 -1
- package/src/shaders/snrm2.wgsl +72 -23
- package/src/shaders/ssymv.wgsl +3 -1
- package/src/snrm2/snrm2.d.mts +2 -2
- package/src/snrm2/snrm2.mjs +41 -23
- package/src/srot/srot.d.mts +2 -4
- package/src/srot/srot.mjs +16 -11
- package/src/srotm/srotm.d.mts +2 -4
- package/src/srotm/srotm.mjs +17 -11
- package/src/sscal/sscal.d.mts +3 -3
- package/src/sscal/sscal.mjs +14 -12
- package/src/sswap/sswap.d.mts +2 -2
- package/src/sswap/sswap.mjs +18 -10
- package/src/ssymm/ssymm.d.mts +5 -4
- package/src/ssymm/ssymm.mjs +150 -54
- package/src/ssymv/ssymv.d.mts +2 -2
- package/src/ssymv/ssymv.mjs +47 -26
- package/src/ssyr/ssyr.d.mts +2 -2
- package/src/ssyr/ssyr.mjs +38 -17
- package/src/ssyr2/ssyr2.d.mts +2 -2
- package/src/ssyr2/ssyr2.mjs +48 -21
- package/src/ssyr2k/ssyr2k.d.mts +3 -2
- package/src/ssyr2k/ssyr2k.mjs +140 -62
- package/src/ssyrk/ssyrk.d.mts +3 -2
- package/src/ssyrk/ssyrk.mjs +91 -39
- package/src/strmm/strmm.d.mts +5 -4
- package/src/strmm/strmm.mjs +174 -60
- package/src/strmv/strmv.d.mts +2 -2
- package/src/strmv/strmv.mjs +42 -20
- package/src/strsm/strsm.d.mts +6 -4
- package/src/strsm/strsm.mjs +438 -174
- package/src/strsv/strsv.d.mts +5 -3
- package/src/strsv/strsv.mjs +89 -34
- package/src/util/benchmark.mjs +9 -9
- package/src/util/bindgroup.mjs +1 -3
- package/src/util/buffer.mjs +139 -24
- package/src/util/complex.mjs +87 -0
- package/src/util/compute.mjs +19 -16
- package/src/util/constants.mjs +57 -0
- package/src/util/device.mjs +49 -0
- package/src/util/pipeline.mjs +44 -10
- package/src/util/workgroup.mjs +72 -7
- package/src/shaders/browser-shaders.mjs +0 -81
- package/src/shaders/f64add.wgsl +0 -281
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# wgblas
|
|
2
2
|
|
|
3
3
|
[](https://github.com/manit2004/wgblas/actions/workflows/test-gpu.yml)
|
|
4
|
+
[](https://www.npmjs.org/package/wgblas)
|
|
5
|
+
[](https://www.npmjs.org/package/wgblas)
|
|
4
6
|
|
|
5
7
|
`wgblas` implements all the standard single-precision level 1, 2, and 3 BLAS routines on top of WebGPU. Next up: double-precision routines, and single- and double-precision complex routines.
|
|
6
8
|
|
|
@@ -19,18 +21,18 @@ npm install wgblas
|
|
|
19
21
|
### Example Code Snippet
|
|
20
22
|
|
|
21
23
|
```js
|
|
22
|
-
import { init, cleanup
|
|
24
|
+
import { init, cleanup } from "wgblas";
|
|
23
25
|
import { sscal } from "wgblas/sscal";
|
|
24
26
|
|
|
25
27
|
const device = await init();
|
|
26
28
|
|
|
27
|
-
const n =
|
|
28
|
-
const alpha =
|
|
29
|
-
const x =
|
|
29
|
+
const n = 5;
|
|
30
|
+
const alpha = 3;
|
|
31
|
+
const x = new Float32Array([1, 2, 3, 4, 5]);
|
|
30
32
|
|
|
31
33
|
console.log("before:", x);
|
|
32
|
-
const result = await sscal(device, n, alpha, x, 1);
|
|
33
|
-
console.log("after: ", result);
|
|
34
|
+
const { x: result } = await sscal(device, n, alpha, x, 1);
|
|
35
|
+
console.log("after: ", result); // [3, 6, 9, 12, 15]
|
|
34
36
|
cleanup();
|
|
35
37
|
```
|
|
36
38
|
|
|
@@ -49,18 +51,18 @@ No bundler needed. Load the pre-built browser bundle from the CDN and use `windo
|
|
|
49
51
|
<body>
|
|
50
52
|
<pre id="out">Running…</pre>
|
|
51
53
|
<script>
|
|
52
|
-
const { init, sscal,
|
|
54
|
+
const { init, sscal, cleanup } = window.wgblas;
|
|
53
55
|
|
|
54
56
|
(async () => {
|
|
55
57
|
const device = await init();
|
|
56
58
|
|
|
57
|
-
const n =
|
|
58
|
-
const alpha =
|
|
59
|
-
const x =
|
|
59
|
+
const n = 5;
|
|
60
|
+
const alpha = 3;
|
|
61
|
+
const x = new Float32Array([1, 2, 3, 4, 5]);
|
|
60
62
|
|
|
61
63
|
const xBefore = Array.from(x).map(v => v.toFixed(4)).join(", ");
|
|
62
64
|
|
|
63
|
-
const result = await sscal(device, n, alpha, x, 1);
|
|
65
|
+
const { x: result } = await sscal(device, n, alpha, x, 1);
|
|
64
66
|
|
|
65
67
|
document.getElementById("out").textContent =
|
|
66
68
|
"before: " + xBefore +
|
|
@@ -78,18 +80,18 @@ No bundler needed. Load the pre-built browser bundle from the CDN and use `windo
|
|
|
78
80
|
`GpuVector` keeps data resident on the GPU between operations — upload once, chain any number of operations, read back once. This eliminates the redundant uploads and readbacks between steps, which are often more expensive than the compute itself.
|
|
79
81
|
|
|
80
82
|
```js
|
|
81
|
-
import { init, cleanup
|
|
83
|
+
import { init, cleanup } from "wgblas";
|
|
82
84
|
import { saxpy } from "wgblas/saxpy";
|
|
83
85
|
import { sscal } from "wgblas/sscal";
|
|
84
86
|
import { GpuVector } from "wgblas/classes/GpuVector";
|
|
85
87
|
|
|
86
88
|
const device = await init();
|
|
87
89
|
|
|
88
|
-
const n =
|
|
90
|
+
const n = 5;
|
|
89
91
|
const alpha = 2;
|
|
90
92
|
const scale = 0.5;
|
|
91
|
-
const x =
|
|
92
|
-
const y =
|
|
93
|
+
const x = new Float32Array([1, 2, 3, 4, 5]);
|
|
94
|
+
const y = new Float32Array([10, 20, 30, 40, 50]);
|
|
93
95
|
|
|
94
96
|
const xGpu = GpuVector.from(x);
|
|
95
97
|
const yGpu = GpuVector.from(y);
|
|
@@ -98,12 +100,12 @@ console.log("x: ", x);
|
|
|
98
100
|
console.log("y: ", y);
|
|
99
101
|
|
|
100
102
|
// results stay in the GPU.
|
|
101
|
-
await saxpy(device, n, alpha, xGpu, 1, yGpu, 1);
|
|
102
|
-
await sscal(device, n, scale, yGpu, 1);
|
|
103
|
+
await saxpy(device, n, alpha, xGpu, 1, yGpu, 1); // y = 2x + y = [12, 24, 36, 48, 60]
|
|
104
|
+
await sscal(device, n, scale, yGpu, 1); // y = 0.5y = [6, 12, 18, 24, 30]
|
|
103
105
|
|
|
104
106
|
// single readback
|
|
105
107
|
const result = await yGpu.read();
|
|
106
|
-
console.log("result: ", result);
|
|
108
|
+
console.log("result: ", result); // [6, 12, 18, 24, 30]
|
|
107
109
|
|
|
108
110
|
xGpu.destroy();
|
|
109
111
|
yGpu.destroy();
|