Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions lib/cusparse/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function densetosparse(A::CuMatrix{T}, fmt::Symbol, index::SparseChar, algo::cus
colPtr = CuVector{Cint}(undef, n+1)
desc_sparse = CuSparseMatrixDescriptor(CuSparseMatrixCSC, colPtr, T, Cint, m, n, index)
else
error("Format :$fmt not available, use :csc, :csr or :coo.")
throw(ArgumentError("Format :$fmt not available, use :csc, :csr or :coo."))
end
desc_dense = CuDenseMatrixDescriptor(A)

Expand Down Expand Up @@ -82,8 +82,6 @@ function densetosparse(A::CuMatrix{T}, fmt::Symbol, index::SparseChar, algo::cus
nzVal = CuVector{T}(undef, nnzB[])
B = CuSparseMatrixCSC{T, Cint}(colPtr, rowVal, nzVal, (m,n))
cusparseCscSetPointers(desc_sparse, B.colPtr, B.rowVal, B.nzVal)
else
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This I think we can remove because it should be caught higher up in the function

error("Format :$fmt not available, use :csc, :csr or :coo.")
end
cusparseDenseToSparse_convert(handle(), desc_dense, desc_sparse, algo, buffer)
end
Expand Down
18 changes: 18 additions & 0 deletions test/libraries/cusparse/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ for SparseMatrixType in [CuSparseMatrixCSC, CuSparseMatrixCSR, CuSparseMatrixCOO
dA_dense = CuMatrix{T}(A_dense)
dA_sparse = CUSPARSE.densetosparse(dA_dense, fmt[SparseMatrixType], 'O', algo)
@test A_sparse ≈ collect(dA_sparse)
@test_throws ArgumentError("Format :bad not available, use :csc, :csr or :coo.") CUSPARSE.densetosparse(dA_dense, :bad, 'O', algo)
end
end
@testset "$SparseMatrixType -- sparsetodense algo=$algo" for algo in [CUSPARSE.CUSPARSE_SPARSETODENSE_ALG_DEFAULT]
Expand Down Expand Up @@ -362,8 +363,25 @@ for SparseMatrixType in keys(SPGEMM_ALGOS)
F = alpha * opa(A) * opb(B) + beta * E
dF = gemm(transa, transb, alpha, dA, dB, beta, dE, 'O', algo, same_pattern=false)
@test F ≈ SparseMatrixCSC(dF)

# not same pattern
G = sprand(T, 25, 35, 0.4)
dG = SparseMatrixType(G)
@test_throws ErrorException("AB and C must have the same sparsity pattern.") gemm!(transa, transb, gamma, dA, dB, beta, dG, 'O', algo)
dG = gemm!(transa, transb, gamma, dA, dB, zero(T), dG, 'O', algo)
H = gamma * opa(A) * opa(B) + zero(T) * G
@test H ≈ SparseMatrixCSC(dG)
end
end
if SparseMatrixType == CuSparseMatrixCSR
A = sprand(T,25,10,0.2)
B = sprand(T,10,35,0.3)
dA = SparseMatrixType(A)
dB = SparseMatrixType(B)
C = A * B
dC = SparseMatrixType(C)
@test_throws ArgumentError("Sparse matrix-matrix multiplication only supports transa (T) = 'N' and transb (C) = 'N'") gemm!('T', 'C', one(T), dA, dB, zero(T), dC, 'O', algo)
end
end
end

Expand Down