spatial-computing 0.13.0__tar.gz → 0.15.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.13.0/spatial_computing.egg-info → spatial_computing-0.15.0}/PKG-INFO +12 -2
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/README.md +11 -1
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/pyproject.toml +2 -1
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/__init__.py +1 -1
- spatial_computing-0.15.0/spatial/ai/llm.py +43 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/cli.py +16 -1
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/core/auth.py +21 -5
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/core/registry.py +6 -3
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/fabric/metal.py +6 -4
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/fabric/metal_run.swift +20 -11
- spatial_computing-0.15.0/spatial/fleet/ha.py +334 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/fleet/hub.py +56 -13
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/kernel/dsl.py +72 -21
- spatial_computing-0.15.0/spatial/platform/__init__.py +5 -0
- spatial_computing-0.15.0/spatial/platform/billing.py +101 -0
- spatial_computing-0.15.0/spatial/platform/db.py +61 -0
- spatial_computing-0.15.0/spatial/platform/security.py +79 -0
- spatial_computing-0.15.0/spatial/platform/server.py +386 -0
- spatial_computing-0.15.0/spatial/platform/service.py +666 -0
- spatial_computing-0.15.0/spatial/platform/static/app.js +367 -0
- spatial_computing-0.15.0/spatial/platform/static/fonts/DMMono-normal-400.woff2 +0 -0
- spatial_computing-0.15.0/spatial/platform/static/fonts/DMMono-normal-500.woff2 +0 -0
- spatial_computing-0.15.0/spatial/platform/static/fonts/InstrumentSerif-italic-400.woff2 +0 -0
- spatial_computing-0.15.0/spatial/platform/static/fonts/InstrumentSerif-normal-400.woff2 +0 -0
- spatial_computing-0.15.0/spatial/platform/static/fonts/Inter-normal-400.woff2 +0 -0
- spatial_computing-0.15.0/spatial/platform/static/fonts/Inter-normal-500.woff2 +0 -0
- spatial_computing-0.15.0/spatial/platform/static/fonts/Inter-normal-600.woff2 +0 -0
- spatial_computing-0.15.0/spatial/platform/static/fonts.css +56 -0
- spatial_computing-0.15.0/spatial/platform/static/index.html +10 -0
- spatial_computing-0.15.0/spatial/platform/static/logo.svg +1 -0
- spatial_computing-0.15.0/spatial/platform/static/style.css +75 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/runtime/planner.py +114 -4
- {spatial_computing-0.13.0 → spatial_computing-0.15.0/spatial_computing.egg-info}/PKG-INFO +12 -2
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial_computing.egg-info/SOURCES.txt +21 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/tests/test_fleet.py +38 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/tests/test_kernel.py +41 -0
- spatial_computing-0.15.0/tests/test_platform.py +508 -0
- spatial_computing-0.15.0/tests/test_quorum.py +188 -0
- spatial_computing-0.15.0/tests/test_runtime.py +122 -0
- spatial_computing-0.13.0/spatial/fleet/ha.py +0 -136
- spatial_computing-0.13.0/tests/test_runtime.py +0 -68
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/LICENSE +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/setup.cfg +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/ai/__init__.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/ai/kvcache.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/compute/__init__.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/compute/cost.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/compute/detect.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/compute/monitor.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/compute/scheduler.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/compute/taskqueue.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/compute/worker.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/compute/workloads.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/core/__init__.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/core/energy.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/core/ledger.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/core/model.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/core/protocol.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/fabric/__init__.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/fabric/cuda.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/fabric/devices.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/fabric/metal_mandel.swift +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/fleet/__init__.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/fleet/agent.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/fleet/alerts.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/fleet/dashboard.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/holographic/__init__.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/holographic/cgh.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/holographic/model.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/intelligence/__init__.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/intelligence/predictor.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/interconnect/__init__.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/interconnect/collectives.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/interconnect/comm.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/interconnect/model.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/interconnect/tasks.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/kernel/__init__.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/kernel/library.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/memory/__init__.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/memory/fararray.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/memory/pageserver.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/memory/secure.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/memory/shared.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/memory/tiered.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/q/__init__.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/q/__main__.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/q/backends/__init__.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/q/codegen.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/q/compiler.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/q/ir.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/q/lexer.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/q/parser.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/q/qir.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/q/runtime.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/q/sim.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/runtime/__init__.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/runtime/envs.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/runtime/inspect.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/runtime/microvm.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/runtime/runner.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/runtime/toolchain.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/scientific/__init__.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/scientific/jobs.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/simulation/__init__.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/simulation/heat.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/simulation/nbody.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/unified/__init__.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/unified/model.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/unified/planner.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial/unified/providers.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial_computing.egg-info/dependency_links.txt +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial_computing.egg-info/entry_points.txt +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial_computing.egg-info/requires.txt +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/spatial_computing.egg-info/top_level.txt +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/tests/test_auth.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/tests/test_compute.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/tests/test_core.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/tests/test_dashboard.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/tests/test_domains.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/tests/test_engines.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/tests/test_fabric.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/tests/test_ha.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/tests/test_hardening.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/tests/test_interconnect.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/tests/test_memory.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/tests/test_optimizer.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/tests/test_q.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/tests/test_unified.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/tests/test_v02.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/tests/test_v03.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.0}/tests/test_v05.py +0 -0
- {spatial_computing-0.13.0 → spatial_computing-0.15.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.15.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.15.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
|
|
|
@@ -68,6 +68,16 @@ curl -o busybox-x86_64 https://busybox.net/downloads/binaries/1.35.0-x86_64-linu
|
|
|
68
68
|
shasum -a 256 -c SHA256SUMS
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
+
## Console (accounts, apps, API keys, jobs, billing)
|
|
72
|
+
```bash
|
|
73
|
+
spatial token init --master-key-file hub.key
|
|
74
|
+
spatial serve hub --master-key-file hub.key --port 7700 --usage-file usage.jsonl --revoked-file revoked.txt
|
|
75
|
+
spatial platform serve --master-key-file hub.key --hub 127.0.0.1:7700 --usage-file usage.jsonl --revoked-file revoked.txt
|
|
76
|
+
# open http://127.0.0.1:8090/ : sign up, create an app, create a node key and a client key
|
|
77
|
+
spatial agent --hub 127.0.0.1:7700 --token-file node.tok # the machine appears in Fleet; submit jobs from Jobs
|
|
78
|
+
```
|
|
79
|
+
Production (hub, console, HTTPS): `docker compose --env-file deploy/.env up -d --build`. See [docs/PLATFORM.md](docs/PLATFORM.md) and [docs/DEPLOY.md](docs/DEPLOY.md).
|
|
80
|
+
|
|
71
81
|
## Use
|
|
72
82
|
|
|
73
83
|
```bash
|
|
@@ -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.15.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
|
|
|
@@ -35,6 +35,16 @@ curl -o busybox-x86_64 https://busybox.net/downloads/binaries/1.35.0-x86_64-linu
|
|
|
35
35
|
shasum -a 256 -c SHA256SUMS
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
## Console (accounts, apps, API keys, jobs, billing)
|
|
39
|
+
```bash
|
|
40
|
+
spatial token init --master-key-file hub.key
|
|
41
|
+
spatial serve hub --master-key-file hub.key --port 7700 --usage-file usage.jsonl --revoked-file revoked.txt
|
|
42
|
+
spatial platform serve --master-key-file hub.key --hub 127.0.0.1:7700 --usage-file usage.jsonl --revoked-file revoked.txt
|
|
43
|
+
# open http://127.0.0.1:8090/ : sign up, create an app, create a node key and a client key
|
|
44
|
+
spatial agent --hub 127.0.0.1:7700 --token-file node.tok # the machine appears in Fleet; submit jobs from Jobs
|
|
45
|
+
```
|
|
46
|
+
Production (hub, console, HTTPS): `docker compose --env-file deploy/.env up -d --build`. See [docs/PLATFORM.md](docs/PLATFORM.md) and [docs/DEPLOY.md](docs/DEPLOY.md).
|
|
47
|
+
|
|
38
48
|
## Use
|
|
39
49
|
|
|
40
50
|
```bash
|
|
@@ -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.15.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"
|
|
@@ -33,6 +33,7 @@ include = ["spatial*"]
|
|
|
33
33
|
|
|
34
34
|
[tool.setuptools.package-data]
|
|
35
35
|
"spatial.fabric" = ["*.swift"]
|
|
36
|
+
"spatial.platform" = ["static/*", "static/fonts/*"]
|
|
36
37
|
|
|
37
38
|
[tool.pytest.ini_options]
|
|
38
39
|
testpaths = ["tests"]
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""Client for a real inference server that speaks the llama.cpp HTTP API (llama-server). Used to measure what the toy
|
|
2
|
+
KV-cache model only simulates: how much a cached prompt prefix really saves on a real model.
|
|
3
|
+
|
|
4
|
+
Only the standard library; the server is yours (a container, a local binary). Nothing is sent anywhere else.
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
import urllib.request
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class LlmError(Exception):
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class LlamaServer:
|
|
17
|
+
def __init__(self, base_url: str = "http://127.0.0.1:8081", timeout: float = 600.0):
|
|
18
|
+
if not base_url.startswith(("http://127.0.0.1", "http://localhost", "https://")):
|
|
19
|
+
raise LlmError("refusing a plain-HTTP non-loopback server URL (use https or a loopback address)")
|
|
20
|
+
self.base, self.timeout = base_url.rstrip("/"), timeout
|
|
21
|
+
|
|
22
|
+
def _post(self, path: str, body: dict) -> dict:
|
|
23
|
+
req = urllib.request.Request(self.base + path, data=json.dumps(body).encode(), headers={"Content-Type": "application/json"}, method="POST")
|
|
24
|
+
try:
|
|
25
|
+
return json.load(urllib.request.urlopen(req, timeout=self.timeout))
|
|
26
|
+
except Exception as e:
|
|
27
|
+
raise LlmError(f"{type(e).__name__}: {e}") from e
|
|
28
|
+
|
|
29
|
+
def healthy(self) -> bool:
|
|
30
|
+
try:
|
|
31
|
+
return json.load(urllib.request.urlopen(self.base + "/health", timeout=5)).get("status") == "ok"
|
|
32
|
+
except Exception:
|
|
33
|
+
return False
|
|
34
|
+
|
|
35
|
+
def complete(self, prompt: str, n_predict: int = 8, cache_prompt: bool = True, seed: int = 0) -> dict:
|
|
36
|
+
"""One greedy completion. Returns the text and the server's own timings (prompt tokens processed, cached
|
|
37
|
+
tokens reused, milliseconds for the prompt and for the generated tokens)."""
|
|
38
|
+
r = self._post("/completion", {"prompt": prompt, "n_predict": n_predict, "temperature": 0, "top_k": 1, "seed": seed,
|
|
39
|
+
"cache_prompt": cache_prompt, "stream": False})
|
|
40
|
+
t = r.get("timings", {})
|
|
41
|
+
return {"text": r.get("content", ""), "prompt_tokens_processed": t.get("prompt_n"), "cached_tokens": t.get("cache_n", r.get("tokens_cached")),
|
|
42
|
+
"prompt_ms": t.get("prompt_ms"), "predicted_n": t.get("predicted_n"), "predicted_ms": t.get("predicted_ms"),
|
|
43
|
+
"total_prompt_tokens": r.get("tokens_evaluated")}
|
|
@@ -103,6 +103,13 @@ def cmd_agent(a):
|
|
|
103
103
|
return 0
|
|
104
104
|
|
|
105
105
|
|
|
106
|
+
def cmd_platform(a):
|
|
107
|
+
from .platform import server
|
|
108
|
+
rest = [x for x in a.rest if x != "serve"] if a.rest[:1] == ["serve"] else a.rest
|
|
109
|
+
server.main(rest)
|
|
110
|
+
return 0
|
|
111
|
+
|
|
112
|
+
|
|
106
113
|
def cmd_dashboard(a):
|
|
107
114
|
from .fleet.dashboard import Dashboard
|
|
108
115
|
d = Dashboard(a.hub, _read_token(a.token_file), port=a.port, min_severity=a.min_severity, webhook=a.webhook).start()
|
|
@@ -241,6 +248,7 @@ def cmd_worker(a):
|
|
|
241
248
|
cmd += ["--audit-log", a.audit_log]
|
|
242
249
|
if a.allow_remote:
|
|
243
250
|
cmd.append("--allow-remote")
|
|
251
|
+
cmd += a.extra # service-specific flags, e.g. the hub's --state-file, --usage-file, --peer
|
|
244
252
|
return subprocess.run(cmd).returncode
|
|
245
253
|
|
|
246
254
|
|
|
@@ -313,6 +321,9 @@ def main(argv=None):
|
|
|
313
321
|
p.add_argument("--workload"); p.add_argument("--params", default="{}"); p.add_argument("--needs", default="{}")
|
|
314
322
|
p.add_argument("--task-id", type=int)
|
|
315
323
|
p.set_defaults(fn=cmd_fleet)
|
|
324
|
+
p = sub.add_parser("platform", help="account service: sign up, sign in, apps, API keys, usage, billing (`spatial platform serve --help`)")
|
|
325
|
+
p.add_argument("rest", nargs=argparse.REMAINDER)
|
|
326
|
+
p.set_defaults(fn=cmd_platform)
|
|
316
327
|
p = sub.add_parser("dashboard", help="read-only fleet dashboard in your browser (served on 127.0.0.1 only, behind a random key)")
|
|
317
328
|
p.add_argument("--hub", required=True, help="host:port, or h1:p,h2:p for a hub pair")
|
|
318
329
|
p.add_argument("--token-file", required=True, help="scoped token with fleet:read")
|
|
@@ -335,7 +346,11 @@ def main(argv=None):
|
|
|
335
346
|
p.add_argument("--max-ops", type=int)
|
|
336
347
|
p.add_argument("--max-bytes", type=int)
|
|
337
348
|
p.set_defaults(fn=cmd_token)
|
|
338
|
-
a = ap.
|
|
349
|
+
a, extra = ap.parse_known_args(argv)
|
|
350
|
+
if getattr(a, "cmd", None) == "serve":
|
|
351
|
+
a.extra = extra # forwarded to the service
|
|
352
|
+
elif extra:
|
|
353
|
+
ap.error("unrecognized arguments: " + " ".join(extra))
|
|
339
354
|
if getattr(a, "cmd", None) == "serve" and bool(a.token_file) == bool(a.master_key_file):
|
|
340
355
|
ap.error("serve needs exactly one of --token-file or --master-key-file")
|
|
341
356
|
try:
|
|
@@ -10,7 +10,8 @@ Scopes are strings such as "run:mandel_numba", "mem:read", "mem:write", "exec:el
|
|
|
10
10
|
"*" matches a prefix ("run:*", "*"). Services call require(scope) before acting.
|
|
11
11
|
Every request (allowed or denied) is appended to a hash-chained audit ledger.
|
|
12
12
|
|
|
13
|
-
Limits:
|
|
13
|
+
Limits: usage counters live in the server process (restart resets them); revocation lives in memory unless a
|
|
14
|
+
revoked-names file is given (one name per line, re-read when it changes);
|
|
14
15
|
a stolen token works until it expires or is revoked.
|
|
15
16
|
"""
|
|
16
17
|
from __future__ import annotations
|
|
@@ -82,13 +83,28 @@ def _unb64(s: str) -> bytes:
|
|
|
82
83
|
|
|
83
84
|
|
|
84
85
|
class Authorizer:
|
|
85
|
-
def __init__(self, master_key: bytes, audit: Ledger | None = None):
|
|
86
|
+
def __init__(self, master_key: bytes, audit: Ledger | None = None, revoked_file=None):
|
|
86
87
|
if len(master_key) < 16:
|
|
87
88
|
raise ValueError("master key must be at least 16 bytes")
|
|
88
89
|
self._master = master_key
|
|
89
90
|
self.audit = audit
|
|
90
91
|
self._revoked: set[str] = set()
|
|
91
92
|
self._seen: dict[str, Principal] = {}
|
|
93
|
+
self._revoked_file, self._revoked_mtime = revoked_file, None # one name per line; edited by the account service
|
|
94
|
+
|
|
95
|
+
def _file_revoked(self, name: str) -> bool:
|
|
96
|
+
if not self._revoked_file:
|
|
97
|
+
return False
|
|
98
|
+
import os
|
|
99
|
+
try:
|
|
100
|
+
m = os.stat(self._revoked_file).st_mtime_ns
|
|
101
|
+
except OSError:
|
|
102
|
+
return False
|
|
103
|
+
if m != self._revoked_mtime:
|
|
104
|
+
with open(self._revoked_file) as f:
|
|
105
|
+
self._file_names = {l.strip() for l in f if l.strip()}
|
|
106
|
+
self._revoked_mtime = m
|
|
107
|
+
return name in getattr(self, "_file_names", ())
|
|
92
108
|
|
|
93
109
|
def _sig(self, payload: str) -> str:
|
|
94
110
|
return hmac.new(self._master, b"sig|" + payload.encode(), hashlib.sha256).hexdigest()[:32]
|
|
@@ -121,7 +137,7 @@ class Authorizer:
|
|
|
121
137
|
body = json.loads(_unb64(payload))
|
|
122
138
|
if body["e"] < time.time():
|
|
123
139
|
raise AuthError("credential expired")
|
|
124
|
-
if body["n"] in self._revoked:
|
|
140
|
+
if body["n"] in self._revoked or self._file_revoked(body["n"]):
|
|
125
141
|
raise AuthError("credential revoked")
|
|
126
142
|
if cred not in self._seen:
|
|
127
143
|
self._seen[cred] = Principal(body["n"], tuple(body["s"]), body["e"], body.get("o"), body.get("b"), cred)
|
|
@@ -164,7 +180,7 @@ def init_master_key(path) -> None:
|
|
|
164
180
|
f.write(os.urandom(32))
|
|
165
181
|
|
|
166
182
|
|
|
167
|
-
def authorizer_from_file(master_key_file, audit_path=None) -> Authorizer:
|
|
183
|
+
def authorizer_from_file(master_key_file, audit_path=None, revoked_file=None) -> Authorizer:
|
|
168
184
|
from pathlib import Path
|
|
169
185
|
audit = Ledger(audit_path) if audit_path else Ledger(Path.home() / ".spatial" / "audit.jsonl")
|
|
170
|
-
return Authorizer(Path(master_key_file).read_bytes(), audit)
|
|
186
|
+
return Authorizer(Path(master_key_file).read_bytes(), audit, revoked_file)
|
|
@@ -37,16 +37,19 @@ ENGINES: list[Engine] = [
|
|
|
37
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
38
|
Engine("kernel", "Portable kernels", "spatial.kernel", Status.FIRST_COMPONENTS,
|
|
39
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;
|
|
40
|
+
"CUDA C and HIP generated, never compiled or run; two kernel shapes (2-D map, whole-grid sum with shared memory), no tiling or tensor cores"),
|
|
41
|
+
Engine("platform", "Console and account service", "spatial.platform", Status.FIRST_COMPONENTS,
|
|
42
|
+
"tests/test_platform.py (14 tests, real hub and agent), a driven browser session",
|
|
43
|
+
"one process with SQLite; no teams, roles, two-factor or e-mail verification; payments tested against a fake Stripe API only; default prices are an example"),
|
|
41
44
|
Engine("planner", "Spatial Planner (the one objective)", "spatial.unified", Status.OPERATIONAL_PROTOTYPE,
|
|
42
45
|
"tests/test_unified.py",
|
|
43
46
|
"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"),
|
|
44
47
|
Engine("fleet", "Spatial Fleet (agent + hub)", "spatial.fleet", Status.OPERATIONAL_PROTOTYPE,
|
|
45
48
|
"tests/test_fleet.py, benchmarks/bench_fleet.py",
|
|
46
|
-
"validated on one machine (agents on loopback); HA
|
|
49
|
+
"validated on one machine (agents on loopback); HA: active/standby for two hubs, majority election (election safety, no replicated log) for three or more, tested on one machine with simulated clocks; dashboard is read-only and local; recommendations are estimates; never applies changes by itself"),
|
|
47
50
|
Engine("runtime", "Spatial Runtime Engine", "spatial.runtime", Status.OPERATIONAL_PROTOTYPE,
|
|
48
51
|
"tests/test_runtime.py, benchmarks/bench_runtime.py",
|
|
49
|
-
"Windows
|
|
52
|
+
"Windows: one console program and one GUI window (Notepad) under Wine, nothing more; containers: static Linux ELF, tested with Docker (Colima) and Podman; no GUI streaming"),
|
|
50
53
|
Engine("q", "SPATIAL Q", "spatial.q", Status.OPERATIONAL_PROTOTYPE,
|
|
51
54
|
"tests/test_q.py, benchmarks/bench_q.py",
|
|
52
55
|
"no real QPU executed (OpenQASM 3 and QIR export only); simulator limited by RAM"),
|
|
@@ -62,16 +62,16 @@ def _ensure_run_binary() -> Path:
|
|
|
62
62
|
return RUN_BIN
|
|
63
63
|
|
|
64
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.
|
|
65
|
+
def run_kernel(k, n: int, params: dict, reps: int = 1, timing: dict | None = None, reduce: bool = False):
|
|
66
|
+
"""Run a portable Kernel (spatial.kernel) on the Metal GPU; returns the (n, n) uint32 output, or with reduce=True the sum of all outputs (computed in threadgroup shared memory, partial sums added on the host).
|
|
67
67
|
`timing`, if given, receives the GPU-side median seconds."""
|
|
68
68
|
import numpy as np
|
|
69
69
|
import tempfile
|
|
70
70
|
binary = _ensure_run_binary()
|
|
71
71
|
with tempfile.TemporaryDirectory() as d:
|
|
72
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)]
|
|
73
|
+
msl.write_text(k.to_metal(reduce=reduce))
|
|
74
|
+
args = [str(binary), str(msl), k.name + ("_sum" if reduce else ""), str(n), str(reps), str(out), "sum" if reduce else "map"]
|
|
75
75
|
args += [f"{t}:{float(params[p]) if t == 'float' else int(params[p])}" for p, t in k.params]
|
|
76
76
|
r = subprocess.run(args, capture_output=True, text=True, timeout=600)
|
|
77
77
|
try:
|
|
@@ -82,4 +82,6 @@ def run_kernel(k, n: int, params: dict, reps: int = 1, timing: dict | None = Non
|
|
|
82
82
|
raise RuntimeError(info.get("error", "Metal error"))
|
|
83
83
|
if timing is not None:
|
|
84
84
|
timing.update(info)
|
|
85
|
+
if reduce:
|
|
86
|
+
return int(np.fromfile(out, dtype=np.uint64).sum())
|
|
85
87
|
return np.fromfile(out, dtype=np.uint32).reshape(n, n)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
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
|
|
2
|
+
// usage: metal_run <msl_file> <kernel_name> <n> <reps> <out_file> <map|sum> [int:<v> | float:<v> ...]
|
|
3
|
+
// Buffers: 0 = output, 1 = n (int), 2.. = parameters in order.
|
|
4
|
+
// map: output uint[n*n]. sum: one uint64 partial sum per 16x16 threadgroup (the kernel reduces in threadgroup memory).
|
|
4
5
|
import Foundation
|
|
5
6
|
import Metal
|
|
6
7
|
|
|
@@ -8,9 +9,11 @@ func now() -> Double { return Double(DispatchTime.now().uptimeNanoseconds) / 1e9
|
|
|
8
9
|
func fail(_ m: String) -> Never { print("{\"ok\": false, \"error\": \"\(m)\"}"); exit(1) }
|
|
9
10
|
|
|
10
11
|
let a = CommandLine.arguments
|
|
11
|
-
if a.count <
|
|
12
|
+
if a.count < 7 { fail("usage") }
|
|
12
13
|
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
|
+
let name = a[2], n = Int(a[3])!, reps = max(1, Int(a[4])!), outPath = a[5], mode = a[6]
|
|
15
|
+
let sumMode = (mode == "sum")
|
|
16
|
+
let gx = (n + 15) / 16
|
|
14
17
|
guard let dev = MTLCreateSystemDefaultDevice() ?? MTLCopyAllDevices().first else { fail("no Metal device") }
|
|
15
18
|
let t0 = now()
|
|
16
19
|
let lib: MTLLibrary
|
|
@@ -21,7 +24,9 @@ do { lib = try dev.makeLibrary(source: src, options: nil) } catch {
|
|
|
21
24
|
guard let fn = lib.makeFunction(name: name) else { fail("kernel not found") }
|
|
22
25
|
let pipe = try! dev.makeComputePipelineState(function: fn)
|
|
23
26
|
let setupS = now() - t0
|
|
24
|
-
|
|
27
|
+
if sumMode && pipe.maxTotalThreadsPerThreadgroup < 256 { fail("device allows fewer than 256 threads per threadgroup") }
|
|
28
|
+
let outLen = sumMode ? gx * gx * 8 : n * n * 4
|
|
29
|
+
let out = dev.makeBuffer(length: outLen, options: .storageModeShared)!
|
|
25
30
|
let queue = dev.makeCommandQueue()!
|
|
26
31
|
var nn = Int32(n)
|
|
27
32
|
|
|
@@ -32,21 +37,25 @@ func run() -> Double {
|
|
|
32
37
|
enc.setComputePipelineState(pipe)
|
|
33
38
|
enc.setBuffer(out, offset: 0, index: 0)
|
|
34
39
|
enc.setBytes(&nn, length: 4, index: 1)
|
|
35
|
-
for (k, spec) in a[
|
|
40
|
+
for (k, spec) in a[7...].enumerated() {
|
|
36
41
|
let parts = spec.split(separator: ":", maxSplits: 1).map(String.init)
|
|
37
42
|
if parts[0] == "int" { var v = Int32(parts[1])!; enc.setBytes(&v, length: 4, index: 2 + k) }
|
|
38
43
|
else { var v = Float(parts[1])!; enc.setBytes(&v, length: 4, index: 2 + k) }
|
|
39
44
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
if sumMode {
|
|
46
|
+
enc.dispatchThreadgroups(MTLSize(width: gx, height: gx, depth: 1), threadsPerThreadgroup: MTLSize(width: 16, height: 16, depth: 1))
|
|
47
|
+
} else {
|
|
48
|
+
let w = pipe.threadExecutionWidth
|
|
49
|
+
let h = pipe.maxTotalThreadsPerThreadgroup / w
|
|
50
|
+
enc.dispatchThreadgroups(MTLSize(width: (n + w - 1) / w, height: (n + h - 1) / h, depth: 1),
|
|
51
|
+
threadsPerThreadgroup: MTLSize(width: w, height: h, depth: 1))
|
|
52
|
+
}
|
|
44
53
|
enc.endEncoding(); cb.commit(); cb.waitUntilCompleted()
|
|
45
54
|
return now() - t
|
|
46
55
|
}
|
|
47
56
|
var times: [Double] = []
|
|
48
57
|
for _ in 0..<reps { times.append(run()) }
|
|
49
|
-
let data = Data(bytes: out.contents(), count:
|
|
58
|
+
let data = Data(bytes: out.contents(), count: outLen)
|
|
50
59
|
do { try data.write(to: URL(fileURLWithPath: outPath)) } catch { fail("cannot write output") }
|
|
51
60
|
times.sort()
|
|
52
61
|
print("{\"ok\": true, \"device\": \"\(dev.name)\", \"gpu_s_median\": \(times[times.count / 2]), \"setup_s\": \(setupS)}")
|