Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid constructing MulAddMuls #623

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/blas/highlevel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,14 @@ else
end

# GEMV

# legacy method
LinearAlgebra.generic_matvecmul!(
Y::ROCVector, tA::AbstractChar, A::StridedROCMatrix, B::StridedROCVector,
_add::MulAddMul
) = LinearAlgebra.generic_matvecmul!(Y, tA, A, B, _add.alpha, _add.beta)
function LinearAlgebra.generic_matvecmul!(
Y::ROCVector, tA::AbstractChar, A::StridedROCMatrix, B::StridedROCVector,
_add::MulAddMul,
alpha::Number, beta::Number,
)
mA, nA = tA == 'N' ? size(A) : reverse(size(A))

Expand All @@ -158,7 +162,6 @@ function LinearAlgebra.generic_matvecmul!(
nA == 0 && return rmul!(Y, 0)

T = eltype(Y)
alpha, beta = _add.alpha, _add.beta
if alpha isa Union{Bool,T} && beta isa Union{Bool,T}
α, β = T(alpha), T(beta)
if T <: ROCBLASFloat && eltype(A) == eltype(B) == T
Expand All @@ -171,7 +174,7 @@ function LinearAlgebra.generic_matvecmul!(
end
end
end
LinearAlgebra.generic_matmatmul!(Y, tA, 'N', A, B, MulAddMul(alpha, beta))
LinearAlgebra.generic_matmatmul!(Y, tA, 'N', A, B, alpha, beta)
end

if VERSION < v"1.10.0-DEV.1365"
Expand All @@ -191,13 +194,16 @@ end
#
# BLAS 3
#

function LinearAlgebra.generic_matmatmul!(
# legacy method
LinearAlgebra.generic_matmatmul!(
C::StridedROCVecOrMat, tA, tB, A::StridedROCVecOrMat,
B::StridedROCVecOrMat, _add::MulAddMul,
) = LinearAlgebra.generic_matmatmul!(C, tA, tB, A, B, _add.alpha, _add.beta)
function LinearAlgebra.generic_matmatmul!(
C::StridedROCVecOrMat, tA, tB, A::StridedROCVecOrMat,
B::StridedROCVecOrMat, alpha::Number, beta::Number,
)
T = eltype(C)
alpha, beta = _add.alpha, _add.beta
mA, nA = size(A, tA == 'N' ? 1 : 2), size(A, tA == 'N' ? 2 : 1)
mB, nB = size(B, tB == 'N' ? 1 : 2), size(B, tB == 'N' ? 2 : 1)

Expand Down