-
Notifications
You must be signed in to change notification settings - Fork 33
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
Atomic compare_exchange implementation #1312
Conversation
a8f6c4e
to
fc4dbee
Compare
16e2488
to
7885146
Compare
7885146
to
69d0bfe
Compare
) | ||
# add conditional bitcast for atomic_ref pointer, | ||
# expected[expected_idx], and desired | ||
if sig.args[0].dtype == types.float32: |
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.
We can do it like follows as well to reduce code duplication:
if isinstance(sig.args[0].dtype, types.Float):
bitwidth = sig.args[0].dtype.bitwidth
atomic_ref_ptr = builder.bitcast(
atomic_ref_ptr,
llvmir.PointerType(
llvmir.IntType(bitwidth), addrspace=sig.args[0].address_space
),
)
expected_arg = builder.bitcast(expected_arg, llvmir.IntType(bitwidth))
desired_arg = builder.bitcast(desired_arg, llvmir.IntType(bitwidth))
Then we do not need two separate cases for fp32 and fp64.
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.
Let us skip as we have the same pattern in multiple places and let us just be consistent.
numba_dpex/experimental/_kernel_dpcpp_spirv_overloads/_atomic_ref_overloads.py
Show resolved
Hide resolved
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.
Overall looks good. I have one last improvement suggestion and after that the PR is good to go. Thank you @adarshyoga!
Atomic compare_exchange implementation 5374eb4
This PR contains the implementation of compare_exchange_strong and compare_exchange_weak atomic functions. It contains a test case that verifies both success and failure scenarios.