gpuarray 0.1.0__tar.gz

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.
@@ -0,0 +1,122 @@
1
+ Metadata-Version: 2.4
2
+ Name: gpuarray
3
+ Version: 0.1.0
4
+ Summary: NumPy-like GPU array library that works on every GPU — NVIDIA, AMD, Intel, Apple Silicon. No CUDA required.
5
+ Author: Arnav Kewalram
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/arnavkewalram/gpuarray
8
+ Project-URL: Repository, https://github.com/arnavkewalram/gpuarray
9
+ Keywords: gpu,numpy,webgpu,array,compute,cuda-alternative
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Scientific/Engineering
16
+ Requires-Python: <3.14,>=3.10
17
+ Description-Content-Type: text/markdown
18
+ Requires-Dist: wgpu>=0.19
19
+ Requires-Dist: numpy>=1.24
20
+ Provides-Extra: dev
21
+ Requires-Dist: pytest>=7.0; extra == "dev"
22
+
23
+ # gpuarray
24
+
25
+ NumPy-like GPU array library that works on **every GPU** — NVIDIA, AMD, Intel, Apple Silicon. No CUDA required.
26
+
27
+ Powered by [WebGPU](https://www.w3.org/TR/webgpu/) via [wgpu-py](https://github.com/pygfx/wgpu-py). Uses Metal on macOS, Vulkan on Windows/Linux, and DirectX 12 on Windows.
28
+
29
+ ## Install
30
+
31
+ ```bash
32
+ pip install gpuarray
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ ```python
38
+ import gpuarray as gp
39
+
40
+ # Create arrays on GPU
41
+ a = gp.array([1, 2, 3, 4, 5])
42
+ b = gp.ones(5) * 3
43
+
44
+ # Operations run on GPU
45
+ c = a + b
46
+ d = a * b
47
+ e = gp.dot(a, b)
48
+
49
+ # Read back to CPU
50
+ print(c.to_numpy()) # [4. 5. 6. 7. 8.]
51
+
52
+ # Matrix multiply
53
+ A = gp.ones((512, 512))
54
+ B = gp.ones((512, 512))
55
+ C = gp.matmul(A, B) # runs on GPU
56
+
57
+ # Reductions
58
+ total = gp.sum(a)
59
+ avg = gp.mean(a)
60
+
61
+ # Math functions
62
+ x = gp.exp(a)
63
+ y = gp.log(a)
64
+ z = gp.sqrt(a)
65
+ ```
66
+
67
+ ## Why?
68
+
69
+ **CuPy** only works on NVIDIA GPUs with CUDA. **gpuarray** works on every GPU:
70
+
71
+ | GPU | CuPy | gpuarray |
72
+ |-----|------|----------|
73
+ | NVIDIA (CUDA) | ✓ | ✓ |
74
+ | AMD (Vulkan) | ✗ | ✓ |
75
+ | Intel (Vulkan) | ✗ | ✓ |
76
+ | Apple Silicon (Metal) | ✗ | ✓ |
77
+
78
+ ## Supported Operations
79
+
80
+ ### Array Creation
81
+ `array`, `zeros`, `ones`, `arange`, `linspace`
82
+
83
+ ### Elementwise Binary
84
+ `+`, `-`, `*`, `/`, `**` (with arrays or scalars)
85
+
86
+ ### Elementwise Unary
87
+ `exp`, `log`, `sqrt`, `abs`, `neg`, `relu`, `sigmoid`, `tanh`
88
+
89
+ ### Reductions
90
+ `sum`, `mean`, `max`, `min`
91
+
92
+ ### Linear Algebra
93
+ `dot`, `matmul`
94
+
95
+ ## Performance
96
+
97
+ Benchmarks on Intel UHD 630 (integrated GPU) vs NumPy (CPU with SIMD):
98
+
99
+ | Operation | NumPy | gpuarray | Speedup |
100
+ |-----------|-------|----------|---------|
101
+ | add 10M elements | 11.6ms | 19.9ms | 0.59x |
102
+ | matmul 512x512 | 1.3ms | 1.0ms | **1.22x** |
103
+ | sum 10M | 4.3ms | 12.5ms | 0.34x |
104
+
105
+ The integrated GPU shows speedup on compute-heavy operations (matmul). Discrete GPUs (RTX 3080, RX 7900, etc.) will show much larger speedups across all operations.
106
+
107
+ ## Requirements
108
+
109
+ - Python 3.10-3.13
110
+ - Any GPU supported by WebGPU (most GPUs from 2015+)
111
+ - No CUDA, no special drivers — just your system GPU
112
+
113
+ ## How It Works
114
+
115
+ 1. Arrays are stored as WebGPU GPU buffers
116
+ 2. Operations dispatch WGSL compute shaders to the GPU
117
+ 3. Pipelines are cached — repeated operations don't recompile
118
+ 4. Results stay on GPU until you call `.to_numpy()`
119
+
120
+ ## License
121
+
122
+ MIT
@@ -0,0 +1,100 @@
1
+ # gpuarray
2
+
3
+ NumPy-like GPU array library that works on **every GPU** — NVIDIA, AMD, Intel, Apple Silicon. No CUDA required.
4
+
5
+ Powered by [WebGPU](https://www.w3.org/TR/webgpu/) via [wgpu-py](https://github.com/pygfx/wgpu-py). Uses Metal on macOS, Vulkan on Windows/Linux, and DirectX 12 on Windows.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pip install gpuarray
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```python
16
+ import gpuarray as gp
17
+
18
+ # Create arrays on GPU
19
+ a = gp.array([1, 2, 3, 4, 5])
20
+ b = gp.ones(5) * 3
21
+
22
+ # Operations run on GPU
23
+ c = a + b
24
+ d = a * b
25
+ e = gp.dot(a, b)
26
+
27
+ # Read back to CPU
28
+ print(c.to_numpy()) # [4. 5. 6. 7. 8.]
29
+
30
+ # Matrix multiply
31
+ A = gp.ones((512, 512))
32
+ B = gp.ones((512, 512))
33
+ C = gp.matmul(A, B) # runs on GPU
34
+
35
+ # Reductions
36
+ total = gp.sum(a)
37
+ avg = gp.mean(a)
38
+
39
+ # Math functions
40
+ x = gp.exp(a)
41
+ y = gp.log(a)
42
+ z = gp.sqrt(a)
43
+ ```
44
+
45
+ ## Why?
46
+
47
+ **CuPy** only works on NVIDIA GPUs with CUDA. **gpuarray** works on every GPU:
48
+
49
+ | GPU | CuPy | gpuarray |
50
+ |-----|------|----------|
51
+ | NVIDIA (CUDA) | ✓ | ✓ |
52
+ | AMD (Vulkan) | ✗ | ✓ |
53
+ | Intel (Vulkan) | ✗ | ✓ |
54
+ | Apple Silicon (Metal) | ✗ | ✓ |
55
+
56
+ ## Supported Operations
57
+
58
+ ### Array Creation
59
+ `array`, `zeros`, `ones`, `arange`, `linspace`
60
+
61
+ ### Elementwise Binary
62
+ `+`, `-`, `*`, `/`, `**` (with arrays or scalars)
63
+
64
+ ### Elementwise Unary
65
+ `exp`, `log`, `sqrt`, `abs`, `neg`, `relu`, `sigmoid`, `tanh`
66
+
67
+ ### Reductions
68
+ `sum`, `mean`, `max`, `min`
69
+
70
+ ### Linear Algebra
71
+ `dot`, `matmul`
72
+
73
+ ## Performance
74
+
75
+ Benchmarks on Intel UHD 630 (integrated GPU) vs NumPy (CPU with SIMD):
76
+
77
+ | Operation | NumPy | gpuarray | Speedup |
78
+ |-----------|-------|----------|---------|
79
+ | add 10M elements | 11.6ms | 19.9ms | 0.59x |
80
+ | matmul 512x512 | 1.3ms | 1.0ms | **1.22x** |
81
+ | sum 10M | 4.3ms | 12.5ms | 0.34x |
82
+
83
+ The integrated GPU shows speedup on compute-heavy operations (matmul). Discrete GPUs (RTX 3080, RX 7900, etc.) will show much larger speedups across all operations.
84
+
85
+ ## Requirements
86
+
87
+ - Python 3.10-3.13
88
+ - Any GPU supported by WebGPU (most GPUs from 2015+)
89
+ - No CUDA, no special drivers — just your system GPU
90
+
91
+ ## How It Works
92
+
93
+ 1. Arrays are stored as WebGPU GPU buffers
94
+ 2. Operations dispatch WGSL compute shaders to the GPU
95
+ 3. Pipelines are cached — repeated operations don't recompile
96
+ 4. Results stay on GPU until you call `.to_numpy()`
97
+
98
+ ## License
99
+
100
+ MIT
@@ -0,0 +1,47 @@
1
+ """gpuarray — WebGPU-accelerated NumPy replacement."""
2
+
3
+ from .core import GPUArray
4
+ from .api import (
5
+ array,
6
+ zeros,
7
+ ones,
8
+ arange,
9
+ linspace,
10
+ dot,
11
+ matmul,
12
+ sum,
13
+ mean,
14
+ exp,
15
+ log,
16
+ sqrt,
17
+ abs,
18
+ max,
19
+ min,
20
+ relu,
21
+ sigmoid,
22
+ tanh,
23
+ )
24
+
25
+ __version__ = "0.1.0"
26
+
27
+ __all__ = [
28
+ "GPUArray",
29
+ "array",
30
+ "zeros",
31
+ "ones",
32
+ "arange",
33
+ "linspace",
34
+ "dot",
35
+ "matmul",
36
+ "sum",
37
+ "mean",
38
+ "exp",
39
+ "log",
40
+ "sqrt",
41
+ "abs",
42
+ "max",
43
+ "min",
44
+ "relu",
45
+ "sigmoid",
46
+ "tanh",
47
+ ]
@@ -0,0 +1,99 @@
1
+ """NumPy-compatible module-level functions."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Sequence
6
+
7
+ import numpy as np
8
+
9
+ from .core import GPUArray, _from_numpy, matmul as _matmul
10
+ from . import shaders
11
+
12
+
13
+ # ----- creation functions -----
14
+
15
+ def array(data) -> GPUArray:
16
+ """Create a GPUArray from a list, nested list, or numpy array."""
17
+ if isinstance(data, GPUArray):
18
+ return data
19
+ arr = np.asarray(data, dtype=np.float32)
20
+ if arr.ndim == 0:
21
+ arr = arr.reshape((1,))
22
+ return _from_numpy(arr)
23
+
24
+
25
+ def zeros(shape) -> GPUArray:
26
+ if isinstance(shape, int):
27
+ shape = (shape,)
28
+ return _from_numpy(np.zeros(shape, dtype=np.float32))
29
+
30
+
31
+ def ones(shape) -> GPUArray:
32
+ if isinstance(shape, int):
33
+ shape = (shape,)
34
+ return _from_numpy(np.ones(shape, dtype=np.float32))
35
+
36
+
37
+ def arange(start, stop=None, step=1) -> GPUArray:
38
+ if stop is None:
39
+ stop = start
40
+ start = 0
41
+ return _from_numpy(np.arange(start, stop, step, dtype=np.float32))
42
+
43
+
44
+ def linspace(start, stop, num=50) -> GPUArray:
45
+ return _from_numpy(np.linspace(start, stop, num, dtype=np.float32))
46
+
47
+
48
+ # ----- operations -----
49
+
50
+ def dot(a: GPUArray, b: GPUArray):
51
+ return a.dot(b)
52
+
53
+
54
+ def matmul(a: GPUArray, b: GPUArray) -> GPUArray:
55
+ return _matmul(a, b)
56
+
57
+
58
+ def sum(a: GPUArray) -> float:
59
+ return a.sum()
60
+
61
+
62
+ def mean(a: GPUArray) -> float:
63
+ return a.mean()
64
+
65
+
66
+ def exp(a: GPUArray) -> GPUArray:
67
+ return a._run_unary_op(shaders.EXP_SHADER)
68
+
69
+
70
+ def log(a: GPUArray) -> GPUArray:
71
+ return a._run_unary_op(shaders.LOG_SHADER)
72
+
73
+
74
+ def sqrt(a: GPUArray) -> GPUArray:
75
+ return a._run_unary_op(shaders.SQRT_SHADER)
76
+
77
+
78
+ def abs(a: GPUArray) -> GPUArray:
79
+ return a._run_unary_op(shaders.ABS_SHADER)
80
+
81
+
82
+ def max(a: GPUArray) -> float:
83
+ return a.max()
84
+
85
+
86
+ def min(a: GPUArray) -> float:
87
+ return a.min()
88
+
89
+
90
+ def relu(a: GPUArray) -> GPUArray:
91
+ return a._run_unary_op(shaders.RELU_SHADER)
92
+
93
+
94
+ def sigmoid(a: GPUArray) -> GPUArray:
95
+ return a._run_unary_op(shaders.SIGMOID_SHADER)
96
+
97
+
98
+ def tanh(a: GPUArray) -> GPUArray:
99
+ return a._run_unary_op(shaders.TANH_SHADER)