Skip to content
Draft
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
5 changes: 3 additions & 2 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ steps:
Pkg.develop(path="lib/intrinsics")

println("+++ :julia: Running tests")
Pkg.test(; coverage=true, test_args=`--platform=cuda`)'
Pkg.test(; coverage=true, test_args=`--debug-stats --verbose --platform=cuda`)'
agents:
queue: "juliagpu"
cuda: "*"
Expand Down Expand Up @@ -43,7 +43,7 @@ steps:
println("+++ :julia: Running tests")
using InteractiveUtils
InteractiveUtils.versioninfo()
Pkg.test(; coverage=true, test_args=`--platform=pocl`)'
Pkg.test(; coverage=true, test_args=`--debug-stats --verbose --platform=pocl`)'
agents:
queue: "juliaecosystem"
os: "macos"
Expand All @@ -55,3 +55,4 @@ steps:
julia:
- "1.10"
- "1.12"
- "1.13"
8 changes: 4 additions & 4 deletions .github/workflows/Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ matrix.memory_backend }} - PoCL ${{ matrix.pocl }}
runs-on: ${{ matrix.os }}
timeout-minutes: 100
timeout-minutes: 400
permissions: # needed to allow julia-actions/cache to proactively delete old caches that it has created
actions: write
contents: read
strategy:
fail-fast: false
matrix:
version: ['1.10', '1.12']
version: ['1.10', '1.12', 'pre']
os: [ubuntu-24.04, ubuntu-24.04-arm, macOS-15-intel, windows-2022]
arch: [x64, arm64]
pocl: [jll, local]
Expand Down Expand Up @@ -137,7 +137,7 @@ jobs:
uses: julia-actions/julia-runtest@v1
if: runner.os != 'Windows'
with:
test_args: '--quickfail --platform=pocl'
test_args: '--quickfail --debug-stats --verbose --platform=pocl'

- name: Setup BusyBox
if: runner.os == 'Windows'
Expand All @@ -149,7 +149,7 @@ jobs:
run: |
using Pkg
Pkg.activate(".")
Pkg.test(; test_args=`--quickfail --platform=pocl`)
Pkg.test(; test_args=`--quickfail --debug-stats --verbose --platform=pocl`)

- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v5
Expand Down
2 changes: 1 addition & 1 deletion src/OpenCL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using Random
using Preferences

import KernelAbstractions: KernelAbstractions

b = 4+3
using Core: LLVMPtr

# library wrappers
Expand Down
3 changes: 3 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
ParallelTestRunner = "d3525ed8-44d0-4b2c-a655-542cee43accc"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
Expand All @@ -25,3 +27,4 @@ pocl_jll = "627d6b7a-bbe6-5189-83e7-98cc0a5aeadd"

[compat]
pocl_jll = "7.0"
ParallelTestRunner = "2"
184 changes: 91 additions & 93 deletions test/array.jl
Original file line number Diff line number Diff line change
@@ -1,107 +1,105 @@
using LinearAlgebra
import Adapt

@testset "CLArray" begin
@testset "constructors" begin
xs = CLArray{Int, 2, cl.Buffer}(undef, 2, 3)
@test collect(CLArray([1 2; 3 4])) == [1 2; 3 4]
@test testf(vec, rand(Float32, 5, 3))
@test Base.elsize(xs) == sizeof(Int)
@test CLArray{Int, 2}(xs) === xs

@test device_accessible(xs)
@test !host_accessible(xs)
@test_throws ArgumentError Base.unsafe_convert(Ptr{Int}, xs)
@test_throws ArgumentError Base.unsafe_convert(Ptr{Float32}, xs)

@test collect(OpenCL.zeros(Float32, 2, 2)) == zeros(Float32, 2, 2)
@test collect(OpenCL.ones(Float32, 2, 2)) == ones(Float32, 2, 2)

@test collect(OpenCL.fill(0, 2, 2)) == zeros(Int, 2, 2)
@test collect(OpenCL.fill(1, 2, 2)) == ones(Int, 2, 2)
end
@testset "constructors" begin
xs = CLArray{Int, 2, cl.Buffer}(undef, 2, 3)
@test collect(CLArray([1 2; 3 4])) == [1 2; 3 4]
@test testf(vec, rand(Float32, 5, 3))
@test Base.elsize(xs) == sizeof(Int)
@test CLArray{Int, 2}(xs) === xs

@test device_accessible(xs)
@test !host_accessible(xs)
@test_throws ArgumentError Base.unsafe_convert(Ptr{Int}, xs)
@test_throws ArgumentError Base.unsafe_convert(Ptr{Float32}, xs)

@test collect(OpenCL.zeros(Float32, 2, 2)) == zeros(Float32, 2, 2)
@test collect(OpenCL.ones(Float32, 2, 2)) == ones(Float32, 2, 2)

