Skip to content

[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

Merged
merged 3 commits into from
Jun 3, 2022

Conversation

sommerlukas
Copy link
Contributor

This is a fix for #6189.

Replaces invalid reinterpret_cast with static_cast for CUdeviceptr in hip_piextMemGetNativeHandle to fix build error occuring when building HIP PI on CUDA machines;

Signed-off-by: Lukas Sommer [email protected]

Replace invalid reinterpret_cast with static_cast
for CUdeviceptr in hip_piextMemGetNativeHandle
when building HIP PI on CUDA machine;

Signed-off-by: Lukas Sommer <[email protected]>
@sommerlukas sommerlukas requested a review from a team as a code owner May 27, 2022 15:23
@sommerlukas sommerlukas mentioned this pull request May 27, 2022
@@ -2131,8 +2131,7 @@ 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) {
*nativeHandle =
reinterpret_cast<pi_native_handle>(mem->mem_.buffer_mem_.get());
*nativeHandle = static_cast<pi_native_handle>(mem->mem_.buffer_mem_.get());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the issue:

Replacing the reinterpret_cast by static_cast avoids the compilation error, but might be unsafe due to narrowing.

Can we have a check that upper bits are zero and return some failure code if that's not the case?

Copy link
Contributor Author

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.

Signed-off-by: Lukas Sommer <[email protected]>
aelovikov-intel
aelovikov-intel previously approved these changes Jun 1, 2022
Copy link
Contributor

@aelovikov-intel aelovikov-intel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@sommerlukas
Copy link
Contributor Author

@aelovikov-intel: It seems that the workflow needs approval to run:

First-time contributors need a maintainer to approve running workflows.

Can you give this approval to trigger the workflow?

@bader bader changed the title [SYCL][HIP] Use valid cast for CUdeviceptr in HIP PI; [SYCL][HIP] Use valid cast for CUdeviceptr in HIP PI Jun 2, 2022
@sommerlukas
Copy link
Contributor Author

@aelovikov-intel: The workflow failed for HIP PI on AMD platform, sorry. I pushed a change that should hopefully fix this, can you approve the workflow again, please?

}
}
*nativeHandle = static_cast<pi_native_handle>(mem->mem_.buffer_mem_.get());
#elif defined(__HIP_PLATFORM_AMD__)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the code above not suitable for __HIP_PLATFORM_AMD__ ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you approve the workflow again, please?

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just FYI. I approved the workflow both times.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 hipDeviceptr_t (which is the same as native_type, the return of mem->mem_buffer_mem_.get()) is different on Nvidia and AMD platforms.

On Nvidia/CUDA platforms, it is an alias for CUdeviceptr, which is unsigned long long, so a static_cast is required to convert it to pi_native_handle (unsigned long).

On AMD platforms, it is an alias for void*, and static_cast of void* to unsigned long are invalid, so a reinterpret_cast is required on the AMD platform (and no checking of upper bits).

Copy link
Contributor

Choose a reason for hiding this comment

The 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!

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 = static_cast<pi_native_handle>(mem->mem_.buffer_mem_.get());
#elif defined(__HIP_PLATFORM_AMD__)
Copy link
Contributor

Choose a reason for hiding this comment

The 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!

@aelovikov-intel
Copy link
Contributor

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?

The failure happened on OpenCL and couldn't be affected by the HIP plugin change. I think it could be merged but I don't have write access to the repo. @againull , can you please merge this in?

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.

4 participants