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

Add atomic_rmw! with syncscope #431

Merged
merged 6 commits into from
Jul 28, 2024

Conversation

pxl-th
Copy link
Contributor

@pxl-th pxl-th commented Jul 24, 2024

Add ability to specify syncscope for atomic_rmw! op.
This is needed to properly enable hardware floating-point atomics for AMDGPU (Ref: JuliaGPU/AMDGPU.jl#569) to avoid CAS loop.

Basically, expose syncscope argument here:
https://github.com/llvm/llvm-project/blob/8ebe499e07760b0d18b5721b298efc9e4a241916/llvm/lib/IR/Core.cpp#L4299-L4308

Before:

  • LLVM IR:
    %15 = atomicrmw fadd float addrspace(1)* %14, float 1.000000e+00 seq_cst, align 4, !dbg !148
  • ASM:
    global_atomic_cmpswap_b32 v2, v[0:1], v[2:3], off offset:-4 glc

With syncscope "agent":

  • LLVM IR:
    %15 = atomicrmw fadd float addrspace(1)* %14, float 1.000000e+00 syncscope("agent") seq_cst, align 4, !dbg !148
  • ASM:
    global_atomic_add_f32 v[0:1], v2, off offset:-4

@maleadt, I suppose wrappers in lib/ will be auto-updated or do I need to do this manually? I did it for a local build.

@maleadt
Copy link
Owner

maleadt commented Jul 24, 2024

@maleadt, I suppose wrappers in lib/ will be auto-updated or do I need to do this manually? I did it for a local build.

You need to manually re-generate the wrappers by running wrap.jl. CI will only build a local copy of LLVMExtra for you.

@pxl-th
Copy link
Contributor Author

pxl-th commented Jul 24, 2024

Done!

@pxl-th
Copy link
Contributor Author

pxl-th commented Jul 25, 2024

@maleadt, kind ping for review.

Copy link
Owner

@maleadt maleadt left a comment

Choose a reason for hiding this comment

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

LGTM, but needs tests.

@pxl-th pxl-th requested a review from maleadt July 25, 2024 13:29
@pxl-th
Copy link
Contributor Author

pxl-th commented Jul 27, 2024

@maleadt, I've updated tests for LLVM < 16. Hopefully now they will pass :)

LocalPreferences.toml.toml Outdated Show resolved Hide resolved
@maleadt
Copy link
Owner

maleadt commented Jul 28, 2024

LGTM. CI failure is EnzymeAD/Enzyme.jl#1688

@maleadt maleadt merged commit 9950c87 into maleadt:master Jul 28, 2024
16 of 20 checks passed
@pxl-th pxl-th deleted the pxl-th/atomic-syncscope branch July 28, 2024 09:06
@pxl-th
Copy link
Contributor Author

pxl-th commented Jul 28, 2024

Thanks! Can we tag a new release so that further packages can use it?

@maleadt
Copy link
Owner

maleadt commented Jul 28, 2024

First needs a JLL bump. I'll create a PR.

nikic pushed a commit to llvm/llvm-project that referenced this pull request Aug 20, 2024
…104775)

Another upstreaming of C API extensions we have in Julia/LLVM.jl.
Although [we went](maleadt/LLVM.jl#431) with a
string-based API there, here I'm proposing something that's similar to
existing metadata/attribute APIs:
- explicit functions to map syncscope names to IDs, and back
- `LLVM*SyncScope` versions of builder APIs that already take a
`SingleThread` argument: atomic rmw, atomic xchg, fence
- `LLVMGetAtomicSyncScopeID` and `LLVMSetAtomicSyncScopeID` for other
atomic instructions
- testing through `llvm-c-test`'s `--echo` functionality
dmpolukhin pushed a commit to dmpolukhin/llvm-project that referenced this pull request Sep 2, 2024
…lvm#104775)

Another upstreaming of C API extensions we have in Julia/LLVM.jl.
Although [we went](maleadt/LLVM.jl#431) with a
string-based API there, here I'm proposing something that's similar to
existing metadata/attribute APIs:
- explicit functions to map syncscope names to IDs, and back
- `LLVM*SyncScope` versions of builder APIs that already take a
`SingleThread` argument: atomic rmw, atomic xchg, fence
- `LLVMGetAtomicSyncScopeID` and `LLVMSetAtomicSyncScopeID` for other
atomic instructions
- testing through `llvm-c-test`'s `--echo` functionality
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants