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

Don't assume host pointers are directly usable on the device. #1342

Merged
merged 1 commit into from
Jan 26, 2022

Conversation

maleadt
Copy link
Member

@maleadt maleadt commented Jan 26, 2022

Since CUDA.jl 3.4, we now always reconstruct a buffer object when
creating an array from a pointer. In the case of a HostBuffer,
that means we want the host pointer in the buffer object,
which is converted to a device pointer on request.

However, unsafe_wrap is invoked with a device pointer. Generally,
those pointers are identical, but on GPUs where
CU_DEVICE_ATTRIBUTE_CAN_USE_HOST_POINTER_FOR_REGISTERED_MEM==0,
that is not the case.

Instead, recover the host pointer from the device pointer passed to
unsafe_wrap. This is going back and forth between both pointer
representations, but those calls are reasonably cheap.

Since CUDA.jl 3.4, we now always reconstruct a buffer object when
creating an array from a pointer. In the case of a HostBuffer,
that means we want the host pointer in the buffer object,
which is converted to a device pointer on request.

However, unsafe_wrap is invoked with a device pointer. Generally,
those pointers are identical, but on GPUs where
CU_DEVICE_ATTRIBUTE_CAN_USE_HOST_POINTER_FOR_REGISTERED_MEM==0,
that is not the case.

Instead, recover the host pointer from the device pointer passed to
unsafe_wrap. This is going back and forth between both pointer
representations, but those calls are reasonably cheap.
@codecov
Copy link

codecov bot commented Jan 26, 2022

Codecov Report

Merging #1342 (1236a12) into master (ca77d18) will decrease coverage by 0.00%.
The diff coverage is 85.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1342      +/-   ##
==========================================
- Coverage   78.97%   78.96%   -0.01%     
==========================================
  Files         119      119              
  Lines        8657     8659       +2     
==========================================
+ Hits         6837     6838       +1     
- Misses       1820     1821       +1     
Impacted Files Coverage Δ
lib/cudadrv/memory.jl 84.87% <50.00%> (-0.26%) ⬇️
src/array.jl 86.07% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ca77d18...1236a12. Read the comment docs.

@maleadt maleadt merged commit 430787d into master Jan 26, 2022
@maleadt maleadt deleted the tb/unsafe_wrap_hostbuffer branch January 26, 2022 17:44
maleadt added a commit that referenced this pull request Jan 27, 2022
Since CUDA.jl 3.4, we now always reconstruct a buffer object when
creating an array from a pointer. In the case of a HostBuffer,
that means we want the host pointer in the buffer object,
which is converted to a device pointer on request.

However, unsafe_wrap is invoked with a device pointer. Generally,
those pointers are identical, but on GPUs where
CU_DEVICE_ATTRIBUTE_CAN_USE_HOST_POINTER_FOR_REGISTERED_MEM==0,
that is not the case.

Instead, recover the host pointer from the device pointer passed to
unsafe_wrap. This is going back and forth between both pointer
representations, but those calls are reasonably cheap.
luraess added a commit to eth-cscs/ImplicitGlobalGrid.jl that referenced this pull request Jan 27, 2022
Modify CUDA compat to v3 excluding v3.4 - v3.7.0 because of #25, now that bug JuliaGPU/CUDA.jl#1342 is fixed.
simonbyrne pushed a commit to simonbyrne/CUDA.jl that referenced this pull request Nov 13, 2023
…PU#1342)

Since CUDA.jl 3.4, we now always reconstruct a buffer object when
creating an array from a pointer. In the case of a HostBuffer,
that means we want the host pointer in the buffer object,
which is converted to a device pointer on request.

However, unsafe_wrap is invoked with a device pointer. Generally,
those pointers are identical, but on GPUs where
CU_DEVICE_ATTRIBUTE_CAN_USE_HOST_POINTER_FOR_REGISTERED_MEM==0,
that is not the case.

Instead, recover the host pointer from the device pointer passed to
unsafe_wrap. This is going back and forth between both pointer
representations, but those calls are reasonably cheap.
marinlauber pushed a commit to marinlauber/ImplicitGlobalGrid.jl that referenced this pull request Jul 10, 2024
Modify CUDA compat to v3 excluding v3.4 - v3.7.0 because of eth-cscs#25, now that bug JuliaGPU/CUDA.jl#1342 is fixed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant