Skip to content

Commit 2a25d64

Browse files
committed
Rename Typ to AT cfr. Base.
1 parent fce9046 commit 2a25d64

File tree

13 files changed

+173
-179
lines changed

13 files changed

+173
-179
lines changed

src/testsuite.jl

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ using StaticArrays
1717
convert_array(f, x) = f(x)
1818
convert_array(f, x::Base.RefValue) = x[]
1919

20-
function compare(f, Typ, xs...)
20+
function compare(f, AT::Type{<:GPUArray}, xs...)
2121
cpu_in = convert_array.(copy, xs)
22-
gpu_in = convert_array.(Typ, xs)
22+
gpu_in = convert_array.(AT, xs)
2323
cpu_out = f(cpu_in...)
2424
gpu_out = f(gpu_in...)
2525
cpu_out Array(gpu_out)
@@ -42,29 +42,23 @@ include("testsuite/fft.jl")
4242
include("testsuite/blas.jl")
4343
include("testsuite/random.jl")
4444

45-
function supported_eltypes()
46-
(Float32, Float64, Int32, Int64, ComplexF32, ComplexF64)
47-
end
48-
49-
export run_tests, supported_eltypes
50-
5145
end
5246

5347

5448
"""
55-
Runs the entire GPUArrays test suite on array type `Typ`
49+
Runs the entire GPUArrays test suite on array type `AT`
5650
"""
57-
function test(Typ)
58-
TestSuite.test_construction(Typ)
59-
TestSuite.test_gpuinterface(Typ)
60-
TestSuite.test_indexing(Typ)
61-
TestSuite.test_io(Typ)
62-
TestSuite.test_base(Typ)
63-
#TestSuite.test_vectors(Typ)
64-
TestSuite.test_mapreduce(Typ)
65-
TestSuite.test_broadcasting(Typ)
66-
TestSuite.test_linalg(Typ)
67-
TestSuite.test_fft(Typ)
68-
TestSuite.test_blas(Typ)
69-
TestSuite.test_random(Typ)
51+
function test(AT::Type{<:GPUArray})
52+
TestSuite.test_construction(AT)
53+
TestSuite.test_gpuinterface(AT)
54+
TestSuite.test_indexing(AT)
55+
TestSuite.test_io(AT)
56+
TestSuite.test_base(AT)
57+
#TestSuite.test_vectors(AT)
58+
TestSuite.test_mapreduce(AT)
59+
TestSuite.test_broadcasting(AT)
60+
TestSuite.test_linalg(AT)
61+
TestSuite.test_fft(AT)
62+
TestSuite.test_blas(AT)
63+
TestSuite.test_random(AT)
7064
end

src/testsuite/base.jl

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ function ntuple_closure(state, result, ::Val{N}, testval) where N
2626
return
2727
end
2828

29-
function test_base(Typ)
29+
function test_base(AT)
3030
@testset "base functionality" begin
3131
@testset "mapidx" begin
3232
a = rand(ComplexF32, 77)
3333
b = rand(ComplexF32, 77)
34-
A = Typ(a)
35-
B = Typ(b)
34+
A = AT(a)
35+
B = AT(b)
3636
off = 1
3737
GPUArrays.mapidx(A, (B, off, length(A))) do i, a, b, off, len
3838
x = b[i]
@@ -50,8 +50,8 @@ function test_base(Typ)
5050
@testset "copyto!" begin
5151
x = fill(0f0, (10, 10))
5252
y = rand(Float32, (20, 10))
53-
a = Typ(x)
54-
b = Typ(y)
53+
a = AT(x)
54+
b = AT(y)
5555
r1 = CartesianIndices((1:7, 3:8))
5656
r2 = CartesianIndices((4:10, 3:8))
5757
copyto!(x, r1, y, r2)
@@ -68,30 +68,30 @@ function test_base(Typ)
6868
end
6969

