Skip to content

Commit 1cef99a

Browse files
cl/upsample
1 parent 92de1d8 commit 1cef99a

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

Project.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
88
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
99
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
10-
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
1110
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1211

1312
[compat]
@@ -17,11 +16,13 @@ julia = "1.3"
1716

1817
[extras]
1918
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
19+
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
2020
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
2121
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
2222
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
2323
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2424
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
2525

2626
[targets]
27-
test = ["ChainRulesTestUtils", "FiniteDifferences", "Random", "StableRNGs", "Test", "Zygote"]
27+
test = ["ChainRulesTestUtils", "CUDA", "FiniteDifferences",
28+
"Random", "StableRNGs", "Test", "Zygote"]

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ using FiniteDifferences: FiniteDifferenceMethod, central_fdm
66
import Zygote
77
using Zygote: gradient
88
using StableRNGs
9+
using CUDA
10+
CUDA.allowscalar(false)
911

1012
const rng = StableRNG(123)
1113

test/upsample.jl

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
using CUDA
2-
CUDA.allowscalar(false)
3-
41
@testset "bilinear_upsample 2d" begin
52
x = reshape(Float32[1. 2.; 3. 4.], (2,2,1,1))
63
y_true = [1//1 5//4 7//4 2//1;
@@ -17,14 +14,15 @@ CUDA.allowscalar(false)
1714

1815
gradtest(x->bilinear_upsample(x, (3, 2)), x, atol=1e-4)
1916

20-
# CUDA compatibility
21-
y = bilinear_upsample(x |> cu, (3, 2))
22-
@test y isa CuArray
23-
@test Array(y) y_true
24-
g_gpu = Zygote.gradient(x -> sum(sin.(bilinear_upsample(x, (3, 2))))
25-
, x |> cu)[1]
26-
@test g_gpu isa CuArray
27-
g_cpu = Zygote.gradient(x -> sum(sin.(bilinear_upsample(x, (3, 2))))
28-
, x)[1]
29-
@test Array(g_cpu) g_cpu atol=1e-4
17+
if CUDA.has_cuda()
18+
y = bilinear_upsample(x |> cu, (3, 2))
19+
@test y isa CuArray
20+
@test Array(y) y_true
21+
g_gpu = Zygote.gradient(x -> sum(sin.(bilinear_upsample(x, (3, 2))))
22+
, x |> cu)[1]
23+
@test g_gpu isa CuArray
24+
g_cpu = Zygote.gradient(x -> sum(sin.(bilinear_upsample(x, (3, 2))))
25+
, x)[1]
26+
@test Array(g_cpu) g_cpu atol=1e-4
27+
end
3028
end

0 commit comments

Comments
 (0)