Skip to content

Commit

Permalink
Use CUBLAS.geam for elementwise + and - on CuMatrix (#1775)
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison authored Feb 17, 2023
1 parent 868d33e commit 042df36
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/cublas/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -591,3 +591,15 @@ end
error("only supports BLAS type, got $T")
end
end

op_wrappers = ((identity, T -> 'N', identity),
(T -> :(Transpose{T, <:$T}), T -> 'T', A -> :(parent($A))),
(T -> :(Adjoint{T, <:$T}), T -> T <: Real ? 'T' : 'C', A -> :(parent($A))))

for op in (:(+), :(-))
for (wrapa, transa, unwrapa) in op_wrappers, (wrapb, transb, unwrapb) in op_wrappers
TypeA = wrapa(:(CuMatrix{T}))
TypeB = wrapb(:(CuMatrix{T}))
@eval Base.$op(A::$TypeA, B::$TypeB) where {T <: CublasFloat} = CUBLAS.geam($transa(T), $transb(T), one(T), $(unwrapa(:A)), $(op)(one(T)), $(unwrapb(:B)))
end
end
21 changes: 21 additions & 0 deletions test/cublas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,27 @@ end
h_C = Array(d_C)
@test D h_C
end
@testset "CuMatrix -- A ± B -- $elty" begin
for opa in (identity, transpose, adjoint)
for opb in (identity, transpose, adjoint)
n = 10
m = 20
geam_A = opa == identity ? rand(elty, n, m) : rand(elty, m, n)
geam_B = opb == identity ? rand(elty, n, m) : rand(elty, m, n)

geam_dA = CuMatrix{elty}(geam_A)
geam_dB = CuMatrix{elty}(geam_B)

geam_C = opa(geam_A) + opb(geam_B)
geam_dC = opa(geam_dA) + opb(geam_dB)
@test geam_C collect(geam_dC)

geam_C = opa(geam_A) - opb(geam_B)
geam_dC = opa(geam_dA) - opb(geam_dB)
@test geam_C collect(geam_dC)
end
end
end
A = rand(elty,m,k)
d_A = CuArray(A)
@testset "syrkx!" begin
Expand Down

0 comments on commit 042df36

Please sign in to comment.