Skip to content

Commit fe25dc6

Browse files
committed
Remove superfluous testsets.
1 parent fdafd68 commit fe25dc6

File tree

12 files changed

+556
-584
lines changed

12 files changed

+556
-584
lines changed

test/array.jl

Lines changed: 91 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,105 @@
11
using LinearAlgebra
22
import Adapt
33

4-
@testset "CLArray" begin
5-
@testset "constructors" begin
6-
xs = CLArray{Int, 2, cl.Buffer}(undef, 2, 3)
7-
@test collect(CLArray([1 2; 3 4])) == [1 2; 3 4]
8-
@test testf(vec, rand(Float32, 5, 3))
9-
@test Base.elsize(xs) == sizeof(Int)
10-
@test CLArray{Int, 2}(xs) === xs
11-
12-
@test device_accessible(xs)
13-
@test !host_accessible(xs)
14-
@test_throws ArgumentError Base.unsafe_convert(Ptr{Int}, xs)
15-
@test_throws ArgumentError Base.unsafe_convert(Ptr{Float32}, xs)
16-
17-
@test collect(OpenCL.zeros(Float32, 2, 2)) == zeros(Float32, 2, 2)
18-
@test collect(OpenCL.ones(Float32, 2, 2)) == ones(Float32, 2, 2)
19-
20-
@test collect(OpenCL.fill(0, 2, 2)) == zeros(Int, 2, 2)
21-
@test collect(OpenCL.fill(1, 2, 2)) == ones(Int, 2, 2)
22-
end
4+
@testset "constructors" begin
5+
xs = CLArray{Int, 2, cl.Buffer}(undef, 2, 3)
6+
@test collect(CLArray([1 2; 3 4])) == [1 2; 3 4]
7+
@test testf(vec, rand(Float32, 5, 3))
8+
@test Base.elsize(xs) == sizeof(Int)
9+
@test CLArray{Int, 2}(xs) === xs
10+
11+
@test device_accessible(xs)
12+
@test !host_accessible(xs)
13+
@test_throws ArgumentError Base.unsafe_convert(Ptr{Int}, xs)
14+
@test_throws ArgumentError Base.unsafe_convert(Ptr{Float32}, xs)
15+
16+
@test collect(OpenCL.zeros(Float32, 2, 2)) == zeros(Float32, 2, 2)
17+
@test collect(OpenCL.ones(Float32, 2, 2)) == ones(Float32, 2, 2)
18+
19+
@test collect(OpenCL.fill(0, 2, 2)) == zeros(Int, 2, 2)
20+
@test collect(OpenCL.fill(1, 2, 2)) == ones(Int, 2, 2)
21+
end
2322

24-
@testset "adapt" begin
25-
A = rand(Float32, 3, 3)
26-
dA = CLArray(A)
27-
@test Adapt.adapt(Array, dA) == A
28-
@test Adapt.adapt(CLArray, A) isa CLArray
29-
@test Array(Adapt.adapt(CLArray, A)) == A
30-
end
23+
@testset "adapt" begin
24+
A = rand(Float32, 3, 3)
25+
dA = CLArray(A)
26+
@test Adapt.adapt(Array, dA) == A
27+
@test Adapt.adapt(CLArray, A) isa CLArray
28+
@test Array(Adapt.adapt(CLArray, A)) == A
29+
end
3130

32-
@testset "reshape" begin
33-
A = [
34-
1 2 3 4
35-
5 6 7 8
36-
]
37-
gA = reshape(CLArray(A), 1, 8)
38-
_A = reshape(A, 1, 8)
39-
_gA = Array(gA)
40-
@test all(_A .== _gA)
41-
A = [1, 2, 3, 4]
42-
gA = reshape(CLArray(A), 4)
43-
end
31+
@testset "reshape" begin
32+
A = [
33+
1 2 3 4
34+
5 6 7 8
35+
]
36+
gA = reshape(CLArray(A), 1, 8)
37+
_A = reshape(A, 1, 8)
38+
_gA = Array(gA)
39+
@test all(_A .== _gA)
40+
A = [1, 2, 3, 4]
41+
gA = reshape(CLArray(A), 4)
42+
end
4443

