Skip to content

Commit

Permalink
Even more CUSPARSE tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt committed Mar 5, 2025
1 parent 2540087 commit da59439
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/cusparse/batched.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ end

# repeat non-matrix dimensions
function Base.repeat(A::Union{CuSparseArrayCSR, CuSparseMatrixCSR}, r1::Int64, r2::Int64, rs::Int64...)
@assert r1 == 1 && r2 == 1 "Cannot repeat matrix dimensions of CuSparseCSR"
(r1 == 1 && r2 == 1) || throw(ArgumentError("Cannot repeat matrix dimensions of CuSparseCSR"))
CuSparseArrayCSR(repeat(A.rowPtr, 1, rs...),
repeat(A.colVal, 1, rs...),
repeat(A.nzVal, 1, rs...),
Expand Down
5 changes: 4 additions & 1 deletion lib/cusparse/device.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# on-device sparse array functionality

# should be excluded from coverage counts
# COV_EXCL_START
using SparseArrays

# NOTE: this functionality is currently very bare-bones, only defining the array types
Expand Down Expand Up @@ -131,3 +132,5 @@ function Base.show(io::IO, ::MIME"text/plain", A::CuSparseDeviceArrayCSR)
println(io, " colVal: $(A.colVal)")
print(io, " nzVal: $(A.nzVal)")
end

# COV_EXCL_STOP
15 changes: 14 additions & 1 deletion test/libraries/cusparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using CUDA.CUSPARSE

using LinearAlgebra
using SparseArrays
using SparseArrays: nonzeroinds, getcolptr
using SparseArrays: rowvals, nonzeroinds, getcolptr

@test CUSPARSE.version() isa VersionNumber

Expand Down Expand Up @@ -34,7 +34,10 @@ blockdim = 5
@test nnz(d_x) == nnz(x)
@test Array(nonzeros(d_x)) == nonzeros(x)
@test Array(nonzeroinds(d_x)) == nonzeroinds(x)
@test Array(rowvals(d_x)) == nonzeroinds(x)
@test nnz(d_x) == length(nonzeros(d_x))
d_y = copy(d_x)
CUDA.unsafe_free!(d_y)
x = sprand(m,n,0.2)
d_x = CuSparseMatrixCSC(x)
@test CuSparseMatrixCSC(d_x) === d_x
Expand Down Expand Up @@ -74,6 +77,8 @@ blockdim = 5
@test !ishermitian(d_x)
@test_throws ArgumentError size(d_x,0)
@test_throws ArgumentError CUSPARSE.CuSparseVector(x)
d_y = copy(d_x)
CUDA.unsafe_free!(d_y)
y = sprand(k,n,0.2)
d_y = CuSparseMatrixCSC(y)
@test_throws ArgumentError copyto!(d_y,d_x)
Expand Down Expand Up @@ -111,7 +116,13 @@ blockdim = 5
@test_throws ArgumentError copyto!(d_y,d_x)
d_y = CuSparseMatrixCSR(d_y)
d_x = CuSparseMatrixCSR(d_x)
d_z = copy(d_x)
CUDA.unsafe_free!(d_z)
@test CuSparseMatrixCSR(d_x) === d_x
@test reshape(d_x, :, :, 1, 1, 1) isa CuSparseArrayCSR
@test_throws ArgumentError("Cannot repeat matrix dimensions of CuSparseCSR") repeat(d_x, 2, 1, 3)
@test repeat(d_x, 1, 1, 3) isa CuSparseArrayCSR
@test reshape(repeat(d_x, 1, 1, 3), size(d_x, 1), size(d_x, 2), 3, 1, 1) isa CuSparseArrayCSR
@test length(d_x) == m*n
@test_throws ArgumentError copyto!(d_y,d_x)
CUDA.@allowscalar begin
Expand All @@ -123,6 +134,8 @@ blockdim = 5
d_y = CuSparseMatrixBSR(d_y, blockdim)
d_x = CuSparseMatrixBSR(d_x, blockdim)
@test CuSparseMatrixBSR(d_x) === d_x
d_z = copy(d_x)
CUDA.unsafe_free!(d_z)
@test_throws ArgumentError copyto!(d_y,d_x)
CUDA.@allowscalar begin
@test d_y[1, 1] y[1, 1]
Expand Down

0 comments on commit da59439

Please sign in to comment.