Skip to content

Commit 6d3ef13

Browse files
committed
add tests for float64
1 parent f52aed1 commit 6d3ef13

File tree

8 files changed

+304
-290
lines changed

8 files changed

+304
-290
lines changed

src/devices.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ is_cudanative(ctx) = false
7676
is_julia(ctx) = false
7777
is_opengl(ctx) = false
7878

79+
supports_double(ctx) = false
80+
7981

8082

8183
#=

src/heuristics.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ function thread_blocks_heuristic(len::Integer)
22
threads = min(len, 256)
33
blocks = ceil(Int, len/threads)
44
blocks = blocks * threads
5-
blocks, threads
5+
(blocks,), (threads,)
66
end

src/testsuite/broadcasting.jl

Lines changed: 68 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
using GPUArrays
22
using Base.Test, GPUArrays.TestSuite
33

4+
45
function run_broadcasting(Typ)
56
@testset "broadcast" begin
67
test_broadcast(Typ)
78
test_vec3(Typ)
89
end
910
end
1011

11-
test_idx(idx, A) = A[idx] * 2f0
12+
test_idx(idx, A::AbstractArray{T}) where T = A[idx] * T(2)
1213

1314
function testv3_1(a, b)
1415
x = a .* b
@@ -34,76 +35,80 @@ end
3435

3536

3637
function test_broadcast(Typ)
37-
N = 10
38-
T = Typ{Float32}
39-
@testset "broadcast" begin
40-
@testset "RefValue" begin
41-
idx = Typ(rand(Cuint(1):Cuint(N), 2*N))
42-
y = Base.RefValue(Typ(rand(Float32, 2*N)))
43-
result = Typ(zeros(Float32, 2*N))
44-
45-
result .= test_idx.(idx, y)
46-
res1 = Array(result)
47-
res2 = similar(res1)
48-
res2 .= test_idx.(Array(idx), Base.RefValue(Array(y[])))
49-
@test res2 == res1
50-
end
51-
@testset "Tuple" begin
52-
against_base(T, (3, N), (3, N), (N,), (N,), (N,)) do out, arr, a, b, c
53-
res2 = broadcast!(out, arr, (a, b, c)) do xx, yy
54-
xx + sum(yy)
38+
for ET in supported_eltypes()
39+
N = 10
40+
T = Typ{ET}
41+
@testset "broadcast" begin
42+
@testset "RefValue" begin
43+
idx = Typ(rand(Cuint(1):Cuint(N), 2*N))
44+
y = Base.RefValue(Typ(TestSuite.toarray(ET, (2*N,))))
45+
result = Typ(zeros(ET, 2*N))
46+
47+
result .= test_idx.(idx, y)
48+
res1 = Array(result)
49+
res2 = similar(res1)
50+
res2 .= test_idx.(Array(idx), Base.RefValue(Array(y[])))
51+
@test res2 == res1
52+
end
53+
@testset "Tuple" begin
54+
against_base(T, (3, N), (3, N), (N,), (N,), (N,)) do out, arr, a, b, c
55+
res2 = broadcast!(out, arr, (a, b, c)) do xx, yy
56+
xx + sum(yy)
57+
end
5558
end
5659
end
57-
end
58-
############
59-
# issue #27
60-
against_base((a, b)-> a .+ b, T, (4, 5, 3), (1, 5, 3))
61-
against_base((a, b)-> a .+ b, T, (4, 5, 3), (1, 5, 1))
62-
63-
############
64-
# issue #22
65-
dim = (32, 32)
66-
against_base(T, dim, dim, dim) do tmp, a1, a2
67-
tmp .= a1 .+ a2 .* 2f0
68-
end
60+
############
61+
# issue #27
62+
against_base((a, b)-> a .+ b, T, (4, 5, 3), (1, 5, 3))
63+
against_base((a, b)-> a .+ b, T, (4, 5, 3), (1, 5, 1))
64+
65+
############
66+
# issue #22
67+
dim = (32, 32)
68+
against_base(T, dim, dim, dim) do tmp, a1, a2
69+
tmp .= a1 .+ a2 .* ET(2)
70+
end
6971