7070
@testset "vcat + hcat" begin
71-
@test compare(vcat, Typ, fill(0f0, (10, 10)), rand(Float32, 20, 10))
72-
@test compare(hcat, Typ, fill(0f0, (10, 10)), rand(Float32, 10, 10))
71+
@test compare(vcat, AT, fill(0f0, (10, 10)), rand(Float32, 20, 10))
72+
@test compare(hcat, AT, fill(0f0, (10, 10)), rand(Float32, 10, 10))
7373

74-
@test compare(hcat, Typ, rand(Float32, 3, 3), rand(Float32, 3, 3))
75-
@test compare(vcat, Typ, rand(Float32, 3, 3), rand(Float32, 3, 3))
76-
@test compare((a,b) -> cat(a, b; dims=4), Typ, rand(Float32, 3, 4), rand(Float32, 3, 4))
74+
@test compare(hcat, AT, rand(Float32, 3, 3), rand(Float32, 3, 3))
75+
@test compare(vcat, AT, rand(Float32, 3, 3), rand(Float32, 3, 3))
76+
@test compare((a,b) -> cat(a, b; dims=4), AT, rand(Float32, 3, 4), rand(Float32, 3, 4))
7777
end
7878

7979
@testset "reinterpret" begin
8080
a = rand(ComplexF32, 22)
81-
A = Typ(a)
81+
A = AT(a)
8282
af0 = reinterpret(Float32, a)
8383
Af0 = reinterpret(Float32, A)
8484
@test Array(Af0) == af0
8585

8686
a = rand(ComplexF32, 10 * 10)
87-
A = Typ(a)
87+
A = AT(a)
8888
af0 = reshape(reinterpret(Float32, vec(a)), (20, 10))
8989
Af0 = reshape(reinterpret(Float32, vec(A)), (20, 10))
9090
@test Array(Af0) == af0
9191
end
9292

9393
@testset "ntuple test" begin
94-
result = Typ(Vector{NTuple{3, Float32}}(undef, 1))
94+
result = AT(Vector{NTuple{3, Float32}}(undef, 1))
9595
gpu_call(ntuple_test, result, (result, Val(3)))
9696
@test Array(result)[1] == (77, 2*77, 3*77)
9797
x = 88f0
@@ -101,31 +101,31 @@ function test_base(Typ)
101101

102102
@testset "cartesian iteration" begin
103103
Ac = rand(Float32, 32, 32)
104-
A = Typ(Ac)
104+
A = AT(Ac)
105105
result = fill!(copy(A), 0.0)
106106
gpu_call(cartesian_iter, result, (A, result, size(A)))
107107
Array(result) == Ac
108108
end
109109

110110
@testset "Custom kernel from Julia function" begin
111-
x = Typ(rand(Float32, 100))
112-
y = Typ(rand(Float32, 100))
111+
x = AT(rand(Float32, 100))
112+
y = AT(rand(Float32, 100))
113113
gpu_call(clmap!, x, (-, x, y))
114114
jy = Array(y)
115115
@test map!(-, jy, jy) Array(x)
116116
end
117117

118118
@testset "map" begin
119-
@test compare((a, b)-> map(+, a, b), Typ, rand(Float32, 10), rand(Float32, 10))
120-
@test compare((a, b)-> map!(-, a, b), Typ, rand(Float32, 10), rand(Float32, 10))
121-
@test compare((a, b, c, d)-> map!(*, a, b, c, d), Typ, rand(Float32, 10), rand(Float32, 10), rand(Float32, 10), rand(Float32, 10))
119+
@test compare((a, b)-> map(+, a, b), AT, rand(Float32, 10), rand(Float32, 10))
120+
@test compare((a, b)-> map!(-, a, b), AT, rand(Float32, 10), rand(Float32, 10))
121+
@test compare((a, b, c, d)-> map!(*, a, b, c, d), AT, rand(Float32, 10), rand(Float32, 10), rand(Float32, 10), rand(Float32, 10))
122122
end
123123

