metaxuda 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,45 @@
1
+ Metadata-Version: 2.4
2
+ Name: metaxuda
3
+ Version: 0.1.0
4
+ Summary: CUDA→Metal universal backend shim (MetaXuda)
5
+ Author-email: Perinban Parameshwaran <p.perinban@gmail.com>
6
+ License: MIT
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: MacOS
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+
15
+ # MetaXuda
16
+
17
+ MetaXuda is a **CUDA runtime shim for Apple Silicon**, written in Rust, that allows **Numba CUDA kernels** to run unmodified by mapping CUDA calls to Metal.
18
+
19
+ ---
20
+
21
+ ## ✨ Features
22
+ - Drop-in replacement for `libcudart.dylib` / `libcuda.dylib`
23
+ - Run Numba CUDA kernels (`@cuda.jit`) directly on Apple Metal
24
+ - Includes precompiled Metal `.metallib` shaders for fused math ops
25
+ - Ships with a stubbed `libdevice.bc` so no CUDA Toolkit is required
26
+
27
+ ---
28
+
29
+ ## ⚙️ Installation
30
+
31
+ ### Requirements
32
+ - macOS 13+ with Apple Silicon (M1/M2/M3)
33
+ - Python >=3.10
34
+ - [NumPy](https://numpy.org/) (>=1.23)
35
+ - [Numba](https://numba.pydata.org/) (>=0.59)
36
+
37
+ ### Steps
38
+ ```bash
39
+ # Clone the repo
40
+ git clone https://github.com/perinban/MetaXuda.git
41
+ cd MetaXuda-
42
+
43
+ # Back to project root
44
+ cd ..
45
+ pip install -e .
@@ -0,0 +1,31 @@
1
+ # MetaXuda
2
+
3
+ MetaXuda is a **CUDA runtime shim for Apple Silicon**, written in Rust, that allows **Numba CUDA kernels** to run unmodified by mapping CUDA calls to Metal.
4
+
5
+ ---
6
+
7
+ ## ✨ Features
8
+ - Drop-in replacement for `libcudart.dylib` / `libcuda.dylib`
9
+ - Run Numba CUDA kernels (`@cuda.jit`) directly on Apple Metal
10
+ - Includes precompiled Metal `.metallib` shaders for fused math ops
11
+ - Ships with a stubbed `libdevice.bc` so no CUDA Toolkit is required
12
+
13
+ ---
14
+
15
+ ## ⚙️ Installation
16
+
17
+ ### Requirements
18
+ - macOS 13+ with Apple Silicon (M1/M2/M3)
19
+ - Python >=3.10
20
+ - [NumPy](https://numpy.org/) (>=1.23)
21
+ - [Numba](https://numba.pydata.org/) (>=0.59)
22
+
23
+ ### Steps
24
+ ```bash
25
+ # Clone the repo
26
+ git clone https://github.com/perinban/MetaXuda.git
27
+ cd MetaXuda-
28
+
29
+ # Back to project root
30
+ cd ..
31
+ pip install -e .
@@ -0,0 +1,15 @@
1
+ from .patch import patch_libdevice, get_libcudart_path
2
+ from .buffer import GPUMemoryBuffer
3
+ from .stream import GPUStream, DEFAULT_STREAM
4
+ from .pipeline import run_pipeline
5
+
6
+ # Apply patch at import
7
+ patch_libdevice()
8
+
9
+ __all__ = [
10
+ "GPUMemoryBuffer",
11
+ "GPUStream",
12
+ "DEFAULT_STREAM",
13
+ "run_pipeline",
14
+ "get_libcudart_path",
15
+ ]
@@ -0,0 +1,26 @@
1
+ import numpy as np
2
+ from numba import cuda
3
+
4
+ class GPUMemoryBuffer:
5
+ """
6
+ Simple GPU buffer wrapper for host ↔ device transfers.
7
+ """
8
+
9
+ def __init__(self, arr: np.ndarray):
10
+ if not isinstance(arr, np.ndarray):
11
+ raise TypeError("GPUMemoryBuffer requires a NumPy array")
12
+ self.host = arr
13
+ self.device = cuda.to_device(arr)
14
+
15
+ def download(self):
16
+ """Copy GPU data back to a new NumPy array."""
17
+ out = np.empty_like(self.host)
18
+ self.device.copy_to_host(out)
19
+ return out
20
+
21
+ def upload(self, arr: np.ndarray):
22
+ """Copy new NumPy array into this buffer."""
23
+ if arr.shape != self.host.shape or arr.dtype != self.host.dtype:
24
+ raise ValueError("Shape and dtype must match the original array")
25
+ self.device.copy_to_device(arr)
26
+ self.host = arr
File without changes
@@ -0,0 +1,59 @@
1
+ import os
2
+ import numba.cuda.cuda_paths
3
+
4
+ def setup_native_libs():
5
+ """
6
+ Ensure native libs exist:
7
+ - libdevice.bc (empty file)
8
+ - libnvvm.dylib (empty stub)
9
+ - libcuda.dylib (symlink -> libcudart.dylib)
10
+ """
11
+ base_dir = os.path.dirname(__file__)
12
+ native_dir = os.path.join(base_dir, "native")
13
+ os.makedirs(native_dir, exist_ok=True)
14
+
15
+ # libdevice.bc (always empty)
16
+ libdevice_path = os.path.join(native_dir, "libdevice.bc")
17
+ if not os.path.exists(libdevice_path):
18
+ with open(libdevice_path, "wb"):
19
+ pass
20
+
21
+ # libnvvm.dylib (empty stub)
22
+ libnvvm_path = os.path.join(native_dir, "libnvvm.dylib")
23
+ if not os.path.exists(libnvvm_path):
24
+ with open(libnvvm_path, "wb"):
25
+ pass
26
+
27
+ # libcudart.dylib (shim must be built and placed manually)
28
+ libcudart_path = os.path.join(native_dir, "libcudart.dylib")
29
+ if not os.path.exists(libcudart_path):
30
+ raise FileNotFoundError(
31
+ f"libcudart shim not found at {libcudart_path}. "
32
+ "Please place your built Rust dylib here."
33
+ )
34
+
35
+ # libcuda.dylib (symlink → libcudart.dylib)
36
+ libcuda_path = os.path.join(native_dir, "libcuda.dylib")
37
+ if not os.path.exists(libcuda_path):
38
+ os.symlink("libcudart.dylib", libcuda_path)
39
+
40
+ return native_dir, libdevice_path, libcudart_path
41
+
42
+ def patch_libdevice():
43
+ """
44
+ Monkeypatch Numba to point libdevice.bc to shim folder.
45
+ """
46
+ _, libdevice_path, _ = setup_native_libs()
47
+
48
+ from collections import namedtuple
49
+ _env_path_tuple = namedtuple("_env_path_tuple", ["by", "info"])
50
+ numba.cuda.cuda_paths._get_libdevice_paths = (
51
+ lambda: _env_path_tuple("CUSTOM_MONKEYPATCH", libdevice_path)
52
+ )
53
+
54
+ def get_libcudart_path():
55
+ """
56
+ Return the absolute path to libcudart shim (Rust-built dylib).
57
+ """
58
+ _, _, libcudart_path = setup_native_libs()
59
+ return libcudart_path
@@ -0,0 +1,13 @@
1
+ import numpy as np
2
+
3
+ def run_pipeline(ops, arr: np.ndarray):
4
+ """
5
+ Run a sequence of operations on an array.
6
+ Currently CPU fallback — in the shim backend this will be GPU fused.
7
+ Example:
8
+ run_pipeline([np.sin, np.sqrt], x)
9
+ """
10
+ out = arr
11
+ for op in ops:
12
+ out = op(out)
13
+ return out
@@ -0,0 +1,16 @@
1
+ from numba import cuda
2
+
3
+ class GPUStream:
4
+ """
5
+ Thin wrapper for cuda.stream.
6
+ """
7
+
8
+ def __init__(self):
9
+ self._stream = cuda.stream()
10
+
11
+ def sync(self):
12
+ """Synchronize the stream."""
13
+ self._stream.synchronize()
14
+
15
+ # Default global stream
16
+ DEFAULT_STREAM = GPUStream()
@@ -0,0 +1,45 @@
1
+ Metadata-Version: 2.4
2
+ Name: metaxuda
3
+ Version: 0.1.0
4
+ Summary: CUDA→Metal universal backend shim (MetaXuda)
5
+ Author-email: Perinban Parameshwaran <p.perinban@gmail.com>
6
+ License: MIT
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: MacOS
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+
15
+ # MetaXuda
16
+
17
+ MetaXuda is a **CUDA runtime shim for Apple Silicon**, written in Rust, that allows **Numba CUDA kernels** to run unmodified by mapping CUDA calls to Metal.
18
+
19
+ ---
20
+
21
+ ## ✨ Features
22
+ - Drop-in replacement for `libcudart.dylib` / `libcuda.dylib`
23
+ - Run Numba CUDA kernels (`@cuda.jit`) directly on Apple Metal
24
+ - Includes precompiled Metal `.metallib` shaders for fused math ops
25
+ - Ships with a stubbed `libdevice.bc` so no CUDA Toolkit is required
26
+
27
+ ---
28
+
29
+ ## ⚙️ Installation
30
+
31
+ ### Requirements
32
+ - macOS 13+ with Apple Silicon (M1/M2/M3)
33
+ - Python >=3.10
34
+ - [NumPy](https://numpy.org/) (>=1.23)
35
+ - [Numba](https://numba.pydata.org/) (>=0.59)
36
+
37
+ ### Steps
38
+ ```bash
39
+ # Clone the repo
40
+ git clone https://github.com/perinban/MetaXuda.git
41
+ cd MetaXuda-
42
+
43
+ # Back to project root
44
+ cd ..
45
+ pip install -e .
@@ -0,0 +1,15 @@
1
+ README.md
2
+ pyproject.toml
3
+ metaxuda/__init__.py
4
+ metaxuda/buffer.py
5
+ metaxuda/patch.py
6
+ metaxuda/pipeline.py
7
+ metaxuda/stream.py
8
+ metaxuda.egg-info/PKG-INFO
9
+ metaxuda.egg-info/SOURCES.txt
10
+ metaxuda.egg-info/dependency_links.txt
11
+ metaxuda.egg-info/top_level.txt
12
+ metaxuda/native/libcuda.dylib
13
+ metaxuda/native/libcudart.dylib
14
+ metaxuda/native/libdevice.bc
15
+ metaxuda/native/libnvvm.dylib
@@ -0,0 +1 @@
1
+ metaxuda
@@ -0,0 +1,33 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "metaxuda"
7
+ version = "0.1.0"
8
+ description = "CUDA→Metal universal backend shim (MetaXuda)"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ authors = [
12
+ { name = "Perinban Parameshwaran", email = "p.perinban@gmail.com" }
13
+ ]
14
+ license = { text = "MIT" }
15
+
16
+ classifiers = [
17
+ "Development Status :: 3 - Alpha",
18
+ "Intended Audience :: Developers",
19
+ "Programming Language :: Python :: 3",
20
+ "Operating System :: MacOS",
21
+ "License :: OSI Approved :: MIT License"
22
+ ]
23
+
24
+ [tool.setuptools]
25
+ packages = ["metaxuda"]
26
+ include-package-data = true
27
+
28
+ [tool.setuptools.package-data]
29
+ # ship your native libs & bc file
30
+ "metaxuda" = [
31
+ "native/*.dylib",
32
+ "native/*.bc"
33
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+