diff --git a/AUTHORS b/AUTHORS index 45790d056..ec3f45d3d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -16,3 +16,4 @@ Auriane Reverdell (aurianer), ETH Zurich (CSCS) Mikael Simberg (msimberg), ETH Zurich (CSCS) Till Ehrengruber (tehrengruber), ETH Zurich (CSCS) Péter Kardos (petiaccja), ETH Zurich (EXCLAIM) +Stefano Ubbiali (stubbiali), ETH Zurich diff --git a/include/gridtools/storage/adapter/python_sid_adapter.hpp b/include/gridtools/storage/adapter/python_sid_adapter.hpp index 255d63485..265c1b4be 100644 --- a/include/gridtools/storage/adapter/python_sid_adapter.hpp +++ b/include/gridtools/storage/adapter/python_sid_adapter.hpp @@ -268,7 +268,13 @@ namespace gridtools { static_assert(std::is_trivially_copy_constructible_v, "as_cuda_sid should be instantiated with the trivially copyable type"); +#if defined(__HIP__) + // This is a custom property that has to be added manually (not provided by cupy). + // Should be replaced by `dlpack` for uniform array interface support. + auto iface = src.attr("__hip_array_interface__").cast(); +#else auto iface = src.attr("__cuda_array_interface__").cast(); +#endif // shape array shape; diff --git a/tests/regression/py_bindings/CMakeLists.txt b/tests/regression/py_bindings/CMakeLists.txt index 2991dc29d..bb8b3d50b 100644 --- a/tests/regression/py_bindings/CMakeLists.txt +++ b/tests/regression/py_bindings/CMakeLists.txt @@ -29,4 +29,4 @@ pybind11_add_module(py_implementation implementation.cpp) target_link_libraries(py_implementation PRIVATE gridtools) -add_test(NAME py_bindings COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/driver.py) +add_test(NAME py_bindings COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/driver.py ${GT_CUDA_TYPE}) diff --git a/tests/regression/py_bindings/driver.py b/tests/regression/py_bindings/driver.py index bcb34845e..e53c85134 100644 --- a/tests/regression/py_bindings/driver.py +++ b/tests/regression/py_bindings/driver.py @@ -6,6 +6,8 @@ import numpy as np import py_implementation as testee +HIP = True if len(sys.argv) > 1 and sys.argv[1] == "HIPCC-AMDGPU" else False + def test_3d(): src = np.fromfunction(lambda i, j, k : i + j + k, (3, 4, 5), dtype=np.double) dst = np.zeros_like(src) @@ -35,9 +37,15 @@ def test_cuda_sid(): class Mock: def __init__(self, **kwargs): self.kwargs = kwargs - @property - def __cuda_array_interface__(self): - return self.kwargs + + if not HIP: + @property + def __cuda_array_interface__(self): + return self.kwargs + else: + @property + def __hip_array_interface__(self): + return self.kwargs mock = Mock( shape=(3, 4, 5),