From 1f23c0d1c8d8cfc87a40a5448bf6a9024cd6e771 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Mon, 8 Feb 2021 09:08:55 +0100 Subject: [PATCH 1/6] Use XUnit for parallel testing. --- Project.toml | 11 +---- src/GPUArrays.jl | 2 - test/Project.toml | 6 +++ test/runtests.jl | 6 ++- test/testsuite.jl | 3 +- test/testsuite/base.jl | 24 +++++----- test/testsuite/broadcasting.jl | 22 ++++----- test/testsuite/construction.jl | 10 +++- test/testsuite/gpuinterface.jl | 78 ++++++++++++++++---------------- test/testsuite/indexing.jl | 52 +++++++++++++++------ test/testsuite/io.jl | 2 +- test/testsuite/linalg.jl | 38 ++++++++++------ test/testsuite/mapreduce.jl | 16 ++++--- test/testsuite/math.jl | 4 +- test/testsuite/random.jl | 4 +- test/testsuite/uniformscaling.jl | 4 +- 16 files changed, 165 insertions(+), 117 deletions(-) create mode 100644 test/Project.toml diff --git a/Project.toml b/Project.toml index b29f7724..a62cde16 100644 --- a/Project.toml +++ b/Project.toml @@ -1,9 +1,8 @@ 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" @@ -11,13 +10,5 @@ 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"] diff --git a/src/GPUArrays.jl b/src/GPUArrays.jl index 7b745999..8aa2f5e6 100644 --- a/src/GPUArrays.jl +++ b/src/GPUArrays.jl @@ -8,8 +8,6 @@ using Printf using LinearAlgebra.BLAS using Base.Cartesian -using AbstractFFTs - using Adapt # device functionality diff --git a/test/Project.toml b/test/Project.toml new file mode 100644 index 00000000..51905b84 --- /dev/null +++ b/test/Project.toml @@ -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" diff --git a/test/runtests.jl b/test/runtests.jl index d097ad42..f43d76be 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,6 @@ -using GPUArrays, Test +using GPUArrays, XUnit + +@testset "GPUArrays" runner=ParallelTestRunner() begin include("testsuite.jl") @@ -15,3 +17,5 @@ end @testset "Array" begin TestSuite.test(Array) end + +end diff --git a/test/testsuite.jl b/test/testsuite.jl index bcc7e192..26154909 100644 --- a/test/testsuite.jl +++ b/test/testsuite.jl @@ -8,9 +8,10 @@ export supported_eltypes using GPUArrays +using XUnit + using LinearAlgebra using Random -using Test using Adapt using FillArrays diff --git a/test/testsuite/base.jl b/test/testsuite/base.jl index 5011aa16..c21bd2bf 100644 --- a/test/testsuite/base.jl +++ b/test/testsuite/base.jl @@ -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) @@ -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)) @@ -124,7 +124,7 @@ 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))) @@ -132,7 +132,7 @@ end @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) @@ -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) @@ -157,7 +157,7 @@ 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) @@ -165,7 +165,7 @@ end 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) @@ -173,13 +173,13 @@ end @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)) @@ -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) diff --git a/test/testsuite/broadcasting.jl b/test/testsuite/broadcasting.jl index e6eeefe4..51bd3f73 100644 --- a/test/testsuite/broadcasting.jl +++ b/test/testsuite/broadcasting.jl @@ -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))) @@ -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) @@ -53,7 +53,7 @@ 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) @@ -61,7 +61,7 @@ function broadcasting(AT) 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)) @@ -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 @@ -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 @@ -151,7 +151,7 @@ function broadcasting(AT) end end - @testset "0D" begin + @testcase "0D" begin x = AT{Float64}(undef) x .= 1 @test collect(x)[] == 1 @@ -159,7 +159,7 @@ function broadcasting(AT) @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]) @@ -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) diff --git a/test/testsuite/construction.jl b/test/testsuite/construction.jl index d0d07daf..9b666103 100644 --- a/test/testsuite/construction.jl +++ b/test/testsuite/construction.jl @@ -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} @@ -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),), @@ -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) @@ -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) @@ -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 @@ -156,4 +161,5 @@ end @test eltype(x) == Float32 end end + end end diff --git a/test/testsuite/gpuinterface.jl b/test/testsuite/gpuinterface.jl index bac710fe..26c0beab 100644 --- a/test/testsuite/gpuinterface.jl +++ b/test/testsuite/gpuinterface.jl @@ -1,47 +1,49 @@ @testsuite "interface" AT->begin AT <: AbstractGPUArray || return - N = 10 - x = AT(Vector{Int}(undef, N)) - x .= 0 - gpu_call(x) do ctx, x - x[linear_index(ctx)] = 2 - return - end - @test all(x-> x == 2, Array(x)) + @testcase "essentials" begin + N = 10 + x = AT(Vector{Int}(undef, N)) + x .= 0 + gpu_call(x) do ctx, x + x[linear_index(ctx)] = 2 + return + end + @test all(x-> x == 2, Array(x)) - gpu_call(x; total_threads=N) do ctx, x - x[linear_index(ctx)] = 2 - return - end - @test all(x-> x == 2, Array(x)) - gpu_call(x; threads=2, blocks=(N ÷ 2)) do ctx, x - x[linear_index(ctx)] = threadidx(ctx) - return - end - @test Array(x) == [1,2,1,2,1,2,1,2,1,2] + gpu_call(x; total_threads=N) do ctx, x + x[linear_index(ctx)] = 2 + return + end + @test all(x-> x == 2, Array(x)) + gpu_call(x; threads=2, blocks=(N ÷ 2)) do ctx, x + x[linear_index(ctx)] = threadidx(ctx) + return + end + @test Array(x) == [1,2,1,2,1,2,1,2,1,2] - gpu_call(x; threads=2, blocks=(N ÷ 2)) do ctx, x - x[linear_index(ctx)] = blockidx(ctx) - return - end - @test Array(x) == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5] - x2 = AT([0]) - gpu_call(x2; threads=2, blocks=(N ÷ 2), target=x) do ctx, x - x[1] = blockdim(ctx) - return - end - @test Array(x2) == [2] + gpu_call(x; threads=2, blocks=(N ÷ 2)) do ctx, x + x[linear_index(ctx)] = blockidx(ctx) + return + end + @test Array(x) == [1, 1, 2, 2, 3, 3, 4, 4, 5, 5] + x2 = AT([0]) + gpu_call(x2; threads=2, blocks=(N ÷ 2), target=x) do ctx, x + x[1] = blockdim(ctx) + return + end + @test Array(x2) == [2] - gpu_call(x2; threads=2, blocks=(N ÷ 2), target=x) do ctx, x - x[1] = griddim(ctx) - return - end - @test Array(x2) == [5] + gpu_call(x2; threads=2, blocks=(N ÷ 2), target=x) do ctx, x + x[1] = griddim(ctx) + return + end + @test Array(x2) == [5] - gpu_call(x2; threads=2, blocks=(N ÷ 2), target=x) do ctx, x - x[1] = global_size(ctx) - return + gpu_call(x2; threads=2, blocks=(N ÷ 2), target=x) do ctx, x + x[1] = global_size(ctx) + return + end + @test Array(x2) == [10] end - @test Array(x2) == [10] end diff --git a/test/testsuite/indexing.jl b/test/testsuite/indexing.jl index 052e1e47..3955146c 100644 --- a/test/testsuite/indexing.jl +++ b/test/testsuite/indexing.jl @@ -1,5 +1,6 @@ -@testsuite "indexing scalar" AT->begin - AT <: AbstractGPUArray && @allowscalar @testset "errors and warnings" begin +@testsuite "scalar indexing" AT->begin + AT <: AbstractGPUArray && @testcase "errors and warnings" begin + @allowscalar begin x = AT([0]) allowscalar(true, false) @@ -41,8 +42,11 @@ # NOTE: this inner testset _needs_ to be wrapped with allowscalar # to make sure its original value is restored. end + end - @allowscalar @testset "getindex with $T" for T in supported_eltypes() + for T in supported_eltypes() + @testcase "getindex with $T" begin + @allowscalar begin x = rand(T, 32) src = AT(x) for (i, xi) in enumerate(x) @@ -51,8 +55,12 @@ @test Array(src[1:3]) == x[1:3] @test Array(src[3:end]) == x[3:end] end + end + end - @allowscalar @testset "setindex! with $T" for T in supported_eltypes() + for T in supported_eltypes() + @testcase "setindex! with $T" begin + @allowscalar begin x = fill(zero(T), 7) src = AT(x) for i = 1:7 @@ -63,16 +71,23 @@ @test Array(src[1:3]) == T[77, 22, 11] src[1] = T(0) end + end + end - @allowscalar @testset "issue #42 with $T" for T in supported_eltypes() + for T in supported_eltypes() + @testcase "issue #42 with $T" begin + @allowscalar begin Ac = rand(Float32, 2, 2) A = AT(Ac) @test A[1] == Ac[1] @test A[end] == Ac[end] @test A[1, 1] == Ac[1, 1] end + end + end - @allowscalar @testset "get/setindex!" begin + @testcase "get/setindex!" begin + @allowscalar begin # literal calls to get/setindex! have different return types @test compare(x->getindex(x,1), AT, zeros(Int, 2)) @test compare(x->setindex!(x,1,1), AT, zeros(Int, 2)) @@ -80,32 +95,39 @@ # issue #319 @test compare(x->setindex!(x,1,1,1), AT, zeros(Float64, 2, 2)) end + end end @testsuite "indexing multidimensional" AT->begin - @testset "sliced setindex" for T in supported_eltypes() + for T in supported_eltypes() + @testcase "sliced setindex with $T" begin x = AT(zeros(T, (10, 10, 10, 10))) y = AT(rand(T, (5, 5, 10, 10))) x[2:6, 2:6, :, :] = y @test Array(x[2:6, 2:6, :, :]) == Array(y) end + end - @testset "sliced setindex, CPU source" for T in supported_eltypes() + for T in supported_eltypes() + @testcase "sliced setindex, CPU source with $T" begin x = AT(zeros(T, (2,3,4))) y = AT(rand(T, (2,3))) x[:, :, 2] = y @test Array(x[:, :, 2]) == Array(y) end + end - @allowscalar @testset "empty array" begin - @testset "1D" begin + @testcase "empty array" begin + @allowscalar begin + @testcase "1D" begin Ac = zeros(Float32, 10) A = AT(Ac) @test typeof(A[[]]) == typeof(AT(Ac[[]])) @test size(A[[]]) == size(Ac[[]]) end - @testset "2D with other index $other" for other in (Colon(), 1:5, 5) + for other in (Colon(), 1:5, 5) + @testcase "2D with other index $other" begin Ac = zeros(Float32, 10, 10) A = AT(Ac) @@ -115,13 +137,15 @@ end @test typeof(A[other, []]) == typeof(AT(Ac[other, []])) @test size(A[other, []]) == size(Ac[other, []]) end + end @test compare(AT, rand(Float32, 2,2)) do a a[:, 2:end-2] = AT{Float32}(undef,2,0) end end + end - @testset "GPU source" begin + @testcase "GPU source" begin a = rand(3) i = rand(1:3, 2) @test compare(getindex, AT, a, i) @@ -129,7 +153,7 @@ end @test compare(getindex, AT, a, view(i, 2:2)) end - @testset "CPU source" begin + @testcase "CPU source" begin # JuliaGPU/CUDA.jl#345 a = rand(3,4) i = rand(1:3,2,2) @@ -138,7 +162,7 @@ end @test compare(a->a[view(i,1,:),:], AT, a) end - @testset "JuliaGPU/CUDA.jl#461: sliced setindex" begin + @testcase "JuliaGPU/CUDA.jl#461: sliced setindex" begin @test compare((X,Y)->(X[1,:] = Y), AT, zeros(2,2), ones(2)) end end diff --git a/test/testsuite/io.jl b/test/testsuite/io.jl index 7d0c58e4..66a87d96 100644 --- a/test/testsuite/io.jl +++ b/test/testsuite/io.jl @@ -4,7 +4,7 @@ replstr(x, kv::Pair...) = sprint((io,x) -> show(IOContext(io, :compact => false, :limit => true, :displaysize => (24, 80), kv...), MIME("text/plain"), x), x) showstr(x, kv::Pair...) = sprint((io,x) -> show(IOContext(io, :limit => true, :displaysize => (24, 80), kv...), x), x) - @testset "showing" begin + @testcase "showing" begin # vectors and non-vector arrays showing # are handled differently in base/arrayshow.jl A = AT(Int64[1]) diff --git a/test/testsuite/linalg.jl b/test/testsuite/linalg.jl index 1276ceef..32b5bbd1 100644 --- a/test/testsuite/linalg.jl +++ b/test/testsuite/linalg.jl @@ -1,5 +1,5 @@ @testsuite "linear algebra" AT->begin - @testset "adjoint and transpose" begin + @testcase "adjoint and transpose" begin @test compare(adjoint, AT, rand(Float32, 32, 32)) @test compare(adjoint!, AT, rand(Float32, 32, 32), rand(Float32, 32, 32)) @test compare(transpose, AT, rand(Float32, 32, 32)) @@ -10,13 +10,13 @@ @test compare(transpose!, AT, Array{Float32}(undef, 128, 32), rand(Float32, 32, 128)) end - @testset "copytri!" begin - @testset for uplo in ('U', 'L') - @test compare(x -> LinearAlgebra.copytri!(x, uplo), AT, rand(Float32, 128, 128)) - end + for uplo in ('U', 'L') + @testcase "copytri! $uplo" begin + @test compare(x -> LinearAlgebra.copytri!(x, uplo), AT, rand(Float32, 128, 128)) + end end - @testset "copyto! for triangular" begin + @testcase "copyto! for triangular" begin for TR in (UpperTriangular, LowerTriangular) @test compare(transpose!, AT, Array{Float32}(undef, 128, 32), rand(Float32, 32, 128)) @@ -45,7 +45,7 @@ end end - @testset "permutedims" begin + @testcase "permutedims" begin @test compare(x -> permutedims(x, (2, 1)), AT, rand(Float32, 2, 3)) @test compare(x -> permutedims(x, (2, 1, 3)), AT, rand(Float32, 4, 5, 6)) @test compare(x -> permutedims(x, (3, 1, 2)), AT, rand(Float32, 4, 5, 6)) @@ -57,15 +57,18 @@ areal = randn(n,n)/2 aimg = randn(n,n)/2 - @testset for eltya in (Float32, Float64, ComplexF32, ComplexF64) + for eltya in (Float32, Float64, ComplexF32, ComplexF64) + @testcase "$eltya" begin a = convert(Matrix{eltya}, eltya <: Complex ? complex.(areal, aimg) : areal) asym = transpose(a) + a # symmetric indefinite aherm = a' + a # Hermitian indefinite @test issymmetric(asym) @test ishermitian(aherm) end + end end - @testset "Array + Diagonal" begin + + @testcase "Array + Diagonal" begin n = 128 A = AT{Float32}(undef, n, n) d = AT{Float32}(undef, n) @@ -76,13 +79,15 @@ @test collect(B) ≈ collect(A) + collect(D) end - @testset "$f! with diagonal $d" for (f, f!) in ((triu, triu!), (tril, tril!)), - d in -2:2 + for (f, f!) in ((triu, triu!), (tril, tril!)), d in -2:2 + @testcase "$f! with diagonal $d" begin A = randn(10, 10) @test f(A, d) == Array(f!(AT(A), d)) end + end - @testset "$T gemv y := $f(A) * x * a + y * b" for f in (identity, transpose, adjoint), T in supported_eltypes() + for f in (identity, transpose, adjoint), T in supported_eltypes() + @testcase "$T gemv y := $f(A) * x * a + y * b" begin y, A, x = rand(T, 4), rand(T, 4, 4), rand(T, 4) # workaround for https://github.com/JuliaLang/julia/issues/35163#issue-584248084 @@ -97,8 +102,10 @@ @test compare(mul!, AT, rand(T, 2,2), rand(T, 2,1), f(rand(T, 2))) end end + end - @testset "$T gemm C := $f(A) * $g(B) * a + C * b" for f in (identity, transpose, adjoint), g in (identity, transpose, adjoint), T in supported_eltypes() + for f in (identity, transpose, adjoint), g in (identity, transpose, adjoint), T in supported_eltypes() + @testcase "$T gemm C := $f(A) * $g(B) * a + C * b" begin A, B, C = rand(T, 4, 4), rand(T, 4, 4), rand(T, 4, 4) # workaround for https://github.com/JuliaLang/julia/issues/35163#issue-584248084 @@ -109,9 +116,12 @@ @test compare(mul!, AT, C, f(A), g(B), Ref(T(4)), Ref(T(5))) @test typeof(AT(rand(3, 3)) * AT(rand(3, 3))) <: AbstractMatrix end + end - @testset "lmul! and rmul!" for (a,b) in [((3,4),(4,3)), ((3,), (1,3)), ((1,3), (3))], T in supported_eltypes() + for (a,b) in [((3,4),(4,3)), ((3,), (1,3)), ((1,3), (3))], T in supported_eltypes() + @testcase "lmul! and rmul! $a x $b with $T" begin @test compare(rmul!, AT, rand(T, a), Ref(rand(T))) @test compare(lmul!, AT, Ref(rand(T)), rand(T, b)) end + end end diff --git a/test/testsuite/mapreduce.jl b/test/testsuite/mapreduce.jl index f35bfcb5..6f3126ee 100644 --- a/test/testsuite/mapreduce.jl +++ b/test/testsuite/mapreduce.jl @@ -1,5 +1,6 @@ @testsuite "mapreduce essentials" AT->begin - @testset "mapreducedim! $ET" for ET in supported_eltypes() + for ET in supported_eltypes() + @testcase "mapreducedim! $ET" begin T = AT{ET} range = ET <: Real ? (ET(1):ET(10)) : ET for (sz,red) in [(10,)=>(1,), (10,10)=>(1,1), (10,10,10)=>(1,1,1), (10,10,10)=>(10,10,10), @@ -14,7 +15,7 @@ @test compare((A,R)->Base.mapreducedim!(identity, +, R, A), AT, rand(range, (2,3)), zeros(ET, (2,))) end - @testset "reducedim! $ET" for ET in supported_eltypes() + @testcase "reducedim! $ET" begin T = AT{ET} range = ET <: Real ? (ET(1):ET(10)) : ET for (sz,red) in [(10,)=>(1,), (10,10)=>(1,1), (10,10,10)=>(1,1,1), (10,10,10)=>(10,10,10), @@ -24,7 +25,7 @@ end end - @testset "mapreduce $ET" for ET in supported_eltypes() + @testcase "mapreduce $ET" begin T = AT{ET} range = ET <: Real ? (ET(1):ET(10)) : ET for (sz,dims) in [(10,)=>[1], (10,10)=>[1,2], (10,10,10)=>[1,2,3], (10,10,10)=>[], @@ -36,7 +37,7 @@ end end - @testset "reduce $ET" for ET in supported_eltypes() + @testcase "reduce $ET" begin T = AT{ET} range = ET <: Real ? (ET(1):ET(10)) : ET for (sz,dims) in [(10,)=>[1], (10,10)=>[1,2], (10,10,10)=>[1,2,3], (10,10,10)=>[], @@ -46,10 +47,12 @@ @test compare(A->reduce(*, A; dims=dims, init=one(ET)), AT, rand(range, sz)) end end + end end @testsuite "mapreduce derivatives" AT->begin - @testset "sum prod minimum maximum $ET" for ET in supported_eltypes() + for ET in supported_eltypes() + @testcase "sum prod minimum maximum $ET" begin T = AT{ET} range = ET <: Real ? (ET(1):ET(10)) : ET for (sz,dims) in [(10,)=>[1], (10,10)=>[1,2], (10,10,10)=>[1,2,3], (10,10,10)=>[], @@ -87,8 +90,9 @@ end end end end + end - @testset "any all count ==" begin + @testcase "any all count ==" begin for Ac in ([false, false], [false, true], [true, true], [false false; false false], [false true; false false], [true true; false false], [true true; true true]) diff --git a/test/testsuite/math.jl b/test/testsuite/math.jl index edf72780..74c42afc 100644 --- a/test/testsuite/math.jl +++ b/test/testsuite/math.jl @@ -4,11 +4,11 @@ ET in (Complex, ComplexF32, ComplexF64) && continue T = AT{ET} - @testset "$ET" begin + @testcase "$ET" begin range = ET <: Integer ? (ET(-2):ET(2)) : ET low = ET(-1) high = ET(1) - @testset "clamp!" begin + @testcase "clamp!" begin for N in (2, 10) @test compare(x -> clamp!(x, low, high), AT, rand(range, N, N)) end diff --git a/test/testsuite/random.jl b/test/testsuite/random.jl index 5cd0ea43..ae1b346c 100644 --- a/test/testsuite/random.jl +++ b/test/testsuite/random.jl @@ -1,5 +1,5 @@ @testsuite "random" AT->begin - @testset "rand" begin # uniform + @testcase "rand" begin # uniform for T in (Int8, Float32, Float64, Int64, Int32, Complex{Float32}, Complex{Float64}, Complex{Int64}, Complex{Int32}), d in (10, (10,10)) @@ -28,7 +28,7 @@ @test false in Array(A) end - @testset "randn" begin # uniform + @testcase "randn" begin # uniform for T in (Float32, Float64), d in (2, (2,2)) A = AT{T}(undef, d) B = copy(A) diff --git a/test/testsuite/uniformscaling.jl b/test/testsuite/uniformscaling.jl index 61793fbc..1f7d0e68 100644 --- a/test/testsuite/uniformscaling.jl +++ b/test/testsuite/uniformscaling.jl @@ -2,7 +2,8 @@ eltypes = (ComplexF32, Float32) wrappers = (identity, UnitLowerTriangular, UnitUpperTriangular, LowerTriangular, UpperTriangular, Hermitian, Symmetric) - @testset "UniformScaling $f $T1 $T2" for T1 in eltypes, T2 in eltypes, f in wrappers + for T1 in eltypes, T2 in eltypes, f in wrappers + @testcase "UniformScaling $f $T1 $T2" begin x = ones(T1, 5, 5) y = AT(x) @@ -17,4 +18,5 @@ # Missing methods in Base it seems... -(x - I) can be removed when Base supports (I - x) @test @allowscalar collect(-(xw - J)) ≈ collect(J - yw) end + end end From 447366331900a7c7c596a70f09171c96222575ae Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Mon, 8 Feb 2021 09:21:35 +0100 Subject: [PATCH 2/6] Run tests with appropriate number of threads. --- .github/workflows/ci.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e7d891f3..ba4b75f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,7 @@ jobs: matrix: version: - '1.5' + - '1.6-nightly' - 'nightly' os: - ubuntu-latest @@ -29,6 +30,10 @@ jobs: with: version: ${{ matrix.version }} arch: ${{ matrix.arch }} + - name: Retrieve system info + run: | + echo "::set-output name=cpu_threads::$(julia -e 'println(Sys.CPU_THREADS)')" + id: sysinfo - uses: actions/cache@v1 env: cache-name: cache-artifacts @@ -44,6 +49,8 @@ jobs: git config --global user.name Tester git config --global user.email te@st.er - uses: julia-actions/julia-runtest@latest + env: + JULIA_NUM_THREADS: ${{ steps.sysinfo.outputs.cpu_threads }} continue-on-error: ${{ matrix.version == 'nightly' }} - uses: julia-actions/julia-processcoverage@v1 - uses: codecov/codecov-action@v1 From 1a5f6eed4eddc4e1b7f0c2e6f9928c400e9e27da Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Mon, 8 Feb 2021 13:56:54 +0100 Subject: [PATCH 3/6] Use more coarse-grained test cases for now. --- test/testsuite.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testsuite.jl b/test/testsuite.jl index 26154909..8073e1da 100644 --- a/test/testsuite.jl +++ b/test/testsuite.jl @@ -83,7 +83,7 @@ function test(AT::Type) code = quote $fun($AT) end - @eval @testset $name $code + @eval @testcase $name $code end end From 54b40440c8a1360dd0e5d0e16dd1bdebbfa776a4 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Mon, 8 Feb 2021 14:20:51 +0100 Subject: [PATCH 4/6] Backwards compatibility with Test.jl. --- test/runtests.jl | 10 ++++++++-- test/testsuite.jl | 7 ++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index f43d76be..b3749f81 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,12 @@ -using GPUArrays, XUnit +using GPUArrays -@testset "GPUArrays" runner=ParallelTestRunner() begin +try + using XUnit +catch + using Test +end + +@testset "GPUArrays" begin include("testsuite.jl") diff --git a/test/testsuite.jl b/test/testsuite.jl index 8073e1da..bd0dda65 100644 --- a/test/testsuite.jl +++ b/test/testsuite.jl @@ -8,7 +8,12 @@ export supported_eltypes using GPUArrays -using XUnit +try + using XUnit +catch + using Test + @eval $(Symbol("@testcase")) = $(getfield(Test, Symbol("@testset"))) +end using LinearAlgebra using Random From 266d2741890eb9acbcb5b55aa1ad382e76ad0846 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Tue, 9 Feb 2021 09:00:24 +0100 Subject: [PATCH 5/6] Use for loops with testsets directly. --- test/Project.toml | 1 + test/runtests.jl | 9 ++++----- test/testsuite/linalg.jl | 12 +++++------- test/testsuite/mapreduce.jl | 14 +++++--------- test/testsuite/uniformscaling.jl | 4 +--- 5 files changed, 16 insertions(+), 24 deletions(-) diff --git a/test/Project.toml b/test/Project.toml index 51905b84..cdc11e13 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -2,5 +2,6 @@ Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" XUnit = "3e3c03f2-1a94-11e9-2981-050a4ca824ab" diff --git a/test/runtests.jl b/test/runtests.jl index b3749f81..9aee6b06 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,10 +1,9 @@ using GPUArrays -try - using XUnit -catch - using Test -end +using Pkg +Pkg.add(url="https://github.com/maleadt/XUnit.jl", rev="tb/for_loop") + +using XUnit @testset "GPUArrays" begin diff --git a/test/testsuite/linalg.jl b/test/testsuite/linalg.jl index 32b5bbd1..09943207 100644 --- a/test/testsuite/linalg.jl +++ b/test/testsuite/linalg.jl @@ -10,10 +10,10 @@ @test compare(transpose!, AT, Array{Float32}(undef, 128, 32), rand(Float32, 32, 128)) end - for uplo in ('U', 'L') - @testcase "copytri! $uplo" begin - @test compare(x -> LinearAlgebra.copytri!(x, uplo), AT, rand(Float32, 128, 128)) - end + @testset "copytri!" begin + @testcase for uplo in ('U', 'L') + @test compare(x -> LinearAlgebra.copytri!(x, uplo), AT, rand(Float32, 128, 128)) + end end @testcase "copyto! for triangular" begin @@ -57,15 +57,13 @@ areal = randn(n,n)/2 aimg = randn(n,n)/2 - for eltya in (Float32, Float64, ComplexF32, ComplexF64) - @testcase "$eltya" begin + @testcase for eltya in (Float32, Float64, ComplexF32, ComplexF64) a = convert(Matrix{eltya}, eltya <: Complex ? complex.(areal, aimg) : areal) asym = transpose(a) + a # symmetric indefinite aherm = a' + a # Hermitian indefinite @test issymmetric(asym) @test ishermitian(aherm) end - end end @testcase "Array + Diagonal" begin diff --git a/test/testsuite/mapreduce.jl b/test/testsuite/mapreduce.jl index 6f3126ee..78070ce1 100644 --- a/test/testsuite/mapreduce.jl +++ b/test/testsuite/mapreduce.jl @@ -1,6 +1,5 @@ @testsuite "mapreduce essentials" AT->begin - for ET in supported_eltypes() - @testcase "mapreducedim! $ET" begin + @testcase "mapreducedim! $ET" for ET in supported_eltypes() T = AT{ET} range = ET <: Real ? (ET(1):ET(10)) : ET for (sz,red) in [(10,)=>(1,), (10,10)=>(1,1), (10,10,10)=>(1,1,1), (10,10,10)=>(10,10,10), @@ -15,7 +14,7 @@ @test compare((A,R)->Base.mapreducedim!(identity, +, R, A), AT, rand(range, (2,3)), zeros(ET, (2,))) end - @testcase "reducedim! $ET" begin + @testcase "reducedim! $ET" for ET in supported_eltypes() T = AT{ET} range = ET <: Real ? (ET(1):ET(10)) : ET for (sz,red) in [(10,)=>(1,), (10,10)=>(1,1), (10,10,10)=>(1,1,1), (10,10,10)=>(10,10,10), @@ -25,7 +24,7 @@ end end - @testcase "mapreduce $ET" begin + @testcase "mapreduce $ET" for ET in supported_eltypes() T = AT{ET} range = ET <: Real ? (ET(1):ET(10)) : ET for (sz,dims) in [(10,)=>[1], (10,10)=>[1,2], (10,10,10)=>[1,2,3], (10,10,10)=>[], @@ -37,7 +36,7 @@ end end - @testcase "reduce $ET" begin + @testcase "reduce $ET" for ET in supported_eltypes() T = AT{ET} range = ET <: Real ? (ET(1):ET(10)) : ET for (sz,dims) in [(10,)=>[1], (10,10)=>[1,2], (10,10,10)=>[1,2,3], (10,10,10)=>[], @@ -47,12 +46,10 @@ @test compare(A->reduce(*, A; dims=dims, init=one(ET)), AT, rand(range, sz)) end end - end end @testsuite "mapreduce derivatives" AT->begin - for ET in supported_eltypes() - @testcase "sum prod minimum maximum $ET" begin + @testcase "sum prod minimum maximum $ET" for ET in supported_eltypes() T = AT{ET} range = ET <: Real ? (ET(1):ET(10)) : ET for (sz,dims) in [(10,)=>[1], (10,10)=>[1,2], (10,10,10)=>[1,2,3], (10,10,10)=>[], @@ -90,7 +87,6 @@ end end end end - end @testcase "any all count ==" begin for Ac in ([false, false], [false, true], [true, true], diff --git a/test/testsuite/uniformscaling.jl b/test/testsuite/uniformscaling.jl index 1f7d0e68..3221f5e8 100644 --- a/test/testsuite/uniformscaling.jl +++ b/test/testsuite/uniformscaling.jl @@ -2,8 +2,7 @@ eltypes = (ComplexF32, Float32) wrappers = (identity, UnitLowerTriangular, UnitUpperTriangular, LowerTriangular, UpperTriangular, Hermitian, Symmetric) - for T1 in eltypes, T2 in eltypes, f in wrappers - @testcase "UniformScaling $f $T1 $T2" begin + @testcase "UniformScaling $f $T1 $T2" for T1 in eltypes, T2 in eltypes, f in wrappers x = ones(T1, 5, 5) y = AT(x) @@ -18,5 +17,4 @@ # Missing methods in Base it seems... -(x - I) can be removed when Base supports (I - x) @test @allowscalar collect(-(xw - J)) ≈ collect(J - yw) end - end end From deb6b2b57b236e7972812e3a370d22ab63f7ea3c Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Tue, 9 Feb 2021 16:07:22 +0100 Subject: [PATCH 6/6] More testcases. --- test/testsuite.jl | 2 +- test/testsuite/indexing.jl | 24 +++++------------ test/testsuite/io.jl | 1 - test/testsuite/linalg.jl | 25 +++++++++--------- test/testsuite/math.jl | 19 ++++++-------- test/testsuite/vector.jl | 54 ++++++++++++++++++++------------------ 6 files changed, 56 insertions(+), 69 deletions(-) diff --git a/test/testsuite.jl b/test/testsuite.jl index bd0dda65..915fc8b7 100644 --- a/test/testsuite.jl +++ b/test/testsuite.jl @@ -88,7 +88,7 @@ function test(AT::Type) code = quote $fun($AT) end - @eval @testcase $name $code + @eval @testset $name $code end end diff --git a/test/testsuite/indexing.jl b/test/testsuite/indexing.jl index 3955146c..75db5332 100644 --- a/test/testsuite/indexing.jl +++ b/test/testsuite/indexing.jl @@ -44,8 +44,7 @@ end end - for T in supported_eltypes() - @testcase "getindex with $T" begin + @testcase "getindex with $T" for T in supported_eltypes() @allowscalar begin x = rand(T, 32) src = AT(x) @@ -56,10 +55,8 @@ @test Array(src[3:end]) == x[3:end] end end - end - for T in supported_eltypes() - @testcase "setindex! with $T" begin + @testcase "setindex! with $T" for T in supported_eltypes() @allowscalar begin x = fill(zero(T), 7) src = AT(x) @@ -72,10 +69,8 @@ src[1] = T(0) end end - end - for T in supported_eltypes() - @testcase "issue #42 with $T" begin + @testcase "issue #42 with $T" for T in supported_eltypes() @allowscalar begin Ac = rand(Float32, 2, 2) A = AT(Ac) @@ -84,7 +79,6 @@ @test A[1, 1] == Ac[1, 1] end end - end @testcase "get/setindex!" begin @allowscalar begin @@ -99,23 +93,19 @@ end @testsuite "indexing multidimensional" AT->begin - for T in supported_eltypes() - @testcase "sliced setindex with $T" begin + @testcase "sliced setindex with $T" for T in supported_eltypes() x = AT(zeros(T, (10, 10, 10, 10))) y = AT(rand(T, (5, 5, 10, 10))) x[2:6, 2:6, :, :] = y @test Array(x[2:6, 2:6, :, :]) == Array(y) end - end - for T in supported_eltypes() - @testcase "sliced setindex, CPU source with $T" begin + @testcase "sliced setindex, CPU source with $T" for T in supported_eltypes() x = AT(zeros(T, (2,3,4))) y = AT(rand(T, (2,3))) x[:, :, 2] = y @test Array(x[:, :, 2]) == Array(y) end - end @testcase "empty array" begin @allowscalar begin @@ -126,8 +116,7 @@ end @test size(A[[]]) == size(Ac[[]]) end - for other in (Colon(), 1:5, 5) - @testcase "2D with other index $other" begin + @testcase "2D with other index $other" for other in (Colon(), 1:5, 5) Ac = zeros(Float32, 10, 10) A = AT(Ac) @@ -137,7 +126,6 @@ end @test typeof(A[other, []]) == typeof(AT(Ac[other, []])) @test size(A[other, []]) == size(Ac[other, []]) end - end @test compare(AT, rand(Float32, 2,2)) do a a[:, 2:end-2] = AT{Float32}(undef,2,0) diff --git a/test/testsuite/io.jl b/test/testsuite/io.jl index 66a87d96..8b56282c 100644 --- a/test/testsuite/io.jl +++ b/test/testsuite/io.jl @@ -1,5 +1,4 @@ @testsuite "input output" AT->begin - # compact=false to avoid type aliases replstr(x, kv::Pair...) = sprint((io,x) -> show(IOContext(io, :compact => false, :limit => true, :displaysize => (24, 80), kv...), MIME("text/plain"), x), x) showstr(x, kv::Pair...) = sprint((io,x) -> show(IOContext(io, :limit => true, :displaysize => (24, 80), kv...), x), x) diff --git a/test/testsuite/linalg.jl b/test/testsuite/linalg.jl index 09943207..31b9792f 100644 --- a/test/testsuite/linalg.jl +++ b/test/testsuite/linalg.jl @@ -77,15 +77,16 @@ @test collect(B) ≈ collect(A) + collect(D) end - for (f, f!) in ((triu, triu!), (tril, tril!)), d in -2:2 - @testcase "$f! with diagonal $d" begin + @testcase "$f! with diagonal $d" for + (f, f!) in ((triu, triu!), (tril, tril!)), + d in -2:2 A = randn(10, 10) @test f(A, d) == Array(f!(AT(A), d)) end - end - for f in (identity, transpose, adjoint), T in supported_eltypes() - @testcase "$T gemv y := $f(A) * x * a + y * b" begin + @testcase "$T gemv y := $f(A) * x * a + y * b" for + f in (identity, transpose, adjoint), + T in supported_eltypes() y, A, x = rand(T, 4), rand(T, 4, 4), rand(T, 4) # workaround for https://github.com/JuliaLang/julia/issues/35163#issue-584248084 @@ -100,10 +101,11 @@ @test compare(mul!, AT, rand(T, 2,2), rand(T, 2,1), f(rand(T, 2))) end end - end - for f in (identity, transpose, adjoint), g in (identity, transpose, adjoint), T in supported_eltypes() - @testcase "$T gemm C := $f(A) * $g(B) * a + C * b" begin + @testcase "$T gemm C := $f(A) * $g(B) * a + C * b" for + f in (identity, transpose, adjoint), + g in (identity, transpose, adjoint), + T in supported_eltypes() A, B, C = rand(T, 4, 4), rand(T, 4, 4), rand(T, 4, 4) # workaround for https://github.com/JuliaLang/julia/issues/35163#issue-584248084 @@ -114,12 +116,11 @@ @test compare(mul!, AT, C, f(A), g(B), Ref(T(4)), Ref(T(5))) @test typeof(AT(rand(3, 3)) * AT(rand(3, 3))) <: AbstractMatrix end - end - for (a,b) in [((3,4),(4,3)), ((3,), (1,3)), ((1,3), (3))], T in supported_eltypes() - @testcase "lmul! and rmul! $a x $b with $T" begin + @testcase "lmul! and rmul! $a x $b with $T" for + (a,b) in [((3,4),(4,3)), ((3,), (1,3)), ((1,3), (3))], + T in supported_eltypes() @test compare(rmul!, AT, rand(T, a), Ref(rand(T))) @test compare(lmul!, AT, Ref(rand(T)), rand(T, b)) end - end end diff --git a/test/testsuite/math.jl b/test/testsuite/math.jl index 74c42afc..341b4183 100644 --- a/test/testsuite/math.jl +++ b/test/testsuite/math.jl @@ -1,17 +1,14 @@ @testsuite "math" AT->begin - for ET in supported_eltypes() + @testcase for ET in supported_eltypes() # Skip complex numbers - ET in (Complex, ComplexF32, ComplexF64) && continue + ET in (Complex, ComplexF32, ComplexF64) && return - T = AT{ET} - @testcase "$ET" begin - range = ET <: Integer ? (ET(-2):ET(2)) : ET - low = ET(-1) - high = ET(1) - @testcase "clamp!" begin - for N in (2, 10) - @test compare(x -> clamp!(x, low, high), AT, rand(range, N, N)) - end + range = ET <: Integer ? (ET(-2):ET(2)) : ET + low = ET(-1) + high = ET(1) + @testcase "clamp!" begin + for N in (2, 10) + @test compare(x -> clamp!(x, low, high), AT, rand(range, N, N)) end end end diff --git a/test/testsuite/vector.jl b/test/testsuite/vector.jl index c5f8bf40..dcd06c0e 100644 --- a/test/testsuite/vector.jl +++ b/test/testsuite/vector.jl @@ -1,31 +1,33 @@ @testsuite "vectors" AT->begin - a = Float32[] - x = AT(a) - @test length(x) == 0 - push!(x, 12f0) - @test length(x) == 1 - @test x[1] == 12f0 + @testcase "basic operations" begin + a = Float32[] + x = AT(a) + @test length(x) == 0 + push!(x, 12f0) + @test length(x) == 1 + @test x[1] == 12f0 - a = Float32[0] - x = AT(a) - @test length(x) == 1 - @test length(GPUArrays.buffer(x)) == 1 - push!(x, 12) - @test length(GPUArrays.buffer(x)) == GPUArrays.grow_dimensions(0, 1, 1) - resize!(x, 5) - @test length(x) == 5 - @test length(GPUArrays.buffer(x)) == 5 + a = Float32[0] + x = AT(a) + @test length(x) == 1 + @test length(GPUArrays.buffer(x)) == 1 + push!(x, 12) + @test length(GPUArrays.buffer(x)) == GPUArrays.grow_dimensions(0, 1, 1) + resize!(x, 5) + @test length(x) == 5 + @test length(GPUArrays.buffer(x)) == 5 - resize!(x, 3) - @test length(x) == 3 - # we don't shrink buffers yet... TODO shrink them... or should we? - @test length(GPUArrays.buffer(x)) == 5 + resize!(x, 3) + @test length(x) == 3 + # we don't shrink buffers yet... TODO shrink them... or should we? + @test length(GPUArrays.buffer(x)) == 5 - x = AT(Array{Float32}(undef, 16)) - reshape!(x, (2, 2, 2, 2)) - @test size(x) == (2, 2, 2, 2) - x = AT(Array{Float32}(undef, 16)) - y = AT(rand(Float32, 32)) - update!(x, y) - @test size(x) == (32,) + x = AT(Array{Float32}(undef, 16)) + reshape!(x, (2, 2, 2, 2)) + @test size(x) == (2, 2, 2, 2) + x = AT(Array{Float32}(undef, 16)) + y = AT(rand(Float32, 32)) + update!(x, y) + @test size(x) == (32,) + end end