Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ChainRulesCore = "1"
EnzymeCore = "0.8"
ExprTools = "0.1"
GPUArrays = "11.5.14"
GPUCompiler = "2.9"
GPUCompiler = "2.12"
GPUToolbox = "3"
KernelAbstractions = "0.9.2"
LLVM = "10"
Expand All @@ -80,5 +80,5 @@ SparseMatricesCSR = "0.6.9"
SpecialFunctions = "2"
StaticArraysCore = "1"
Statistics = "1"
UnsafeAtomics = "0.3"
UnsafeAtomics = "0.4"
julia = "1.10"
6 changes: 3 additions & 3 deletions src/AMDGPU.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ include("memory.jl")

Base.Experimental.@MethodTable(method_table)

#needs to be before Device since sync uses this
const syncscope_agent = UnsafeAtomics.Internal.LLVMSyncScope{:agent}()
const syncscope_workgroup = UnsafeAtomics.Internal.LLVMSyncScope{:workgroup}()
# Needs to be before Device since sync uses this. GPUCompiler emits `device` as LLVM's `agent`.
const syncscope_agent = UnsafeAtomics.device
const syncscope_workgroup = UnsafeAtomics.workgroup

# Referenced by the generated `kernel_state()`, and generators run in the world they are
# defined in, so this has to precede the device code.
Expand Down
14 changes: 0 additions & 14 deletions src/device/gcn/synchronization.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@

@llvmgenerated builder function _fence(::Val{ordering}, ::Val{scope})::Nothing where {ordering, scope}
fence!(builder, parse(LLVM.AtomicOrdering.T, String(ordering)); scope=String(scope))
nothing
end

for ord in UnsafeAtomics.Internal.orderings
for sync in (AMDGPU.syncscope_agent, AMDGPU.syncscope_workgroup)
ordering = Val(UnsafeAtomics.Internal.llvm_ordering(ord))
scope = Val(UnsafeAtomics.Internal.llvm_syncscope(sync))
@eval @device_function UnsafeAtomics.fence(::$(typeof(ord)), ::$(typeof(sync))) =
_fence($ordering, $scope)
end
end

"""
sync_workgroup()

Expand Down
23 changes: 23 additions & 0 deletions test/core/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,29 @@ using KernelAbstractions: @atomic
iob = IOBuffer()
AMDGPU.code_gcn(iob, synckern, Tuple{}; kernel=true)
@test occursin("s_barrier", String(take!(iob)))

AMDGPU.code_llvm(iob, synckern, Tuple{}; kernel=true)
@test count("fence syncscope(\"workgroup\") seq_cst", String(take!(iob))) == 2
end

@testset "Synchronization scopes" begin
# UnsafeAtomics' `device` scope has to reach LLVM as AMDGPU's `agent`
function atomic_add_ker!(x)
@inbounds @atomic x[1] += 1f0
return
end
function agent_fence_ker()
AMDGPU.UnsafeAtomics.fence(AMDGPU.UnsafeAtomics.seq_cst, AMDGPU.syncscope_agent)
return
end

iob = IOBuffer()
tt = Tuple{AMDGPU.Device.ROCDeviceVector{Float32, AMDGPU.Device.AS.Global}}
AMDGPU.code_llvm(iob, atomic_add_ker!, tt; kernel=true)
@test occursin(r"atomicrmw fadd .* syncscope\(\"agent\"\) seq_cst", String(take!(iob)))

AMDGPU.code_llvm(iob, agent_fence_ker, Tuple{}; kernel=true)
@test occursin("fence syncscope(\"agent\") seq_cst", String(take!(iob)))
end

@testset "Trapping" begin
Expand Down
Loading