124124
@testset "repeat" begin
125-
@test compare(a-> repeat(a, 5, 6), Typ, rand(Float32, 10))
126-
@test compare(a-> repeat(a, 5), Typ, rand(Float32, 10))
127-
@test compare(a-> repeat(a, 5), Typ, rand(Float32, 5, 4))
128-
@test compare(a-> repeat(a, 4, 3), Typ, rand(Float32, 10, 15))
125+
@test compare(a-> repeat(a, 5, 6), AT, rand(Float32, 10))
126+
@test compare(a-> repeat(a, 5), AT, rand(Float32, 10))
127+
@test compare(a-> repeat(a, 5), AT, rand(Float32, 5, 4))
128+
@test compare(a-> repeat(a, 4, 3), AT, rand(Float32, 10, 15))
129129
end
130130
end
131131
end

src/testsuite/blas.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
function test_blas(Typ)
1+
function test_blas(AT)
22
@testset "BLAS" begin
33
@testset "matmul" begin
4-
@test compare(*, Typ, rand(Float32, 5, 5), rand(Float32, 5, 5))
5-
@test compare(*, Typ, rand(Float32, 5, 5), rand(Float32, 5))
6-
@test compare((a, b)-> a * transpose(b), Typ, rand(Float32, 5, 5), rand(Float32, 5, 5))
7-
@test compare((c, a, b)-> mul!(c, a, transpose(b)), Typ, rand(Float32, 10, 32), rand(Float32, 10, 60), rand(Float32, 32, 60))
8-
@test compare((a, b)-> transpose(a) * b, Typ, rand(Float32, 5, 5), rand(Float32, 5, 5))
9-
@test compare((a, b)-> transpose(a) * transpose(b), Typ, rand(Float32, 10, 15), rand(Float32, 1, 10))
10-
@test compare((a, b)-> transpose(a) * b, Typ, rand(Float32, 10, 15), rand(Float32, 10))
11-
@test compare(mul!, Typ, rand(Float32, 15), rand(Float32, 15, 10), rand(Float32, 10))
4+
@test compare(*, AT, rand(Float32, 5, 5), rand(Float32, 5, 5))
5+
@test compare(*, AT, rand(Float32, 5, 5), rand(Float32, 5))
6+
@test compare((a, b)-> a * transpose(b), AT, rand(Float32, 5, 5), rand(Float32, 5, 5))
7+
@test compare((c, a, b)-> mul!(c, a, transpose(b)), AT, rand(Float32, 10, 32), rand(Float32, 10, 60), rand(Float32, 32, 60))
8+
@test compare((a, b)-> transpose(a) * b, AT, rand(Float32, 5, 5), rand(Float32, 5, 5))
9+
@test compare((a, b)-> transpose(a) * transpose(b), AT, rand(Float32, 10, 15), rand(Float32, 1, 10))
10+
@test compare((a, b)-> transpose(a) * b, AT, rand(Float32, 10, 15), rand(Float32, 10))
11+
@test compare(mul!, AT, rand(Float32, 15), rand(Float32, 15, 10), rand(Float32, 10))
1212
end
1313

1414
for T in (ComplexF32, Float32)
1515
@testset "rmul! $T" begin
16-
@test compare(rmul!, Typ, rand(T, 13, 23), Ref(77f0))
16+
@test compare(rmul!, AT, rand(T, 13, 23), Ref(77f0))
1717
end
1818
end
1919

2020
@testset "gbmv" begin
2121
m, n = 10, 11
2222
A, x, y = randn(Float32, 3, n), randn(Float32, n), fill(0f0, m)
2323

24-
Ag, xg, yg = Typ(A), Typ(x), Typ(y)
24+
Ag, xg, yg = AT(A), AT(x), AT(y)
2525

2626
BLAS.gbmv!('N', m, 1, 1, 1f0, A, x, 0f0, y)
2727
BLAS.gbmv!('N', m, 1, 1, 1f0, Ag, xg, 0f0, yg)

src/testsuite/broadcasting.jl

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
function test_broadcasting(Typ)
1+
function test_broadcasting(AT)
22
@testset "broadcast" begin
3-
broadcasting(Typ)
4-
vec3(Typ)
3+
broadcasting(AT)
4+
vec3(AT)
55
end
66
end
77

