wgblas 1.2.1 → 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.
Files changed (96) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +54 -72
  3. package/dist/wgblas.browser.js +1637 -858
  4. package/index.d.mts +51 -6
  5. package/index.mjs +8 -0
  6. package/package.json +56 -2
  7. package/src/classes/GpuMatrix.mjs +17 -10
  8. package/src/classes/GpuVector.mjs +28 -10
  9. package/src/dasum/dasum.d.mts +6 -6
  10. package/src/dasum/dasum.mjs +25 -21
  11. package/src/devdocs.mjs +13 -0
  12. package/src/idamax/idamax.d.mts +69 -0
  13. package/src/idamax/idamax.mjs +130 -0
  14. package/src/init.mjs +115 -49
  15. package/src/isamax/isamax.d.mts +21 -3
  16. package/src/isamax/isamax.mjs +16 -14
  17. package/src/random/random.d.mts +1 -0
  18. package/src/sasum/sasum.d.mts +3 -3
  19. package/src/sasum/sasum.mjs +15 -13
  20. package/src/saxpy/saxpy.d.mts +3 -3
  21. package/src/saxpy/saxpy.mjs +10 -8
  22. package/src/scopy/scopy.d.mts +3 -3
  23. package/src/scopy/scopy.mjs +10 -8
  24. package/src/sdot/sdot.d.mts +3 -3
  25. package/src/sdot/sdot.mjs +16 -14
  26. package/src/sgemm/sgemm.d.mts +102 -0
  27. package/src/sgemm/sgemm.mjs +208 -0
  28. package/src/sgemmtr/sgemmtr.d.mts +104 -0
  29. package/src/sgemmtr/sgemmtr.mjs +204 -0
  30. package/src/sgemv/sgemv.d.mts +1 -38
  31. package/src/sgemv/sgemv.mjs +42 -26
  32. package/src/sger/sger.d.mts +1 -34
  33. package/src/sger/sger.mjs +12 -8
  34. package/src/shaders/block_transfer.wgsl +42 -0
  35. package/src/shaders/dasum.wgsl +3 -2
  36. package/src/shaders/f64/dekker.wgsl +4 -85
  37. package/src/shaders/f64/utils/abs.wgsl +10 -0
  38. package/src/shaders/f64/utils/add.wgsl +77 -0
  39. package/src/shaders/f64/utils/equal.wgsl +7 -0
  40. package/src/shaders/f64/utils/greater.wgsl +12 -0
  41. package/src/shaders/f64/utils/multiply.wgsl +81 -0
  42. package/src/shaders/idamax.wgsl +96 -0
  43. package/src/shaders/index.mjs +164 -14
  44. package/src/shaders/reduction/argmaxF64.wgsl +50 -0
  45. package/src/shaders/reduction/scaledSum.wgsl +65 -0
  46. package/src/shaders/reduction/sumF64.wgsl +2 -2
  47. package/src/shaders/sgemm_large.wgsl +206 -0
  48. package/src/shaders/sgemm_small.wgsl +212 -0
  49. package/src/shaders/sgemmtr_large.wgsl +120 -0
  50. package/src/shaders/sgemmtr_small.wgsl +113 -0
  51. package/src/shaders/sgemv_n.wgsl +3 -1
  52. package/src/shaders/sgemv_t.wgsl +3 -1
  53. package/src/shaders/snrm2.wgsl +72 -23
  54. package/src/shaders/ssymv.wgsl +3 -1
  55. package/src/shaders/symmetrize.wgsl +31 -0
  56. package/src/shaders/triangularize.wgsl +44 -0
  57. package/src/snrm2/snrm2.d.mts +3 -3
  58. package/src/snrm2/snrm2.mjs +33 -21
  59. package/src/srot/srot.d.mts +3 -5
  60. package/src/srot/srot.mjs +11 -9
  61. package/src/srotm/srotm.d.mts +3 -5
  62. package/src/srotm/srotm.mjs +19 -10
  63. package/src/sscal/sscal.d.mts +4 -4
  64. package/src/sscal/sscal.mjs +12 -10
  65. package/src/sswap/sswap.d.mts +3 -3
  66. package/src/sswap/sswap.mjs +11 -9
  67. package/src/ssymm/ssymm.d.mts +103 -0
  68. package/src/ssymm/ssymm.mjs +218 -0
  69. package/src/ssymv/ssymv.d.mts +1 -36
  70. package/src/ssymv/ssymv.mjs +12 -8
  71. package/src/ssyr/ssyr.d.mts +1 -30
  72. package/src/ssyr/ssyr.mjs +11 -7
  73. package/src/ssyr2/ssyr2.d.mts +1 -34
  74. package/src/ssyr2/ssyr2.mjs +12 -8
  75. package/src/ssyr2k/ssyr2k.d.mts +100 -0
  76. package/src/ssyr2k/ssyr2k.mjs +202 -0
  77. package/src/ssyrk/ssyrk.d.mts +90 -0
  78. package/src/ssyrk/ssyrk.mjs +177 -0
  79. package/src/strmm/strmm.d.mts +100 -0
  80. package/src/strmm/strmm.mjs +226 -0
  81. package/src/strmv/strmv.d.mts +1 -36
  82. package/src/strmv/strmv.mjs +12 -8
  83. package/src/strsm/strsm.d.mts +99 -0
  84. package/src/strsm/strsm.mjs +360 -0
  85. package/src/strsv/strsv.d.mts +1 -32
  86. package/src/strsv/strsv.mjs +18 -12
  87. package/src/util/benchmark.mjs +4 -6
  88. package/src/util/bindgroup.mjs +1 -3
  89. package/src/util/buffer.mjs +116 -20
  90. package/src/util/compute.mjs +12 -12
  91. package/src/util/constants.mjs +57 -0
  92. package/src/util/device.mjs +34 -0
  93. package/src/util/f64.mjs +3 -3
  94. package/src/util/pipeline.mjs +5 -6
  95. package/src/util/workgroup.mjs +55 -7
  96. package/src/shaders/browser-shaders.mjs +0 -55
