-
Notifications
You must be signed in to change notification settings - Fork 772
[SYCL][HIP] Use valid cast for CUdeviceptr in HIP PI #6207
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2131,8 +2131,27 @@ pi_result hip_piMemGetInfo(pi_mem memObj, pi_mem_info queriedInfo, | |
/// \return PI_SUCCESS | ||
pi_result hip_piextMemGetNativeHandle(pi_mem mem, | ||
pi_native_handle *nativeHandle) { | ||
#if defined(__HIP_PLATFORM_NVIDIA__) | ||
if (sizeof(_pi_mem::mem_::buffer_mem_::native_type) > | ||
sizeof(pi_native_handle)) { | ||
// Check that all the upper bits that cannot be represented by | ||
// pi_native_handle are empty. | ||
// NOTE: The following shift might trigger a warning, but the check in the | ||
// if above makes sure that this does not underflow. | ||
_pi_mem::mem_::buffer_mem_::native_type upperBits = | ||
mem->mem_.buffer_mem_.get() >> (sizeof(pi_native_handle) * CHAR_BIT); | ||
if (upperBits) { | ||
// Return an error if any of the remaining bits is non-zero. | ||
return PI_INVALID_MEM_OBJECT; | ||
} | ||
} | ||
*nativeHandle = static_cast<pi_native_handle>(mem->mem_.buffer_mem_.get()); | ||
#elif defined(__HIP_PLATFORM_AMD__) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the code above not suitable for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
My outlook filters for github notifications aren't perfect yet and different notifications end up in different folders. Just saw your comment. I'd like to understand what exactly is wrong with the AMD platform because it's not obvious to me. The upperbits handling looks like the right thing to me regardless of the problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just FYI. I approved the workflow both times. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bader Thanks for approving the workflows! I'm not sure why the second run failed, I don't see how my changes could affect a reduction test on OpenCL on Intel GPU. @aelovikov-intel: The definition of On Nvidia/CUDA platforms, it is an alias for On AMD platforms, it is an alias for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And such a cast would error if information would be lost: https://godbolt.org/z/dj8TKhrnM That makes sense, thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aelovikov-intel Thanks for the approval! What should I do about the failed workflow? I do not see any relation between the error and my changes, would it make sense to re-run the workflow? Or can the PR still be merged? |
||
*nativeHandle = | ||
reinterpret_cast<pi_native_handle>(mem->mem_.buffer_mem_.get()); | ||
#else | ||
#error("Must define exactly one of __HIP_PLATFORM_AMD__ or __HIP_PLATFORM_NVIDIA__"); | ||
#endif | ||
return PI_SUCCESS; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the issue:
Can we have a check that upper bits are zero and return some failure code if that's not the case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @aelovikov-intel, thanks for the review.
I've added a check to make sure that the upper bits are zero.