@test collect(OpenCL.fill(0, 2, 2)) == zeros(Int, 2, 2)
@test collect(OpenCL.fill(1, 2, 2)) == ones(Int, 2, 2)
end

@testset "adapt" begin
A = rand(Float32, 3, 3)
dA = CLArray(A)
@test Adapt.adapt(Array, dA) == A
@test Adapt.adapt(CLArray, A) isa CLArray
@test Array(Adapt.adapt(CLArray, A)) == A
end
@testset "adapt" begin
A = rand(Float32, 3, 3)
dA = CLArray(A)
@test Adapt.adapt(Array, dA) == A
@test Adapt.adapt(CLArray, A) isa CLArray
@test Array(Adapt.adapt(CLArray, A)) == A
end

@testset "reshape" begin
A = [
1 2 3 4
5 6 7 8
]
gA = reshape(CLArray(A), 1, 8)
_A = reshape(A, 1, 8)
_gA = Array(gA)
@test all(_A .== _gA)
A = [1, 2, 3, 4]
gA = reshape(CLArray(A), 4)
end
@testset "reshape" begin
A = [
1 2 3 4
5 6 7 8
]
gA = reshape(CLArray(A), 1, 8)
_A = reshape(A, 1, 8)
_gA = Array(gA)
@test all(_A .== _gA)
A = [1, 2, 3, 4]
gA = reshape(CLArray(A), 4)
end

@testset "fill(::SubArray)" begin
xs = OpenCL.zeros(Float32, 3)
fill!(view(xs, 2:2), 1)
@test Array(xs) == [0, 1, 0]
@testset "fill(::SubArray)" begin
xs = OpenCL.zeros(Float32, 3)
fill!(view(xs, 2:2), 1)
@test Array(xs) == [0, 1, 0]
end
# TODO: Look into how to port the @sync

if cl.USMBackend() in cl.supported_memory_backends(cl.device())
@testset "shared buffers & unsafe_wrap" begin
a = CLVector{Int, cl.UnifiedSharedMemory}(undef, 2)

# check that basic operations work on arrays backed by shared memory
fill!(a, 40)
a .+= 2
@test Array(a) == [42, 42]

# derive an Array object and test that the memory keeps in sync
b = unsafe_wrap(Array, a)
b[1] = 100
@test Array(a) == [100, 42]
copyto!(a, 2, [200], 1, 1)
cl.finish(cl.queue())
@test b == [100, 200]
end
# TODO: Look into how to port the @sync

if cl.USMBackend() in cl.supported_memory_backends(cl.device())
@testset "shared buffers & unsafe_wrap" begin
a = CLVector{Int, cl.UnifiedSharedMemory}(undef, 2)

# check that basic operations work on arrays backed by shared memory
fill!(a, 40)
a .+= 2
@test Array(a) == [42, 42]

# derive an Array object and test that the memory keeps in sync
b = unsafe_wrap(Array, a)
b[1] = 100
@test Array(a) == [100, 42]
copyto!(a, 2, [200], 1, 1)
cl.finish(cl.queue())
@test b == [100, 200]
end

# https://github.com/JuliaGPU/CUDA.jl/issues/2191
@testset "preserving memory types" begin
a = CLVector{Int, cl.UnifiedSharedMemory}([1])
@test OpenCL.memtype(a) == cl.UnifiedSharedMemory

# unified-ness should be preserved
b = a .+ 1
@test OpenCL.memtype(b) == cl.UnifiedSharedMemory

# when there's a conflict, we should defer to unified memory
c = CLVector{Int, cl.UnifiedSharedMemory}([1])
d = CLVector{Int, cl.UnifiedDeviceMemory}([1])
e = c .+ d
@test OpenCL.memtype(e) == cl.UnifiedSharedMemory
end

# https://github.com/JuliaGPU/CUDA.jl/issues/2191
@testset "preserving memory types" begin
a = CLVector{Int, cl.UnifiedSharedMemory}([1])
@test OpenCL.memtype(a) == cl.UnifiedSharedMemory

# unified-ness should be preserved
b = a .+ 1
@test OpenCL.memtype(b) == cl.UnifiedSharedMemory

# when there's a conflict, we should defer to unified memory
c = CLVector{Int, cl.UnifiedSharedMemory}([1])
d = CLVector{Int, cl.UnifiedDeviceMemory}([1])
e = c .+ d
@test OpenCL.memtype(e) == cl.UnifiedSharedMemory
end
end

@testset "resizing" begin
a = CLArray([1, 2, 3])
@testset "resizing" begin
a = CLArray([1, 2, 3])

resize!(a, 3)
@test length(a) == 3
@test Array(a) == [1, 2, 3]
resize!(a, 3)
@test length(a) == 3
@test Array(a) == [1, 2, 3]