45-
@testset "fill(::SubArray)" begin
46-
xs = OpenCL.zeros(Float32, 3)
47-
fill!(view(xs, 2:2), 1)
48-
@test Array(xs) == [0, 1, 0]
44+
@testset "fill(::SubArray)" begin
45+
xs = OpenCL.zeros(Float32, 3)
46+
fill!(view(xs, 2:2), 1)
47+
@test Array(xs) == [0, 1, 0]
48+
end
49+
# TODO: Look into how to port the @sync
50+
51+
if cl.memory_backend() isa cl.USMBackend
52+
@testset "shared buffers & unsafe_wrap" begin
53+
a = CLVector{Int, cl.UnifiedSharedMemory}(undef, 2)
54+
55+
# check that basic operations work on arrays backed by shared memory
56+
fill!(a, 40)
57+
a .+= 2
58+
@test Array(a) == [42, 42]
59+
60+
# derive an Array object and test that the memory keeps in sync
61+
b = unsafe_wrap(Array, a)
62+
b[1] = 100
63+
@test Array(a) == [100, 42]
64+
copyto!(a, 2, [200], 1, 1)
65+
cl.finish(cl.queue())
66+
@test b == [100, 200]
4967
end
50-
# TODO: Look into how to port the @sync
51-
52-
if cl.memory_backend() isa cl.USMBackend
53-
@testset "shared buffers & unsafe_wrap" begin
54-
a = CLVector{Int, cl.UnifiedSharedMemory}(undef, 2)
55-
56-
# check that basic operations work on arrays backed by shared memory
57-
fill!(a, 40)
58-
a .+= 2
59-
@test Array(a) == [42, 42]
60-
61-
# derive an Array object and test that the memory keeps in sync
62-
b = unsafe_wrap(Array, a)
63-
b[1] = 100
64-
@test Array(a) == [100, 42]
65-
copyto!(a, 2, [200], 1, 1)
66-
cl.finish(cl.queue())
67-
@test b == [100, 200]
68-
end
69-
70-
# https://github.com/JuliaGPU/CUDA.jl/issues/2191
71-
@testset "preserving memory types" begin
72-
a = CLVector{Int, cl.UnifiedSharedMemory}([1])
73-
@test OpenCL.memtype(a) == cl.UnifiedSharedMemory
74-
75-
# unified-ness should be preserved
76-
b = a .+ 1
77-
@test OpenCL.memtype(b) == cl.UnifiedSharedMemory
78-
79-
# when there's a conflict, we should defer to unified memory
80-
c = CLVector{Int, cl.UnifiedSharedMemory}([1])
81-
d = CLVector{Int, cl.UnifiedDeviceMemory}([1])
82-
e = c .+ d
83-
@test OpenCL.memtype(e) == cl.UnifiedSharedMemory
84-
end
68+
69+
# https://github.com/JuliaGPU/CUDA.jl/issues/2191
70+
@testset "preserving memory types" begin
71+
a = CLVector{Int, cl.UnifiedSharedMemory}([1])
72+
@test OpenCL.memtype(a) == cl.UnifiedSharedMemory
73+
74+
# unified-ness should be preserved
75+
b = a .+ 1
76+
@test OpenCL.memtype(b) == cl.UnifiedSharedMemory
77+
78+
# when there's a conflict, we should defer to unified memory
79+
c = CLVector{Int, cl.UnifiedSharedMemory}([1])
80+
d = CLVector{Int, cl.UnifiedDeviceMemory}([1])
81+
e = c .+ d
82+
@test OpenCL.memtype(e) == cl.UnifiedSharedMemory
8583
end
84+
end
8685

87-
@testset "resizing" begin
88-
a = CLArray([1, 2, 3])
86+
@testset "resizing" begin
87+
a = CLArray([1, 2, 3])
8988

90-
resize!(a, 3)
91-
@test length(a) == 3
92-
@test Array(a) == [1, 2, 3]
89+
resize!(a, 3)
90+
@test length(a) == 3
91+
@test Array(a) == [1, 2, 3]
9392

94-
resize!(a, 5)
95-
@test length(a) == 5
96-
@test Array(a)[1:3] == [1, 2, 3]
93+
resize!(a, 5)
94+
@test length(a) == 5
95+
@test Array(a)[1:3] == [1, 2, 3]
9796

98-
resize!(a, 2)
99-
@test length(a) == 2
100-
@test Array(a)[1:2] == [1, 2]
97+
resize!(a, 2)
98+
@test length(a) == 2
99+
@test Array(a)[1:2] == [1, 2]
101100

102-
b = CLArray{Int}(undef, 0)
103-
@test length(b) == 0
104-
resize!(b, 1)
105-
@test length(b) == 1
106-
end
101+
b = CLArray{Int}(undef, 0)
102+
@test length(b) == 0
103+
resize!(b, 1)
104+
@test length(b) == 1
107105
end

test/atomics.jl

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using SPIRVIntrinsics: @builtin_ccall, @typed_ccall, LLVMPtr
22

3-
@testset "atomics" begin
4-
53
function atomic_count(counter)
64
OpenCL.@atomic counter[] += 1
75
return
@@ -15,27 +13,25 @@ end
1513
end
1614
end
1715

