2018-01-16 17:58:14 +00:00
|
|
|
using Flux, Flux.Tracker, CuArrays, Base.Test
|
2018-02-28 22:51:08 +00:00
|
|
|
using Flux: gpu
|
2018-01-16 17:58:14 +00:00
|
|
|
|
2018-01-24 13:12:22 +00:00
|
|
|
info("Testing Flux/GPU")
|
|
|
|
|
2018-01-16 17:58:14 +00:00
|
|
|
@testset "CuArrays" begin
|
|
|
|
|
|
|
|
CuArrays.allowscalar(false)
|
|
|
|
|
|
|
|
x = param(randn(5, 5))
|
2018-02-28 22:51:08 +00:00
|
|
|
cx = gpu(x)
|
2018-01-16 17:58:14 +00:00
|
|
|
@test cx isa TrackedArray && cx.data isa CuArray
|
|
|
|
|
|
|
|
x = Flux.onehotbatch([1, 2, 3], 1:3)
|
2018-02-28 22:51:08 +00:00
|
|
|
cx = gpu(x)
|
2018-01-16 17:58:14 +00:00
|
|
|
@test cx isa Flux.OneHotMatrix && cx.data isa CuArray
|
|
|
|
|
2018-03-01 16:37:52 +00:00
|
|
|
m = Chain(Dense(10, 5, tanh), Dense(5, 2), softmax)
|
2018-02-28 22:51:08 +00:00
|
|
|
cm = gpu(m)
|
2018-01-16 17:58:14 +00:00
|
|
|
|
|
|
|
@test all(p isa TrackedArray && p.data isa CuArray for p in params(cm))
|
2018-02-28 22:51:08 +00:00
|
|
|
@test cm(gpu(rand(10, 10))) isa TrackedArray{Float32,2,CuArray{Float32,2}}
|
2018-01-16 17:58:14 +00:00
|
|
|
|
2018-04-17 16:20:51 +00:00
|
|
|
x = [1,2,3]
|
|
|
|
cx = gpu(x)
|
|
|
|
@test Flux.crossentropy(x,x) ≈ Flux.crossentropy(cx,cx)
|
|
|
|
|
2018-02-28 23:18:49 +00:00
|
|
|
# Fails in Pkg.test ffs
|
|
|
|
# c = gpu(Conv((2,2),3=>4))
|
|
|
|
# l = c(gpu(rand(10,10,3,2)))
|
|
|
|
# Flux.back!(sum(l))
|
|
|
|
|
2018-01-16 17:58:14 +00:00
|
|
|
end
|
2018-01-30 13:12:33 +00:00
|
|
|
|
|
|
|
CuArrays.cudnn_available() && include("cudnn.jl")
|