From df509ce9f0504e475e5e59deae9de571f029a75e Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Wed, 6 Feb 2019 15:01:01 +0100 Subject: [PATCH] Adapt to the new CUDAdrv.CuPtr pointer type. --- src/cuda/cuda.jl | 1 + src/cuda/cudnn.jl | 36 ++++++++++++++++++------------------ src/cuda/curnn.jl | 34 +++++++++++++++++----------------- 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/cuda/cuda.jl b/src/cuda/cuda.jl index 070c9228..762b9b2e 100644 --- a/src/cuda/cuda.jl +++ b/src/cuda/cuda.jl @@ -1,5 +1,6 @@ module CUDA +import CUDAdrv: CuPtr, CU_NULL using ..CuArrays using Pkg.TOML diff --git a/src/cuda/cudnn.jl b/src/cuda/cudnn.jl index 8bd8135e..8671d166 100644 --- a/src/cuda/cudnn.jl +++ b/src/cuda/cudnn.jl @@ -17,7 +17,7 @@ function DropoutDesc(ρ::Real; seed::Integer=0) @check ccall((:cudnnDropoutGetStatesSize,libcudnn),cudnnStatus_t,(Ptr{Nothing},Ptr{Csize_t}),handle(),s) states = CuArray{UInt8}(undef, s[]) # TODO: can we drop this when ρ=0? desc = DropoutDesc(d[], states) - @check ccall((:cudnnSetDropoutDescriptor,libcudnn),cudnnStatus_t,(Ptr{Nothing},Ptr{Nothing},Cfloat,Ptr{Nothing},Csize_t,Culonglong), + @check ccall((:cudnnSetDropoutDescriptor,libcudnn),cudnnStatus_t,(Ptr{Nothing},Ptr{Nothing},Cfloat,CuPtr{Nothing},Csize_t,Culonglong), desc,handle(),ρ,states,length(states),seed) finalizer(desc) do x @check ccall((:cudnnDestroyDropoutDescriptor,libcudnn),cudnnStatus_t,(Ptr{Nothing},),x) @@ -79,18 +79,18 @@ function cudnnBNForward!(y::CuArray{T}, g::CuArray{T}, b::CuArray{T}, x::CuArray mean = zeros(CuArray{T}, dims...) ivar = ones(CuArray{T}, dims...) else - mean = C_NULL - ivar = C_NULL + mean = CU_NULL + ivar = CU_NULL end @check ccall((:cudnnBatchNormalizationForwardTraining, libcudnn), cudnnStatus_t, (cudnnHandle_t,cudnnBatchNormMode_t, Ptr{T}, Ptr{T}, - Ptr{Nothing}, Ptr{T}, - Ptr{Nothing}, Ptr{T}, - Ptr{Nothing}, Ptr{T}, Ptr{T}, - Cdouble, Ptr{T}, Ptr{T}, - Cdouble, Ptr{T}, Ptr{T}), + Ptr{Nothing}, CuPtr{T}, + Ptr{Nothing}, CuPtr{T}, + Ptr{Nothing}, CuPtr{T}, CuPtr{T}, + Cdouble, CuPtr{T}, CuPtr{T}, + Cdouble, CuPtr{T}, CuPtr{T}), handle(), BATCHNORM_SPATIAL, Ref(T(alpha)), Ref(T(beta)), xd, x, @@ -107,10 +107,10 @@ function cudnnBNForward!(y::CuArray{T}, g::CuArray{T}, b::CuArray{T}, x::CuArray @check ccall((:cudnnBatchNormalizationForwardInference, libcudnn), cudnnStatus_t, (Ptr{cudnnHandle_t},cudnnBatchNormMode_t, Ptr{T}, Ptr{T}, - Ptr{Nothing}, Ptr{T}, - Ptr{Nothing}, Ptr{T}, - Ptr{Nothing}, Ptr{T}, Ptr{T}, - Ptr{T}, Ptr{T}, + Ptr{Nothing}, CuPtr{T}, + Ptr{Nothing}, CuPtr{T}, + Ptr{Nothing}, CuPtr{T}, CuPtr{T}, + CuPtr{T}, CuPtr{T}, Cdouble), handle(), BATCHNORM_SPATIAL, Ref(T(alpha)), Ref(T(beta)), @@ -159,7 +159,7 @@ function cudnnBNBackward!(dg::CuArray{T}, g::CuArray{T}, db::CuArray{T}, mean, ivar = cache.mean, cache.ivar info("mean and ivar are fetched from the cache") else - mean, ivar = C_NULL, C_NULL + mean, ivar = CU_NULL, CU_NULL end if eps < BATCHNORM_MIN_EPS @@ -170,11 +170,11 @@ function cudnnBNBackward!(dg::CuArray{T}, g::CuArray{T}, db::CuArray{T}, (cudnnHandle_t,cudnnBatchNormMode_t, Ptr{T}, Ptr{T}, Ptr{T}, Ptr{T}, - Ptr{Nothing}, Ptr{T}, - Ptr{Nothing}, Ptr{T}, - Ptr{Nothing}, Ptr{T}, - Ptr{Nothing}, Ptr{T}, Ptr{T}, Ptr{T}, - Cdouble, Ptr{T}, Ptr{T}), + Ptr{Nothing}, CuPtr{T}, + Ptr{Nothing}, CuPtr{T}, + Ptr{Nothing}, CuPtr{T}, + Ptr{Nothing}, CuPtr{T}, CuPtr{T}, CuPtr{T}, + Cdouble, CuPtr{T}, CuPtr{T}), handle(), BATCHNORM_SPATIAL, Ref(T(alpha)), Ref(T(beta)), Ref(T(dalpha)), Ref(T(dbeta)), diff --git a/src/cuda/curnn.jl b/src/cuda/curnn.jl index 210ddd7c..09f6d43c 100644 --- a/src/cuda/curnn.jl +++ b/src/cuda/curnn.jl @@ -101,18 +101,18 @@ function cudnnRNNForward(rnn::RNNDesc{T}, seqlen, xd, x, hd, h, cd, c, wd, w, yd if reserve == nothing @check ccall((:cudnnRNNForwardInference, libcudnn), cudnnStatus_t, (Ptr{Nothing}, Ptr{Nothing}, Cint, - Ptr{Ptr{Nothing}}, Ptr{T}, Ptr{Nothing}, Ptr{T}, Ptr{Nothing}, Ptr{T}, - Ptr{Nothing}, Ptr{T}, Ptr{Ptr{Nothing}}, Ptr{T}, Ptr{Nothing}, Ptr{T}, - Ptr{Nothing}, Ptr{T}, - Ptr{Nothing}, Csize_t), + Ptr{Ptr{Nothing}}, CuPtr{T}, Ptr{Nothing}, CuPtr{T}, Ptr{Nothing}, CuPtr{T}, + Ptr{Nothing}, CuPtr{T}, Ptr{Ptr{Nothing}}, CuPtr{T}, Ptr{Nothing}, CuPtr{T}, + Ptr{Nothing}, CuPtr{T}, + CuPtr{Nothing}, Csize_t), handle(), rnn, seqlen, xd, x, hd, h, cd, c, wd, w, yd, y, hod, ho, cod, co, workspace, length(workspace)) else @check ccall((:cudnnRNNForwardTraining, libcudnn), cudnnStatus_t, (Ptr{Nothing}, Ptr{Nothing}, Cint, - Ptr{Ptr{Nothing}}, Ptr{T}, Ptr{Nothing}, Ptr{T}, Ptr{Nothing}, Ptr{T}, Ptr{Nothing}, Ptr{T}, Ptr{Ptr{Nothing}}, Ptr{T}, Ptr{Nothing}, Ptr{T}, Ptr{Nothing}, Ptr{T}, - Ptr{Nothing}, Csize_t, Ptr{Nothing}, Csize_t), + Ptr{Ptr{Nothing}}, CuPtr{T}, Ptr{Nothing}, CuPtr{T}, Ptr{Nothing}, CuPtr{T}, Ptr{Nothing}, CuPtr{T}, Ptr{Ptr{Nothing}}, CuPtr{T}, Ptr{Nothing}, CuPtr{T}, Ptr{Nothing}, CuPtr{T}, + CuPtr{Nothing}, Csize_t, CuPtr{Nothing}, Csize_t), handle(), rnn, seqlen, xd, x, hd, h, cd, c, wd, w, yd, y, hod, ho, cod, co, workspace, length(workspace), reserve, length(reserve)) @@ -121,7 +121,7 @@ end xDesc(x) = [TensorDesc(eltype(x), (1, size(x, 1), size(x, 2)))] -hDesc(h::Nothing) = C_NULL, C_NULL +hDesc(h::Nothing) = C_NULL, CU_NULL hDesc(x::Integer) = (@assert x == 0; hDesc(nothing)) function hDesc(h::CuArray) TensorDesc(eltype(h), (size(h, 1), size(h, 2), 1)), h @@ -169,10 +169,10 @@ function cudnnRNNBackwardData(rnn::RNNDesc{T}, seqlen, yd, y, dyd, dy, dhod, dho wd, w, hd, h, cd, c, dxd, dx, dhd, dh, dcd, dc, ws, rs) where T @check ccall((:cudnnRNNBackwardData,libcudnn),cudnnStatus_t, (Ptr{Nothing}, Ptr{Nothing}, Cint, - Ptr{Ptr{Nothing}}, Ptr{T}, Ptr{Ptr{Nothing}}, Ptr{T}, Ptr{Nothing}, Ptr{T}, - Ptr{Nothing}, Ptr{T}, Ptr{Nothing}, Ptr{T}, Ptr{Nothing}, Ptr{T}, Ptr{Nothing}, - Ptr{T}, Ptr{Ptr{Nothing}}, Ptr{T}, Ptr{Nothing}, Ptr{T}, Ptr{Nothing}, Ptr{T}, - Ptr{Nothing}, Csize_t, Ptr{Nothing}, Csize_t), + Ptr{Ptr{Nothing}}, CuPtr{T}, Ptr{Ptr{Nothing}}, CuPtr{T}, Ptr{Nothing}, CuPtr{T}, + Ptr{Nothing}, CuPtr{T}, Ptr{Nothing}, CuPtr{T}, Ptr{Nothing}, CuPtr{T}, Ptr{Nothing}, + CuPtr{T}, Ptr{Ptr{Nothing}}, CuPtr{T}, Ptr{Nothing}, CuPtr{T}, Ptr{Nothing}, CuPtr{T}, + CuPtr{Nothing}, Csize_t, CuPtr{Nothing}, Csize_t), handle(), rnn, seqlen, yd, y, dyd, dy, dhod, dho, dcod, dco, wd, w, hd, h, cd, c, dxd, dx, dhd, dh, dcd, dc, ws, length(ws), rs, length(rs)) end @@ -199,12 +199,12 @@ function cudnnRNNBackwardWeights(rnn::RNNDesc{T}, seqlen, xd, x, hd, h, yd, y, d workspace, reserve) where T @check ccall((:cudnnRNNBackwardWeights,libcudnn), cudnnStatus_t, (Ptr{Nothing}, Ptr{Nothing}, Cint, # handle, rnnDesc, seqLength - Ptr{Ptr{Nothing}}, Ptr{T}, #x - Ptr{Nothing}, Ptr{T}, #hx - Ptr{Ptr{Nothing}}, Ptr{T}, #y - Ptr{Nothing}, Csize_t, #ws - Ptr{Nothing}, Ptr{T}, #dw - Ptr{Nothing}, Csize_t), #rs + Ptr{Ptr{Nothing}}, CuPtr{T}, #x + Ptr{Nothing}, CuPtr{T}, #hx + Ptr{Ptr{Nothing}}, CuPtr{T}, #y + CuPtr{Nothing}, Csize_t, #ws + Ptr{Nothing}, CuPtr{T}, #dw + CuPtr{Nothing}, Csize_t), #rs handle(), rnn, seqlen, xd, x, hd, h, yd, y, workspace, length(workspace), dwd, dw, reserve, length(reserve)) end