resize!(a, 5)
@test length(a) == 5
@test Array(a)[1:3] == [1, 2, 3]
resize!(a, 5)
@test length(a) == 5
@test Array(a)[1:3] == [1, 2, 3]

resize!(a, 2)
@test length(a) == 2
@test Array(a)[1:2] == [1, 2]
resize!(a, 2)
@test length(a) == 2
@test Array(a)[1:2] == [1, 2]

b = CLArray{Int}(undef, 0)
@test length(b) == 0
resize!(b, 1)
@test length(b) == 1
end
b = CLArray{Int}(undef, 0)
@test length(b) == 0
resize!(b, 1)
@test length(b) == 1
end
36 changes: 18 additions & 18 deletions test/atomics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,28 +101,28 @@ end
if T == Float64 && !("cl_khr_fp64" in cl.device().extensions)
continue
end
if "cl_ext_float_atomics" in cl.device().extensions
@eval function atomic_float_add(counter, val::$T)
@builtin_ccall(
"atomic_add", $T,
(LLVMPtr{$T, AS.CrossWorkgroup}, $T),
pointer(counter), val,
)
return
end
if "cl_ext_float_atomics" in cl.device().extensions
@eval function atomic_float_add(counter, val::$T)
@builtin_ccall(
"atomic_add", $T,
(LLVMPtr{$T, AS.CrossWorkgroup}, $T),
pointer(counter), val,
)
return
end

@testset "SPV_EXT_shader_atomic_float_add extension" begin
a = OpenCL.zeros(T)
@opencl global_size = 1000 extensions = ["SPV_EXT_shader_atomic_float_add"] atomic_float_add(a, one(T))
@test OpenCL.@allowscalar a[] == T(1000.0)
@testset "SPV_EXT_shader_atomic_float_add extension" begin
a = OpenCL.zeros(T)
@opencl global_size = 1000 extensions = ["SPV_EXT_shader_atomic_float_add"] atomic_float_add(a, one(T))
@test OpenCL.@allowscalar a[] == T(1000.0)

spv = sprint() do io
OpenCL.code_native(io, atomic_float_add, Tuple{CLDeviceArray{T, 0, 1}, T}; extensions = ["SPV_EXT_shader_atomic_float_add"])
end
@test occursin("OpExtension \"SPV_EXT_shader_atomic_float_add\"", spv)
@test occursin("OpAtomicFAddEXT", spv)
spv = sprint() do io
OpenCL.code_native(io, atomic_float_add, Tuple{CLDeviceArray{T, 0, 1}, T}; extensions = ["SPV_EXT_shader_atomic_float_add"])
end
@test occursin("OpExtension \"SPV_EXT_shader_atomic_float_add\"", spv)
@test occursin("OpAtomicFAddEXT", spv)
end
end

end
end
46 changes: 22 additions & 24 deletions test/cmdqueue.jl
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
@testset "CmdQueue" begin
@testset "constructor" begin
@test cl.CmdQueue() != nothing
@test cl.CmdQueue(:profile) != nothing
try
cl.CmdQueue(:out_of_order)
cl.CmdQueue((:profile, :out_of_order))
catch err
@warn("Platform $(cl.device().platform.name) does not seem to " *
"suport out of order queues: \n$err",maxlog=1,
exception=(err, catch_backtrace()))
end
@test_throws ArgumentError cl.CmdQueue(:unrecognized_flag)
for flag in [:profile, :out_of_order]
@test_throws ArgumentError cl.CmdQueue((flag, :unrecognized_flag))
@test_throws ArgumentError cl.CmdQueue((flag, flag))
end
@testset "constructor" begin
@test cl.CmdQueue() != nothing
@test cl.CmdQueue(:profile) != nothing
try
cl.CmdQueue(:out_of_order)
cl.CmdQueue((:profile, :out_of_order))
catch err
@warn("Platform $(cl.device().platform.name) does not seem to " *
"suport out of order queues: \n$err",maxlog=1,
exception=(err, catch_backtrace()))
end

@testset "info" begin
q = cl.CmdQueue()
@test q.context == cl.context()
@test q.device == cl.device()
@test q.reference_count > 0
@test typeof(q.properties) == cl.cl_command_queue_properties
@test_throws ArgumentError cl.CmdQueue(:unrecognized_flag)
for flag in [:profile, :out_of_order]
@test_throws ArgumentError cl.CmdQueue((flag, :unrecognized_flag))
@test_throws ArgumentError cl.CmdQueue((flag, flag))
end
end

@testset "info" begin
q = cl.CmdQueue()
@test q.context == cl.context()
@test q.device == cl.device()
@test q.reference_count > 0
@test typeof(q.properties) == cl.cl_command_queue_properties
end
Loading
Loading