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
7 changes: 6 additions & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
Expand All @@ -23,4 +24,8 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
pocl_jll = "627d6b7a-bbe6-5189-83e7-98cc0a5aeadd"

[compat]
pocl_jll = "7.0"
pocl_jll = "~7.0"
ParallelTestRunner = "1.0.1"

[sources]
ParallelTestRunner = {url="https://github.com/JuliaTesting/ParallelTestRunner.jl", rev="tb/testsuite"}
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.memory_backend() isa cl.USMBackend
@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.memory_backend() isa cl.USMBackend
@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
38 changes: 17 additions & 21 deletions test/atomics.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using SPIRVIntrinsics: @builtin_ccall, @typed_ccall, LLVMPtr

@testset "atomics" begin

function atomic_count(counter)
OpenCL.@atomic counter[] += 1
return
Expand All @@ -15,27 +13,25 @@ end
end
end

if "cl_ext_float_atomics" in cl.device().extensions
function atomic_float_add(counter, val)
@builtin_ccall(
"atomic_add", Float32,
(LLVMPtr{Float32, AS.CrossWorkgroup}, Float32),
pointer(counter), val,
)
return
end
if "cl_ext_float_atomics" in cl.device().extensions
function atomic_float_add(counter, val)
@builtin_ccall(
"atomic_add", Float32,
(LLVMPtr{Float32, AS.CrossWorkgroup}, Float32),
pointer(counter), val,
)
return
end

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

spv = sprint() do io
OpenCL.code_native(io, atomic_float_add, Tuple{CLDeviceArray{Float32, 0, 1}, Float32}; 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{Float32, 0, 1}, Float32}; extensions = ["SPV_EXT_shader_atomic_float_add"])
end
@test occursin("OpExtension \"SPV_EXT_shader_atomic_float_add\"", spv)
@test occursin("OpAtomicFAddEXT", spv)
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