Skip to content
Open
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
51 changes: 46 additions & 5 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ steps:
matrix:
setup:
version:
- "1.10"
- "1.11"
- "1.12"
test_args:
- "--verbose"
Expand All @@ -83,6 +81,48 @@ steps:
(build.message =~ /\[only [^\]]*(tests|julia)/ ||
build.message !~ /\[only / && !build.pull_request.draft)

# XXX: KernelAbstractions 0.10 and KernelInterface 0.4 aren't registered yet, and the
# registered AcceleratedKernels doesn't support KernelAbstractions 0.10. Without
# workspaces (Julia 1.11), only the test project, which depends on KernelAbstractions,
# can take it from [sources], and Julia 1.10 doesn't support [sources] at all. So run
# the tests in the test project, developing the packages from git on Julia 1.10, in
# one Pkg operation because AMDGPU's compat excludes the registered versions.
- label: "Julia {{matrix.version}}"
matrix:
setup:
version:
- "1.10"
- "1.11"
plugins:
- JuliaCI/julia#v1:
version: "{{matrix.version}}"
- JuliaCI/julia-coverage#v1:
codecov: true
agents:
queue: "rocm"
rocmgpu: "*"
if: |
build.message !~ /\[skip [^\]]*(tests|julia)/ &&
(build.message =~ /\[only [^\]]*(tests|julia)/ ||
build.message !~ /\[only / && !build.pull_request.draft)
commands: |
git clone --depth 1 --branch main https://github.com/JuliaGPU/KernelAbstractions.jl ka
git clone --depth 1 https://github.com/JuliaGPU/AcceleratedKernels.jl ak
julia --project=test -e '
using Pkg
if VERSION < v"1.11"
Pkg.develop([PackageSpec(; path) for path in (".", "ka", "ka/lib/KernelInterface", "ak")])
else
Pkg.instantiate()
end'
julia --project=test --check-bounds=yes --code-coverage=@. test/runtests.jl --verbose
timeout_in_minutes: 90
env:
JULIA_NUM_THREADS: 4
JULIA_AMDGPU_CORE_MUST_LOAD: "1"
JULIA_AMDGPU_HIP_MUST_LOAD: "1"
JULIA_AMDGPU_DISABLE_ARTIFACTS: "1"

- <<: *julia
matrix:
setup:
Expand All @@ -99,8 +139,8 @@ steps:
matrix:
setup:
version:
- "1.10"
- "1.11"
# XXX: needs Julia 1.12+ to pick up KernelAbstractions 0.10 from [sources]
- "1.12"
plugins:
- JuliaCI/julia#v1:
version: "{{matrix.version}}"
Expand All @@ -125,7 +165,8 @@ steps:
- label: "GPU-less environment"
plugins:
- JuliaCI/julia#v1:
version: "1.10"
# XXX: needs Julia 1.12+ to pick up KernelAbstractions 0.10 from [sources]
version: "1.12"
- JuliaCI/julia-test#v1:
run_tests: false
command: |
Expand Down
15 changes: 13 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ExprTools = "e2ba6199-217a-4e67-a87a-7c52f15ade04"
GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
GPUCompiler = "61eb1bfa-7361-4325-ad38-22787b887f55"
GPUToolbox = "096a3bc2-3ced-46d0-87f4-dd12716f4bfc"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
KernelInterface = "4ee993da-d684-4d17-a7dd-4e58e78d92bf"
LLVM = "929cbde3-209d-540e-8aea-75f648917ca0"
LLVMDowngrader_jll = "f52de702-fb25-5922-94ba-81dd59b07444"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Expand All @@ -39,15 +39,22 @@ UnsafeAtomics = "013be700-e6cd-48c3-b4a1-df204f14c38f"
[weakdeps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
EnzymeCore = "f151be2c-9106-41f4-ab19-57ee4f262869"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
SparseMatricesCSR = "a0a7dd2c-ebf4-11e9-1f05-cf50bc540ca1"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"

[extensions]
AMDGPUChainRulesCoreExt = "ChainRulesCore"
AMDGPUEnzymeCoreExt = "EnzymeCore"
AMDGPUKernelAbstractionsExt = "KernelAbstractions"
AMDGPUSparseMatricesCSRExt = "SparseMatricesCSR"
AMDGPUSpecialFunctionsExt = "SpecialFunctions"

[sources]
AcceleratedKernels = {url = "https://github.com/JuliaGPU/AcceleratedKernels.jl", rev = "main"}
KernelAbstractions = {url = "https://github.com/JuliaGPU/KernelAbstractions.jl", rev = "main"}
KernelInterface = {url = "https://github.com/JuliaGPU/KernelAbstractions.jl", rev = "main", subdir = "lib/KernelInterface"}

[compat]
AMDGPU_LLVM_Backend_jll = "23"
AbstractFFTs = "1.0"
Expand All @@ -62,7 +69,8 @@ ExprTools = "0.1"
GPUArrays = "11.5.14"
GPUCompiler = "2.9"
GPUToolbox = "3"
KernelAbstractions = "0.9.2"
KernelAbstractions = "0.10"
KernelInterface = "0.4"
LLVM = "9"
LLVMDowngrader_jll = "0.11"
Libdl = "1"
Expand All @@ -82,3 +90,6 @@ StaticArraysCore = "1"
Statistics = "1"
UnsafeAtomics = "0.3"
julia = "1.10"

[extras]
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
1 change: 1 addition & 0 deletions docs/src/api/devices.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ AMDGPU.device_id!
```@docs
AMDGPU.HIP.name
AMDGPU.HIP.wavefrontsize
AMDGPU.HIP.max_workgroup_dims
AMDGPU.HIP.gcn_arch
AMDGPU.HIP.device_id
AMDGPU.HIP.properties
Expand Down
1 change: 1 addition & 0 deletions docs/src/api/intrinsics.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ AMDGPU.Device.blockDim

```@docs
AMDGPU.sync_workgroup
AMDGPU.sync_wavefront
AMDGPU.sync_workgroup_count
AMDGPU.sync_workgroup_and
AMDGPU.sync_workgroup_or
Expand Down
42 changes: 42 additions & 0 deletions ext/AMDGPUKernelAbstractionsExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module AMDGPUKernelAbstractionsExt

import AMDGPU
import AMDGPU.Device: @device_override
using AMDGPU: GPUArrays, ROCBackend

import Adapt
import KernelAbstractions as KA
import LLVM

using StaticArraysCore: MArray

Adapt.adapt_storage(::KA.CPU, a::Union{AMDGPU.ROCArray, GPUArrays.AbstractGPUSparseArray}) =
Adapt.adapt(Array, a)

## kernel launch

# KernelAbstractions launches kernels through the KernelInterface back-end; tell the
# compiler about statically sized workgroups
function KA.compiler_options(obj::KA.Kernel{ROCBackend})
if KA.workgroupsize(obj) <: KA.StaticSize
return (; maxthreads = prod(KA.get(KA.workgroupsize(obj))))
else
return (;)
end
end

## scratch memory

@device_override @inline function KA.Scratchpad(ctx, ::Type{T}, ::Val{Dims}) where {T, Dims}
MArray{Tuple{Dims...}, T}(undef)
end

## other

# `@Const` arrays are read through the constant address space
function Adapt.adapt_storage(::KA.ConstAdaptor, a::AMDGPU.ROCDeviceArray{T}) where T
ptr = LLVM.Interop.addrspacecast(Core.LLVMPtr{T,AMDGPU.Device.AS.Constant}, a.ptr)
AMDGPU.ROCDeviceArray(a.dims, ptr)
end

end
5 changes: 4 additions & 1 deletion src/AMDGPU.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ using Preferences
using Printf

import AcceleratedKernels as AK
import KernelInterface
import UnsafeAtomics
import Atomix
import Atomix: @atomic, @atomicswap, @atomicreplace
Expand Down Expand Up @@ -82,6 +83,7 @@ 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}()
const syncscope_wavefront = UnsafeAtomics.Internal.LLVMSyncScope{:wavefront}()

# 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 All @@ -102,7 +104,7 @@ import .Device: ROCDeviceArray, AS, HostCall, HostCallHolder, hostcall!
import .Device: @ROCDynamicLocalArray, @ROCStaticLocalArray
import .Device: workitemIdx, workgroupIdx, workgroupDim, gridItemDim, gridGroupDim
import .Device: threadIdx, blockIdx, blockDim
import .Device: sync_workgroup, sync_workgroup_count, sync_workgroup_and, sync_workgroup_or
import .Device: sync_workgroup, sync_wavefront, sync_workgroup_count, sync_workgroup_and, sync_workgroup_or
import .Device: @rocprint, @rocprintln, @rocprintf

export ROCDeviceArray, @ROCDynamicLocalArray, @ROCStaticLocalArray
Expand Down Expand Up @@ -147,6 +149,7 @@ function Atomix.modify!(ref::ROCIndexableRef, op::OP, x, ord) where OP <: Union{
GC.@preserve root UnsafeAtomics.modify!(ptr, op, x, ord, syncscope_agent)
end

# KernelInterface
include("ROCKernels.jl")
import .ROCKernels: ROCBackend
export ROCBackend
Expand Down
Loading
Loading