Add auto GPU->CPU conversion at interpreter level

Convert GPU frames/CuPy arrays to numpy before calling primitives.
This fixes all CPU primitives without modifying each one individually.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-03 21:40:37 +00:00
parent 92eeb58c71
commit 7009840712

View File

@@ -102,8 +102,17 @@ class StreamInterpreter:
self.errors.append(msg)
print(f"ERROR: {msg}", file=sys.stderr)
import random
self.rng = random.Random(self.config.get('seed', 42))
def _maybe_to_numpy(self, val):
"""Convert GPU frames/CuPy arrays to numpy for CPU primitives."""
if val is None:
return val
# Handle GPUFrame objects (have .cpu property)
if hasattr(val, 'cpu'):
return val.cpu
# Handle CuPy arrays (have .get() method)
if hasattr(val, 'get') and callable(val.get):
return val.get()
return val
def _load_config_file(self, config_path):
"""Load a config file and process its definitions."""
@@ -773,10 +782,10 @@ class StreamInterpreter:
if isinstance(args[i], Keyword):
k = args[i].name
v = self._eval(args[i + 1], env) if i + 1 < len(args) else None
kwargs[k] = v
kwargs[k] = self._maybe_to_numpy(v)
i += 2
else:
evaluated_args.append(self._eval(args[i], env))
evaluated_args.append(self._maybe_to_numpy(self._eval(args[i], env)))
i += 1
try:
if kwargs: