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.
Files changed (124) hide show
  1. package/README.md +20 -18
  2. package/dist/wgblas.browser.js +2172 -1174
  3. package/index.d.mts +49 -44
  4. package/index.mjs +11 -0
  5. package/package.json +133 -63
  6. package/src/classes/Complex32.d.mts +43 -0
  7. package/src/classes/Complex32.mjs +82 -0
  8. package/src/classes/Complex64.d.mts +44 -0
  9. package/src/classes/Complex64.mjs +76 -0
  10. package/src/classes/GpuMatrix.d.mts +41 -41
  11. package/src/classes/GpuMatrix.mjs +126 -17
  12. package/src/classes/GpuVector.d.mts +36 -40
  13. package/src/classes/GpuVector.mjs +66 -11
  14. package/src/cscal/cscal.d.mts +47 -0
  15. package/src/cscal/cscal.mjs +98 -0
  16. package/src/dasum/dasum.d.mts +4 -4
  17. package/src/dasum/dasum.mjs +38 -20
  18. package/src/daxpy/daxpy.d.mts +56 -0
  19. package/src/daxpy/daxpy.mjs +150 -0
  20. package/src/dcopy/dcopy.d.mts +52 -0
  21. package/src/dcopy/dcopy.mjs +140 -0
  22. package/src/ddot/ddot.d.mts +62 -0
  23. package/src/ddot/ddot.mjs +184 -0
  24. package/src/devdocs.mjs +13 -0
  25. package/src/dnrm2/dnrm2.d.mts +50 -0
  26. package/src/dnrm2/dnrm2.mjs +189 -0
  27. package/src/drot/drot.d.mts +67 -0
  28. package/src/drot/drot.mjs +170 -0
  29. package/src/drotm/drotm.d.mts +67 -0
  30. package/src/drotm/drotm.mjs +171 -0
  31. package/src/dscal/dscal.d.mts +52 -0
  32. package/src/dscal/dscal.mjs +119 -0
  33. package/src/dswap/dswap.d.mts +57 -0
  34. package/src/dswap/dswap.mjs +155 -0
  35. package/src/idamax/idamax.d.mts +20 -2
  36. package/src/idamax/idamax.mjs +56 -24
  37. package/src/init.mjs +117 -56
  38. package/src/isamax/isamax.d.mts +20 -2
  39. package/src/isamax/isamax.mjs +21 -16
  40. package/src/random/random.d.mts +37 -39
  41. package/src/random/random.mjs +39 -7
  42. package/src/sasum/sasum.d.mts +2 -2
  43. package/src/sasum/sasum.mjs +20 -16
  44. package/src/saxpy/saxpy.d.mts +2 -2
  45. package/src/saxpy/saxpy.mjs +14 -11
  46. package/src/scopy/scopy.d.mts +2 -2
  47. package/src/scopy/scopy.mjs +13 -9
  48. package/src/sdot/sdot.d.mts +2 -2
  49. package/src/sdot/sdot.mjs +21 -17
  50. package/src/sgemm/sgemm.d.mts +2 -2
  51. package/src/sgemm/sgemm.mjs +109 -40
  52. package/src/sgemmtr/sgemmtr.d.mts +3 -2
  53. package/src/sgemmtr/sgemmtr.mjs +98 -40
  54. package/src/sgemv/sgemv.d.mts +2 -2
  55. package/src/sgemv/sgemv.mjs +69 -41
  56. package/src/sger/sger.d.mts +2 -2
  57. package/src/sger/sger.mjs +43 -19
  58. package/src/shaders/__test_pipeline_a.wgsl +3 -0
  59. package/src/shaders/__test_pipeline_b.wgsl +2 -0
  60. package/src/shaders/cscal.wgsl +33 -0
  61. package/src/shaders/daxpy.wgsl +66 -0
  62. package/src/shaders/dcopy.wgsl +34 -0
  63. package/src/shaders/ddot.wgsl +106 -0
  64. package/src/shaders/dnrm2.wgsl +167 -0
  65. package/src/shaders/drot.wgsl +81 -0
  66. package/src/shaders/drotm.wgsl +99 -0
  67. package/src/shaders/dscal.wgsl +60 -0
  68. package/src/shaders/dswap.wgsl +38 -0
  69. package/src/shaders/f64/utils/add.wgsl +6 -0
  70. package/src/shaders/f64/utils/divide.wgsl +45 -0
  71. package/src/shaders/f64/utils/multiply.wgsl +19 -10
  72. package/src/shaders/f64/utils/sqrt.wgsl +45 -0
  73. package/src/shaders/index.mjs +233 -14
  74. package/src/shaders/reduction/scaledSum.wgsl +65 -0
  75. package/src/shaders/reduction/scaledSumF64.wgsl +93 -0
  76. package/src/shaders/sgemm_large.wgsl +107 -18
  77. package/src/shaders/sgemm_small.wgsl +115 -15
  78. package/src/shaders/sgemmtr_large.wgsl +4 -1
  79. package/src/shaders/sgemmtr_small.wgsl +4 -1
  80. package/src/shaders/sgemv_n.wgsl +3 -1
  81. package/src/shaders/sgemv_t.wgsl +3 -1
  82. package/src/shaders/snrm2.wgsl +72 -23
  83. package/src/shaders/ssymv.wgsl +3 -1
  84. package/src/snrm2/snrm2.d.mts +2 -2
  85. package/src/snrm2/snrm2.mjs +41 -23
  86. package/src/srot/srot.d.mts +2 -4
  87. package/src/srot/srot.mjs +16 -11
  88. package/src/srotm/srotm.d.mts +2 -4
  89. package/src/srotm/srotm.mjs +17 -11
  90. package/src/sscal/sscal.d.mts +3 -3
  91. package/src/sscal/sscal.mjs +14 -12
  92. package/src/sswap/sswap.d.mts +2 -2
  93. package/src/sswap/sswap.mjs +18 -10
  94. package/src/ssymm/ssymm.d.mts +5 -4
  95. package/src/ssymm/ssymm.mjs +150 -54
  96. package/src/ssymv/ssymv.d.mts +2 -2
  97. package/src/ssymv/ssymv.mjs +47 -26
  98. package/src/ssyr/ssyr.d.mts +2 -2
  99. package/src/ssyr/ssyr.mjs +38 -17
  100. package/src/ssyr2/ssyr2.d.mts +2 -2
  101. package/src/ssyr2/ssyr2.mjs +48 -21
  102. package/src/ssyr2k/ssyr2k.d.mts +3 -2
  103. package/src/ssyr2k/ssyr2k.mjs +140 -62
  104. package/src/ssyrk/ssyrk.d.mts +3 -2
  105. package/src/ssyrk/ssyrk.mjs +91 -39
  106. package/src/strmm/strmm.d.mts +5 -4
  107. package/src/strmm/strmm.mjs +174 -60
  108. package/src/strmv/strmv.d.mts +2 -2
  109. package/src/strmv/strmv.mjs +42 -20
  110. package/src/strsm/strsm.d.mts +6 -4
  111. package/src/strsm/strsm.mjs +438 -174
  112. package/src/strsv/strsv.d.mts +5 -3
  113. package/src/strsv/strsv.mjs +89 -34
  114. package/src/util/benchmark.mjs +9 -9
  115. package/src/util/bindgroup.mjs +1 -3
  116. package/src/util/buffer.mjs +139 -24
  117. package/src/util/complex.mjs +87 -0
  118. package/src/util/compute.mjs +19 -16
  119. package/src/util/constants.mjs +57 -0
  120. package/src/util/device.mjs +49 -0
  121. package/src/util/pipeline.mjs +44 -10
  122. package/src/util/workgroup.mjs +72 -7
  123. package/src/shaders/browser-shaders.mjs +0 -81
  124. package/src/shaders/f64add.wgsl +0 -281
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # wgblas
2
2
 
3
3
  [![Tests](https://github.com/manit2004/wgblas/actions/workflows/test-gpu.yml/badge.svg)](https://github.com/manit2004/wgblas/actions/workflows/test-gpu.yml)
4
+ [![NPM version](https://img.shields.io/npm/v/wgblas.svg?style=plastic)](https://www.npmjs.org/package/wgblas)
5
+ [![NPM downloads](https://img.shields.io/npm/dm/wgblas.svg?style=plastic)](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, randomFloat32Array } from "wgblas";
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 = 10;
28
- const alpha = 2.0;
29
- const x = randomFloat32Array(n, -10, 10);
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, randomFloat32Array, cleanup } = window.wgblas;
54
+ const { init, sscal, cleanup } = window.wgblas;
53
55
 
54
56
  (async () => {
55
57
  const device = await init();
56
58
 
57
- const n = 10;
58
- const alpha = 2.0;
59
- const x = randomFloat32Array(n, -10, 10);
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, randomFloat32Array } from "wgblas";
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 = 10;
90
+ const n = 5;
89
91
  const alpha = 2;
90
92
  const scale = 0.5;
91
- const x = randomFloat32Array(n, -10, 10);
92
- const y = randomFloat32Array(n, -10, 10);
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();