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

Commit

Permalink
Merge #636
Browse files Browse the repository at this point in the history
636: Add BLAS.axpby! r=amontoison a=amontoison



Co-authored-by: Alexis Montoison <[email protected]>
  • Loading branch information
bors[bot] and amontoison authored Mar 21, 2020
2 parents bc03269 + b51ed34 commit 1154509
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/blas/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ function LinearAlgebra.axpy!(alpha::Number, x::CuArray{T}, y::CuArray{T}) where
axpy!(length(x), convert(T,alpha), x, 1, y, 1)
end

function LinearAlgebra.axpby!(alpha::Number, x::CuArray{T}, beta::Number, y::CuArray{T}) where T<:CublasFloat
length(x)==length(y) || throw(DimensionMismatch("axpy arguments have lengths $(length(x)) and $(length(y))"))
axpby!(length(x), convert(T,alpha), x, 1, convert(T,beta), y, 1)
end


#
Expand Down
27 changes: 27 additions & 0 deletions src/blas/wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,33 @@ function axpy!(alpha::Ta,
y
end

function axpby!(n::Integer,
alpha::T,
dx::CuArray{T},
incx::Integer,
beta::T,
dy::CuArray{T},
incy::Integer) where T <: CublasFloat
scal!(n, beta, dy, incy)
axpy!(n, alpha, dx, incx, dy, incy)
dy
end

function axpby!(alpha::Ta,
x::CuArray{T},
rx::Union{UnitRange{Ti},AbstractRange{Ti}},
beta::Tb,
y::CuArray{T},
ry::Union{UnitRange{Ti},AbstractRange{Ti}}) where {T<:CublasFloat,Ta<:Number,Tb<: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())
end
axpby!(length(rx), convert(T, alpha), pointer(x)+(first(rx)-1)*sizeof(T),
step(rx), convert(T, beta), pointer(y)+(first(ry)-1)*sizeof(T), step(ry))
y
end

## iamax
# TODO: fix iamax in julia base
for (fname, elty) in ((:cublasIdamax_v2,:Float64),
Expand Down
1 change: 1 addition & 0 deletions test/blas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ k = 13
@test testf(norm, rand(T, m))
@test testf(BLAS.asum, rand(T, m))
@test testf(BLAS.axpy!, Ref(rand()), rand(T, m), rand(T, m))
@test testf(BLAS.axpby!, Ref(rand()), rand(T, m), Ref(rand()), rand(T, m))

if T <: Complex
@test testf(BLAS.dotu, rand(T, m), rand(T, m))
Expand Down

0 comments on commit 1154509

Please sign in to comment.