18-
if "cl_ext_float_atomics" in cl.device().extensions
19-
function atomic_float_add(counter, val)
20-
@builtin_ccall(
21-
"atomic_add", Float32,
22-
(LLVMPtr{Float32, AS.CrossWorkgroup}, Float32),
23-
pointer(counter), val,
24-
)
25-
return
26-
end
16+
if "cl_ext_float_atomics" in cl.device().extensions
17+
function atomic_float_add(counter, val)
18+
@builtin_ccall(
19+
"atomic_add", Float32,
20+
(LLVMPtr{Float32, AS.CrossWorkgroup}, Float32),
21+
pointer(counter), val,
22+
)
23+
return
24+
end
2725

28-
@testset "SPV_EXT_shader_atomic_float_add extension" begin
29-
a = OpenCL.zeros(Float32)
30-
@opencl global_size = 1000 extensions = ["SPV_EXT_shader_atomic_float_add"] atomic_float_add(a, 1.0f0)
31-
@test OpenCL.@allowscalar a[] == 1000.0f0
26+
@testset "SPV_EXT_shader_atomic_float_add extension" begin
27+
a = OpenCL.zeros(Float32)
28+
@opencl global_size = 1000 extensions = ["SPV_EXT_shader_atomic_float_add"] atomic_float_add(a, 1.0f0)
29+
@test OpenCL.@allowscalar a[] == 1000.0f0
3230

33-
spv = sprint() do io
34-
OpenCL.code_native(io, atomic_float_add, Tuple{CLDeviceArray{Float32, 0, 1}, Float32}; extensions = ["SPV_EXT_shader_atomic_float_add"])
35-
end
36-
@test occursin("OpExtension \"SPV_EXT_shader_atomic_float_add\"", spv)
37-
@test occursin("OpAtomicFAddEXT", spv)
31+
spv = sprint() do io
32+
OpenCL.code_native(io, atomic_float_add, Tuple{CLDeviceArray{Float32, 0, 1}, Float32}; extensions = ["SPV_EXT_shader_atomic_float_add"])
3833
end
34+
@test occursin("OpExtension \"SPV_EXT_shader_atomic_float_add\"", spv)
35+
@test occursin("OpAtomicFAddEXT", spv)
3936
end
40-
4137
end

test/cmdqueue.jl

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
1-
@testset "CmdQueue" begin
2-
@testset "constructor" begin
3-
@test cl.CmdQueue() != nothing
4-
@test cl.CmdQueue(:profile) != nothing
5-
try
6-
cl.CmdQueue(:out_of_order)
7-
cl.CmdQueue((:profile, :out_of_order))
8-
catch err
9-
@warn("Platform $(cl.device().platform.name) does not seem to " *
10-
"suport out of order queues: \n$err",maxlog=1,
11-
exception=(err, catch_backtrace()))
12-
end
13-
@test_throws ArgumentError cl.CmdQueue(:unrecognized_flag)
14-
for flag in [:profile, :out_of_order]
15-
@test_throws ArgumentError cl.CmdQueue((flag, :unrecognized_flag))
16-
@test_throws ArgumentError cl.CmdQueue((flag, flag))
17-
end
1+
@testset "constructor" begin
2+
@test cl.CmdQueue() != nothing
3+
@test cl.CmdQueue(:profile) != nothing
4+
try
5+
cl.CmdQueue(:out_of_order)
6+
cl.CmdQueue((:profile, :out_of_order))
7+
catch err
8+
@warn("Platform $(cl.device().platform.name) does not seem to " *
9+
"suport out of order queues: \n$err",maxlog=1,
10+
exception=(err, catch_backtrace()))
1811
end
19-
20-
@testset "info" begin
21-
q = cl.CmdQueue()
22-
@test q.context == cl.context()
23-
@test q.device == cl.device()
24-
@test q.reference_count > 0
25-
@test typeof(q.properties) == cl.cl_command_queue_properties
12+
@test_throws ArgumentError cl.CmdQueue(:unrecognized_flag)
13+
for flag in [:profile, :out_of_order]
14+
@test_throws ArgumentError cl.CmdQueue((flag, :unrecognized_flag))
15+
@test_throws ArgumentError cl.CmdQueue((flag, flag))
2616
end
2717
end
18+
19+
@testset "info" begin
20+
q = cl.CmdQueue()
21+
@test q.context == cl.context()
22+
@test q.device == cl.device()
23+
@test q.reference_count > 0
24+
@test typeof(q.properties) == cl.cl_command_queue_properties
25+
end

0 commit comments

Comments
 (0)