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:
@@ -102,8 +102,17 @@ class StreamInterpreter:
|
|||||||
self.errors.append(msg)
|
self.errors.append(msg)
|
||||||
print(f"ERROR: {msg}", file=sys.stderr)
|
print(f"ERROR: {msg}", file=sys.stderr)
|
||||||
|
|
||||||
import random
|
def _maybe_to_numpy(self, val):
|
||||||
self.rng = random.Random(self.config.get('seed', 42))
|
"""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):
|
def _load_config_file(self, config_path):
|
||||||
"""Load a config file and process its definitions."""
|
"""Load a config file and process its definitions."""
|
||||||
@@ -773,10 +782,10 @@ class StreamInterpreter:
|
|||||||
if isinstance(args[i], Keyword):
|
if isinstance(args[i], Keyword):
|
||||||
k = args[i].name
|
k = args[i].name
|
||||||
v = self._eval(args[i + 1], env) if i + 1 < len(args) else None
|
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
|
i += 2
|
||||||
else:
|
else:
|
||||||
evaluated_args.append(self._eval(args[i], env))
|
evaluated_args.append(self._maybe_to_numpy(self._eval(args[i], env)))
|
||||||
i += 1
|
i += 1
|
||||||
try:
|
try:
|
||||||
if kwargs:
|
if kwargs:
|
||||||
|
|||||||
Reference in New Issue
Block a user