wgblas 2.0.0 → 2.1.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 +18 -18
- package/dist/wgblas.browser.js +1273 -1239
- package/index.d.mts +38 -6
- package/package.json +2 -1
- package/src/classes/GpuMatrix.mjs +17 -10
- package/src/classes/GpuVector.mjs +28 -10
- package/src/dasum/dasum.d.mts +4 -4
- package/src/dasum/dasum.mjs +19 -17
- package/src/devdocs.mjs +13 -0
- package/src/idamax/idamax.d.mts +20 -2
- package/src/idamax/idamax.mjs +18 -16
- package/src/init.mjs +114 -56
- package/src/isamax/isamax.d.mts +20 -2
- package/src/isamax/isamax.mjs +16 -14
- package/src/random/random.d.mts +1 -0
- package/src/sasum/sasum.d.mts +2 -2
- package/src/sasum/sasum.mjs +15 -13
- package/src/saxpy/saxpy.d.mts +2 -2
- package/src/saxpy/saxpy.mjs +10 -8
- package/src/scopy/scopy.d.mts +2 -2
- package/src/scopy/scopy.mjs +10 -8
- package/src/sdot/sdot.d.mts +2 -2
- package/src/sdot/sdot.mjs +16 -14
- package/src/sgemm/sgemm.mjs +28 -15
- package/src/sgemmtr/sgemmtr.mjs +16 -15
- package/src/sgemv/sgemv.mjs +38 -26
- package/src/sger/sger.mjs +10 -8
- package/src/shaders/index.mjs +164 -14
- package/src/shaders/reduction/scaledSum.wgsl +65 -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 +33 -21
- package/src/srot/srot.d.mts +2 -4
- package/src/srot/srot.mjs +11 -9
- package/src/srotm/srotm.d.mts +2 -4
- package/src/srotm/srotm.mjs +19 -10
- package/src/sscal/sscal.d.mts +3 -3
- package/src/sscal/sscal.mjs +12 -10
- package/src/sswap/sswap.d.mts +2 -2
- package/src/sswap/sswap.mjs +11 -9
- package/src/ssymm/ssymm.mjs +31 -22
- package/src/ssymv/ssymv.mjs +10 -8
- package/src/ssyr/ssyr.mjs +9 -7
- package/src/ssyr2/ssyr2.mjs +10 -8
- package/src/ssyr2k/ssyr2k.mjs +18 -17
- package/src/ssyrk/ssyrk.mjs +18 -17
- package/src/strmm/strmm.mjs +47 -32
- package/src/strmv/strmv.mjs +10 -8
- package/src/strsm/strsm.mjs +54 -36
- package/src/strsv/strsv.mjs +16 -12
- package/src/util/benchmark.mjs +4 -6
- package/src/util/bindgroup.mjs +1 -3
- package/src/util/buffer.mjs +113 -19
- package/src/util/compute.mjs +6 -9
- package/src/util/constants.mjs +57 -0
- package/src/util/device.mjs +34 -0
- package/src/util/pipeline.mjs +5 -6
- package/src/util/workgroup.mjs +55 -7
- package/src/shaders/browser-shaders.mjs +0 -81
package/README.md
CHANGED
|
@@ -19,18 +19,18 @@ npm install wgblas
|
|
|
19
19
|
### Example Code Snippet
|
|
20
20
|
|
|
21
21
|
```js
|
|
22
|
-
import { init, cleanup
|
|
22
|
+
import { init, cleanup } from "wgblas";
|
|
23
23
|
import { sscal } from "wgblas/sscal";
|
|
24
24
|
|
|
25
25
|
const device = await init();
|
|
26
26
|
|
|
27
|
-
const n =
|
|
28
|
-
const alpha =
|
|
29
|
-
const x =
|
|
27
|
+
const n = 5;
|
|
28
|
+
const alpha = 3;
|
|
29
|
+
const x = new Float32Array([1, 2, 3, 4, 5]);
|
|
30
30
|
|
|
31
31
|
console.log("before:", x);
|
|
32
|
-
const result = await sscal(device, n, alpha, x, 1);
|
|
33
|
-
console.log("after: ", result);
|
|
32
|
+
const { x: result } = await sscal(device, n, alpha, x, 1);
|
|
33
|
+
console.log("after: ", result); // [3, 6, 9, 12, 15]
|
|
34
34
|
cleanup();
|
|
35
35
|
```
|
|
36
36
|
|
|
@@ -49,18 +49,18 @@ No bundler needed. Load the pre-built browser bundle from the CDN and use `windo
|
|
|
49
49
|
<body>
|
|
50
50
|
<pre id="out">Running…</pre>
|
|
51
51
|
<script>
|
|
52
|
-
const { init, sscal,
|
|
52
|
+
const { init, sscal, cleanup } = window.wgblas;
|
|
53
53
|
|
|
54
54
|
(async () => {
|
|
55
55
|
const device = await init();
|
|
56
56
|
|
|
57
|
-
const n =
|
|
58
|
-
const alpha =
|
|
59
|
-
const x =
|
|
57
|
+
const n = 5;
|
|
58
|
+
const alpha = 3;
|
|
59
|
+
const x = new Float32Array([1, 2, 3, 4, 5]);
|
|
60
60
|
|
|
61
61
|
const xBefore = Array.from(x).map(v => v.toFixed(4)).join(", ");
|
|
62
62
|
|
|
63
|
-
const result = await sscal(device, n, alpha, x, 1);
|
|
63
|
+
const { x: result } = await sscal(device, n, alpha, x, 1);
|
|
64
64
|
|
|
65
65
|
document.getElementById("out").textContent =
|
|
66
66
|
"before: " + xBefore +
|
|
@@ -78,18 +78,18 @@ No bundler needed. Load the pre-built browser bundle from the CDN and use `windo
|
|
|
78
78
|
`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
79
|
|
|
80
80
|
```js
|
|
81
|
-
import { init, cleanup
|
|
81
|
+
import { init, cleanup } from "wgblas";
|
|
82
82
|
import { saxpy } from "wgblas/saxpy";
|
|
83
83
|
import { sscal } from "wgblas/sscal";
|
|
84
84
|
import { GpuVector } from "wgblas/classes/GpuVector";
|
|
85
85
|
|
|
86
86
|
const device = await init();
|
|
87
87
|
|
|
88
|
-
const n =
|
|
88
|
+
const n = 5;
|
|
89
89
|
const alpha = 2;
|
|
90
90
|
const scale = 0.5;
|
|
91
|
-
const x =
|
|
92
|
-
const y =
|
|
91
|
+
const x = new Float32Array([1, 2, 3, 4, 5]);
|
|
92
|
+
const y = new Float32Array([10, 20, 30, 40, 50]);
|
|
93
93
|
|
|
94
94
|
const xGpu = GpuVector.from(x);
|
|
95
95
|
const yGpu = GpuVector.from(y);
|
|
@@ -98,12 +98,12 @@ console.log("x: ", x);
|
|
|
98
98
|
console.log("y: ", y);
|
|
99
99
|
|
|
100
100
|
// results stay in the GPU.
|
|
101
|
-
await saxpy(device, n, alpha, xGpu, 1, yGpu, 1);
|
|
102
|
-
await sscal(device, n, scale, yGpu, 1);
|
|
101
|
+
await saxpy(device, n, alpha, xGpu, 1, yGpu, 1); // y = 2x + y = [12, 24, 36, 48, 60]
|
|
102
|
+
await sscal(device, n, scale, yGpu, 1); // y = 0.5y = [6, 12, 18, 24, 30]
|
|
103
103
|
|
|
104
104
|
// single readback
|
|
105
105
|
const result = await yGpu.read();
|
|
106
|
-
console.log("result: ", result);
|
|
106
|
+
console.log("result: ", result); // [6, 12, 18, 24, 30]
|
|
107
107
|
|
|
108
108
|
xGpu.destroy();
|
|
109
109
|
yGpu.destroy();
|