Skip to content

Commit bb83e17

Browse files
committed
Restructure the testsuite a little.
1 parent 2439b75 commit bb83e17

16 files changed

+99
-116
lines changed

src/GPUArrays.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
__precompile__(true)
21
module GPUArrays
32

43
using Serialization
54
using Random
65
using LinearAlgebra
76
using Printf
8-
import Base: copyto!
97

108
import Random: rand, rand!
119
using LinearAlgebra.BLAS
12-
using FFTW
13-
import FFTW: *, plan_ifft!, plan_fft!, plan_fft, plan_ifft, size, plan_bfft, plan_bfft!
1410
import Base: pointer, similar, size, convert
1511
using Base: @propagate_inbounds, @pure, RefValue
1612
using Base.Cartesian
17-
using Random
13+
14+
using FFTW
15+
import FFTW: *, plan_ifft!, plan_fft!, plan_fft, plan_ifft, size, plan_bfft, plan_bfft!
1816

1917
include("abstractarray.jl")
2018
include("abstract_gpu_interface.jl")
@@ -30,10 +28,12 @@ include("linalg.jl")
3028
include("mapreduce.jl")
3129
include("vectors.jl")
3230
include("convolution.jl")
33-
include("testsuite/testsuite.jl")
34-
include("jlbackend.jl")
3531
include("random.jl")
3632

33+
include("array.jl")
34+
35+
include("testsuite.jl")
36+
3737
export GPUArray, gpu_call, thread_blocks_heuristic, global_size, synchronize_threads
3838
export linear_index, @linearidx, @cartesianidx, convolution!, device, synchronize
3939
export JLArray
File renamed without changes.

src/testsuite.jl

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Abstract test suite that can be used for all packages inheriting from GPUArray
2+
3+
module TestSuite
4+
5+
using GPUArrays
6+
using GPUArrays: mapidx, gpu_sub2ind
7+
8+
using LinearAlgebra
9+
using Random
10+
using Test
11+
12+
using FFTW
13+
using FillArrays
14+
using StaticArrays
15+
16+
toarray(T, x::Tuple{X, Vararg{Int}}) where X = fill(first(x), Base.tail(x))
17+
toarray(::Type{T}, x::NTuple{N, Int}) where {T <: Bool, N} = rand(T, x)
18+
toarray(::Type{T}, x::NTuple{N, Int}) where {T <: Integer, N} = rand(T(1):T(10), x)
19+
toarray(T, x::NTuple{N, Int}) where N = rand(T, x)
20+
toarray(T, x) = x
21+
togpu(T, x::AbstractArray) = T(x)
22+
togpu(T, x) = x
23+
24+
"""
25+
Calls function `f` on input arrays generated by `sizes` as Base.Array and converted to
26+
`Typ`. Compares the result of `f` and tests if they agree. `sizes` can be the shape of the
27+
array, a value or a tuple `(val, shape...)` which will create a `fill(val, shape...)`.
28+
"""
29+
function against_base(f, Typ, sizes...)
30+
jl_arrays = toarray.(eltype(Typ), sizes)
31+
gpu_arrays = togpu.(Typ, jl_arrays)
32+
res_jl = f(jl_arrays...)
33+
res_gpu = f(gpu_arrays...)
34+
@test res_jl Array(res_gpu)
35+
end
36+
37+
38+
include("testsuite/blas.jl")
39+
include("testsuite/broadcasting.jl")
40+
include("testsuite/construction.jl")
41+
include("testsuite/fft.jl")
42+
include("testsuite/gpuinterface.jl")
43+
include("testsuite/linalg.jl")
44+
include("testsuite/mapreduce.jl")
45+
include("testsuite/base.jl")
46+
include("testsuite/indexing.jl")
47+
# include("testsuite/vector.jl")
48+
include("testsuite/random.jl")
49+
50+
function supported_eltypes()
51+
(Float32, Float64, Int32, Int64, ComplexF32, ComplexF64)
52+
end
53+
54+
export against_base, run_tests, supported_eltypes
55+
56+
end
57+
58+
59+
"""
60+
Runs the GPUArrays test suite on array type `Typ`
61+
"""
62+
function test(Typ)
63+
GPUArrays.allowslow(false)
64+
TestSuite.test_gpuinterface(Typ)
65+
TestSuite.test_base(Typ)
66+
TestSuite.test_blas(Typ)
67+
TestSuite.test_broadcasting(Typ)
68+
TestSuite.test_construction(Typ)
69+
TestSuite.test_fft(Typ)
70+
TestSuite.test_linalg(Typ)
71+
TestSuite.test_mapreduce(Typ)
72+
TestSuite.test_indexing(Typ)
73+
TestSuite.test_random(Typ)
74+
end

src/testsuite/base.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function ntuple_closure(state, result, ::Val{N}, testval) where N
2626
return
2727
end
2828

29-
function run_base(Typ)
29+
function test_base(Typ)
3030
@testset "base functionality" begin
3131
@testset "mapidx" begin
3232
a = rand(ComplexF32, 77)

src/testsuite/blas.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using LinearAlgebra
2-
3-
function run_blas(Typ)
1+
function test_blas(Typ)
42
@testset "BLAS" begin
53
T = Typ{Float32}
64
@testset "matmul" begin

src/testsuite/broadcasting.jl

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
2-
3-
function run_broadcasting(Typ)
1+
function test_broadcasting(Typ)
42
@testset "broadcast" begin
5-
test_broadcast(Typ)
6-
test_vec3(Typ)
3+
broadcasting(Typ)
4+
vec3(Typ)
75
end
86
end
97

@@ -31,16 +29,15 @@ function test_kernel(a::T, b) where T
3129
return c
3230
end
3331

34-
35-
function test_broadcast(Typ)
32+
function broadcasting(Typ)
3633
for ET in supported_eltypes()
3734
N = 10
3835
T = Typ{ET}
3936
@testset "broadcast $ET" begin
4037
@testset "RefValue" begin
4138
cidx = rand(1:Int(N), 2*N)
4239
gidx = Typ(cidx)
43-
cy = TestSuite.toarray(ET, (2*N,))
40+
cy = toarray(ET, (2*N,))
4441
gy = Typ(cy)
4542
cres = fill(zero(ET), size(cidx))
4643
gres = Typ(cres)
@@ -115,7 +112,7 @@ function test_broadcast(Typ)
115112
end
116113
end
117114

118-
function test_vec3(Typ)
115+
function vec3(Typ)
119116
@testset "vec 3" begin
120117
N = 20
121118

src/testsuite/construction.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using FillArrays
2-
3-
function run_construction(Typ)
1+
function test_construction(Typ)
42
@testset "Construction" begin
53
constructors(Typ)
64
conversion(Typ)

src/testsuite/fft.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
function run_fft(Typ)
1+
function test_fft(Typ)
32
T = Typ{ComplexF32}
43
for n = 1:3
54
@testset "FFT with ND = $n" begin

src/testsuite/gpuinterface.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function run_gpuinterface(Typ)
1+
function test_gpuinterface(Typ)
22
@testset "parallel execution interface" begin
33
N = 10
44
x = Typ(Vector{Int}(undef, N))

src/testsuite/indexing.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
2-
3-
function run_indexing(Typ)
1+
function test_indexing(Typ)
42
@testset "indexing" begin
53
for T in (Float32, Int32#=, SVector{3, Float32}=#)
64
@testset "Indexing with $T" begin

0 commit comments

Comments
 (0)