spatial-computing 0.10.0__tar.gz → 0.12.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.
- {spatial_computing-0.10.0/spatial_computing.egg-info → spatial_computing-0.12.0}/PKG-INFO +3 -2
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/README.md +2 -1
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/pyproject.toml +4 -1
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/__init__.py +1 -1
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/cli.py +8 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/compute/workloads.py +69 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/core/registry.py +9 -0
- spatial_computing-0.12.0/spatial/fabric/__init__.py +8 -0
- spatial_computing-0.12.0/spatial/fabric/cuda.py +40 -0
- spatial_computing-0.12.0/spatial/fabric/devices.py +35 -0
- spatial_computing-0.12.0/spatial/fabric/metal.py +85 -0
- spatial_computing-0.12.0/spatial/fabric/metal_mandel.swift +82 -0
- spatial_computing-0.12.0/spatial/fabric/metal_run.swift +52 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/fleet/hub.py +126 -14
- spatial_computing-0.12.0/spatial/interconnect/__init__.py +10 -0
- spatial_computing-0.12.0/spatial/interconnect/collectives.py +102 -0
- spatial_computing-0.12.0/spatial/interconnect/comm.py +114 -0
- spatial_computing-0.12.0/spatial/interconnect/model.py +77 -0
- spatial_computing-0.12.0/spatial/interconnect/tasks.py +72 -0
- spatial_computing-0.12.0/spatial/kernel/__init__.py +3 -0
- spatial_computing-0.12.0/spatial/kernel/dsl.py +389 -0
- spatial_computing-0.12.0/spatial/kernel/library.py +46 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/unified/model.py +1 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/unified/providers.py +27 -4
- {spatial_computing-0.10.0 → spatial_computing-0.12.0/spatial_computing.egg-info}/PKG-INFO +3 -2
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial_computing.egg-info/SOURCES.txt +17 -0
- spatial_computing-0.12.0/tests/test_fabric.py +64 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/tests/test_fleet.py +64 -0
- spatial_computing-0.12.0/tests/test_interconnect.py +50 -0
- spatial_computing-0.12.0/tests/test_kernel.py +96 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/LICENSE +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/setup.cfg +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/ai/__init__.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/ai/kvcache.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/compute/__init__.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/compute/cost.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/compute/detect.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/compute/monitor.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/compute/scheduler.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/compute/taskqueue.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/compute/worker.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/core/__init__.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/core/auth.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/core/energy.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/core/ledger.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/core/model.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/core/protocol.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/fleet/__init__.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/fleet/agent.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/holographic/__init__.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/holographic/cgh.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/holographic/model.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/intelligence/__init__.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/intelligence/predictor.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/memory/__init__.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/memory/fararray.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/memory/pageserver.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/memory/secure.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/memory/shared.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/memory/tiered.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/q/__init__.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/q/__main__.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/q/backends/__init__.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/q/codegen.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/q/compiler.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/q/ir.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/q/lexer.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/q/parser.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/q/qir.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/q/runtime.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/q/sim.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/runtime/__init__.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/runtime/envs.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/runtime/inspect.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/runtime/microvm.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/runtime/planner.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/runtime/runner.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/runtime/toolchain.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/scientific/__init__.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/scientific/jobs.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/simulation/__init__.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/simulation/heat.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/simulation/nbody.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/unified/__init__.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial/unified/planner.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial_computing.egg-info/dependency_links.txt +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial_computing.egg-info/entry_points.txt +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial_computing.egg-info/requires.txt +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/spatial_computing.egg-info/top_level.txt +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/tests/test_auth.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/tests/test_compute.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/tests/test_core.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/tests/test_domains.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/tests/test_engines.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/tests/test_memory.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/tests/test_optimizer.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/tests/test_q.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/tests/test_runtime.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/tests/test_unified.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/tests/test_v02.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/tests/test_v03.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/tests/test_v05.py +0 -0
- {spatial_computing-0.10.0 → spatial_computing-0.12.0}/tests/test_v07.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: spatial-computing
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.12.0
|
|
4
4
|
Summary: Spatial Computing: open-source infrastructure efficiency toolkit. Measure, decide, prove (compute, tiered memory, runtime routing, hybrid quantum language)
|
|
5
5
|
Author: Spatial Computing contributors
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -37,7 +37,7 @@ Dynamic: license-file
|
|
|
37
37
|
|
|
38
38
|
One objective for the whole infrastructure: get every job done correctly at the lowest cost, and prove it. Spatial Computing prices every way to run a job across compute, memory, runtime, quantum, AI, science and a fleet of machines, picks the cheapest, and records the estimate next to what really happened. A gain is claimed only when it is measured. It does not add RAM, cores or GPUs: it compares execution strategies on the hardware you have, trades one resource for another in numbers, and says plainly what it cannot do.
|
|
39
39
|
|
|
40
|
-
> **Status: v0.
|
|
40
|
+
> **Status: v0.12.0, early-stage open-source toolkit.** Everything here was built and measured on a single 2017 MacBook Pro (Intel i7-7660U, 2 cores, 16 GB). Nothing has been proven on a second machine, a data-center GPU or a real quantum computer. See [Limitations](docs/LIMITATIONS.md) and the [site](https://spatial-computing-ecru.vercel.app).
|
|
41
41
|
|
|
42
42
|
[Français](README.fr.md)
|
|
43
43
|
|
|
@@ -93,6 +93,7 @@ st.put(0, b"..." * 1000); st.get(0); print(st.stats())
|
|
|
93
93
|
|
|
94
94
|
| Engine | Level | Evidence |
|
|
95
95
|
|---|---|---|
|
|
96
|
+
| Virtual accelerator fabric (one job, several devices: CPU, Metal GPU, NVIDIA when present) | first components | `tests/test_fabric.py`, `benchmarks/bench_unified.py` |
|
|
96
97
|
| Planner (the one objective: price every option across all engines, choose, run, check) | operational prototype | `tests/test_unified.py`, `benchmarks/bench_unified.py` |
|
|
97
98
|
| Fleet (agent on every machine + hub: measure, place, recommend, audit) | operational prototype | `tests/test_fleet.py`, `benchmarks/bench_fleet.py` |
|
|
98
99
|
| Compute Engine (detect, monitor, compare strategies, offload, cost) | operational prototype | `tests/test_compute.py`, `benchmarks/bench_cpu.py` |
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
One objective for the whole infrastructure: get every job done correctly at the lowest cost, and prove it. Spatial Computing prices every way to run a job across compute, memory, runtime, quantum, AI, science and a fleet of machines, picks the cheapest, and records the estimate next to what really happened. A gain is claimed only when it is measured. It does not add RAM, cores or GPUs: it compares execution strategies on the hardware you have, trades one resource for another in numbers, and says plainly what it cannot do.
|
|
6
6
|
|
|
7
|
-
> **Status: v0.
|
|
7
|
+
> **Status: v0.12.0, early-stage open-source toolkit.** Everything here was built and measured on a single 2017 MacBook Pro (Intel i7-7660U, 2 cores, 16 GB). Nothing has been proven on a second machine, a data-center GPU or a real quantum computer. See [Limitations](docs/LIMITATIONS.md) and the [site](https://spatial-computing-ecru.vercel.app).
|
|
8
8
|
|
|
9
9
|
[Français](README.fr.md)
|
|
10
10
|
|
|
@@ -60,6 +60,7 @@ st.put(0, b"..." * 1000); st.get(0); print(st.stats())
|
|
|
60
60
|
|
|
61
61
|
| Engine | Level | Evidence |
|
|
62
62
|
|---|---|---|
|
|
63
|
+
| Virtual accelerator fabric (one job, several devices: CPU, Metal GPU, NVIDIA when present) | first components | `tests/test_fabric.py`, `benchmarks/bench_unified.py` |
|
|
63
64
|
| Planner (the one objective: price every option across all engines, choose, run, check) | operational prototype | `tests/test_unified.py`, `benchmarks/bench_unified.py` |
|
|
64
65
|
| Fleet (agent on every machine + hub: measure, place, recommend, audit) | operational prototype | `tests/test_fleet.py`, `benchmarks/bench_fleet.py` |
|
|
65
66
|
| Compute Engine (detect, monitor, compare strategies, offload, cost) | operational prototype | `tests/test_compute.py`, `benchmarks/bench_cpu.py` |
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "spatial-computing"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.12.0"
|
|
8
8
|
description = "Spatial Computing: open-source infrastructure efficiency toolkit. Measure, decide, prove (compute, tiered memory, runtime routing, hybrid quantum language)"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "Apache-2.0"
|
|
@@ -31,5 +31,8 @@ spatialq = "spatial.q.runtime:main"
|
|
|
31
31
|
[tool.setuptools.packages.find]
|
|
32
32
|
include = ["spatial*"]
|
|
33
33
|
|
|
34
|
+
[tool.setuptools.package-data]
|
|
35
|
+
"spatial.fabric" = ["*.swift"]
|
|
36
|
+
|
|
34
37
|
[tool.pytest.ini_options]
|
|
35
38
|
testpaths = ["tests"]
|
|
@@ -171,6 +171,13 @@ def cmd_optimize(a):
|
|
|
171
171
|
return 0
|
|
172
172
|
|
|
173
173
|
|
|
174
|
+
def cmd_devices(a):
|
|
175
|
+
from .fabric import discover
|
|
176
|
+
for d in discover():
|
|
177
|
+
print(f"{d.id:<8}{d.kind:<5}{d.vendor:<22}{d.name:<40}{'available' if d.available else 'UNAVAILABLE'}" + (f" ({d.note})" if d.note else ""))
|
|
178
|
+
return 0
|
|
179
|
+
|
|
180
|
+
|
|
174
181
|
def cmd_token(a):
|
|
175
182
|
from .core import auth
|
|
176
183
|
if a.action == "init":
|
|
@@ -248,6 +255,7 @@ def main(argv=None):
|
|
|
248
255
|
p.add_argument("--hub", help="host:port of a fleet hub: nodes become options"); p.add_argument("--token-file")
|
|
249
256
|
p.add_argument("--execute", action="store_true", help="run the chosen option and compare with the estimate")
|
|
250
257
|
p.set_defaults(fn=cmd_optimize)
|
|
258
|
+
sub.add_parser("devices", help="compute devices the planner can use on this machine (CPU, Metal GPU, NVIDIA GPU)").set_defaults(fn=cmd_devices)
|
|
251
259
|
p = sub.add_parser("agent", help="run a fleet agent: measure this machine, report to a hub, run allow-listed tasks")
|
|
252
260
|
p.add_argument("--hub", required=True, help="host:port of the hub")
|
|
253
261
|
p.add_argument("--token-file", required=True, help="shared secret file, or a scoped token with fleet:report,fleet:work")
|
|
@@ -73,6 +73,27 @@ if HAVE_NUMBA:
|
|
|
73
73
|
total += k
|
|
74
74
|
return total
|
|
75
75
|
|
|
76
|
+
@njit(cache=True, parallel=True)
|
|
77
|
+
def _mandel_f32_cpu(n, iters):
|
|
78
|
+
total = 0
|
|
79
|
+
fn = np.float32(n)
|
|
80
|
+
for i in prange(n):
|
|
81
|
+
ci = np.float32(-1.3) + np.float32(2.6) * np.float32(i) / fn
|
|
82
|
+
row = 0
|
|
83
|
+
for j in range(n):
|
|
84
|
+
cr = np.float32(-2.0) + np.float32(2.6) * np.float32(j) / fn
|
|
85
|
+
zr = np.float32(0.0)
|
|
86
|
+
zi = np.float32(0.0)
|
|
87
|
+
k = 0
|
|
88
|
+
while k < iters and zr * zr + zi * zi <= np.float32(4.0):
|
|
89
|
+
t = zr * zr - zi * zi + cr
|
|
90
|
+
zi = np.float32(2.0) * zr * zi + ci
|
|
91
|
+
zr = t
|
|
92
|
+
k += 1
|
|
93
|
+
row += k
|
|
94
|
+
total += row
|
|
95
|
+
return total
|
|
96
|
+
|
|
76
97
|
@njit(cache=True, parallel=True, fastmath=False)
|
|
77
98
|
def _mandel_nb_par(n, iters, r0, r1):
|
|
78
99
|
total = 0
|
|
@@ -102,6 +123,47 @@ def mandel_numba_parallel(n: int, iters: int, r0: int = 0, r1: int | None = None
|
|
|
102
123
|
return int(_mandel_nb_par(n, iters, r0, n if r1 is None else r1))
|
|
103
124
|
|
|
104
125
|
|
|
126
|
+
def mandel_f32_cpu(n: int, iters: int) -> int:
|
|
127
|
+
"""Fabric: float32 Mandelbrot on the CPU (Numba, all cores). Same job as the GPU variants."""
|
|
128
|
+
return int(_mandel_f32_cpu(n, iters))
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def mandel_f32_metal(n: int, iters: int) -> int:
|
|
132
|
+
"""Fabric: the same job on a Metal GPU (macOS)."""
|
|
133
|
+
from ..fabric import metal
|
|
134
|
+
return int(metal.mandel(n, iters, 1)["checksum"])
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def mandel_f32_cuda(n: int, iters: int) -> int:
|
|
138
|
+
"""Fabric: the same job on an NVIDIA GPU. Never run on real NVIDIA hardware."""
|
|
139
|
+
from ..fabric import cuda
|
|
140
|
+
if not cuda.available():
|
|
141
|
+
raise RuntimeError("no CUDA device visible to numba")
|
|
142
|
+
return cuda.mandel(n, iters)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _pk(name: str, device: str, n: int, **params) -> int:
|
|
146
|
+
from ..kernel.library import LIBRARY
|
|
147
|
+
return int(LIBRARY[name].run(device, n, **params).astype("uint64").sum())
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def pk_mandel_cpu(n: int, iters: int) -> int:
|
|
151
|
+
"""Portable kernel (spatial.kernel) on the CPU: the SAME source as the Metal variant."""
|
|
152
|
+
return _pk("mandelbrot", "cpu", n, iters=iters)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def pk_mandel_metal(n: int, iters: int) -> int:
|
|
156
|
+
return _pk("mandelbrot", "metal", n, iters=iters)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def pk_collatz_cpu(n: int, limit: int) -> int:
|
|
160
|
+
return _pk("collatz", "cpu", n, limit=limit)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def pk_collatz_metal(n: int, limit: int) -> int:
|
|
164
|
+
return _pk("collatz", "metal", n, limit=limit)
|
|
165
|
+
|
|
166
|
+
|
|
105
167
|
def montecarlo_pi(samples: int, seed: int = 0) -> float:
|
|
106
168
|
rng = np.random.default_rng(seed)
|
|
107
169
|
inside = 0
|
|
@@ -188,6 +250,13 @@ REGISTRY = {
|
|
|
188
250
|
"montecarlo_pi": montecarlo_pi,
|
|
189
251
|
"sha256_chain": sha256_chain,
|
|
190
252
|
"matmul": matmul,
|
|
253
|
+
"mandel_f32_cpu": mandel_f32_cpu,
|
|
254
|
+
"mandel_f32_metal": mandel_f32_metal,
|
|
255
|
+
"mandel_f32_cuda": mandel_f32_cuda,
|
|
256
|
+
"pk_mandel_cpu": pk_mandel_cpu,
|
|
257
|
+
"pk_mandel_metal": pk_mandel_metal,
|
|
258
|
+
"pk_collatz_cpu": pk_collatz_cpu,
|
|
259
|
+
"pk_collatz_metal": pk_collatz_metal,
|
|
191
260
|
"heat_numpy": heat_numpy,
|
|
192
261
|
"heat_numba": heat_numba,
|
|
193
262
|
"nbody": nbody,
|
|
@@ -29,6 +29,15 @@ ENGINES: list[Engine] = [
|
|
|
29
29
|
Status.OPERATIONAL_PROTOTYPE,
|
|
30
30
|
"tests/test_memory.py, benchmarks/bench_memory.py",
|
|
31
31
|
"user-space object store only; not kernel paging; single writer; no RDMA/CXL hardware"),
|
|
32
|
+
Engine("fabric", "Virtual accelerator fabric", "spatial.fabric", Status.FIRST_COMPONENTS,
|
|
33
|
+
"tests/test_fabric.py, benchmarks/bench_unified.py (FABRIC=1: 7 of 7 device choices correct)",
|
|
34
|
+
"CPU and Metal GPU tested; the NVIDIA (numba.cuda) path is written and never run on real NVIDIA hardware; one job family; no host-device transfer model"),
|
|
35
|
+
Engine("interconnect", "Virtual interconnect (collectives)", "spatial.interconnect", Status.FIRST_COMPONENTS,
|
|
36
|
+
"tests/test_interconnect.py, benchmarks/bench_interconnect.py (uncalibrated model right 1 of 6; calibrated per algorithm 4 of 6)",
|
|
37
|
+
"N = 4 and 8 processes on one machine over loopback; no real network, RDMA or GPU memory; about 3,000x slower than NVLink 5 (vendor figure); no fault tolerance"),
|
|
38
|
+
Engine("kernel", "Portable kernels", "spatial.kernel", Status.FIRST_COMPONENTS,
|
|
39
|
+
"tests/test_kernel.py, benchmarks/bench_kernel.py (planner right 4 of 6; integer kernel bit-identical CPU vs Metal)",
|
|
40
|
+
"CUDA C generated, never compiled or run; one kernel shape (2-D per-element, no shared memory or reductions)"),
|
|
32
41
|
Engine("planner", "Spatial Planner (the one objective)", "spatial.unified", Status.OPERATIONAL_PROTOTYPE,
|
|
33
42
|
"tests/test_unified.py",
|
|
34
43
|
"estimates come from probes and measured constants on one machine; calibration is a median of past ratios; no learned model; fleet and QPU pricing need the caller's prices"),
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""Virtual accelerator fabric: describe a job once, run it on whichever device is cheapest.
|
|
2
|
+
|
|
3
|
+
Devices today: the CPU (Numba), a Metal GPU (macOS, compiled on first use), an NVIDIA GPU through
|
|
4
|
+
numba.cuda (code present, NEVER RUN on real NVIDIA hardware). This is not CUDA emulation and not
|
|
5
|
+
a translation layer: each device runs its own native implementation of the same job, and the
|
|
6
|
+
planner chooses by measured cost. See docs/FABRIC.md.
|
|
7
|
+
"""
|
|
8
|
+
from .devices import Device, discover # noqa: F401
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""NVIDIA backend through numba.cuda. WRITTEN BUT NEVER RUN ON REAL NVIDIA HARDWARE: this machine
|
|
2
|
+
has none. The planner treats this variant as unavailable unless numba reports a CUDA device, and the
|
|
3
|
+
first real run is test A2 in docs/TESTS_NOT_DONE.md."""
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def available() -> bool:
|
|
8
|
+
try:
|
|
9
|
+
from numba import cuda
|
|
10
|
+
return bool(cuda.is_available())
|
|
11
|
+
except Exception:
|
|
12
|
+
return False
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def mandel(n: int, iters: int) -> int:
|
|
16
|
+
import numpy as np
|
|
17
|
+
from numba import cuda
|
|
18
|
+
|
|
19
|
+
@cuda.jit
|
|
20
|
+
def kern(out, n, iters):
|
|
21
|
+
j, i = cuda.grid(2)
|
|
22
|
+
if i >= n or j >= n:
|
|
23
|
+
return
|
|
24
|
+
ci = np.float32(-1.3) + np.float32(2.6) * np.float32(i) / np.float32(n)
|
|
25
|
+
cr = np.float32(-2.0) + np.float32(2.6) * np.float32(j) / np.float32(n)
|
|
26
|
+
zr = np.float32(0.0)
|
|
27
|
+
zi = np.float32(0.0)
|
|
28
|
+
k = 0
|
|
29
|
+
while k < iters and zr * zr + zi * zi <= np.float32(4.0):
|
|
30
|
+
t = zr * zr - zi * zi + cr
|
|
31
|
+
zi = np.float32(2.0) * zr * zi + ci
|
|
32
|
+
zr = t
|
|
33
|
+
k += 1
|
|
34
|
+
out[i, j] = k
|
|
35
|
+
|
|
36
|
+
d = cuda.device_array((n, n), dtype=np.uint32)
|
|
37
|
+
tpb = (16, 16)
|
|
38
|
+
kern[((n + 15) // 16, (n + 15) // 16), tpb](d, n, iters)
|
|
39
|
+
cuda.synchronize()
|
|
40
|
+
return int(d.copy_to_host().astype(np.uint64).sum())
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Discover the compute devices this machine can offer to the planner."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import platform
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
import psutil
|
|
8
|
+
|
|
9
|
+
from . import cuda, metal
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class Device:
|
|
14
|
+
id: str
|
|
15
|
+
kind: str # cpu | gpu
|
|
16
|
+
vendor: str
|
|
17
|
+
name: str
|
|
18
|
+
backend: str # numba | metal | cuda
|
|
19
|
+
available: bool
|
|
20
|
+
note: str = ""
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def discover() -> list[Device]:
|
|
24
|
+
from ..compute.detect import _nvidia_gpus
|
|
25
|
+
out = [Device("cpu", "cpu", platform.processor() or platform.machine(), f"{psutil.cpu_count(logical=False)} cores", "numba", True)]
|
|
26
|
+
if platform.system() == "Darwin":
|
|
27
|
+
ok = metal.available()
|
|
28
|
+
out.append(Device("metal", "gpu", "Apple/Intel (Metal)", (metal.device_name() or "Metal GPU") if ok else "Metal GPU", "metal", ok,
|
|
29
|
+
"" if ok else "needs swiftc"))
|
|
30
|
+
for i, g in enumerate(_nvidia_gpus()):
|
|
31
|
+
out.append(Device(f"cuda:{i}", "gpu", "NVIDIA", g["name"], "cuda", cuda.available(),
|
|
32
|
+
"" if cuda.available() else "nvidia-smi sees it but numba.cuda does not: install numba CUDA support"))
|
|
33
|
+
if not any(d.vendor == "NVIDIA" for d in out):
|
|
34
|
+
out.append(Device("cuda", "gpu", "NVIDIA", "no NVIDIA GPU detected", "cuda", False, "no nvidia-smi"))
|
|
35
|
+
return out
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""Metal compute backend (macOS): compiles the bundled Swift program once, then runs it per job."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import platform
|
|
6
|
+
import shutil
|
|
7
|
+
import subprocess
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
SRC = Path(__file__).with_name("metal_mandel.swift")
|
|
11
|
+
CACHE = Path.home() / ".cache" / "spatial"
|
|
12
|
+
BIN = CACHE / "metal_mandel"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def available() -> bool:
|
|
16
|
+
return platform.system() == "Darwin" and (BIN.exists() or shutil.which("swiftc") is not None)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def ensure_binary() -> Path:
|
|
20
|
+
if BIN.exists() and BIN.stat().st_mtime >= SRC.stat().st_mtime:
|
|
21
|
+
return BIN
|
|
22
|
+
if platform.system() != "Darwin" or not shutil.which("swiftc"):
|
|
23
|
+
raise RuntimeError("Metal backend needs macOS and swiftc")
|
|
24
|
+
CACHE.mkdir(parents=True, exist_ok=True)
|
|
25
|
+
r = subprocess.run(["swiftc", "-O", str(SRC), "-o", str(BIN)], capture_output=True, text=True, timeout=600)
|
|
26
|
+
if r.returncode != 0:
|
|
27
|
+
raise RuntimeError("swiftc failed: " + r.stderr[-300:])
|
|
28
|
+
return BIN
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def mandel(n: int, iters: int, reps: int = 1) -> dict:
|
|
32
|
+
out = subprocess.run([str(ensure_binary()), str(n), str(iters), str(reps)], capture_output=True, text=True, timeout=600)
|
|
33
|
+
try:
|
|
34
|
+
d = json.loads(out.stdout.strip().splitlines()[-1])
|
|
35
|
+
except Exception:
|
|
36
|
+
raise RuntimeError("Metal program failed: " + (out.stdout + out.stderr)[-300:])
|
|
37
|
+
if not d.get("ok"):
|
|
38
|
+
raise RuntimeError(d.get("error", "Metal error"))
|
|
39
|
+
return d
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def device_name() -> str | None:
|
|
43
|
+
try:
|
|
44
|
+
return mandel(8, 8, 1)["device"]
|
|
45
|
+
except Exception:
|
|
46
|
+
return None
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
RUN_SRC = Path(__file__).with_name("metal_run.swift")
|
|
50
|
+
RUN_BIN = CACHE / "metal_run"
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _ensure_run_binary() -> Path:
|
|
54
|
+
if RUN_BIN.exists() and RUN_BIN.stat().st_mtime >= RUN_SRC.stat().st_mtime:
|
|
55
|
+
return RUN_BIN
|
|
56
|
+
if platform.system() != "Darwin" or not shutil.which("swiftc"):
|
|
57
|
+
raise RuntimeError("Metal backend needs macOS and swiftc")
|
|
58
|
+
CACHE.mkdir(parents=True, exist_ok=True)
|
|
59
|
+
r = subprocess.run(["swiftc", "-O", str(RUN_SRC), "-o", str(RUN_BIN)], capture_output=True, text=True, timeout=600)
|
|
60
|
+
if r.returncode != 0:
|
|
61
|
+
raise RuntimeError("swiftc failed: " + r.stderr[-300:])
|
|
62
|
+
return RUN_BIN
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def run_kernel(k, n: int, params: dict, reps: int = 1, timing: dict | None = None):
|
|
66
|
+
"""Run a portable Kernel (spatial.kernel) on the Metal GPU; returns the (n, n) uint32 output.
|
|
67
|
+
`timing`, if given, receives the GPU-side median seconds."""
|
|
68
|
+
import numpy as np
|
|
69
|
+
import tempfile
|
|
70
|
+
binary = _ensure_run_binary()
|
|
71
|
+
with tempfile.TemporaryDirectory() as d:
|
|
72
|
+
msl, out = Path(d) / "k.metal", Path(d) / "out.bin"
|
|
73
|
+
msl.write_text(k.to_metal())
|
|
74
|
+
args = [str(binary), str(msl), k.name, str(n), str(reps), str(out)]
|
|
75
|
+
args += [f"{t}:{float(params[p]) if t == 'float' else int(params[p])}" for p, t in k.params]
|
|
76
|
+
r = subprocess.run(args, capture_output=True, text=True, timeout=600)
|
|
77
|
+
try:
|
|
78
|
+
info = json.loads(r.stdout.strip().splitlines()[-1])
|
|
79
|
+
except Exception:
|
|
80
|
+
raise RuntimeError("Metal program failed: " + (r.stdout + r.stderr)[-300:])
|
|
81
|
+
if not info.get("ok"):
|
|
82
|
+
raise RuntimeError(info.get("error", "Metal error"))
|
|
83
|
+
if timing is not None:
|
|
84
|
+
timing.update(info)
|
|
85
|
+
return np.fromfile(out, dtype=np.uint32).reshape(n, n)
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// GPU reference workload: Mandelbrot iteration counts on the Metal GPU (float32).
|
|
2
|
+
// usage: metal_mandel <n> <iters> [reps=3]
|
|
3
|
+
// prints one JSON line. The shader is compiled at run time (no Xcode toolchain needed).
|
|
4
|
+
import Foundation
|
|
5
|
+
import CoreGraphics
|
|
6
|
+
import Metal
|
|
7
|
+
|
|
8
|
+
let shader = """
|
|
9
|
+
#include <metal_stdlib>
|
|
10
|
+
using namespace metal;
|
|
11
|
+
struct P { uint n; uint iters; };
|
|
12
|
+
kernel void mandel(device uint *out [[buffer(0)]], constant P &p [[buffer(1)]],
|
|
13
|
+
uint2 gid [[thread_position_in_grid]]) {
|
|
14
|
+
if (gid.x >= p.n || gid.y >= p.n) return;
|
|
15
|
+
float ci = -1.3f + 2.6f * float(gid.y) / float(p.n);
|
|
16
|
+
float cr = -2.0f + 2.6f * float(gid.x) / float(p.n);
|
|
17
|
+
float zr = 0.0f, zi = 0.0f;
|
|
18
|
+
uint k = 0;
|
|
19
|
+
while (k < p.iters && zr * zr + zi * zi <= 4.0f) {
|
|
20
|
+
float t = zr * zr - zi * zi + cr;
|
|
21
|
+
zi = 2.0f * zr * zi + ci;
|
|
22
|
+
zr = t;
|
|
23
|
+
k++;
|
|
24
|
+
}
|
|
25
|
+
out[gid.y * p.n + gid.x] = k;
|
|
26
|
+
}
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
struct P { var n: UInt32; var iters: UInt32 }
|
|
30
|
+
|
|
31
|
+
func now() -> Double { return Double(DispatchTime.now().uptimeNanoseconds) / 1e9 }
|
|
32
|
+
|
|
33
|
+
let args = CommandLine.arguments
|
|
34
|
+
let n = args.count > 1 ? Int(args[1])! : 1024
|
|
35
|
+
let iters = args.count > 2 ? Int(args[2])! : 300
|
|
36
|
+
let reps = max(1, args.count > 3 ? Int(args[3])! : 3)
|
|
37
|
+
|
|
38
|
+
// In a command-line tool the default device can be nil; enumerate explicitly as a fallback.
|
|
39
|
+
guard let dev = MTLCreateSystemDefaultDevice() ?? MTLCopyAllDevices().first else {
|
|
40
|
+
print("{\"ok\": false, \"error\": \"no Metal device\"}")
|
|
41
|
+
exit(1)
|
|
42
|
+
}
|
|
43
|
+
let t0 = now()
|
|
44
|
+
let lib: MTLLibrary
|
|
45
|
+
do { lib = try dev.makeLibrary(source: shader, options: nil) } catch {
|
|
46
|
+
print("{\"ok\": false, \"error\": \"shader compile failed\"}")
|
|
47
|
+
exit(1)
|
|
48
|
+
}
|
|
49
|
+
let fn = lib.makeFunction(name: "mandel")!
|
|
50
|
+
let pipe = try! dev.makeComputePipelineState(function: fn)
|
|
51
|
+
let setupS = now() - t0
|
|
52
|
+
|
|
53
|
+
let out = dev.makeBuffer(length: n * n * 4, options: .storageModeShared)!
|
|
54
|
+
var p = P(n: UInt32(n), iters: UInt32(iters))
|
|
55
|
+
let queue = dev.makeCommandQueue()!
|
|
56
|
+
|
|
57
|
+
func run() -> Double {
|
|
58
|
+
let t = now()
|
|
59
|
+
let cb = queue.makeCommandBuffer()!
|
|
60
|
+
let enc = cb.makeComputeCommandEncoder()!
|
|
61
|
+
enc.setComputePipelineState(pipe)
|
|
62
|
+
enc.setBuffer(out, offset: 0, index: 0)
|
|
63
|
+
enc.setBytes(&p, length: MemoryLayout<P>.size, index: 1)
|
|
64
|
+
let w = pipe.threadExecutionWidth
|
|
65
|
+
let h = pipe.maxTotalThreadsPerThreadgroup / w
|
|
66
|
+
enc.dispatchThreadgroups(MTLSize(width: (n + w - 1) / w, height: (n + h - 1) / h, depth: 1),
|
|
67
|
+
threadsPerThreadgroup: MTLSize(width: w, height: h, depth: 1))
|
|
68
|
+
enc.endEncoding()
|
|
69
|
+
cb.commit()
|
|
70
|
+
cb.waitUntilCompleted()
|
|
71
|
+
return now() - t
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
var times: [Double] = []
|
|
75
|
+
for _ in 0..<reps { times.append(run()) }
|
|
76
|
+
let ptr = out.contents().bindMemory(to: UInt32.self, capacity: n * n)
|
|
77
|
+
var total: UInt64 = 0
|
|
78
|
+
for i in 0..<(n * n) { total += UInt64(ptr[i]) }
|
|
79
|
+
times.sort()
|
|
80
|
+
print("{\"ok\": true, \"device\": \"\(dev.name)\", \"n\": \(n), \"iters\": \(iters), \"checksum\": \(total), " +
|
|
81
|
+
"\"gpu_s_median\": \(times[times.count / 2]), \"gpu_s_all\": \(times), \"setup_s\": \(setupS), " +
|
|
82
|
+
"\"low_power\": \(dev.isLowPower), \"max_buffer_MB\": \(dev.maxBufferLength / 1_000_000)}")
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Generic Metal host for portable kernels generated by spatial.kernel.
|
|
2
|
+
// usage: metal_run <msl_file> <kernel_name> <n> <reps> <out_file> [int:<v> | float:<v> ...]
|
|
3
|
+
// Buffers: 0 = output uint[n*n], 1 = n (int), 2.. = parameters in order. Writes raw uint32 to <out_file>.
|
|
4
|
+
import Foundation
|
|
5
|
+
import Metal
|
|
6
|
+
|
|
7
|
+
func now() -> Double { return Double(DispatchTime.now().uptimeNanoseconds) / 1e9 }
|
|
8
|
+
func fail(_ m: String) -> Never { print("{\"ok\": false, \"error\": \"\(m)\"}"); exit(1) }
|
|
9
|
+
|
|
10
|
+
let a = CommandLine.arguments
|
|
11
|
+
if a.count < 6 { fail("usage") }
|
|
12
|
+
guard let src = try? String(contentsOfFile: a[1], encoding: .utf8) else { fail("cannot read msl") }
|
|
13
|
+
let name = a[2], n = Int(a[3])!, reps = max(1, Int(a[4])!), outPath = a[5]
|
|
14
|
+
guard let dev = MTLCreateSystemDefaultDevice() ?? MTLCopyAllDevices().first else { fail("no Metal device") }
|
|
15
|
+
let t0 = now()
|
|
16
|
+
let lib: MTLLibrary
|
|
17
|
+
do { lib = try dev.makeLibrary(source: src, options: nil) } catch {
|
|
18
|
+
let msg = "\(error)".replacingOccurrences(of: "\"", with: "'").replacingOccurrences(of: "\n", with: " ")
|
|
19
|
+
fail("shader compile failed: " + String(msg.prefix(300)))
|
|
20
|
+
}
|
|
21
|
+
guard let fn = lib.makeFunction(name: name) else { fail("kernel not found") }
|
|
22
|
+
let pipe = try! dev.makeComputePipelineState(function: fn)
|
|
23
|
+
let setupS = now() - t0
|
|
24
|
+
let out = dev.makeBuffer(length: n * n * 4, options: .storageModeShared)!
|
|
25
|
+
let queue = dev.makeCommandQueue()!
|
|
26
|
+
var nn = Int32(n)
|
|
27
|
+
|
|
28
|
+
func run() -> Double {
|
|
29
|
+
let t = now()
|
|
30
|
+
let cb = queue.makeCommandBuffer()!
|
|
31
|
+
let enc = cb.makeComputeCommandEncoder()!
|
|
32
|
+
enc.setComputePipelineState(pipe)
|
|
33
|
+
enc.setBuffer(out, offset: 0, index: 0)
|
|
34
|
+
enc.setBytes(&nn, length: 4, index: 1)
|
|
35
|
+
for (k, spec) in a[6...].enumerated() {
|
|
36
|
+
let parts = spec.split(separator: ":", maxSplits: 1).map(String.init)
|
|
37
|
+
if parts[0] == "int" { var v = Int32(parts[1])!; enc.setBytes(&v, length: 4, index: 2 + k) }
|
|
38
|
+
else { var v = Float(parts[1])!; enc.setBytes(&v, length: 4, index: 2 + k) }
|
|
39
|
+
}
|
|
40
|
+
let w = pipe.threadExecutionWidth
|
|
41
|
+
let h = pipe.maxTotalThreadsPerThreadgroup / w
|
|
42
|
+
enc.dispatchThreadgroups(MTLSize(width: (n + w - 1) / w, height: (n + h - 1) / h, depth: 1),
|
|
43
|
+
threadsPerThreadgroup: MTLSize(width: w, height: h, depth: 1))
|
|
44
|
+
enc.endEncoding(); cb.commit(); cb.waitUntilCompleted()
|
|
45
|
+
return now() - t
|
|
46
|
+
}
|
|
47
|
+
var times: [Double] = []
|
|
48
|
+
for _ in 0..<reps { times.append(run()) }
|
|
49
|
+
let data = Data(bytes: out.contents(), count: n * n * 4)
|
|
50
|
+
do { try data.write(to: URL(fileURLWithPath: outPath)) } catch { fail("cannot write output") }
|
|
51
|
+
times.sort()
|
|
52
|
+
print("{\"ok\": true, \"device\": \"\(dev.name)\", \"gpu_s_median\": \(times[times.count / 2]), \"setup_s\": \(setupS)}")
|