-
Notifications
You must be signed in to change notification settings - Fork 14
Fix DecoupledLookback with a device-scope memory fence #116
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
Open
shreyas-omkar
wants to merge
3
commits into
JuliaGPU:main
Choose a base branch
from
shreyas-omkar:sh/device-fence
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,17 +13,29 @@ SIMD = "fdea26ae-647d-5447-a871-4b548cad5224" | |
| UnsafeAtomics = "013be700-e6cd-48c3-b4a1-df204f14c38f" | ||
|
|
||
| [weakdeps] | ||
| AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e" | ||
| CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" | ||
| Metal = "dde4c033-4e86-420c-a63e-0dd931031962" | ||
| OpenCL = "08131aa3-fb12-5dee-8b74-c09406e224a2" | ||
| oneAPI = "8f75cd03-7ff8-4ecb-9b8f-daf728133b1b" | ||
|
|
||
| [extensions] | ||
| AcceleratedKernelsAMDGPUExt = "AMDGPU" | ||
| AcceleratedKernelsCUDAExt = "CUDA" | ||
| AcceleratedKernelsMetalExt = "Metal" | ||
| AcceleratedKernelsOpenCLExt = "OpenCL" | ||
| AcceleratedKernelsoneAPIExt = "oneAPI" | ||
|
|
||
| [compat] | ||
| AMDGPU = "1, 2" | ||
| ArgCheck = "2" | ||
| Atomix = "0.1, 1" | ||
| CUDA = "5, 6" | ||
| GPUArraysCore = "0.2.0" | ||
| KernelAbstractions = "0.9.34, 0.10" | ||
| Markdown = "1" | ||
| Metal = "1.10, 2" | ||
|
Member
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. ??? |
||
| OpenCL = "0.10" | ||
| SIMD = "3" | ||
| UnsafeAtomics = "0.3.0" | ||
| julia = "1.10" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| module AcceleratedKernelsAMDGPUExt | ||
|
|
||
| using AMDGPU | ||
| import UnsafeAtomics | ||
| import AcceleratedKernels as AK | ||
|
|
||
| # Device-scope (agent) fence for the DecoupledLookback scan. | ||
| AMDGPU.Device.@device_override AK._decoupled_fence() = | ||
| UnsafeAtomics.fence(UnsafeAtomics.seq_cst, AMDGPU.syncscope_agent) | ||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| module AcceleratedKernelsCUDAExt | ||
|
|
||
| using CUDA | ||
| import AcceleratedKernels as AK | ||
|
|
||
| # Device-scope fence for the DecoupledLookback scan. | ||
| CUDA.@device_override AK._decoupled_fence() = CUDA.threadfence() | ||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| module AcceleratedKernelsMetalExt | ||
|
|
||
| using Metal | ||
| import AcceleratedKernels as AK | ||
|
|
||
| # Device-scope fence for the DecoupledLookback scan (Metal 3.2+). | ||
| Metal.@device_override AK._decoupled_fence() = | ||
| Metal.atomic_thread_fence(Metal.MemoryFlagDevice, Metal.memory_order_seq_cst, Metal.thread_scope_device) | ||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| module AcceleratedKernelsOpenCLExt | ||
|
|
||
| using OpenCL | ||
| using OpenCL: method_table # used by OpenCL.@device_override | ||
| import AcceleratedKernels as AK | ||
|
|
||
| # Device-scope SPIR-V fence for the DecoupledLookback scan (also the POCL path). | ||
| const SPIRV = OpenCL.SPIRVIntrinsics | ||
| OpenCL.@device_override AK._decoupled_fence() = | ||
| SPIRV.atomic_work_item_fence(SPIRV.GLOBAL_MEM_FENCE, SPIRV.memory_order_seq_cst, SPIRV.memory_scope_device) | ||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,11 @@ const ACC_FLAG_P::UInt8 = 1 # Only current block's prefix available | |||||
| end | ||||||
|
|
||||||
|
|
||||||
| # Device-scope memory fence for the DecoupledLookback scan. Each GPU backend overrides it with a | ||||||
| # native device fence in its package extension; a plain UnsafeAtomics.fence is not device scoped. | ||||||
| @inline _decoupled_fence() = nothing | ||||||
|
Member
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.
Suggested change
|
||||||
|
|
||||||
|
|
||||||
| # Register-raking block scan with striped loads and stores. | ||||||
| @kernel cpu=false inbounds=true unsafe_indices=true function _accumulate_block!( | ||||||
| op, v, init, neutral, | ||||||
|
|
@@ -147,7 +152,7 @@ end | |||||
| UnsafeAtomics.monotonic, | ||||||
| ) | ||||||
| if flag == ACC_FLAG_A | ||||||
| UnsafeAtomics.fence(UnsafeAtomics.acquire) | ||||||
| _decoupled_fence() # acquire: order the `v` read after the flag load | ||||||
| running_prefix = op(running_prefix, v[(inspected_block + 0x1) * block_size * ITEMS]) | ||||||
| break | ||||||
| else | ||||||
|
|
@@ -169,7 +174,7 @@ end | |||||
|
|
||||||
| # Publish writes to `v` before marking the block complete. | ||||||
| @synchronize() | ||||||
| UnsafeAtomics.fence(UnsafeAtomics.release) | ||||||
| _decoupled_fence() # release: order the flag store after the `v` writes | ||||||
| if ithread == 0x0 | ||||||
| UnsafeAtomics.store!( | ||||||
| pointer(flags, iblock + 0x1), | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Any reason you added AMDGPU v1 compat?