Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python: Add support for HIP/ROCm buffers #1759

Merged
merged 3 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions include/gridtools/storage/adapter/python_sid_adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,13 @@ namespace gridtools {
static_assert(std::is_trivially_copy_constructible_v<T>,
"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<pybind11::dict>();
#else
auto iface = src.attr("__cuda_array_interface__").cast<pybind11::dict>();
#endif

// shape
array<size_t, Dim> shape;
Expand Down
2 changes: 1 addition & 1 deletion tests/regression/py_bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
14 changes: 11 additions & 3 deletions tests/regression/py_bindings/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down
Loading