Skip to content
This repository has been archived by the owner on Mar 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #33 from JuliaGPU/fbot/deps
Browse files Browse the repository at this point in the history
Fix deprecations
  • Loading branch information
MikeInnes authored Aug 19, 2017
2 parents 2e0fa4c + 61efff2 commit 746505a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 45 deletions.
22 changes: 11 additions & 11 deletions src/blas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,17 @@ for (jname, fname, elty) in ((:dot,:cublasDdot_v2,:Float64),
end
end
# TODO: inspect blas.jl in julia to correct types here (dot{c,u})
function dot{T<:Union{Float32,Float64}}(DX::CuArray{T}, DY::CuArray{T})
function dot(DX::CuArray{T}, DY::CuArray{T}) where T<:Union{Float32,Float64}
n = length(DX)
n==length(DY) || throw(DimensionMismatch("dot product arguments have lengths $(length(DX)) and $(length(DY))"))
dot(n, DX, 1, DY, 1)
end
function dotc{T<:Union{Complex64,Complex128}}(DX::CuArray{T}, DY::CuArray{T})
function dotc(DX::CuArray{T}, DY::CuArray{T}) where T<:Union{Complex64,Complex128}
n = length(DX)
n==length(DY) || throw(DimensionMismatch("dot product arguments have lengths $(length(DX)) and $(length(DY))"))
dotc(n, DX, 1, DY, 1)
end
function dotu{T<:Union{Complex64,Complex128}}(DX::CuArray{T}, DY::CuArray{T})
function dotu(DX::CuArray{T}, DY::CuArray{T}) where T<:Union{Complex64,Complex128}
n = length(DX)
n==length(DY) || throw(DimensionMismatch("dot product arguments have lengths $(length(DX)) and $(length(DY))"))
dotu(n, DX, 1, DY, 1)
Expand Down Expand Up @@ -242,18 +242,18 @@ for (fname, elty) in ((:cublasDaxpy_v2,:Float64),
end
end

function axpy!{T<:CublasFloat,Ta<:Number}(alpha::Ta,
x::CuArray{T},
y::CuArray{T})
function axpy!(alpha::Ta,
x::CuArray{T},
y::CuArray{T}) where {T<:CublasFloat,Ta<:Number}
length(x)==length(y) || throw(DimensionMismatch(""))
axpy!(length(x), convert(T,alpha), x, 1, y, 1)
end

function axpy!{T<:CublasFloat,Ta<:Number,Ti<:Integer}(alpha::Ta,
x::CuArray{T},
rx::Union{UnitRange{Ti},Range{Ti}},
y::CuArray{T},
ry::Union{UnitRange{Ti},Range{Ti}})
function axpy!(alpha::Ta,
x::CuArray{T},
rx::Union{UnitRange{Ti},Range{Ti}},
y::CuArray{T},
ry::Union{UnitRange{Ti},Range{Ti}}) where {T<:CublasFloat,Ta<:Number,Ti<:Integer}
length(rx)==length(ry) || throw(DimensionMismatch(""))
if minimum(rx) < 1 || maximum(rx) > length(x) || minimum(ry) < 1 || maximum(ry) > length(y)
throw(BoundsError())
Expand Down
64 changes: 32 additions & 32 deletions src/highlevel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ cublas_size(t::Char, M::CuVecOrMat) = (size(M, t=='N' ? 1:2), size(M, t=='N' ? 2
#######
# SCAL
#######
scale!{T<:CublasFloat}(x::CuArray{T}, k::Number) = CUBLAS.scal!(length(x), k, x, 1)
scale!(x::CuArray{T}, k::Number) where {T<:CublasFloat} = CUBLAS.scal!(length(x), k, x, 1)

#######
# DOT
#######
function dot{T <: CublasFloat, TI<:Integer}(x::CuVector{T}, rx::Union{UnitRange{TI},Range{TI}}, y::CuVector{T}, ry::Union{UnitRange{TI},Range{TI}})
function dot(x::CuVector{T}, rx::Union{UnitRange{TI},Range{TI}}, y::CuVector{T}, ry::Union{UnitRange{TI},Range{TI}}) where {T <: CublasFloat, TI<:Integer}
if length(rx) != length(ry)
throw(DimensionMismatch("length of rx, $(length(rx)), does not equal length of ry, $(length(ry))"))
end
Expand All @@ -34,12 +34,12 @@ function dot{T <: CublasFloat, TI<:Integer}(x::CuVector{T}, rx::Union{UnitRange{
dot(length(rx), pointer(x)+(first(rx)-1)*sizeof(T), step(rx), pointer(y)+(first(ry)-1)*sizeof(T), step(ry))
end

At_mul_B{T<:CublasReal}(x::CuVector{T}, y::CuVector{T}) = [CUBLAS.dot(x, y)]
At_mul_B{T<:CublasComplex}(x::CuVector{T}, y::CuVector{T}) = [CUBLAS.dotu(x, y)]
Ac_mul_B{T<:CublasComplex}(x::CuVector{T}, y::CuVector{T}) = [CUBLAS.dotc(x, y)]
At_mul_B(x::CuVector{T}, y::CuVector{T}) where {T<:CublasReal} = [CUBLAS.dot(x, y)]
At_mul_B(x::CuVector{T}, y::CuVector{T}) where {T<:CublasComplex} = [CUBLAS.dotu(x, y)]
Ac_mul_B(x::CuVector{T}, y::CuVector{T}) where {T<:CublasComplex} = [CUBLAS.dotc(x, y)]

vecdot{T<:CublasReal}(x::CuVector{T}, y::CuVector{T}) = dot(x, y)
vecdot{T<:CublasComplex}(x::CuVector{T}, y::CuVector{T}) = dotc(x, y)
vecdot(x::CuVector{T}, y::CuVector{T}) where {T<:CublasReal} = dot(x, y)
vecdot(x::CuVector{T}, y::CuVector{T}) where {T<:CublasComplex} = dotc(x, y)

#######
# NRM2
Expand All @@ -57,8 +57,8 @@ norm(x::CuArray) = nrm2(x)
#########
# GEMV
##########
function gemv_wrapper!{T<:CublasFloat}(y::CuVector{T}, tA::Char, A::CuMatrix{T}, x::CuVector{T},
alpha = one(T), beta = zero(T))
function gemv_wrapper!(y::CuVector{T}, tA::Char, A::CuMatrix{T}, x::CuVector{T},
alpha = one(T), beta = zero(T)) where T<:CublasFloat
mA, nA = cublas_size(tA, A)
if nA != length(x)
throw(DimensionMismatch("second dimension of A, $nA, does not match length of x, $(length(x))"))
Expand All @@ -75,20 +75,20 @@ function gemv_wrapper!{T<:CublasFloat}(y::CuVector{T}, tA::Char, A::CuMatrix{T},
gemv!(tA, alpha, A, x, beta, y)
end

A_mul_B!{T<:CublasFloat}(y::CuVector{T}, A::CuMatrix{T}, x::CuVector{T}) = gemv_wrapper!(y, 'N', A, x)
At_mul_B!{T<:CublasFloat}(y::CuVector{T}, A::CuMatrix{T}, x::CuVector{T}) = gemv_wrapper!(y, 'T', A, x)
Ac_mul_B!{T<:CublasFloat}(y::CuVector{T}, A::CuMatrix{T}, x::CuVector{T}) = gemv_wrapper!(y, 'T', A, x)
Ac_mul_B!{T<:CublasComplex}(y::CuVector{T}, A::CuMatrix{T}, x::CuVector{T}) = gemv_wrapper!(y, 'C', A, x)
A_mul_B!(y::CuVector{T}, A::CuMatrix{T}, x::CuVector{T}) where {T<:CublasFloat} = gemv_wrapper!(y, 'N', A, x)
At_mul_B!(y::CuVector{T}, A::CuMatrix{T}, x::CuVector{T}) where {T<:CublasFloat} = gemv_wrapper!(y, 'T', A, x)
Ac_mul_B!(y::CuVector{T}, A::CuMatrix{T}, x::CuVector{T}) where {T<:CublasFloat} = gemv_wrapper!(y, 'T', A, x)
Ac_mul_B!(y::CuVector{T}, A::CuMatrix{T}, x::CuVector{T}) where {T<:CublasComplex} = gemv_wrapper!(y, 'C', A, x)

function (*){T<:CublasFloat}(A::CuMatrix{T}, x::CuVector{T})
function (*)(A::CuMatrix{T}, x::CuVector{T}) where T<:CublasFloat
A_mul_B!(similar(x, T, size(A,1)), A, x)
end

function At_mul_B{T<:CublasFloat}(A::CuMatrix{T}, x::CuVector{T})
function At_mul_B(A::CuMatrix{T}, x::CuVector{T}) where T<:CublasFloat
At_mul_B!(similar(x, T, size(A,2)), A, x)
end

function Ac_mul_B{T<:CublasFloat}(A::CuMatrix{T}, x::CuVector{T})
function Ac_mul_B(A::CuMatrix{T}, x::CuVector{T}) where T<:CublasFloat
Ac_mul_B!(similar(x, T, size(A,2)), A, x)
end

Expand All @@ -102,11 +102,11 @@ end
########
# GEMM
########
function gemm_wrapper!{T <: CublasFloat}(C::CuVecOrMat{T}, tA::Char, tB::Char,
A::CuVecOrMat{T},
B::CuVecOrMat{T},
alpha = one(T),
beta = zero(T))
function gemm_wrapper!(C::CuVecOrMat{T}, tA::Char, tB::Char,
A::CuVecOrMat{T},
B::CuVecOrMat{T},
alpha = one(T),
beta = zero(T)) where T <: CublasFloat
mA, nA = cublas_size(tA, A)
mB, nB = cublas_size(tB, B)

Expand All @@ -129,49 +129,49 @@ function gemm_wrapper!{T <: CublasFloat}(C::CuVecOrMat{T}, tA::Char, tB::Char,
end

# Mutating
A_mul_B!{T <: CublasFloat}(C::CuMatrix{T}, A::CuMatrix{T}, B::CuMatrix{T}) = gemm_wrapper!(C, 'N', 'N', A, B)
A_mul_B!(C::CuMatrix{T}, A::CuMatrix{T}, B::CuMatrix{T}) where {T <: CublasFloat} = gemm_wrapper!(C, 'N', 'N', A, B)
At_mul_B!(C::CuMatrix, A::CuMatrix, B::CuMatrix) = gemm_wrapper!(C, 'T', 'N', A, B)
At_mul_Bt!(C::CuMatrix, A::CuMatrix, B::CuMatrix) = gemm_wrapper!(C, 'T', 'T', A, B)
Ac_mul_B!{T<:CublasReal}(C::CuMatrix{T}, A::CuMatrix{T}, B::CuMatrix{T}) = At_mul_B!(C, A, B)
Ac_mul_B!(C::CuMatrix{T}, A::CuMatrix{T}, B::CuMatrix{T}) where {T<:CublasReal} = At_mul_B!(C, A, B)
Ac_mul_B!(C::CuMatrix, A::CuMatrix, B::CuMatrix) = gemm_wrapper!(C, 'C', 'N', A, B)

function A_mul_B!{T}(C::CuMatrix{T}, A::CuVecOrMat{T}, B::CuVecOrMat{T})
function A_mul_B!(C::CuMatrix{T}, A::CuVecOrMat{T}, B::CuVecOrMat{T}) where T
gemm_wrapper!(C, 'N', 'N', A, B)
end

# Non mutating

# A_mul_Bx
function (*){T <: CublasFloat}(A::CuMatrix{T}, B::CuMatrix{T})
function (*)(A::CuMatrix{T}, B::CuMatrix{T}) where T <: CublasFloat
A_mul_B!(similar(B, T,(size(A,1), size(B,2))), A, B)
end

function A_mul_Bt{T}(A::CuMatrix{T}, B::CuMatrix{T})
function A_mul_Bt(A::CuMatrix{T}, B::CuMatrix{T}) where T
A_mul_Bt!(similar(B, T, (size(A,1), size(B,1))), A, B)
end

function A_mul_Bc{T}(A::CuMatrix{T}, B::CuMatrix{T})
function A_mul_Bc(A::CuMatrix{T}, B::CuMatrix{T}) where T
A_mul_Bc!(similar(B, T,(size(A,1),size(B,1))),A, B)
end

# At_mul_Bx
function At_mul_B{T}(A::CuMatrix{T}, B::CuMatrix{T})
function At_mul_B(A::CuMatrix{T}, B::CuMatrix{T}) where T
At_mul_B!(similar(B, T, (size(A,2), size(B,2))), A, B)
end

function At_mul_Bt{T}(A::CuMatrix{T}, B::CuMatrix{T})
function At_mul_Bt(A::CuMatrix{T}, B::CuMatrix{T}) where T
At_mul_Bt!(similar(B, T, (size(A,2), size(B,1))), A, B)
end

# Ac_mul_Bx
function Ac_mul_B{T}(A::CuMatrix{T}, B::CuMatrix{T})
function Ac_mul_B(A::CuMatrix{T}, B::CuMatrix{T}) where T
Ac_mul_B!(similar(B, T, (size(A,2), size(B,2))), A, B)
end

function Ac_mul_Bt{T,S}(A::CuMatrix{T}, B::CuMatrix{S})
function Ac_mul_Bt(A::CuMatrix{T}, B::CuMatrix{S}) where {T,S}
Ac_mul_Bt(similar(B, T, (size(A,2), size(B,1))), A, B)
end

function Ac_mul_Bc{T,S}(A::CuMatrix{T}, B::CuMatrix{S})
function Ac_mul_Bc(A::CuMatrix{T}, B::CuMatrix{S}) where {T,S}
Ac_mul_Bc!(similar(B, T, (size(A,2), size(B,1))), A, B)
end
2 changes: 1 addition & 1 deletion src/libcublas_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const CublasReal = Union{Float64,Float32}
const CublasComplex = Union{Complex128,Complex64}
# FP16 (cuda_fp16.h) in cuda
const __half = Float16
immutable __half2
struct __half2
x1::__half
x2::__half
end
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ end
end

@testset "scal!" begin
function test_scal!{T}(alpha,A::Array{T})
function test_scal!(alpha,A::Array{T}) where T
@test ndims(A) == 1
n1 = length(A)
d_A = CuArray(A)
Expand Down

0 comments on commit 746505a

Please sign in to comment.