spatial-computing 0.9.0__tar.gz → 0.11.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.9.0/spatial_computing.egg-info → spatial_computing-0.11.0}/PKG-INFO +5 -3
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/README.md +4 -2
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/pyproject.toml +4 -1
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/__init__.py +1 -1
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/cli.py +62 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/compute/workloads.py +101 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/core/registry.py +6 -0
- spatial_computing-0.11.0/spatial/fabric/__init__.py +8 -0
- spatial_computing-0.11.0/spatial/fabric/cuda.py +40 -0
- spatial_computing-0.11.0/spatial/fabric/devices.py +35 -0
- spatial_computing-0.11.0/spatial/fabric/metal.py +46 -0
- spatial_computing-0.11.0/spatial/fabric/metal_mandel.swift +82 -0
- spatial_computing-0.11.0/spatial/unified/__init__.py +11 -0
- spatial_computing-0.11.0/spatial/unified/model.py +161 -0
- spatial_computing-0.11.0/spatial/unified/planner.py +99 -0
- spatial_computing-0.11.0/spatial/unified/providers.py +416 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0/spatial_computing.egg-info}/PKG-INFO +5 -3
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial_computing.egg-info/SOURCES.txt +11 -0
- spatial_computing-0.11.0/tests/test_fabric.py +54 -0
- spatial_computing-0.11.0/tests/test_unified.py +162 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/LICENSE +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/setup.cfg +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/ai/__init__.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/ai/kvcache.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/compute/__init__.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/compute/cost.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/compute/detect.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/compute/monitor.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/compute/scheduler.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/compute/taskqueue.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/compute/worker.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/core/__init__.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/core/auth.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/core/energy.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/core/ledger.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/core/model.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/core/protocol.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/fleet/__init__.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/fleet/agent.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/fleet/hub.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/holographic/__init__.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/holographic/cgh.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/holographic/model.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/intelligence/__init__.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/intelligence/predictor.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/memory/__init__.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/memory/fararray.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/memory/pageserver.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/memory/secure.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/memory/shared.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/memory/tiered.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/q/__init__.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/q/__main__.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/q/backends/__init__.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/q/codegen.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/q/compiler.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/q/ir.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/q/lexer.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/q/parser.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/q/qir.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/q/runtime.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/q/sim.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/runtime/__init__.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/runtime/envs.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/runtime/inspect.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/runtime/microvm.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/runtime/planner.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/runtime/runner.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/runtime/toolchain.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/scientific/__init__.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/scientific/jobs.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/simulation/__init__.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/simulation/heat.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial/simulation/nbody.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial_computing.egg-info/dependency_links.txt +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial_computing.egg-info/entry_points.txt +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial_computing.egg-info/requires.txt +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/spatial_computing.egg-info/top_level.txt +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/tests/test_auth.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/tests/test_compute.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/tests/test_core.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/tests/test_domains.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/tests/test_engines.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/tests/test_fleet.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/tests/test_memory.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/tests/test_optimizer.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/tests/test_q.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/tests/test_runtime.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/tests/test_v02.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/tests/test_v03.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.0}/tests/test_v05.py +0 -0
- {spatial_computing-0.9.0 → spatial_computing-0.11.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.11.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
|
|
@@ -35,9 +35,9 @@ Dynamic: license-file
|
|
|
35
35
|
|
|
36
36
|
**Measure. Decide. Prove.**
|
|
37
37
|
|
|
38
|
-
Spatial Computing
|
|
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.11.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,8 @@ 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` |
|
|
97
|
+
| Planner (the one objective: price every option across all engines, choose, run, check) | operational prototype | `tests/test_unified.py`, `benchmarks/bench_unified.py` |
|
|
96
98
|
| Fleet (agent on every machine + hub: measure, place, recommend, audit) | operational prototype | `tests/test_fleet.py`, `benchmarks/bench_fleet.py` |
|
|
97
99
|
| Compute Engine (detect, monitor, compare strategies, offload, cost) | operational prototype | `tests/test_compute.py`, `benchmarks/bench_cpu.py` |
|
|
98
100
|
| Tiered memory (hot / compressed / far) | operational prototype | `tests/test_memory.py`, `benchmarks/bench_memory.py` |
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
**Measure. Decide. Prove.**
|
|
4
4
|
|
|
5
|
-
Spatial Computing
|
|
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.11.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,8 @@ 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` |
|
|
64
|
+
| Planner (the one objective: price every option across all engines, choose, run, check) | operational prototype | `tests/test_unified.py`, `benchmarks/bench_unified.py` |
|
|
63
65
|
| Fleet (agent on every machine + hub: measure, place, recommend, audit) | operational prototype | `tests/test_fleet.py`, `benchmarks/bench_fleet.py` |
|
|
64
66
|
| Compute Engine (detect, monitor, compare strategies, offload, cost) | operational prototype | `tests/test_compute.py`, `benchmarks/bench_cpu.py` |
|
|
65
67
|
| Tiered memory (hot / compressed / far) | operational prototype | `tests/test_memory.py`, `benchmarks/bench_memory.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.11.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"]
|
|
@@ -137,6 +137,47 @@ def cmd_fleet(a):
|
|
|
137
137
|
return 0
|
|
138
138
|
|
|
139
139
|
|
|
140
|
+
def cmd_optimize(a):
|
|
141
|
+
import json as _json
|
|
142
|
+
from .unified import Job, Objective, Planner, PlanError, Prices
|
|
143
|
+
prices = Prices(local_usd_per_hour=a.local_usd_per_hour, qpu_usd_per_shot=a.qpu_usd_per_shot, qpu_usd_per_task=a.qpu_usd_per_task,
|
|
144
|
+
ram_usd_gb_hour=a.ram_usd_gb_hour, storage_usd_gb_hour=a.storage_usd_gb_hour)
|
|
145
|
+
obj = Objective(minimize=a.objective, deadline_s=a.deadline, max_ram_bytes=int(a.max_ram_gib * 2**30) if a.max_ram_gib else None,
|
|
146
|
+
require_isolation=a.isolated, allow_qpu=a.allow_qpu, require_hardware=a.require_hardware)
|
|
147
|
+
hub = _hub_client(a) if a.hub else None
|
|
148
|
+
if a.job == "compute":
|
|
149
|
+
job = Job.compute(a.family, **_json.loads(a.params))
|
|
150
|
+
elif a.job == "binary":
|
|
151
|
+
job = Job.binary(a.file, a.args, a.est_native_s)
|
|
152
|
+
elif a.job == "quantum":
|
|
153
|
+
job = Job.quantum(Path(a.file).read_text(), a.kernel, _json.loads(a.kargs), a.shots)
|
|
154
|
+
elif a.job == "dataset":
|
|
155
|
+
job = Job.dataset(int(a.gib * 2**30), a.accesses, a.locality, a.hot_fraction)
|
|
156
|
+
else:
|
|
157
|
+
job = Job.kv_cache(a.prefix_tokens, a.reuse, a.horizon_h)
|
|
158
|
+
planner = Planner(prices=prices, hub=hub)
|
|
159
|
+
try:
|
|
160
|
+
plan = planner.plan(job, obj)
|
|
161
|
+
except PlanError as e:
|
|
162
|
+
print(e)
|
|
163
|
+
return 1
|
|
164
|
+
print(plan.explain())
|
|
165
|
+
if a.execute:
|
|
166
|
+
ex = planner.execute(plan)
|
|
167
|
+
err = "n/a" if ex.time_error_pct is None else f"{ex.time_error_pct:+.0f}%"
|
|
168
|
+
print(f"\nexecuted {ex.option}: {ex.wall_s:.4g} s (estimated {ex.est_time_s if ex.est_time_s is None else format(ex.est_time_s, '.4g')} s, error {err}); "
|
|
169
|
+
f"cost {ex.actual_cost_usd:.3g} $ (estimated {ex.est_cost_usd if ex.est_cost_usd is None else format(ex.est_cost_usd, '.3g')} $)")
|
|
170
|
+
print("result:", str(ex.result)[:300])
|
|
171
|
+
return 0
|
|
172
|
+
|
|
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
|
+
|
|
140
181
|
def cmd_token(a):
|
|
141
182
|
from .core import auth
|
|
142
183
|
if a.action == "init":
|
|
@@ -194,6 +235,27 @@ def main(argv=None):
|
|
|
194
235
|
p.add_argument("--port", type=int, default=0)
|
|
195
236
|
p.add_argument("--allow-remote", action="store_true", help="explicit consent to accept LAN connections")
|
|
196
237
|
p.set_defaults(fn=cmd_worker)
|
|
238
|
+
p = sub.add_parser("optimize", help="ONE objective for every engine: price each way to do a job, pick the cheapest, optionally run and check")
|
|
239
|
+
p.add_argument("job", choices=["compute", "binary", "quantum", "dataset", "kv"])
|
|
240
|
+
p.add_argument("--family", default="mandel", help="compute: mandel|heat|nbody|hologram|option|ode")
|
|
241
|
+
p.add_argument("--params", default="{}", help="compute: JSON parameters, e.g. '{\"n\":800,\"iters\":300}'")
|
|
242
|
+
p.add_argument("--file", help="binary: path; quantum: .sq file")
|
|
243
|
+
p.add_argument("args", nargs="*", help="binary: arguments")
|
|
244
|
+
p.add_argument("--est-native-s", type=float, default=1.0, help="binary: expected run time when native")
|
|
245
|
+
p.add_argument("--kernel", help="quantum: kernel name"); p.add_argument("--kargs", default="[]"); p.add_argument("--shots", type=int, default=1000)
|
|
246
|
+
p.add_argument("--gib", type=float, default=1.0, help="dataset: size in GiB"); p.add_argument("--accesses", type=int, default=100000)
|
|
247
|
+
p.add_argument("--locality", type=float, default=0.8); p.add_argument("--hot-fraction", type=float, default=0.2)
|
|
248
|
+
p.add_argument("--prefix-tokens", type=int, default=1000); p.add_argument("--reuse", type=float, default=0.5); p.add_argument("--horizon-h", type=float, default=1.0)
|
|
249
|
+
p.add_argument("--objective", choices=["cost", "time"], default="cost")
|
|
250
|
+
p.add_argument("--deadline", type=float); p.add_argument("--max-ram-gib", type=float)
|
|
251
|
+
p.add_argument("--isolated", action="store_true"); p.add_argument("--allow-qpu", action="store_true"); p.add_argument("--require-hardware", action="store_true")
|
|
252
|
+
p.add_argument("--local-usd-per-hour", type=float, default=0.134, help="price of this machine (default is an assumption)")
|
|
253
|
+
p.add_argument("--ram-usd-gb-hour", type=float, default=0.0); p.add_argument("--storage-usd-gb-hour", type=float, default=0.0)
|
|
254
|
+
p.add_argument("--qpu-usd-per-shot", type=float, default=0.0); p.add_argument("--qpu-usd-per-task", type=float, default=0.0)
|
|
255
|
+
p.add_argument("--hub", help="host:port of a fleet hub: nodes become options"); p.add_argument("--token-file")
|
|
256
|
+
p.add_argument("--execute", action="store_true", help="run the chosen option and compare with the estimate")
|
|
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)
|
|
197
259
|
p = sub.add_parser("agent", help="run a fleet agent: measure this machine, report to a hub, run allow-listed tasks")
|
|
198
260
|
p.add_argument("--hub", required=True, help="host:port of the hub")
|
|
199
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,25 @@ 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
|
+
|
|
105
145
|
def montecarlo_pi(samples: int, seed: int = 0) -> float:
|
|
106
146
|
rng = np.random.default_rng(seed)
|
|
107
147
|
inside = 0
|
|
@@ -130,12 +170,73 @@ def matmul(n: int, seed: int = 0) -> float:
|
|
|
130
170
|
return float((a @ b).trace())
|
|
131
171
|
|
|
132
172
|
|
|
173
|
+
def heat_numpy(n: int, steps: int, c: float = 0.2) -> float:
|
|
174
|
+
"""Simulation engine: 2-D heat diffusion from a hot square; returns the peak temperature."""
|
|
175
|
+
import numpy as np
|
|
176
|
+
from ..simulation.heat import simulate
|
|
177
|
+
u0 = np.zeros((n, n))
|
|
178
|
+
u0[n // 2 - n // 10: n // 2 + n // 10 + 1, n // 2 - n // 10: n // 2 + n // 10 + 1] = 100.0
|
|
179
|
+
return float(simulate(u0, c, steps, "numpy").max())
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def heat_numba(n: int, steps: int, c: float = 0.2) -> float:
|
|
183
|
+
import numpy as np
|
|
184
|
+
from ..simulation.heat import simulate
|
|
185
|
+
u0 = np.zeros((n, n))
|
|
186
|
+
u0[n // 2 - n // 10: n // 2 + n // 10 + 1, n // 2 - n // 10: n // 2 + n // 10 + 1] = 100.0
|
|
187
|
+
return float(simulate(u0, c, steps, "numba").max())
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def nbody(bodies: int, steps: int, seed: int = 1) -> float:
|
|
191
|
+
"""Simulation engine: relative energy drift of a leapfrog N-body run (should be tiny)."""
|
|
192
|
+
import numpy as np
|
|
193
|
+
from ..simulation import nbody as nb
|
|
194
|
+
rng = np.random.default_rng(seed)
|
|
195
|
+
pos, vel, mass = rng.normal(size=(bodies, 3)), rng.normal(size=(bodies, 3)) * 0.1, rng.uniform(0.5, 1.5, bodies)
|
|
196
|
+
e0 = nb.energy(pos, vel, mass, 0.05)
|
|
197
|
+
p, v = nb.leapfrog(pos, vel, mass, dt=1e-3, steps=steps, soft=0.05)
|
|
198
|
+
return float(abs(nb.energy(p, v, mass, 0.05) - e0) / abs(e0))
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def hologram_peak(n: int, seed: int = 1) -> int:
|
|
202
|
+
"""Holographic engine: synthesise a 1-point hologram, reconstruct it, return the focus position
|
|
203
|
+
(row * n + column) of the brightest pixel (it must be the emitter's pixel)."""
|
|
204
|
+
import numpy as np
|
|
205
|
+
from ..holographic import hologram, reconstruct
|
|
206
|
+
wl, pitch = 633e-9, 8e-6
|
|
207
|
+
k = int(np.random.default_rng(seed).integers(-n // 8, n // 8 + 1))
|
|
208
|
+
H = hologram(np.array([[k * pitch, 0.0, 0.05]]), np.array([1.0]), n, pitch, wl)
|
|
209
|
+
img = reconstruct(H, 0.05, pitch, wl)
|
|
210
|
+
return int(np.argmax(img))
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def option_mc(paths: int, seed: int = 0) -> float:
|
|
214
|
+
"""Scientific engine: Monte-Carlo European call price (Black-Scholes reference exists in tests)."""
|
|
215
|
+
from ..scientific import european_call_mc
|
|
216
|
+
return float(european_call_mc(100.0, 105.0, 0.03, 0.2, 1.0, paths, seed)[0])
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def harmonic_rk4_x(omega: float, t_end: float, steps: int) -> float:
|
|
220
|
+
"""Scientific engine: RK4 solution of x'' = -omega^2 x at t_end (exact: cos(omega * t_end))."""
|
|
221
|
+
from ..scientific import harmonic_rk4
|
|
222
|
+
return float(harmonic_rk4(omega, t_end, steps)[0])
|
|
223
|
+
|
|
224
|
+
|
|
133
225
|
REGISTRY = {
|
|
134
226
|
"mandel_python": mandel_python,
|
|
135
227
|
"mandel_numpy": mandel_numpy,
|
|
136
228
|
"montecarlo_pi": montecarlo_pi,
|
|
137
229
|
"sha256_chain": sha256_chain,
|
|
138
230
|
"matmul": matmul,
|
|
231
|
+
"mandel_f32_cpu": mandel_f32_cpu,
|
|
232
|
+
"mandel_f32_metal": mandel_f32_metal,
|
|
233
|
+
"mandel_f32_cuda": mandel_f32_cuda,
|
|
234
|
+
"heat_numpy": heat_numpy,
|
|
235
|
+
"heat_numba": heat_numba,
|
|
236
|
+
"nbody": nbody,
|
|
237
|
+
"hologram_peak": hologram_peak,
|
|
238
|
+
"option_mc": option_mc,
|
|
239
|
+
"harmonic_rk4": harmonic_rk4_x,
|
|
139
240
|
}
|
|
140
241
|
if HAVE_NUMBA:
|
|
141
242
|
REGISTRY["mandel_numba"] = mandel_numba
|
|
@@ -29,6 +29,12 @@ 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("planner", "Spatial Planner (the one objective)", "spatial.unified", Status.OPERATIONAL_PROTOTYPE,
|
|
36
|
+
"tests/test_unified.py",
|
|
37
|
+
"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"),
|
|
32
38
|
Engine("fleet", "Spatial Fleet (agent + hub)", "spatial.fleet", Status.OPERATIONAL_PROTOTYPE,
|
|
33
39
|
"tests/test_fleet.py, benchmarks/bench_fleet.py",
|
|
34
40
|
"validated on one machine (agents on loopback); no dashboard UI; recommendations are estimates; never applies changes by itself"),
|
|
@@ -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,46 @@
|
|
|
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
|
|
@@ -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,11 @@
|
|
|
1
|
+
"""The unified planner: ONE objective for the whole infrastructure.
|
|
2
|
+
|
|
3
|
+
get the job done correctly at the lowest cost in dollars, within the stated constraints,
|
|
4
|
+
and prove it (estimate recorded next to reality; future estimates corrected by that history).
|
|
5
|
+
|
|
6
|
+
Every engine plugs in through a provider that turns a job into priced options:
|
|
7
|
+
compute / simulation / scientific / holographic (numerical families), fleet (nodes), tiered memory
|
|
8
|
+
(datasets), runtime (binaries), SPATIAL Q (circuits) and the AI cache (KV prefixes).
|
|
9
|
+
"""
|
|
10
|
+
from .model import Execution, Job, Objective, Option, Plan, PlanError, Prices, Validated # noqa: F401
|
|
11
|
+
from .planner import Planner # noqa: F401
|