70-
############
71-
# issue #21
72-
against_base((a1, a2)-> muladd.(2f0, a1, a2), T, dim, dim)
73-
74-
###########
75-
# issue #20
76-
against_base(a-> abs.(a), T, dim)
77-
78-
#########
79-
# issue #41
80-
# The first issue is likely https://github.com/JuliaLang/julia/issues/22255
81-
# since GPUArrays adds some arguments to the function, it becomes longer longer, hitting the 12
82-
# so this wont fix for now
83-
against_base(T, dim, dim, dim, dim, dim, dim) do a1, a2, a3, a4, a5, a6
84-
@. a1 = a2 + 1.2f0*(1.3f0*a3 + 1.4f0*a4 + 1.5f0*a5 + 1.6f0*a6)
85-
end
72+
############
73+
# issue #21
74+
if ET in (Float32, Float64)
75+
against_base((a1, a2)-> muladd.(ET(2), a1, a2), T, dim, dim)
76+
#########
77+
# issue #41
78+
# The first issue is likely https://github.com/JuliaLang/julia/issues/22255
79+
# since GPUArrays adds some arguments to the function, it becomes longer longer, hitting the 12
80+
# so this wont fix for now
81+
against_base(T, dim, dim, dim, dim, dim, dim) do a1, a2, a3, a4, a5, a6
82+
@. a1 = a2 + (1.2) *((1.3)*a3 + (1.4)*a4 + (1.5)*a5 + (1.6)*a6)
83+
end
8684