@@ -29,24 +29,24 @@ function test_kernel(a::T, b) where T
2929
return c
3030
end
3131

32-
function broadcasting(Typ)
32+
function broadcasting(AT)
3333
for ET in supported_eltypes()
3434
N = 10
3535
@testset "broadcast $ET" begin
3636
@testset "RefValue" begin
3737
cidx = rand(1:Int(N), 2*N)
38-
gidx = Typ(cidx)
38+
gidx = AT(cidx)
3939
cy = rand(ET, 2*N)
40-
gy = Typ(cy)
40+
gy = AT(cy)
4141
cres = fill(zero(ET), size(cidx))
42-
gres = Typ(cres)
42+
gres = AT(cres)
4343
gres .= test_idx.(gidx, Base.RefValue(gy))
4444
cres .= test_idx.(cidx, Base.RefValue(cy))
4545
@test Array(gres) == cres
4646
end
4747

4848
@testset "Tuple" begin
49-
@test compare(Typ, rand(ET, 3, N), rand(ET, 3, N), rand(ET, N), rand(ET, N), rand(ET, N)) do out, arr, a, b, c
49+
@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
5050
broadcast!(out, arr, (a, b, c)) do xx, yy
5151
xx + first(yy)
5252
end
@@ -55,38 +55,38 @@ function broadcasting(Typ)
5555

5656
############
5757
# issue #27
58-
@test compare((a, b)-> a .+ b, Typ, rand(ET, 4, 5, 3), rand(ET, 1, 5, 3))
59-
@test compare((a, b)-> a .+ b, Typ, rand(ET, 4, 5, 3), rand(ET, 1, 5, 1))
58+
@test compare((a, b)-> a .+ b, AT, rand(ET, 4, 5, 3), rand(ET, 1, 5, 3))
59+
@test compare((a, b)-> a .+ b, AT, rand(ET, 4, 5, 3), rand(ET, 1, 5, 1))
6060

6161
############
6262
# issue #22
6363
dim = (32, 32)
64-
@test compare(Typ, rand(ET, dim), rand(ET, dim), rand(ET, dim)) do tmp, a1, a2
64+
@test compare(AT, rand(ET, dim), rand(ET, dim), rand(ET, dim)) do tmp, a1, a2
6565
tmp .= a1 .+ a2 .* ET(2)
6666
end
6767

6868
############
6969
# issue #21
7070
if ET in (Float32, Float64)
71-
@test compare((a1, a2)-> muladd.(ET(2), a1, a2), Typ, rand(ET, dim), rand(ET, dim))
71+
@test compare((a1, a2)-> muladd.(ET(2), a1, a2), AT, rand(ET, dim), rand(ET, dim))
7272
#########
7373
# issue #41
7474
# The first issue is likely https://github.com/JuliaLang/julia/issues/22255
7575
# since GPUArrays adds some arguments to the function, it becomes longer longer, hitting the 12
7676
# so this wont fix for now
77-
@test compare(Typ, rand(ET, dim), rand(ET, dim), rand(ET, dim), rand(ET, dim), rand(ET, dim), rand(ET, dim)) do a1, a2, a3, a4, a5, a6
77+
@test compare(AT, rand(ET, dim), rand(ET, dim), rand(ET, dim), rand(ET, dim), rand(ET, dim), rand(ET, dim)) do a1, a2, a3, a4, a5, a6
7878
@. a1 = a2 + (1.2) *((1.3)*a3 + (1.4)*a4 + (1.5)*a5 + (1.6)*a6)
7979
end
8080

