|
8 | 8 | from pykokkos.core.cppast import BuiltinType |
9 | 9 |
|
10 | 10 | from .execution_policy import ExecutionPolicy, RangePolicy |
11 | | -from .execution_space import ExecutionSpace |
| 11 | +from .execution_space import ExecutionSpace, is_host_execution_space |
12 | 12 | from .views import ViewType, array |
13 | 13 |
|
14 | 14 | from .interface_util import generic_error, get_filename, get_lineno |
@@ -228,8 +228,23 @@ def convert_arrays(kwargs: Dict[str, Any], workunit: Optional[Callable] = None) |
228 | 228 | # Convert Python list to numpy array, then to View |
229 | 229 | kwargs[k] = array(np.array(v, dtype=dtype)) |
230 | 230 | elif isinstance(v, np.ndarray): |
| 231 | + default_space: ExecutionSpace = km.get_default_space() |
| 232 | + _gpu_spaces = {ExecutionSpace.Cuda, ExecutionSpace.HIP} |
| 233 | + if default_space in _gpu_spaces: |
| 234 | + raise TypeError( |
| 235 | + f"Argument '{k}' is a numpy array, which cannot be accessed " |
| 236 | + f"from the {default_space.value} execution space. " |
| 237 | + f"Use a pk.View (e.g. pk.View([...], dtype)) or a CuPy array instead." |
| 238 | + ) |
231 | 239 | kwargs[k] = array(v) |
232 | 240 | elif cp_available and isinstance(v, cp.ndarray): |
| 241 | + default_space = km.get_default_space() |
| 242 | + if is_host_execution_space(default_space): |
| 243 | + raise TypeError( |
| 244 | + f"Argument '{k}' is a CuPy array, which cannot be accessed " |
| 245 | + f"from the {default_space.value} (host) execution space. " |
| 246 | + f"Convert it to a numpy array or pk.View in host memory first." |
| 247 | + ) |
233 | 248 | kwargs[k] = array(v) |
234 | 249 | elif torch_available and torch.is_tensor(v): |
235 | 250 | kwargs[k] = array(v) |
|
0 commit comments