Skip to content

Commit

Permalink
Use XUnit for parallel testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Feb 8, 2021
1 parent 7f68400 commit 1f23c0d
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 117 deletions.
11 changes: 1 addition & 10 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
name = "GPUArrays"
uuid = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
version = "6.2.0"
version = "6.3.0"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[compat]
AbstractFFTs = "0.4, 0.5, 1.0"
Adapt = "2.0, 3.0"
julia = "1.5"

[extras]
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "FillArrays"]
2 changes: 0 additions & 2 deletions src/GPUArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ using Printf
using LinearAlgebra.BLAS
using Base.Cartesian

using AbstractFFTs

using Adapt

# device functionality
Expand Down
6 changes: 6 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
XUnit = "3e3c03f2-1a94-11e9-2981-050a4ca824ab"
6 changes: 5 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using GPUArrays, Test
using GPUArrays, XUnit

@testset "GPUArrays" runner=ParallelTestRunner() begin

include("testsuite.jl")

Expand All @@ -15,3 +17,5 @@ end
@testset "Array" begin
TestSuite.test(Array)
end

end
3 changes: 2 additions & 1 deletion test/testsuite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ export supported_eltypes

using GPUArrays

using XUnit

using LinearAlgebra
using Random
using Test

using Adapt
using FillArrays
Expand Down
24 changes: 12 additions & 12 deletions test/testsuite/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function ntuple_closure(ctx, result, ::Val{N}, testval) where N
end

@testsuite "base" AT->begin
@testset "copyto!" begin
@testcase "copyto!" begin
x = fill(0f0, (10, 10))
y = rand(Float32, (20, 10))
a = AT(x)
Expand Down Expand Up @@ -115,7 +115,7 @@ end
end
end

@testset "vcat + hcat" begin
@testcase "vcat + hcat" begin
@test compare(vcat, AT, fill(0f0, (10, 10)), rand(Float32, 20, 10))
@test compare(hcat, AT, fill(0f0, (10, 10)), rand(Float32, 10, 10))

Expand All @@ -124,15 +124,15 @@ end
@test compare((a,b) -> cat(a, b; dims=4), AT, rand(Float32, 3, 4), rand(Float32, 3, 4))
end

@testset "reshape" begin
@testcase "reshape" begin
@test compare(reshape, AT, rand(10), Ref((10,)))
@test compare(reshape, AT, rand(10), Ref((10,1)))
@test compare(reshape, AT, rand(10), Ref((1,10)))

@test_throws Exception reshape(AT(rand(10)), (10,2))
end

@testset "reinterpret" begin
@testcase "reinterpret" begin
a = rand(ComplexF32, 22)
A = AT(a)
af0 = reinterpret(Float32, a)
Expand All @@ -148,7 +148,7 @@ end
@test Array(Af0) == af0
end

AT <: AbstractGPUArray && @testset "ntuple test" begin
AT <: AbstractGPUArray && @testcase "ntuple test" begin
result = AT(Vector{NTuple{3, Float32}}(undef, 1))
gpu_call(ntuple_test, result, Val(3))
@test Array(result)[1] == (77, 2*77, 3*77)
Expand All @@ -157,29 +157,29 @@ end
@test Array(result)[1] == (x, 2*x, 3*x)
end

AT <: AbstractGPUArray && @testset "cartesian iteration" begin
AT <: AbstractGPUArray && @testcase "cartesian iteration" begin
Ac = rand(Float32, 32, 32)
A = AT(Ac)
result = fill!(copy(A), 0.0)
gpu_call(cartesian_iter, result, A, size(A))
Array(result) == Ac
end

AT <: AbstractGPUArray && @testset "Custom kernel from Julia function" begin
AT <: AbstractGPUArray && @testcase "Custom kernel from Julia function" begin
x = AT(rand(Float32, 100))
y = AT(rand(Float32, 100))
gpu_call(clmap!, -, x, y; target=x)
jy = Array(y)
@test map!(-, jy, jy) Array(x)
end

@testset "map" begin
@testcase "map" begin
@test compare((a, b)-> map(+, a, b), AT, rand(Float32, 10), rand(Float32, 10))
@test compare((a, b)-> map!(-, a, b), AT, rand(Float32, 10), rand(Float32, 10))
@test compare((a, b, c, d)-> map!(*, a, b, c, d), AT, rand(Float32, 10), rand(Float32, 10), rand(Float32, 10), rand(Float32, 10))
end

@testset "repeat" begin
@testcase "repeat" begin
@test compare(a-> repeat(a, 5, 6), AT, rand(Float32, 10))
@test compare(a-> repeat(a, 5), AT, rand(Float32, 10))
@test compare(a-> repeat(a, 5), AT, rand(Float32, 5, 4))
Expand All @@ -189,18 +189,18 @@ end
@test compare(a-> repeat(a, 4, 0), AT, rand(Float32, 10, 15))
end

@testset "permutedims" begin
@testcase "permutedims" begin
@test compare(x->permutedims(x, [1, 2]), AT, rand(4, 4))

inds = rand(1:100, 150, 150)
@test compare(x->permutedims(view(x, inds, :), (3, 2, 1)), AT, rand(100, 100))
end