81-
@test compare(Typ, rand(ET, dim), rand(ET, dim), rand(ET, dim), rand(ET, dim)) do u, uprev, duprev, ku
81+
@test compare(AT, rand(ET, dim), rand(ET, dim), rand(ET, dim), rand(ET, dim)) do u, uprev, duprev, ku
8282
fract = ET(1//2)
8383
dt = ET(1.4)
8484
dt2 = dt^2
8585
@. u = uprev + dt*duprev + dt2*(fract*ku)
8686
end
87-
@test compare((x) -> (-).(x), Typ, rand(ET, 2, 3))
87+
@test compare((x) -> (-).(x), AT, rand(ET, 2, 3))
8888

89-
@test compare(Typ, rand(ET, dim), rand(ET, dim), rand(ET, dim), rand(ET, dim), rand(ET, dim), rand(ET, dim)) do utilde, gA, k1, k2, k3, k4
89+
@test compare(AT, rand(ET, dim), rand(ET, dim), rand(ET, dim), rand(ET, dim), rand(ET, dim), rand(ET, dim)) do utilde, gA, k1, k2, k3, k4
9090
btilde1 = ET(1)
9191
btilde2 = ET(1)
9292
btilde3 = ET(1)
@@ -96,37 +96,37 @@ function broadcasting(Typ)
9696
end
9797
end
9898

99-
@test compare((x) -> fill!(x, 1), Typ, rand(ET, 3,3))
100-
@test compare((x, y) -> map(+, x, y), Typ, rand(ET, 2, 3), rand(ET, 2, 3))
99+
@test compare((x) -> fill!(x, 1), AT, rand(ET, 3,3))
100+
@test compare((x, y) -> map(+, x, y), AT, rand(ET, 2, 3), rand(ET, 2, 3))
101101

102-
@test compare((x) -> 2x, Typ, rand(ET, 2, 3))
103-
@test compare((x, y) -> x .+ y, Typ, rand(ET, 2, 3), rand(ET, 1, 3))
104-
@test compare((z, x, y) -> z .= x .+ y, Typ, rand(ET, 2, 3), rand(ET, 2, 3), rand(ET, 2))
102+
@test compare((x) -> 2x, AT, rand(ET, 2, 3))
103+
@test compare((x, y) -> x .+ y, AT, rand(ET, 2, 3), rand(ET, 1, 3))
104+
@test compare((z, x, y) -> z .= x .+ y, AT, rand(ET, 2, 3), rand(ET, 2, 3), rand(ET, 2))
105105

106-
@test compare(A -> A .= identity.(ET(10)), Typ, rand(ET, 40, 40))
107-
@test compare(A -> test_kernel.(A, ET(10)), Typ, rand(ET, 40, 40))
108-
@test compare(A -> A .* ET(10), Typ, rand(ET, 40, 40))
109-
@test compare((A, B) -> A .* B, Typ, rand(ET, 40, 40), rand(ET, 40, 40))
110-
@test compare((A, B) -> A .* B .+ ET(10), Typ, rand(ET, 40, 40), rand(ET, 40, 40))
106+
@test compare(A -> A .= identity.(ET(10)), AT, rand(ET, 40, 40))
107+
@test compare(A -> test_kernel.(A, ET(10)), AT, rand(ET, 40, 40))
108+
@test compare(A -> A .* ET(10), AT, rand(ET, 40, 40))
109+
@test compare((A, B) -> A .* B, AT, rand(ET, 40, 40), rand(ET, 40, 40))
110+
@test compare((A, B) -> A .* B .+ ET(10), AT, rand(ET, 40, 40), rand(ET, 40, 40))
111111
end
112112
end
113113
end
114114

115-
function vec3(Typ)
115+
function vec3(AT)
116116
@testset "vec 3" begin
117117
N = 20
118118

119119
xc = map(x-> ntuple(i-> rand(Float32), Val(3)), 1:N)
120120
yc = map(x-> ntuple(i-> rand(Float32), Val(3)), 1:N)
121121

122-
x = Typ(xc)
123-
y = Typ(yc)
122+
x = AT(xc)
123+
y = AT(yc)
124124

125125
res1c = fill(0f0, N)
126126
res2c = similar(xc)
127127

128-
res1 = Typ(res1c)
129-
res2 = Typ(res2c)
128+
res1 = AT(res1c)
129+
res2 = AT(res2c)
130130

131131
res1 .= testv3_1.(x, y)
132132
res1c .= testv3_1.(xc, yc)

0 commit comments

Comments
 (0)