Hackathon Project 8: Expose CUDA-managed STIR image and acquisition queries in sirf.STIR#1381
Conversation
KrisThielemans
left a comment
There was a problem hiding this comment.
I think we need to move some things to DataContainer, in particular . Not so sure why we didn't do that yet with address() itself.
I suggest to rename is_cuda_managed to supports_cuda_array_view to be consistent with existing code. We should have a virtual DataContainer version that just returns false.
I'm not so sure we need cuda_address() as it's really the same as address() but with a check. If we do have it, it should be in DataContainer (calling virtual DataContainer::address()), and it shouldn't be anywhere else.
.github/workflows/build-test.yml
Outdated
| on: | ||
| push: | ||
| branches: [ master ] | ||
| branches: [ master, Hackathon_project8_II ] |
|
|
||
| @property | ||
| def __cuda_array_interface__(self): | ||
| """As per https://numba.readthedocs.io/en/stable/cuda/cuda_array_interface.html""" |
There was a problem hiding this comment.
apparently that site is deprecated.
| """As per https://numba.readthedocs.io/en/stable/cuda/cuda_array_interface.html""" | |
| """As per https://nvidia.github.io/numba-cuda/user/cuda_array_interface.html""" |
There was a problem hiding this comment.
resolved, but not changed?
|
Dear Professor @KrisThielemans, |
806c38b to
1ecb7ad
Compare
|
Dear Professor @KrisThielemans ,
I moved the CUDA-array-view support to the generic
Please inform me if any of the changes are not OK, and i will very gladly attempt to correct them. THANK YOU WHOLEHEARTEDLY!!! |
KrisThielemans
left a comment
There was a problem hiding this comment.
Thanks!
Let's move the pointer functions to common/utilities.h (sorry).
Also, all address() functions in the derived classes will now need override. And add something to CHANGES.md along the lines of "add supports_cuda_array_view() and related functions to expose CUDA arrays directly to Python for DataContainers that support it."
| bool | ||
| STIRAcquisitionDataInMemory::supports_cuda_array_view() const | ||
| { | ||
| return this->supports_array_view() && pointer_supports_cuda_array_view(reinterpret_cast<const void*>(this->address())); |
There was a problem hiding this comment.
I think this is a generic implementation that can be used in DataContainer, and we then won't need it anywhere else
There was a problem hiding this comment.
Done: moved to the generic DataContainer/common path and removed the STIR-specific implementation.
|
|
||
| @property | ||
| def __cuda_array_interface__(self): | ||
| """As per https://numba.readthedocs.io/en/stable/cuda/cuda_array_interface.html""" |
There was a problem hiding this comment.
resolved, but not changed?
src/xSTIR/cSTIR/CMakeLists.txt
Outdated
| if (TARGET CUDA::cudart) | ||
| get_target_property(_cudart_include_dirs CUDA::cudart INTERFACE_INCLUDE_DIRECTORIES) | ||
| set(_saved_required_includes "${CMAKE_REQUIRED_INCLUDES}") | ||
| if (_cudart_include_dirs) | ||
| set(CMAKE_REQUIRED_INCLUDES ${_cudart_include_dirs}) | ||
| endif() | ||
| check_include_file_cxx(cuda_runtime_api.h HAS_CUDA_RUNTIME_API) | ||
| set(CMAKE_REQUIRED_INCLUDES "${_saved_required_includes}") | ||
| if (HAS_CUDA_RUNTIME_API) | ||
| target_compile_definitions(cstir PUBLIC HAS_CUDA_RUNTIME_API) | ||
| target_link_libraries(cstir CUDA::cudart) | ||
| endif() | ||
| endif() |
There was a problem hiding this comment.
@casperdcl are these checks needed? i.e. if the target exists, aren't we guaranteed to have cuda_runtime_api.h?
There was a problem hiding this comment.
I simplified this by dropping the extra header check and using TARGET CUDA::cudart directly.
| \ingroup Common | ||
|
|
||
| \author Dimitra Kyriakopoulou | ||
| \author Kris Thielemans |
There was a problem hiding this comment.
I didn't write any of this, so remove me!
There was a problem hiding this comment.
Because your guidance raises points I would not have thought of on my own, I experience this as a collaborative effort and for that reason I regard you as a coauthor.
|
Dear Professor @KrisThielemans ,
Moved to src/common/include/sirf/common/utilities.h.
Done.
Added.
This had already been changed; the current code raises AttributeError when unsupported, and the thread appears to be attached to an outdated diff. I will be looking forward to your further evaluation! THANK YOU WHOLEHEARTEDLY FOR ALL YOUR INVALUABLE HELP!!! |
KrisThielemans
left a comment
There was a problem hiding this comment.
A little bit of clean-up. We have reduced the number of changes, which is always good!
| bool | ||
| DataContainer::supports_cuda_array_view() const | ||
| { | ||
| return this->supports_array_view() && | ||
| pointer_supports_cuda_array_view(reinterpret_cast<const void*>(this->address())); | ||
| } | ||
|
|
There was a problem hiding this comment.
This really doesn't belong in csirf.cpp, which defines the C interface. I think best to create a DataContainer.cpp and put it in there. The alternative would be to add it to the .h file, but then we need to include utilities.h in there, which I'd like to avoid.
There was a problem hiding this comment.
Done: I moved the implementation to a new src/common/DataContainer.cpp, so it is no longer in the C interface file and DataContainer.h no longer needs to include utilities.h.
There was a problem hiding this comment.
This proved related to the second CI issue (please see post below). The problem there was that I had placed the generic DataContainer::supports_cuda_array_view() implementation in csirf.cpp. I now moved it to src/common/DataContainer.cpp and removed it from src/common/csirf.cpp, so it no longer lives in the C interface file and DataContainer.h still does not need to include utilities.h.
| SyneRBI Synergistic Image Reconstruction Framework (SIRF) | ||
| Copyright 2017 - 2020 University College London | ||
| Copyright 2017 - 2020, 2026 University College London | ||
| Copyright 2026 Biomedical Research Foundation, Academy of Athens |
There was a problem hiding this comment.
I don't think it makes sense to add copyright info and authorship for just adding override. (also in other places)
There was a problem hiding this comment.
Undone here and in the related files where only override/plumbing changes had prompted those metadata edits.
src/xSTIR/cSTIR/CMakeLists.txt
Outdated
| # Author: Kris Thielemans, Richard Brown | ||
| # Author: Kris Thielemans | ||
| # Author: Richard Brown | ||
| # Author: Dimitra Kyriakopoulou |
There was a problem hiding this comment.
looks like we should undo these changes
| Copyright 2017 - 2023 Rutherford Appleton Laboratory STFC | ||
| Copyright 2018 - 2023 University College London | ||
| Copyright 2018 - 2023, 2026 University College London | ||
| Copyright 2026 Biomedical Research Foundation, Academy of Athens |
CHANGES.md
Outdated
|
|
||
| * SIRF/STIR | ||
| - The implementation of the creation of `sirf.STIR.ImageData` from `sirf.STIR.AcquisitionData` has been revised to ensure compatibility of `ImageData` dimensions and voxel sizes with `AcquisitionData`. | ||
| - Added `supports_cuda_array_view()` and related `DataContainer`/Python support, including `__cuda_array_interface__`, to expose CUDA-backed arrays directly for supported containers such as STIR image and acquisition data. |
There was a problem hiding this comment.
| - Added `supports_cuda_array_view()` and related `DataContainer`/Python support, including `__cuda_array_interface__`, to expose CUDA-backed arrays directly for supported containers such as STIR image and acquisition data. | |
| - Added `supports_cuda_array_view()` and related `DataContainer`/Python support, including `__cuda_array_interface__`, to expose CUDA-backed arrays directly for supported containers |
we have to cut STIR support, as it hasn't been merged yet
|
Dear Professor @KrisThielemans, I faced two separate CI failures locally.
I applied the review request that all derived
Undoing the temporary CI restrictions restored the full build in The likely direct trigger in my implementation was that, in the follow-up review changes, I moved the generic I am therefore keeping I will be looking forward to your further evaluation! THANK YOU WHOLEHEARTEDLY FOR ALL YOUR INVALUABLE HELP!!! |
This PR is PART of Hackathon Project 8: update STIR data to CUDA managed pointers, then adapt
sirf.STIRdata-containers and expose the underlying CUDA managed pointer to Python. This PR contains the full SIRF side of that work across Stage 1, Stage 2, and Stage 3.The STIR image part has already been merged upstream in
UCL/STIR#1693(Stage 1) andUCL/STIR#1694(Stage 2 and Stage 3). The runnable benchmark/proof repository for the whole Project 8 path, including Stage 1, Stage 2, and Stage 3, isDimitra-Kyriakopoulou/hackathon_project_08_stir_cuda_managed_pointers.Changes in this pull request
cSTIR.cSTIR.sirf.STIRfor both managed-image and managed-acquisition paths.is_cuda_managedcuda_address__cuda_array_interface__cstir_p.cpp.Stage 2 and Stage 3, rather than introducing a separate parallel interface.
STIR_WITH_CUDAintocstirand linkedCUDA::cudart, so the CUDA-aware query path is actually compiled in the relevant target.Testing performed
sirf.STIRwith the managed-image factory.is_cuda_managedcuda_address__cuda_array_interface__supports_array_view = trueis_cuda_managed = truecuda_address = nonzeroDimitra-Kyriakopoulou/hackathon_project_08_stir_cuda_managed_pointers.Related issues
Checklist before requesting a review
Contribution Notes
Please read and adhere to the contribution guidelines.
Please tick the following: