spatial-computing 0.18.0__tar.gz → 0.20.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.
Files changed (145) hide show
  1. {spatial_computing-0.18.0/spatial_computing.egg-info → spatial_computing-0.20.0}/PKG-INFO +1 -1
  2. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/pyproject.toml +1 -1
  3. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/__init__.py +1 -1
  4. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/compute/workloads.py +11 -0
  5. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/kernel/__init__.py +1 -1
  6. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/kernel/dsl.py +101 -7
  7. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/kernel/library.py +24 -2
  8. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/service.py +1 -0
  9. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/runtime/desktop/__init__.py +1 -1
  10. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/unified/providers.py +3 -1
  11. {spatial_computing-0.18.0 → spatial_computing-0.20.0/spatial_computing.egg-info}/PKG-INFO +1 -1
  12. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_interconnect.py +2 -1
  13. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_kernel.py +42 -2
  14. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_runtime.py +3 -3
  15. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/LICENSE +0 -0
  16. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/README.md +0 -0
  17. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/setup.cfg +0 -0
  18. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/ai/__init__.py +0 -0
  19. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/ai/kvcache.py +0 -0
  20. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/ai/llm.py +0 -0
  21. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/cli.py +0 -0
  22. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/compute/__init__.py +0 -0
  23. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/compute/cost.py +0 -0
  24. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/compute/detect.py +0 -0
  25. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/compute/monitor.py +0 -0
  26. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/compute/scheduler.py +0 -0
  27. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/compute/taskqueue.py +0 -0
  28. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/compute/worker.py +0 -0
  29. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/core/__init__.py +0 -0
  30. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/core/auth.py +0 -0
  31. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/core/energy.py +0 -0
  32. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/core/ledger.py +0 -0
  33. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/core/model.py +0 -0
  34. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/core/protocol.py +0 -0
  35. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/core/registry.py +0 -0
  36. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/fabric/__init__.py +0 -0
  37. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/fabric/cuda.py +0 -0
  38. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/fabric/devices.py +0 -0
  39. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/fabric/metal.py +0 -0
  40. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/fabric/metal_mandel.swift +0 -0
  41. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/fabric/metal_run.swift +0 -0
  42. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/fleet/__init__.py +0 -0
  43. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/fleet/agent.py +0 -0
  44. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/fleet/alerts.py +0 -0
  45. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/fleet/dashboard.py +0 -0
  46. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/fleet/ha.py +0 -0
  47. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/fleet/hub.py +0 -0
  48. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/holographic/__init__.py +0 -0
  49. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/holographic/cgh.py +0 -0
  50. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/holographic/model.py +0 -0
  51. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/intelligence/__init__.py +0 -0
  52. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/intelligence/predictor.py +0 -0
  53. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/interconnect/__init__.py +0 -0
  54. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/interconnect/collectives.py +0 -0
  55. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/interconnect/comm.py +0 -0
  56. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/interconnect/model.py +0 -0
  57. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/interconnect/tasks.py +0 -0
  58. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/memory/__init__.py +0 -0
  59. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/memory/fararray.py +0 -0
  60. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/memory/pageserver.py +0 -0
  61. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/memory/secure.py +0 -0
  62. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/memory/shared.py +0 -0
  63. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/memory/tiered.py +0 -0
  64. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/__init__.py +0 -0
  65. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/billing.py +0 -0
  66. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/db.py +0 -0
  67. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/invoice_rules.py +0 -0
  68. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/mailer.py +0 -0
  69. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/oidc.py +0 -0
  70. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/pdf.py +0 -0
  71. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/qr.py +0 -0
  72. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/security.py +0 -0
  73. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/server.py +0 -0
  74. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/static/app.js +0 -0
  75. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/static/fonts/DMMono-normal-400.woff2 +0 -0
  76. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/static/fonts/DMMono-normal-500.woff2 +0 -0
  77. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/static/fonts/InstrumentSerif-italic-400.woff2 +0 -0
  78. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/static/fonts/InstrumentSerif-normal-400.woff2 +0 -0
  79. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/static/fonts/Inter-normal-400.woff2 +0 -0
  80. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/static/fonts/Inter-normal-500.woff2 +0 -0
  81. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/static/fonts/Inter-normal-600.woff2 +0 -0
  82. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/static/fonts.css +0 -0
  83. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/static/index.html +0 -0
  84. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/static/logo.svg +0 -0
  85. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/static/style.css +0 -0
  86. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/totp.py +0 -0
  87. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/ubl.py +0 -0
  88. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/platform/vat.py +0 -0
  89. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/q/__init__.py +0 -0
  90. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/q/__main__.py +0 -0
  91. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/q/backends/__init__.py +0 -0
  92. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/q/codegen.py +0 -0
  93. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/q/compiler.py +0 -0
  94. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/q/ir.py +0 -0
  95. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/q/lexer.py +0 -0
  96. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/q/parser.py +0 -0
  97. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/q/qir.py +0 -0
  98. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/q/runtime.py +0 -0
  99. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/q/sim.py +0 -0
  100. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/runtime/__init__.py +0 -0
  101. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/runtime/desktop/Dockerfile +0 -0
  102. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/runtime/desktop/start.sh +0 -0
  103. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/runtime/envs.py +0 -0
  104. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/runtime/inspect.py +0 -0
  105. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/runtime/microvm.py +0 -0
  106. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/runtime/planner.py +0 -0
  107. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/runtime/runner.py +0 -0
  108. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/runtime/toolchain.py +0 -0
  109. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/scientific/__init__.py +0 -0
  110. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/scientific/jobs.py +0 -0
  111. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/simulation/__init__.py +0 -0
  112. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/simulation/heat.py +0 -0
  113. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/simulation/nbody.py +0 -0
  114. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/unified/__init__.py +0 -0
  115. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/unified/model.py +0 -0
  116. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial/unified/planner.py +0 -0
  117. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial_computing.egg-info/SOURCES.txt +0 -0
  118. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial_computing.egg-info/dependency_links.txt +0 -0
  119. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial_computing.egg-info/entry_points.txt +0 -0
  120. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial_computing.egg-info/requires.txt +0 -0
  121. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/spatial_computing.egg-info/top_level.txt +0 -0
  122. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_auth.py +0 -0
  123. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_compute.py +0 -0
  124. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_core.py +0 -0
  125. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_dashboard.py +0 -0
  126. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_domains.py +0 -0
  127. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_engines.py +0 -0
  128. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_fabric.py +0 -0
  129. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_fleet.py +0 -0
  130. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_ha.py +0 -0
  131. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_hardening.py +0 -0
  132. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_memory.py +0 -0
  133. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_optimizer.py +0 -0
  134. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_platform.py +0 -0
  135. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_platform2.py +0 -0
  136. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_q.py +0 -0
  137. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_qr.py +0 -0
  138. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_quorum.py +0 -0
  139. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_real_servers.py +0 -0
  140. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_sso.py +0 -0
  141. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_unified.py +0 -0
  142. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_v02.py +0 -0
  143. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_v03.py +0 -0
  144. {spatial_computing-0.18.0 → spatial_computing-0.20.0}/tests/test_v05.py +0 -0
  145. {spatial_computing-0.18.0 → spatial_computing-0.20.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.18.0
3
+ Version: 0.20.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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "spatial-computing"
7
- version = "0.18.0"
7
+ version = "0.20.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"
@@ -3,4 +3,4 @@
3
3
  Status of every engine is declared in spatial.core.registry and must be backed
4
4
  by a test or benchmark before being set to OPERATIONAL.
5
5
  """
6
- __version__ = "0.18.0"
6
+ __version__ = "0.20.0"
@@ -164,6 +164,15 @@ def pk_collatz_metal(n: int, limit: int) -> int:
164
164
  return _pk("collatz", "metal", n, limit=limit)
165
165
 
166
166
 
167
+ def pk_batch_score_cpu(n: int, signals: int) -> int:
168
+ """Portable kernel (spatial.kernel): a batch-scoring workload (fraud/risk/ranking-shaped), on the CPU."""
169
+ return _pk("batch_score", "cpu", n, signals=signals)
170
+
171
+
172
+ def pk_batch_score_metal(n: int, signals: int) -> int:
173
+ return _pk("batch_score", "metal", n, signals=signals)
174
+
175
+
167
176
  def montecarlo_pi(samples: int, seed: int = 0) -> float:
168
177
  rng = np.random.default_rng(seed)
169
178
  inside = 0
@@ -257,6 +266,8 @@ REGISTRY = {
257
266
  "pk_mandel_metal": pk_mandel_metal,
258
267
  "pk_collatz_cpu": pk_collatz_cpu,
259
268
  "pk_collatz_metal": pk_collatz_metal,
269
+ "pk_batch_score_cpu": pk_batch_score_cpu,
270
+ "pk_batch_score_metal": pk_batch_score_metal,
260
271
  "heat_numpy": heat_numpy,
261
272
  "heat_numba": heat_numba,
262
273
  "nbody": nbody,
@@ -1,3 +1,3 @@
1
- """Portable kernels: write once in a typed Python subset, run on CPU (Numba), Metal, or emit CUDA C."""
1
+ """Portable kernels: write once in a typed Python subset, run on CPU (Numba), Metal, or emit CUDA C, HIP, or Triton."""
2
2
  from .dsl import Kernel, KernelError, kernel # noqa: F401
3
3
  from . import library # noqa: F401
@@ -1,9 +1,11 @@
1
1
  """Portable kernel language: write a per-pixel kernel ONCE in a small, typed subset of Python and run
2
- it on the CPU (Numba), a Metal GPU (generated Metal Shading Language) or an NVIDIA GPU (generated
3
- CUDA C, never compiled or run here).
2
+ it on the CPU (Numba), a Metal GPU (generated Metal Shading Language), or emit CUDA C, HIP, or
3
+ **Triton** (OpenAI's Python GPU language) source for NVIDIA, AMD, or Triton's own targets.
4
4
 
5
5
  This is not a translator of CUDA and uses nothing from NVIDIA: the source language is ours, the
6
- back ends are generated from its AST. Same idea as Triton or SYCL at a much smaller scale.
6
+ back ends are generated from its AST. Same idea as Triton or SYCL at a much smaller scale; the
7
+ Triton back end itself is generated-only here (section "Triton" below) since no GPU Triton can
8
+ target is available on this machine.
7
9
 
8
10
  Kernel shape: def k(i: int, j: int, n: int, <params>) -> int (i, j = row, column; n = grid size)
9
11
  Params annotated int or float; floats are float32, ints are 32-bit on every back end
@@ -99,7 +101,8 @@ class Kernel:
99
101
  self._err(e, f"unknown function '{f}'")
100
102
  self._err(e, f"unsupported expression ({type(e).__name__})")
101
103
 
102
- RESERVED = {"out", "partial", "gid", "lid", "tgid", "ngroups", "blockIdx", "blockDim", "threadIdx", "gridDim", "total"}
104
+ RESERVED = {"out", "partial", "gid", "lid", "tgid", "ngroups", "blockIdx", "blockDim", "threadIdx", "gridDim", "total",
105
+ "tl", "triton", "out_ptr"}
103
106
 
104
107
  def _check_names(self, names) -> None:
105
108
  for nm in names:
@@ -279,6 +282,96 @@ class Kernel:
279
282
  Generated only: no AMD GPU, no ROCm here, so it has never been compiled or run."""
280
283
  return self.to_c(cuda=True, reduce=reduce, hip=True)
281
284
 
285
+ # ------------------------------------------------------------------ Triton (generated only: no Triton install, no
286
+ # NVIDIA/AMD/Intel GPU for it to target here; never loaded by triton.jit, never executed)
287
+ TL_MATH = {"sqrt": "tl.sqrt", "sin": "tl.sin", "cos": "tl.cos", "exp": "tl.exp", "log": "tl.log", "floor": "tl.math.floor"}
288
+
289
+ def _expr_triton(self, e, env) -> str:
290
+ t = lambda x: self.type_of(x, env)
291
+ rec = lambda x: self._expr_triton(x, env)
292
+ tof = lambda x: rec(x) if t(x) == "float" else f"({rec(x)}).to(tl.float32)"
293
+ if isinstance(e, ast.Constant):
294
+ return repr(float(e.value)) if isinstance(e.value, float) else str(e.value)
295
+ if isinstance(e, ast.Name):
296
+ return e.id
297
+ if isinstance(e, ast.UnaryOp):
298
+ if isinstance(e.op, ast.Not):
299
+ return f"({rec(e.operand)} == 0)"
300
+ return f"(-{rec(e.operand)})" if isinstance(e.op, ast.USub) else rec(e.operand)
301
+ if isinstance(e, ast.BinOp):
302
+ a, b = e.left, e.right
303
+ if isinstance(e.op, ast.Div):
304
+ return f"({tof(a)} / {tof(b)})"
305
+ if isinstance(e.op, ast.FloorDiv):
306
+ return f"({tof(a)} / {tof(b)}).to(tl.int32)" # truncates toward zero (a cast), like the C back ends; Triton's own // floors
307
+ op = {ast.Add: "+", ast.Sub: "-", ast.Mult: "*", ast.Mod: "%"}[type(e.op)]
308
+ if t(e) == "float":
309
+ return f"({tof(a)} {op} {tof(b)})"
310
+ return f"({rec(a)} {op} {rec(b)})" # int %: trusted to match C, like the CUDA back end trusts its compiler
311
+ if isinstance(e, ast.Compare):
312
+ op = {ast.Lt: "<", ast.LtE: "<=", ast.Gt: ">", ast.GtE: ">=", ast.Eq: "==", ast.NotEq: "!="}[type(e.ops[0])]
313
+ a, b = e.left, e.comparators[0]
314
+ if "float" in (t(a), t(b)):
315
+ return f"({tof(a)} {op} {tof(b)})"
316
+ return f"({rec(a)} {op} {rec(b)})"
317
+ if isinstance(e, ast.BoolOp):
318
+ op = " & " if isinstance(e.op, ast.And) else " | " # tensors have no short-circuit and/or: boolify, then bitwise-combine
319
+ return "(" + op.join(f"({rec(v)} != 0)" for v in e.values) + ")"
320
+ fn, args = e.func.id, e.args
321
+ if fn in self.TL_MATH:
322
+ return f"{self.TL_MATH[fn]}({tof(args[0])})"
323
+ if fn == "int":
324
+ return f"({tof(args[0])}).to(tl.int32)" if t(args[0]) == "float" else rec(args[0])
325
+ if fn == "float":
326
+ return f"({rec(args[0])}).to(tl.float32)"
327
+ if fn == "abs":
328
+ return f"tl.abs({rec(args[0])})"
329
+ if fn in ("min", "max"):
330
+ fname = "tl.minimum" if fn == "min" else "tl.maximum"
331
+ return f"{fname}({tof(args[0])}, {tof(args[1])})" if t(e) == "float" else f"{fname}({rec(args[0])}, {rec(args[1])})"
332
+ raise KernelError("internal: unsupported expression in Triton code generation")
333
+
334
+ def _stmts_triton(self, stmts, env, ind) -> list[str]:
335
+ out = []
336
+ cast = lambda name, v: (lambda e: e if self.type_of(v, env) == env[name] else
337
+ (f"({e}).to(tl.float32)" if env[name] == "float" else f"({e}).to(tl.int32)"))(self._expr_triton(v, env))
338
+ for s in stmts:
339
+ if isinstance(s, ast.Assign):
340
+ out.append(f"{ind}{s.targets[0].id} = {cast(s.targets[0].id, s.value)}")
341
+ elif isinstance(s, ast.AugAssign):
342
+ op = {ast.Add: "+", ast.Sub: "-", ast.Mult: "*"}[type(s.op)]
343
+ v = s.target.id
344
+ out.append(f"{ind}{v} = {v} {op} {cast(v, s.value)}")
345
+ elif isinstance(s, ast.While):
346
+ out.append(f"{ind}while {self._expr_triton(s.test, env)} != 0:")
347
+ out += self._stmts_triton(s.body, env, ind + " ") or [ind + " pass"]
348
+ elif isinstance(s, ast.If):
349
+ out.append(f"{ind}if {self._expr_triton(s.test, env)} != 0:")
350
+ out += self._stmts_triton(s.body, env, ind + " ") or [ind + " pass"]
351
+ if s.orelse:
352
+ out.append(f"{ind}else:")
353
+ out += self._stmts_triton(s.orelse, env, ind + " ")
354
+ elif isinstance(s, ast.For):
355
+ out.append(f"{ind}for {s.target.id} in range({self._expr_triton(s.iter.args[0], env)}):")
356
+ out += self._stmts_triton(s.body, env, ind + " ") or [ind + " pass"]
357
+ return out
358
+
359
+ def to_triton(self) -> str:
360
+ """Triton (github.com/openai/triton, a Python GPU kernel language, now co-maintained across several GPU
361
+ vendors) source: one `tl.program_id` per output pixel, the same "one thread per pixel" shape as the CUDA
362
+ back end. GENERATED ONLY: Triton needs an NVIDIA, AMD, or Intel GPU (plus the `triton` package) to actually
363
+ trace and compile a kernel; none is available here, so this source has never been passed to `triton.jit`,
364
+ never compiled, never run. No reduction variant: Triton's own cross-program reduction (atomics or a second
365
+ pass) does not map onto the single-pass threadgroup/shared-memory shape used by `to_metal`/`to_cuda_c`."""
366
+ env = self._env()
367
+ body = self._stmts_triton(self.body, env, " ")
368
+ ret = self._expr_triton(self.ret, env)
369
+ sig = ", ".join(["out_ptr", "n"] + [p for p, _ in self.params])
370
+ lines = ["import triton", "import triton.language as tl", "", "", "@triton.jit", f"def {self.name}({sig}):",
371
+ " j = tl.program_id(axis=0)", " i = tl.program_id(axis=1)"] + body
372
+ lines.append(f" tl.store(out_ptr + i * n + j, ({ret}).to(tl.uint32))")
373
+ return "\n".join(lines) + "\n"
374
+
282
375
  def _expr_py(self, e, env) -> str:
283
376
  t = lambda x: self.type_of(x, env)
284
377
  rec = lambda x: self._expr_py(x, env)
@@ -370,7 +463,7 @@ class Kernel:
370
463
  if device == "metal":
371
464
  from ..fabric import metal
372
465
  return metal.run_kernel(self, n, params, reduce=True)
373
- if device in ("cuda", "hip"):
466
+ if device in ("cuda", "hip", "triton"):
374
467
  raise KernelError(f"the {device} back end only generates source; it has never been run on that hardware")
375
468
  raise KernelError(f"unknown device '{device}'")
376
469
 
@@ -385,8 +478,9 @@ class Kernel:
385
478
  if device == "metal":
386
479
  from ..fabric import metal
387
480
  return metal.run_kernel(self, n, params)
388
- if device == "cuda":
389
- raise KernelError("the CUDA back end only generates source (to_cuda_c); it has never been run on NVIDIA hardware")
481
+ if device in ("cuda", "hip", "triton"):
482
+ raise KernelError(f"the {device} back end only generates source (to_{'cuda_c' if device == 'cuda' else device}); "
483
+ f"it has never been run on {'NVIDIA' if device == 'cuda' else 'AMD' if device == 'hip' else 'any Triton-targeted'} hardware")
390
484
  raise KernelError(f"unknown device '{device}'")
391
485
 
392
486
  def _run_cpu(self, n, params, reduce: bool = False):
@@ -1,4 +1,4 @@
1
- """Kernels written in the portable language. Each runs unchanged on CPU and Metal; CUDA C is generated."""
1
+ """Kernels written in the portable language. Each runs unchanged on CPU and Metal; CUDA C, HIP, and Triton are generated."""
2
2
  from .dsl import kernel
3
3
 
4
4
 
@@ -43,4 +43,26 @@ def waves(i: int, j: int, n: int, terms: int):
43
43
  return int((s + 8.0) * 1000.0)
44
44
 
45
45
 
46
- LIBRARY = {"mandelbrot": mandelbrot, "collatz": collatz, "waves": waves}
46
+ @kernel
47
+ def batch_score(i: int, j: int, n: int, signals: int):
48
+ """A batch-scoring kernel: element (i, j) is one of n*n independent items, scored by combining
49
+ `signals` weighted features through a logistic sum — the same shape as scoring a transaction for
50
+ fraud/credit risk, ranking a search or ad result, flagging an anomaly, or filtering content, whichever
51
+ software already does that scoring in a batch or a stream. The features and weights here are SYNTHETIC
52
+ (no real data, no trained model): this demonstrates that the planner places and measures a batch-scoring
53
+ job exactly like it places Mandelbrot or Collatz, not a validated scoring model for any one domain.
54
+ Returns the score quantised to [0, 10000] (hundredths of a percent)."""
55
+ idx = i * n + j
56
+ x1 = float(idx % 2000) / 20.0 - 50.0
57
+ x2 = float(i) / float(n) - 0.5
58
+ z = 0.0
59
+ k = 0
60
+ while k < signals:
61
+ w = sin(float(k + 1) * 0.37) * 1.3
62
+ z += w * (x1 / (float(k) + 1.0) + x2)
63
+ k += 1
64
+ p = 1.0 / (1.0 + exp(-z))
65
+ return int(p * 10000.0)
66
+
67
+
68
+ LIBRARY = {"mandelbrot": mandelbrot, "collatz": collatz, "waves": waves, "batch_score": batch_score}
@@ -31,6 +31,7 @@ CATALOG = {
31
31
  "montecarlo_pi": dict(title="Monte Carlo pi", doc="Estimate pi by random sampling (CPU-bound, embarrassingly parallel).", params={"samples": (1_000_000, 1000, 50_000_000)}),
32
32
  "mandel_numba_parallel": dict(title="Mandelbrot (multi-core)", doc="Iteration counts of the Mandelbrot set on a grid, Numba on all cores.", params={"n": (600, 16, 3000), "iters": (200, 10, 2000)}),
33
33
  "pk_mandel_cpu": dict(title="Portable kernel: Mandelbrot", doc="The same kernel source that also runs on a Metal GPU, on the CPU.", params={"n": (512, 16, 2048), "iters": (200, 10, 2000)}),
34
+ "pk_batch_score_cpu": dict(title="Portable kernel: batch scoring", doc="Fraud/risk/ranking/anomaly-shaped batch scoring (synthetic signals, no real model) on the CPU.", params={"n": (512, 16, 2048), "signals": (16, 1, 200)}),
34
35
  "matmul": dict(title="Matrix multiply", doc="Dense float64 matrix product of size n.", params={"n": (600, 16, 1500)}),
35
36
  "heat_numba": dict(title="Heat diffusion", doc="2-D heat diffusion from a hot square (simulation engine, Numba).", params={"n": (200, 16, 800), "steps": (500, 1, 5000)}),
36
37
  "nbody": dict(title="N-body", doc="Leapfrog N-body integration; returns the relative energy drift.", params={"bodies": (100, 2, 300), "steps": (400, 1, 2000)}),
@@ -25,7 +25,7 @@ from ..planner import find_oci
25
25
 
26
26
  HERE = Path(__file__).parent
27
27
  IMAGE = "spatial-desktop:1"
28
- APPS = {"xterm": ["xterm"], "xclock": ["xclock"], "mousepad": ["mousepad"], "xcalc": ["xcalc"]} # an allow-list: no arbitrary command from the caller
28
+ APPS = {"xterm": ["xterm", "-geometry", "90x28+20+20"], "xclock": ["xclock"], "mousepad": ["mousepad"], "xcalc": ["xcalc"]} # an allow-list: no arbitrary command from the caller
29
29
 
30
30
 
31
31
  class DesktopError(Exception):
@@ -36,6 +36,8 @@ FAMILIES = {
36
36
  # but has no run path here, so it is not offered as an option.
37
37
  "pk_mandel": dict(variants={"cpu": "pk_mandel_cpu", "gpu_metal": "pk_mandel_metal"}, scale="n", exp=2.0, min=8, exact=False, tol=1e-3),
38
38
  "pk_collatz": dict(variants={"cpu": "pk_collatz_cpu", "gpu_metal": "pk_collatz_metal"}, scale="n", exp=2.0, min=8, exact=True),
39
+ # batch scoring (fraud/risk/ranking/anomaly-shaped): same "one job, several devices" idea, a different work shape
40
+ "pk_batch_score": dict(variants={"cpu": "pk_batch_score_cpu", "gpu_metal": "pk_batch_score_metal"}, scale="n", exp=2.0, min=8, exact=False, tol=1e-3),
39
41
  "heat": dict(variants={"numpy": "heat_numpy", "numba": "heat_numba"}, scale="steps", exp=1.0, min=2, exact=False),
40
42
  "nbody": dict(variants={"cpu": "nbody"}, scale="steps", exp=1.0, min=2, exact=False),
41
43
  "hologram": dict(variants={"cpu": "hologram_peak"}, scale="n", exp=2.0, min=32, exact=True),
@@ -50,7 +52,7 @@ def _same(a, b, exact: bool, tol: float = 1e-6) -> bool:
50
52
 
51
53
  def _variant_available(workload: str) -> str | None:
52
54
  """None if the variant can run here, else why not."""
53
- if workload in ("mandel_f32_metal", "pk_mandel_metal", "pk_collatz_metal"):
55
+ if workload in ("mandel_f32_metal", "pk_mandel_metal", "pk_collatz_metal", "pk_batch_score_metal"):
54
56
  from ..fabric import metal
55
57
  return None if metal.available() else "no Metal GPU (macOS with swiftc is required)"
56
58
  if workload == "mandel_f32_cuda":
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: spatial-computing
3
- Version: 0.18.0
3
+ Version: 0.20.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
@@ -47,4 +47,5 @@ def test_measured_link_and_prediction_are_in_the_right_order_of_magnitude_on_thi
47
47
  for row in out["rows"]:
48
48
  for algo, meas in row["measured_s"].items():
49
49
  pred = row["predicted_s"][algo]
50
- assert 0.1 < meas / pred < 10, (algo, row["bytes"], meas, pred) # same order of magnitude
50
+ lo, hi = (0.1, 10) if row["bytes"] >= 65536 else (0.02, 60) # tiny messages are dominated by scheduler noise on a shared runner
51
+ assert lo < meas / pred < hi, (algo, row["bytes"], meas, pred) # same order of magnitude
@@ -4,7 +4,7 @@ import pytest
4
4
 
5
5
  from spatial.fabric import metal
6
6
  from spatial.kernel import KernelError, kernel
7
- from spatial.kernel.library import LIBRARY, collatz, mandelbrot, waves
7
+ from spatial.kernel.library import LIBRARY, batch_score, collatz, mandelbrot, waves
8
8
 
9
9
  needs_metal = pytest.mark.skipif(not metal.available(), reason="no Metal")
10
10
 
@@ -14,6 +14,8 @@ def test_generated_sources_have_expected_shape():
14
14
  assert "kernel void mandelbrot" in msl and "thread_position_in_grid" in msl
15
15
  assert '__global__ void mandelbrot' in cu and "blockIdx" in cu
16
16
  assert "while" in msl and "while" in cu
17
+ tl_src = mandelbrot.to_triton()
18
+ assert "@triton.jit" in tl_src and "def mandelbrot(" in tl_src and "tl.program_id" in tl_src and "while" in tl_src
17
19
 
18
20
 
19
21
  def test_cpu_matches_plain_python_for_collatz():
@@ -44,6 +46,8 @@ def test_float_kernels_agree_within_tolerance():
44
46
  assert np.mean(a != b) < 0.01 # float32 chaos at the set's boundary: a few pixels may differ
45
47
  w1, w2 = waves.run("cpu", 64, terms=8), waves.run("metal", 64, terms=8)
46
48
  assert np.abs(w1.astype(np.int64) - w2.astype(np.int64)).max() <= 3 # GPU sin/cos differ in the last bits
49
+ r1, r2 = batch_score.run("cpu", 64, signals=16), batch_score.run("metal", 64, signals=16)
50
+ assert np.abs(r1.astype(np.int64) - r2.astype(np.int64)).max() <= 5
47
51
 
48
52
 
49
53
  def test_unsupported_constructs_are_refused():
@@ -75,8 +79,39 @@ def test_cuda_backend_refuses_to_pretend():
75
79
  mandelbrot.run("cuda", 8, iters=10)
76
80
 
77
81
 
82
+ def test_triton_backend_refuses_to_pretend_and_has_no_reduction():
83
+ for dev in ("run", "reduce"):
84
+ with pytest.raises(KernelError, match="triton"):
85
+ getattr(mandelbrot, dev)("triton", 8, iters=10)
86
+ with pytest.raises(TypeError):
87
+ collatz.to_triton(reduce=True)
88
+
89
+
90
+ def test_triton_source_handles_ints_floats_and_control_flow_syntactically():
91
+ src = collatz.to_triton()
92
+ assert "import triton" in src and "import triton.language as tl" in src
93
+ assert "tl.store(out_ptr + i * n + j" in src and ".to(tl.uint32)" in src
94
+ assert ").to(tl.int32)" in src # the // floor-vs-truncate cast
95
+ compile(src, "<triton collatz>", "exec") # at least syntactically valid Python
96
+ msl = mandelbrot.to_triton()
97
+ assert "while" in msl and "tl.program_id" in msl
98
+ compile(msl, "<triton mandelbrot>", "exec")
99
+ w = waves.to_triton()
100
+ assert "tl.sin" in w and "tl.cos" in w
101
+ compile(w, "<triton waves>", "exec")
102
+
103
+
78
104
  def test_library_complete():
79
- assert set(LIBRARY) == {"mandelbrot", "collatz", "waves"}
105
+ assert set(LIBRARY) == {"mandelbrot", "collatz", "waves", "batch_score"}
106
+
107
+
108
+ def test_batch_score_is_a_plausible_probability_and_matches_cpu_metal():
109
+ out = batch_score.run("cpu", 64, signals=16)
110
+ assert out.min() >= 0 and out.max() <= 10000 and out.std() > 0 # quantised probability, not a constant
111
+ tl = batch_score.to_triton()
112
+ assert "@triton.jit" in tl and "while" in tl and "tl.exp" in tl
113
+ compile(tl, "<triton batch_score>", "exec")
114
+
80
115
 
81
116
 
82
117
  def test_planner_offers_portable_kernel_families():
@@ -135,3 +170,8 @@ def test_names_that_would_clash_with_generated_code_are_refused():
135
170
  @kernel
136
171
  def bad2(i: int, j: int, n: int, total: int):
137
172
  return 1
173
+ with pytest.raises(KernelError, match="reserved"):
174
+ @kernel
175
+ def bad3(i: int, j: int, n: int):
176
+ tl = 1
177
+ return tl
@@ -237,12 +237,12 @@ def test_remote_desktop_view_only_password_and_clipboard_policy_are_enforced():
237
237
  while time.time() < deadline and "xterm" not in run("exec", d.container, "ps", "-o", "args"): # the application must be up before anyone types
238
238
  time.sleep(0.5)
239
239
  time.sleep(3) # and its window mapped (slow runners)
240
- view.click(500, 300); view.type("touch /tmp/by-viewer"); time.sleep(1.0) # the watcher clicks and types...
240
+ view.click(300, 200); view.type("touch /tmp/by-viewer"); time.sleep(1.0) # the watcher clicks and types...
241
241
  listing = run("exec", d.container, "ls", "-a", "/tmp")
242
242
  assert ".X11-unix" in listing, "the container stopped answering: " + run("logs", "--tail", "20", d.container)
243
243
  assert "by-viewer" not in listing # ...and nothing happens
244
- for attempt in range(4): # the owner types (retried: a window may take a moment to take focus)
245
- full.click(500, 300); full.type("touch /tmp/by-owner")
244
+ for attempt in range(6): # the owner types (retried: a window may take a moment to take focus)
245
+ full.click(300, 200); full.type("touch /tmp/by-owner")
246
246
  end = time.time() + 8
247
247
  while time.time() < end and "by-owner" not in run("exec", d.container, "ls", "/tmp"):
248
248
  time.sleep(0.5)