@testset "circshift" begin
@testcase "circshift" begin
@test compare(x->circshift(x, (0,1)), AT, reshape(Vector(1:16), (4,4)))
end

@testset "copy" begin
@testcase "copy" begin
a = AT([1])
b = copy(a)
fill!(b, 0)
Expand Down
22 changes: 11 additions & 11 deletions test/testsuite/broadcasting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
broadcasting(AT)
vec3(AT)

@testset "type instabilities" begin
@testcase "type instabilities" begin
f(x) = x ? 1.0 : 0
try
f.(AT(rand(Bool, 1)))
Expand Down Expand Up @@ -40,8 +40,8 @@ end
function broadcasting(AT)
for ET in supported_eltypes()
N = 10
@testset "broadcast $ET" begin
@testset "RefValue" begin
@testcase "broadcast $ET" begin
@testcase "RefValue" begin
cidx = rand(1:Int(N), 2*N)
gidx = AT(cidx)
cy = rand(ET, 2*N)
Expand All @@ -53,15 +53,15 @@ function broadcasting(AT)
@test Array(gres) == cres
end

@testset "Tuple" begin
@testcase "Tuple" begin
@test compare(AT, rand(ET, 3, N), rand(ET, 3, N), rand(ET, N), rand(ET, N), rand(ET, N)) do out, arr, a, b, c
broadcast!(out, arr, (a, b, c)) do xx, yy
xx + first(yy)
end
end
end

@testset "Adjoint and Transpose" begin
@testcase "Adjoint and Transpose" begin
A = AT(rand(ET, N))
A' .= ET(2)
@test all(isequal(ET(2)'), Array(A))
Expand Down Expand Up @@ -126,7 +126,7 @@ function broadcasting(AT)
@test compare((A, B) -> A .* B .+ ET(10), AT, rand(ET, 40, 40), rand(ET, 40, 40))
end

@testset "map! $ET" begin
@testcase "map! $ET" begin
@test compare(AT, rand(2,2), rand(2,2)) do x,y
map!(+, x, y)
end
Expand All @@ -138,7 +138,7 @@ function broadcasting(AT)
end
end

@testset "map $ET" begin
@testcase "map $ET" begin
@test compare(AT, rand(2,2), rand(2,2)) do x,y
map(+, x, y)
end
Expand All @@ -151,15 +151,15 @@ function broadcasting(AT)
end
end

@testset "0D" begin
@testcase "0D" begin
x = AT{Float64}(undef)
x .= 1
@test collect(x)[] == 1
x /= 2
@test collect(x)[] == 0.5
end

@testset "Ref" begin
@testcase "Ref" begin
# as first arg, 0d broadcast
@test compare(x->getindex.(Ref(x),1), AT, [0])

Expand All @@ -174,13 +174,13 @@ function broadcasting(AT)
@test Array(a) == Array(b)
end

@testset "stackoverflow in copy(::Broadcast)" begin
@testcase "stackoverflow in copy(::Broadcast)" begin
copy(Base.broadcasted(identity, AT(Int[])))
end
end

function vec3(AT)
@testset "vec 3" begin
@testcase "vec 3" begin
N = 20

xc = map(x-> ntuple(i-> rand(Float32), Val(3)), 1:N)
Expand Down
10 changes: 8 additions & 2 deletions test/testsuite/construction.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@testsuite "constructors" AT->begin
@testset "constructors + similar" begin
@testcase "constructors + similar" begin
for T in supported_eltypes()
B = AT{T}(undef, 10)
@test B isa AT{T,1}
Expand Down Expand Up @@ -65,7 +65,7 @@
end
end

@testset "comparison against Array" begin
@testcase "comparison against Array" begin
for typs in [(), (Int,), (Int,1), (Int,2), (Float32,), (Float32,1), (Float32,2)],
args in [(), (1,), (1,2), ((1,),), ((1,2),),
(undef,), (undef, 1,), (undef, 1,2), (undef, (1,),), (undef, (1,2),),
Expand Down Expand Up @@ -97,6 +97,7 @@ end

@testsuite "conversions" AT->begin
for T in supported_eltypes()
@testcase "$T" begin
Bc = round.(rand(10, 10) .* 10.0)
B = AT{T}(Bc)
@test size(B) == (10, 10)
Expand All @@ -121,10 +122,12 @@ end
@test eltype(B) == T
@test Array(B) Bc
end
end
end

@testsuite "value constructors" AT->begin
for T in supported_eltypes()
@testcase "$T" begin
@test compare((a,b)->fill!(a, b), AT, rand(T, 3), rand(T))

x = Matrix{T}(I, 4, 2)
Expand All @@ -142,10 +145,12 @@ end
@test eltype(x1) == T
@test Array(x1) x
end
end
end

@testsuite "iterator constructors" AT->begin
for T in supported_eltypes()
@testcase "$T" begin
@test Array(AT(Fill(T(0), (10,)))) == Array(fill!(similar(AT{T}, (10,)), T(0)))
@test Array(AT(Fill(T(0), (10, 10)))) == Array(fill!(similar(AT{T}, (10, 10)), T(0)))
if T <: Real
Expand All @@ -156,4 +161,5 @@ end
@test eltype(x) == Float32
end
end
end
end
Loading

0 comments on commit 1f23c0d

Please sign in to comment.