87-
against_base(T, dim, dim, dim, dim) do u, uprev, duprev, ku
88-
fract = Float32(1//2)
89-
dt = 1.4f0
90-
@. u = uprev + dt*duprev + dt^2*(fract*ku)
91-
end
85+
against_base(T, dim, dim, dim, dim) do u, uprev, duprev, ku
86+
fract = ET(1//2)
87+
dt = ET(1.4)
88+
@. u = uprev + dt*duprev + dt^2*(fract*ku)
89+
end
90+
against_base((x) -> sin.(x), T, (2, 3))
91+
end
92+
93+
###########
94+
# issue #20
95+
against_base(a-> abs.(a), T, dim)
96+
97+
98+
99+
against_base((x) -> fill!(x, 1), T, (3,3))
100+
against_base((x, y) -> map(+, x, y), T, (2, 3), (2, 3))
92101

93-
against_base((x) -> fill!(x, 1), T, (3,3))
94-
against_base((x, y) -> map(+, x, y), T, (2, 3), (2, 3))
95-
against_base((x) -> sin.(x), T, (2, 3))
96-
against_base((x) -> 2x, T, (2, 3))
97-
against_base((x, y) -> x .+ y, T, (2, 3), (1, 3))
98-
against_base((z, x, y) -> z .= x .+ y, T, (2, 3), (2, 3), (2,))
102+
against_base((x) -> 2x, T, (2, 3))
103+
against_base((x, y) -> x .+ y, T, (2, 3), (1, 3))
104+
against_base((z, x, y) -> z .= x .+ y, T, (2, 3), (2, 3), (2,))
99105

100-
for ET in (Float32, Complex64)
101106
T = Typ{ET}
102-
against_base(A -> A .= identity.(10f0), T, (40, 40))
103-
against_base(A -> test_kernel.(A, 10f0), T, (40, 40))
104-
against_base(A -> A .* 10f0, T, (40, 40))
107+
against_base(A -> A .= identity.(ET(10)), T, (40, 40))
108+
against_base(A -> test_kernel.(A, ET(10)), T, (40, 40))
109+
against_base(A -> A .* ET(10), T, (40, 40))
105110
against_base((A, B) -> A .* B, T, (40, 40), (40, 40))
106-
against_base((A, B) -> A .* B .+ 10f0, T, (40, 40), (40, 40))
111+
against_base((A, B) -> A .* B .+ ET(10), T, (40, 40), (40, 40))
107112
end
108113
end
109114
end

src/testsuite/construction.jl

Lines changed: 90 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -11,111 +11,116 @@ end
1111

1212
function constructors(Typ)
1313
@testset "similar + constructor" begin
14-
B = Typ{Float32}(10)
15-
@test size(B) == (10,)
16-
@test eltype(B) == Float32
14+
for T in supported_eltypes()
15+
B = Typ{T}(10)
16+
@test size(B) == (10,)
17+
@test eltype(B) == T
1718

18-
B = Typ{Float32}(10, 10)
19-
@test size(B) == (10, 10)
20-
@test eltype(B) == Float32
19+
B = Typ{T}(10, 10)
20+
@test size(B) == (10, 10)
21+
@test eltype(B) == T
2122

22-
B = Typ{Float32}((10, 10))
23-
@test size(B) == (10, 10)
24-
@test eltype(B) == Float32
23+
B = Typ{T}((10, 10))
24+
@test size(B) == (10, 10)
25+
@test eltype(B) == T
2526

26-
B = similar(B, Int32, (11, 15))
27-
@test size(B) == (11, 15)
28-
@test eltype(B) == Int32
27+
B = similar(B, Int32, (11, 15))
28+
@test size(B) == (11, 15)
29+
@test eltype(B) == Int32
2930

30-
B = similar(B, Float32)
31-
@test size(B) == (11, 15)
32-
@test eltype(B) == Float32
31+
B = similar(B, T)
32+
@test size(B) == (11, 15)
33+
@test eltype(B) == T
3334

34-
B = similar(B, (5,))
35-
@test size(B) == (5,)
36-
@test eltype(B) == Float32
35+
B = similar(B, (5,))
36+
@test size(B) == (5,)
37+
@test eltype(B) == T
3738

38-
B = similar(B, 7)
39-
@test size(B) == (7,)
40-
@test eltype(B) == Float32
39+
B = similar(B, 7)
40+
@test size(B) == (7,)
41+
@test eltype(B) == T
4142

4243

43-
B = similar(Typ{Int32}, (11, 15))
44-
@test size(B) == (11, 15)
45-
@test eltype(B) == Int32
44+
B = similar(Typ{Int32}, (11, 15))
45+
@test size(B) == (11, 15)
46+
@test eltype(B) == Int32
4647

47-
B = similar(Typ{Int32, 2}, Float32, (11, 15))
48-
@test size(B) == (11, 15)
49-
@test eltype(B) == Float32
48+
B = similar(Typ{Int32, 2}, T, (11, 15))
49+
@test size(B) == (11, 15)
50+
@test eltype(B) == T
5051

51-
B = similar(Typ{Float32}, (5,))
52-
@test size(B) == (5,)
53-
@test eltype(B) == Float32
52+
B = similar(Typ{T}, (5,))
53+
@test size(B) == (5,)
54+
@test eltype(B) == T
5455

55-
B = similar(Typ{Float32}, 7)
56-
@test size(B) == (7,)
57-
@test eltype(B) == Float32
56+
B = similar(Typ{T}, 7)
57+
@test size(B) == (7,)
58+
@test eltype(B) == T
59+
end
5860
end
5961
end
6062

6163
function conversion(Typ)
6264
@testset "conversion" begin
63-
Bc = rand(10, 10)
64-
B = Typ{Float32}(Bc)
65-
@test size(B) == (10, 10)
66-
@test eltype(B) == Float32
67-
@test Array(B) Bc
68-
69-
Bc = rand(Float32, 10)
70-
B = Typ(Bc)
71-
@test size(B) == (10,)
72-
@test eltype(B) == Float32
73-
@test Array(B) Bc
74-
75-
Bc = rand(Int32, 10, 10)
76-
B = Typ{Int32, 2}(Bc)
77-
@test size(B) == (10, 10)
78-
@test eltype(B) == Int32
79-
@test Array(B) Bc
80-
81-
Bc = rand(Int32, 3, 3, 3)
82-
B = convert(Typ{Float32, 3}, Bc)
83-
@test size(B) == (3, 3, 3)
84-
@test eltype(B) == Float32
85-
@test Array(B) Bc
65+
for T in supported_eltypes()
66+
Bc = round.(rand(10, 10) .* 10.0)
67+
B = Typ{T}(Bc)
68+
@test size(B) == (10, 10)
69+
@test eltype(B) == T
70+
@test Array(B) Bc
71+
72+
Bc = rand(T, 10)
73+
B = Typ(Bc)
74+
@test size(B) == (10,)
75+
@test eltype(B) == T
76+
@test Array(B) Bc
77+
78+
Bc = rand(T, 10, 10)
79+
B = Typ{T, 2}(Bc)
80+
@test size(B) == (10, 10)
81+
@test eltype(B) == T
82+
@test Array(B) Bc
83+
84+
Bc = rand(Int32, 3, 3, 3)
85+
B = convert(Typ{T, 3}, Bc)
86+
@test size(B) == (3, 3, 3)
87+
@test eltype(B) == T
88+
@test Array(B) Bc
89+
end
8690
end
8791
end
8892

8993
function value_constructor(Typ)
9094
@testset "value constructor" begin
91-
x = zeros(Float32, 2, 2)
92-
x1 = zeros(Typ{Float32}, 2, 2)
93-
x2 = zeros(Typ{Int32}, (2, 2))
94-
x3 = zeros(Typ{Int32, 2}, (2, 2))
95-
@test Array(x1) x
96-
@test Array(x2) x
97-
@test Array(x3) x
98-
99-
x1 = fill(Typ{Float32}, 0f0, 2, 2)
100-
x2 = fill(Typ{Int32}, 0f0, (2, 2))
101-
x3 = fill(Typ{Float32, 2}, 0f0, (2, 2))
102-
@test Array(x1) x
103-
@test Array(x2) x
104-
@test Array(x3) x
105-
106-
fill!(x1, 2f0)
107-
x2 = fill!(Typ{Int32}((4, 4, 4)), 77f0)
108-
@test all(x-> x == 2f0, Array(x1))
109-
@test all(x-> x == Int32(77), Array(x2))
110-
111-
x = eye(Float32, 2, 2)
112-
x1 = eye(Typ{Int32, 2}, 2, 2)
113-
x2 = eye(Typ{Float32}, (2, 2))
114-
x3 = eye(Typ{Float32, 2}, (2, 2))
115-
116-
@test Array(x1) x
117-
@test Array(x2) x
118-
@test Array(x3) x
119-
95+
for T in supported_eltypes()
96+
x = zeros(T, 2, 2)
97+
x1 = zeros(Typ{T}, 2, 2)
98+
x2 = zeros(Typ{T}, (2, 2))
99+
x3 = zeros(Typ{T, 2}, (2, 2))
100+
@test Array(x1) x
101+
@test Array(x2) x
102+
@test Array(x3) x
103+
104+
x1 = fill(Typ{T}, 0f0, 2, 2)
105+
x2 = fill(Typ{T}, T(0), (2, 2))
106+
x3 = fill(Typ{T, 2}, T(0), (2, 2))
107+
@test Array(x1) x
108+
@test Array(x2) x
109+
@test Array(x3) x
110+
111+
fill!(x1, 2f0)
112+
x2 = fill!(Typ{Int32}((4, 4, 4)), 77f0)
113+
@test all(x-> x == 2f0, Array(x1))
114+
@test all(x-> x == Int32(77), Array(x2))
115+
116+
x = eye(T, 2, 2)
117+
x1 = eye(Typ{T, 2}, 2, 2)
118+
x2 = eye(Typ{T}, (2, 2))
119+
x3 = eye(Typ{T, 2}, (2, 2))
120+
121+
@test Array(x1) x
122+
@test Array(x2) x
123+
@test Array(x3) x
124+
end
120125
end
121126
end

0 commit comments

Comments
 (0)