package/LICENSE CHANGED
@@ -186,7 +186,7 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright [2026] [manit2004]
189
+ Copyright [2026] [Manit Roy]
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
package/README.md CHANGED
@@ -1,60 +1,8 @@
1
1
  # wgblas
2
2
 
3
- `wgblas` is an initiative to implement all the standard level 1, 2, 3 BLAS functions on the top of webgpu.
4
-
5
- ## Available Functions
6
-
7
- - [sscal](https://manit2004.github.io/wgblas/functions/docs.sscal.html)
8
- - [sswap](https://manit2004.github.io/wgblas/functions/docs.sswap.html)
9
- - [saxpy](https://manit2004.github.io/wgblas/functions/docs.saxpy.html)
10
- - [scopy](https://manit2004.github.io/wgblas/functions/docs.scopy.html)
11
- - [sdot](https://manit2004.github.io/wgblas/functions/docs.sdot.html)
12
- - [sasum](https://manit2004.github.io/wgblas/functions/docs.sasum.html)
13
- - [snrm2](https://manit2004.github.io/wgblas/functions/docs.snrm2.html)
14
- - [isamax](https://manit2004.github.io/wgblas/functions/docs.isamax.html)
15
- - [srot](https://manit2004.github.io/wgblas/functions/docs.srot.html)
16
- - [srotm](https://manit2004.github.io/wgblas/functions/docs.srotm.html)
17
- - [sgemv](https://manit2004.github.io/wgblas/functions/docs.sgemv.html)
18
- - [ssymv](https://manit2004.github.io/wgblas/functions/docs.ssymv.html)
19
- - [strmv](https://manit2004.github.io/wgblas/functions/docs.strmv.html)
20
- - [strsv](https://manit2004.github.io/wgblas/functions/docs.strsv.html)
21
- - [sger](https://manit2004.github.io/wgblas/functions/docs.sger.html)
22
- - [ssyr](https://manit2004.github.io/wgblas/functions/docs.ssyr.html)
23
- - [ssyr2](https://manit2004.github.io/wgblas/functions/docs.ssyr2.html)
24
-
25
- ## Browser Support
3
+ [![Tests](https://github.com/manit2004/wgblas/actions/workflows/test-gpu.yml/badge.svg)](https://github.com/manit2004/wgblas/actions/workflows/test-gpu.yml)
26
4
 
27
- wgblas runs in any browser with WebGPU enabled. Check if it's working in your browser at [webgpureport.org](https://webgpureport.org).
28
-
29
- ### Chrome (recommended)
30
-
31
- For full WebGPU control, enable all three flags at `chrome://flags` and relaunch:
32
-
33
- | Flag | What it does |
34
- |------|--------------|
35
- | `#enable-unsafe-webgpu` | Enables WebGPU |
36
- | `#force-enable-webgpu-interop` | Uses the real GPU via Vulkan (Linux) — without this Chrome may fall back to SwiftShader, a CPU-based software renderer |
37
- | `#enable-webgpu-developer-features` | Unlocks additional GPU features |
38
-
39
- You can verify which GPU is being used at [webgpureport.org](https://webgpureport.org) — if the adapter name shows **SwiftShader**, the real GPU is not being used.
40
-
41
- ### Firefox
42
-
43
- WebGPU must be enabled manually via `about:config`. Search for each preference and set it:
44
-
45
- | Preference | Value | What it does |
46
- |------------|-------|--------------|
47
- | `dom.webgpu.enabled` | `true` | Enables WebGPU |
48
- | `dom.webgpu.wgpu-backend` | `vulkan` | Forces the real GPU via Vulkan — without this Firefox may use a software renderer |
49
- | `gfx.webgpu.ignore-blocklist` | `true` | Bypasses the GPU blocklist |
50
-
51
- Note: `dom.webgpu.wgpu-backend` is a **string** preference — click the pencil icon to edit it and type `vulkan`.
52
-
53
- Restart Firefox after making changes.
54
-
55
- > **Note:** Firefox's WebGPU implementation is incomplete and some routines may not work correctly. Chrome is recommended.
56
- >
57
- > **Multi-GPU:** Firefox only exposes one WebGPU adapter (the display GPU, typically integrated) even on dual-GPU systems — verified via `about:support` → Graphics → WebGPU Default Adapter. Chrome picks the discrete GPU via `powerPreference: "high-performance"`; Firefox does not.
5
+ `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.
58
6
 
59
7
  ## Requirements
60
8
 
@@ -71,18 +19,18 @@ npm install wgblas
71
19
  ### Example Code Snippet
72
20
 
73
21
  ```js
74
- import { init, cleanup, randomFloat32Array } from "wgblas";
22
+ import { init, cleanup } from "wgblas";
75
23
  import { sscal } from "wgblas/sscal";
76
24
 
77
25
  const device = await init();
78
26
 
79
- const n = 10;
80
- const alpha = 2.0;
81
- const x = randomFloat32Array(n, -10, 10);
27
+ const n = 5;
28
+ const alpha = 3;
29
+ const x = new Float32Array([1, 2, 3, 4, 5]);
82
30
 
83
31
  console.log("before:", x);
84
- const result = await sscal(device, n, alpha, x, 1);
85
- 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]
86
34
  cleanup();
87
35
  ```
88
36
 
@@ -101,18 +49,18 @@ No bundler needed. Load the pre-built browser bundle from the CDN and use `windo
101
49
  <body>
102
50
  <pre id="out">Running…</pre>
103
51
  <script>
104
- const { init, sscal, randomFloat32Array, cleanup } = window.wgblas;
52
+ const { init, sscal, cleanup } = window.wgblas;
105
53
 
106
54
  (async () => {
107
55
  const device = await init();
108
56
 
109
- const n = 10;
110
- const alpha = 2.0;
111
- const x = randomFloat32Array(n, -10, 10);
57
+ const n = 5;
58
+ const alpha = 3;
59
+ const x = new Float32Array([1, 2, 3, 4, 5]);
112
60
 
113
61
  const xBefore = Array.from(x).map(v => v.toFixed(4)).join(", ");
114
62
 
115
- const result = await sscal(device, n, alpha, x, 1);
63
+ const { x: result } = await sscal(device, n, alpha, x, 1);
116
64
 
117
65
  document.getElementById("out").textContent =
118
66
  "before: " + xBefore +
@@ -130,18 +78,18 @@ No bundler needed. Load the pre-built browser bundle from the CDN and use `windo
130
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.
131
79
 
132
80
  ```js
133
- import { init, cleanup, randomFloat32Array } from "wgblas";
81
+ import { init, cleanup } from "wgblas";
134
82
  import { saxpy } from "wgblas/saxpy";
135
83
  import { sscal } from "wgblas/sscal";
136
84
  import { GpuVector } from "wgblas/classes/GpuVector";
137
85
 
138
86
  const device = await init();
139
87
 
140
- const n = 10;
88
+ const n = 5;
141
89
  const alpha = 2;
142
90
  const scale = 0.5;
143
- const x = randomFloat32Array(n, -10, 10);
144
- const y = randomFloat32Array(n, -10, 10);
91
+ const x = new Float32Array([1, 2, 3, 4, 5]);
92
+ const y = new Float32Array([10, 20, 30, 40, 50]);
145
93
 
146
94
  const xGpu = GpuVector.from(x);
147
95
  const yGpu = GpuVector.from(y);
@@ -150,15 +98,49 @@ console.log("x: ", x);
150
98
  console.log("y: ", y);
151
99
 
152
100
  // results stay in the GPU.
153
- await saxpy(device, n, alpha, xGpu, 1, yGpu, 1);
154
- 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]
155
103
 
156
104
  // single readback
157
105
  const result = await yGpu.read();
158
- console.log("result: ", result);
106
+ console.log("result: ", result); // [6, 12, 18, 24, 30]
159
107
 
160
108
  xGpu.destroy();
161
109
  yGpu.destroy();
162
110
 
163
111
  cleanup();
164
112
  ```
113
+
114
+ ## Browser Support
115
+
116
+ wgblas runs in any browser with WebGPU enabled. Check if it's working in your browser at [webgpureport.org](https://webgpureport.org).
117
+
118
+ ### Chrome (recommended)
119
+
120
+ For full WebGPU control, enable all three flags at `chrome://flags` and relaunch:
121
+
122
+ | Flag | What it does |
123
+ |------|--------------|
124
+ | `#enable-unsafe-webgpu` | Enables WebGPU |
125
+ | `#force-enable-webgpu-interop` | Uses the real GPU via Vulkan (Linux) — without this Chrome may fall back to SwiftShader, a CPU-based software renderer |
126
+ | `#enable-webgpu-developer-features` | Unlocks additional GPU features |
127
+
128
+ You can verify which GPU is being used at [webgpureport.org](https://webgpureport.org) — if the adapter name shows **SwiftShader**, the real GPU is not being used.
129
+
130
+ ### Firefox
131
+
132
+ WebGPU must be enabled manually via `about:config`. Search for each preference and set it:
133
+
134
+ | Preference | Value | What it does |
135
+ |------------|-------|--------------|
136
+ | `dom.webgpu.enabled` | `true` | Enables WebGPU |
137
+ | `dom.webgpu.wgpu-backend` | `vulkan` | Forces the real GPU via Vulkan — without this Firefox may use a software renderer |
138
+ | `gfx.webgpu.ignore-blocklist` | `true` | Bypasses the GPU blocklist |
139
+
140
+ Note: `dom.webgpu.wgpu-backend` is a **string** preference — click the pencil icon to edit it and type `vulkan`.
141
+
142
+ Restart Firefox after making changes.
143
+
144
+ > **Note:** Firefox's WebGPU implementation is incomplete and some routines may not work correctly. Chrome is recommended.
145
+ >
146
+ > **Multi-GPU:** Firefox only exposes one WebGPU adapter (the display GPU, typically integrated) even on dual-GPU systems — verified via `about:support` → Graphics → WebGPU Default Adapter. Chrome picks the discrete GPU via `powerPreference: "high-performance"`; Firefox does not.