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

Atomic compare_exchange implementation #1312

Merged
merged 1 commit into from
Feb 6, 2024
Merged

Conversation

adarshyoga
Copy link
Contributor

@adarshyoga adarshyoga commented Feb 3, 2024

  • Have you provided a meaningful PR description?

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.

  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • If this PR is a work in progress, are you filing the PR as a draft?

@adarshyoga adarshyoga requested a review from diptorupd February 3, 2024 07:30
@adarshyoga adarshyoga self-assigned this Feb 3, 2024
@adarshyoga adarshyoga force-pushed the experimental/cmp_exchg_ols branch 2 times, most recently from a8f6c4e to fc4dbee Compare February 3, 2024 08:08
@diptorupd diptorupd force-pushed the experimental/cmp_exchg_ols branch 2 times, most recently from 16e2488 to 7885146 Compare February 4, 2024 02:25
@adarshyoga adarshyoga force-pushed the experimental/cmp_exchg_ols branch from 7885146 to 69d0bfe Compare February 5, 2024 22:11
)
# add conditional bitcast for atomic_ref pointer,
# expected[expected_idx], and desired
if sig.args[0].dtype == types.float32:
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

@diptorupd diptorupd left a 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!

@diptorupd diptorupd merged commit 5374eb4 into main Feb 6, 2024
55 of 61 checks passed
@diptorupd diptorupd deleted the experimental/cmp_exchg_ols branch February 6, 2024 03:52
github-actions bot added a commit that referenced this pull request Feb 6, 2024
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.

2 participants