@alex000291/jstorch 0.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 ADDED
@@ -0,0 +1,143 @@
1
+ # JsTorch
2
+
3
+ A JavaScript version of PyTorch with CUDA acceleration for Node.js.
4
+
5
+ ## Features
6
+
7
+ - πŸš€ CUDA-accelerated tensor operations
8
+ - πŸ“¦ Native Node.js addon (N-API)
9
+ - 🎯 PyTorch-like API
10
+ - πŸ”§ Universal binary supporting multiple GPU architectures
11
+
12
+ ## Requirements
13
+
14
+ - **OS**: Windows x64 (Linux/Mac support coming soon)
15
+ - **Node.js**: >= 18.0.0
16
+ - **CUDA**: 13.0 or higher
17
+ - **GPU**: NVIDIA GPU with compute capability >= 7.5
18
+ - RTX 20xx/30xx/40xx series
19
+ - GTX 16xx series
20
+ - Tesla T4/A100/H100
21
+ - Quadro RTX series
22
+
23
+ **Note**: GTX 10xx and older GPUs are not supported (require compute capability < 7.5).
24
+
25
+ ## Installation
26
+
27
+ ```bash
28
+ npm install @alex000291/jstorch
29
+ ```
30
+
31
+ **Important**: Make sure CUDA runtime DLLs are in your PATH:
32
+ - Add `C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.x\bin` to your system PATH
33
+ - Or ensure `cudart64_XX.dll` is accessible
34
+
35
+ ## Quick Start
36
+
37
+ ```javascript
38
+ import { torch } from '@alex000291/jstorch';
39
+
40
+ // Create matrices (row-major order)
41
+ const a = new Float32Array([
42
+ 1, 2, 3,
43
+ 4, 5, 6
44
+ ]); // 2x3 matrix
45
+
46
+ const b = new Float32Array([
47
+ 1, 2, 3, 4,
48
+ 5, 6, 7, 8,
49
+ 9, 10, 11, 12
50
+ ]); // 3x4 matrix
51
+
52
+ // Matrix multiplication on GPU: C = A Γ— B
53
+ const result = torch.matmul(a, b, 2, 3, 4); // (M, K, N)
54
+ console.log(result);
55
+ // Float32Array(8) [ 38, 44, 50, 56, 83, 98, 113, 128 ]
56
+ ```
57
+
58
+ ## API Reference
59
+
60
+ ### `torch.matmul(a, b, M, K, N)`
61
+
62
+ Performs matrix multiplication on GPU: **C = A Γ— B**
63
+
64
+ **Parameters:**
65
+ - `a` (Float32Array): Matrix A with shape (M, K), stored in row-major order
66
+ - `b` (Float32Array): Matrix B with shape (K, N), stored in row-major order
67
+ - `M` (number): Number of rows in A
68
+ - `K` (number): Number of columns in A / rows in B
69
+ - `N` (number): Number of columns in B
70
+
71
+ **Returns:**
72
+ - `Float32Array`: Result matrix C with shape (M, N)
73
+
74
+ **Example:**
75
+ ```javascript
76
+ // 2Γ—3 matrix
77
+ const A = new Float32Array([1, 2, 3, 4, 5, 6]);
78
+
79
+ // 3Γ—2 matrix
80
+ const B = new Float32Array([7, 8, 9, 10, 11, 12]);
81
+
82
+ // Result: 2Γ—2 matrix
83
+ const C = torch.matmul(A, B, 2, 3, 2);
84
+ ```
85
+
86
+ ## Supported GPU Architectures
87
+
88
+ The package includes a universal binary that supports:
89
+ - **sm_75**: Turing (RTX 20xx, GTX 16xx, Tesla T4)
90
+ - **sm_80**: Ampere (A100, A30, A40)
91
+ - **sm_86**: Ampere (RTX 30xx, A10, A16)
92
+ - **sm_89**: Ada Lovelace (RTX 40xx, L4, L40)
93
+ - **sm_90**: Hopper (H100, H800)
94
+ - **PTX**: Future architectures (JIT compiled at runtime)
95
+
96
+ The CUDA runtime automatically selects the optimal code for your GPU.
97
+
98
+ ## Troubleshooting
99
+
100
+ ### `Error: Cannot find module 'jstorch.node'`
101
+ Make sure the package was installed correctly and `build/win/jstorch.node` exists.
102
+
103
+ ### `Error: the provided PTX was compiled with an unsupported toolchain`
104
+ Your GPU may be too old. JsTorch requires compute capability >= 7.5 (RTX 20xx or newer).
105
+
106
+ ### `Error loading CUDA runtime`
107
+ Ensure CUDA is installed and `cudart64_XX.dll` is in your PATH.
108
+
109
+ ## Roadmap
110
+
111
+ - [x] Matrix multiplication (matmul)
112
+ - [ ] Tensor class with automatic shape tracking
113
+ - [ ] Element-wise operations (add, mul, div, etc.)
114
+ - [ ] Reduction operations (sum, mean, max, etc.)
115
+ - [ ] Broadcasting support
116
+ - [ ] Autograd / backpropagation
117
+ - [ ] Linux / macOS support
118
+ - [ ] CPU fallback
119
+
120
+ ## Performance
121
+
122
+ JsTorch uses CUDA for GPU acceleration. Performance depends on:
123
+ - Matrix size (larger matrices benefit more from GPU)
124
+ - GPU model (newer GPUs are faster)
125
+ - Memory transfer overhead (minimize CPU↔GPU transfers)
126
+
127
+ ## Contributing
128
+
129
+ Contributions welcome! Please open an issue or PR on [GitHub](https://github.com/Alex000291/JsTorch).
130
+
131
+ ## License
132
+
133
+ MIT
134
+
135
+ ## Author
136
+
137
+ Alex000291
138
+
139
+ ## Links
140
+
141
+ - [GitHub Repository](https://github.com/Alex000291/JsTorch)
142
+ - [Issue Tracker](https://github.com/Alex000291/JsTorch/issues)
143
+ - [npm Package](https://www.npmjs.com/package/@alex000291/jstorch)
Binary file
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@alex000291/jstorch",
3
+ "version": "0.1.0",
4
+ "description": "A JavaScript version of PyTorch with CUDA acceleration",
5
+ "homepage": "https://github.com/Alex000291/JsTorch#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/Alex000291/JsTorch/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/Alex000291/JsTorch.git"
12
+ },
13
+ "license": "MIT",
14
+ "author": "Alex000291",
15
+ "type": "module",
16
+ "main": "src/index.js",
17
+ "exports": {
18
+ ".": "./src/index.js"
19
+ },
20
+ "scripts": {
21
+ "build": "node Makefile.js",
22
+ "test": "node src/test1.js",
23
+ "prepublishOnly": "npm run build"
24
+ },
25
+ "files": [
26
+ "src/index.js",
27
+ "build/win/jstorch.node"
28
+ ],
29
+ "keywords": [
30
+ "pytorch",
31
+ "tensor",
32
+ "cuda",
33
+ "gpu",
34
+ "machine-learning",
35
+ "deep-learning"
36
+ ],
37
+ "engines": {
38
+ "node": ">=18.0.0"
39
+ },
40
+ "os": [
41
+ "win32"
42
+ ],
43
+ "cpu": [
44
+ "x64"
45
+ ],
46
+ "dependencies": {
47
+ "node-addon-api": "^8.9.0",
48
+ "node-api-headers": "^1.9.0"
49
+ },
50
+ "devDependencies": {}
51
+ }
package/src/index.js ADDED
@@ -0,0 +1,11 @@
1
+ import { createRequire } from 'module';
2
+ import { fileURLToPath } from 'url';
3
+ import path from 'path';
4
+
5
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
6
+ const require = createRequire(import.meta.url);
7
+
8
+ // εŠ θ½½εŒ…ε«ζ‰€ζœ‰ζžΆζž„ηš„ universal binary
9
+ const addon = require(path.join(__dirname, '../build/win/jstorch.node'));
10
+ export const torch = addon.torch;
11
+