-
Notifications
You must be signed in to change notification settings - Fork 254
[CUSPARSE] Interface generic mv! for SparseMatrixBSR #2929
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
Open
amontoison
wants to merge
1
commit into
JuliaGPU:master
Choose a base branch
from
amontoison:am/cusparse_bsr_mv
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Your PR requires formatting changes to meet the project's style guidelines. Click here to view the suggested changes.diff --git a/lib/cusparse/generic.jl b/lib/cusparse/generic.jl
index eb7abad69..8bbb57ee7 100644
--- a/lib/cusparse/generic.jl
+++ b/lib/cusparse/generic.jl
@@ -152,7 +152,8 @@ function vv!(transx::SparseChar, X::CuSparseVector{T}, Y::DenseCuVector{T}, inde
return result[]
end
-function mv!(transa::SparseChar, alpha::Number, A::CuSparseMatrix{TA}, X::DenseCuVector{T},
+function mv!(
+ transa::SparseChar, alpha::Number, A::CuSparseMatrix{TA}, X::DenseCuVector{T},
beta::Number, Y::DenseCuVector{T}, index::SparseChar, algo::cusparseSpMVAlg_t=CUSPARSE_SPMV_ALG_DEFAULT) where {TA, T}
(A isa CuSparseMatrixBSR) && (CUSPARSE.version() < v"12.6.3") && throw(ErrorException("This operation is not supported by the current CUDA version."))
@@ -161,7 +162,7 @@ function mv!(transa::SparseChar, alpha::Number, A::CuSparseMatrix{TA}, X::DenseC
transa = T <: Real && transa == 'C' ? 'T' : transa
descA = CuSparseMatrixDescriptor(A, index)
- m,n = size(A)
+ m, n = size(A)
if transa == 'N'
chkmvdims(X,n,Y,m)
diff --git a/lib/cusparse/level2.jl b/lib/cusparse/level2.jl
index 37a9bd686..afccca8b6 100644
--- a/lib/cusparse/level2.jl
+++ b/lib/cusparse/level2.jl
@@ -8,13 +8,15 @@ for (fname,elty) in ((:cusparseSbsrmv, :Float32),
(:cusparseCbsrmv, :ComplexF32),
(:cusparseZbsrmv, :ComplexF64))
@eval begin
- function mv2!(transa::SparseChar,
- alpha::Number,
- A::CuSparseMatrixBSR{$elty},
- X::CuVector{$elty},
- beta::Number,
- Y::CuVector{$elty},
- index::SparseChar)
+ function mv2!(
+ transa::SparseChar,
+ alpha::Number,
+ A::CuSparseMatrixBSR{$elty},
+ X::CuVector{$elty},
+ beta::Number,
+ Y::CuVector{$elty},
+ index::SparseChar
+ )
# Support transa = 'C' for real matrices
transa = $elty <: Real && transa == 'C' ? 'T' : transa
diff --git a/test/libraries/cusparse.jl b/test/libraries/cusparse.jl
index e09a338a2..17e1c68ca 100644
--- a/test/libraries/cusparse.jl
+++ b/test/libraries/cusparse.jl
@@ -756,7 +756,8 @@ end
alpha = rand(elty)
beta = rand(elty)
@testset "$(typeof(d_A))" for d_A in [CuSparseMatrixCSR(A),
- CuSparseMatrixCSC(A)]
+ CuSparseMatrixCSC(A),
+ ]
d_x = CuArray(x)
d_y = CuArray(y)
@test_throws DimensionMismatch CUSPARSE.mv!('T',alpha,d_A,d_x,beta,d_y,'O')
@@ -769,9 +770,9 @@ end
@testset "$(typeof(d_A))" for d_A in [CuSparseMatrixBSR(A, blockdim)]
d_x = CuArray(x)
d_y = CuArray(y)
- @test_throws DimensionMismatch CUSPARSE.mv2!('T',alpha,d_A,d_x,beta,d_y,'O')
- @test_throws DimensionMismatch CUSPARSE.mv2!('N',alpha,d_A,d_y,beta,d_x,'O')
- CUSPARSE.mv2!('N',alpha,d_A,d_x,beta,d_y,'O')
+ @test_throws DimensionMismatch CUSPARSE.mv2!('T', alpha, d_A, d_x, beta, d_y, 'O')
+ @test_throws DimensionMismatch CUSPARSE.mv2!('N', alpha, d_A, d_y, beta, d_x, 'O')
+ CUSPARSE.mv2!('N', alpha, d_A, d_x, beta, d_y, 'O')
h_z = collect(d_y)
z = alpha * A * x + beta * y
@test z ≈ h_z
diff --git a/test/libraries/cusparse/generic.jl b/test/libraries/cusparse/generic.jl
index 7843fd40b..b729c92b9 100644
--- a/test/libraries/cusparse/generic.jl
+++ b/test/libraries/cusparse/generic.jl
@@ -32,7 +32,9 @@ SPMV_ALGOS = Dict(CuSparseMatrixCSC => [CUSPARSE.CUSPARSE_SPMV_ALG_DEFAULT],
CUSPARSE.CUSPARSE_SPMV_CSR_ALG1,
CUSPARSE.CUSPARSE_SPMV_CSR_ALG2],
CuSparseMatrixCOO => [CUSPARSE.CUSPARSE_SPMV_ALG_DEFAULT,
- CUSPARSE.CUSPARSE_SPMV_COO_ALG1])
+ CUSPARSE.CUSPARSE_SPMV_COO_ALG1,
+ ]
+)
SPMM_ALGOS = Dict(CuSparseMatrixCSC => [CUSPARSE.CUSPARSE_SPMM_ALG_DEFAULT],
CuSparseMatrixCSR => [CUSPARSE.CUSPARSE_SPMM_ALG_DEFAULT,
@@ -41,9 +43,11 @@ SPMM_ALGOS = Dict(CuSparseMatrixCSC => [CUSPARSE.CUSPARSE_SPMM_ALG_DEFAULT],
CUSPARSE.CUSPARSE_SPMM_CSR_ALG3],
CuSparseMatrixCOO => [CUSPARSE.CUSPARSE_SPMM_ALG_DEFAULT,
CUSPARSE.CUSPARSE_SPMM_COO_ALG1,
- CUSPARSE.CUSPARSE_SPMM_COO_ALG2,
+ CUSPARSE.CUSPARSE_SPMM_COO_ALG2,
CUSPARSE.CUSPARSE_SPMM_COO_ALG3,
- CUSPARSE.CUSPARSE_SPMM_COO_ALG4])
+ CUSPARSE.CUSPARSE_SPMM_COO_ALG4,
+ ]
+)
if CUSPARSE.version() >= v"12.1.3"
push!(SPMV_ALGOS[CuSparseMatrixCOO], CUSPARSE.CUSPARSE_SPMV_COO_ALG2)
@@ -55,8 +59,10 @@ if CUSPARSE.version() >= v"12.5.1"
end
if CUSPARSE.version() >= v"12.6.3"
- SPMV_ALGOS[CuSparseMatrixBSR] = [CUSPARSE.CUSPARSE_SPMV_ALG_DEFAULT,
- CUSPARSE.CUSPARSE_SPMV_BSR_ALG1]
+ SPMV_ALGOS[CuSparseMatrixBSR] = [
+ CUSPARSE.CUSPARSE_SPMV_ALG_DEFAULT,
+ CUSPARSE.CUSPARSE_SPMV_BSR_ALG1,
+ ]
end
for SparseMatrixType in keys(SPMV_ALGOS)
@@ -67,7 +73,7 @@ for SparseMatrixType in keys(SPMV_ALGOS)
A = sprand(T, 20, 10, 0.1)
B = transa == 'N' ? rand(T, 10) : rand(T, 20)
C = transa == 'N' ? rand(T, 20) : rand(T, 10)
- dA = SparseMatrixType == CuSparseMatrixBSR ? SparseMatrixType(A,1) : SparseMatrixType(A)
+ dA = SparseMatrixType == CuSparseMatrixBSR ? SparseMatrixType(A, 1) : SparseMatrixType(A)
dB = CuArray(B)
dC = CuArray(C)
@@ -313,14 +319,20 @@ end
@test Z ≈ collect(dY)
end
-SPGEMM_ALGOS = Dict(CuSparseMatrixCSR => [CUSPARSE.CUSPARSE_SPGEMM_DEFAULT,
- CUSPARSE.CUSPARSE_SPGEMM_ALG1,
- CUSPARSE.CUSPARSE_SPGEMM_ALG2,
- CUSPARSE.CUSPARSE_SPGEMM_ALG3],
- CuSparseMatrixCSC => [CUSPARSE.CUSPARSE_SPGEMM_DEFAULT,
- CUSPARSE.CUSPARSE_SPGEMM_ALG1,
- CUSPARSE.CUSPARSE_SPGEMM_ALG2,
- CUSPARSE.CUSPARSE_SPGEMM_ALG3])
+SPGEMM_ALGOS = Dict(
+ CuSparseMatrixCSR => [
+ CUSPARSE.CUSPARSE_SPGEMM_DEFAULT,
+ CUSPARSE.CUSPARSE_SPGEMM_ALG1,
+ CUSPARSE.CUSPARSE_SPGEMM_ALG2,
+ CUSPARSE.CUSPARSE_SPGEMM_ALG3,
+ ],
+ CuSparseMatrixCSC => [
+ CUSPARSE.CUSPARSE_SPGEMM_DEFAULT,
+ CUSPARSE.CUSPARSE_SPGEMM_ALG1,
+ CUSPARSE.CUSPARSE_SPGEMM_ALG2,
+ CUSPARSE.CUSPARSE_SPGEMM_ALG3,
+ ]
+)
# Algorithms CUSPARSE.CUSPARSE_SPGEMM_CSR_ALG_DETERMINITIC and
# CUSPARSE.CUSPARSE_SPGEMM_CSR_ALG_NONDETERMINITIC are dedicated to the cusparseSpGEMMreuse routine.
@@ -406,9 +418,9 @@ for SparseMatrixType in keys(SDDMM_ALGOS)
mB = transb == 'N' ? 10 : 35
nB = transb == 'N' ? 35 : 10
- A = rand(T,mA,nA)
- B = rand(T,mB,nB)
- C = sprand(T,25,35,0.3)
+ A = rand(T, mA, nA)
+ B = rand(T, mB, nB)
+ C = sprand(T, 25, 35, 0.3)
spyC = copy(C)
spyC.nzval .= one(T) |
acabc12
to
4e9d911
Compare
CI failures are related |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
CuSparseMatrixBSR
for generic sparsemv!
added with CUDA13.0.1
.mv!
andmm!
because we don't have any high-level way to reuse the buffer / descriptor. We just do more work for nothing.