Skip to content

Commit 6bf72dd

Browse files
authored
Even more CUSPARSE tests (#2682)
* Even more CUSPARSE tests * More tests and a bugfix * Move show test into allowscalar block
1 parent da014f0 commit 6bf72dd

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

lib/cusparse/array.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ CuSparseVector{T}(Mat::SparseMatrixCSC) where {T} =
490490
throw(ArgumentError("The input argument must have a single column"))
491491
CuSparseMatrixCSC{T}(Vec::SparseVector) where {T} =
492492
CuSparseMatrixCSC{T}(CuVector{Cint}([1]), CuVector{Cint}(Vec.nzind),
493-
CuVector{T}(Vec.nzval), size(Vec))
493+
CuVector{T}(Vec.nzval), (length(Vec), 1))
494494
CuSparseMatrixCSC{T}(Mat::SparseMatrixCSC) where {T} =
495495
CuSparseMatrixCSC{T}(CuVector{Cint}(Mat.colptr), CuVector{Cint}(Mat.rowval),
496496
CuVector{T}(Mat.nzval), size(Mat))

lib/cusparse/batched.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ end
4646

4747
# repeat non-matrix dimensions
4848
function Base.repeat(A::Union{CuSparseArrayCSR, CuSparseMatrixCSR}, r1::Int64, r2::Int64, rs::Int64...)
49-
@assert r1 == 1 && r2 == 1 "Cannot repeat matrix dimensions of CuSparseCSR"
49+
(r1 == 1 && r2 == 1) || throw(ArgumentError("Cannot repeat matrix dimensions of CuSparseCSR"))
5050
CuSparseArrayCSR(repeat(A.rowPtr, 1, rs...),
5151
repeat(A.colVal, 1, rs...),
5252
repeat(A.nzVal, 1, rs...),

lib/cusparse/device.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# on-device sparse array functionality
2-
2+
# should be excluded from coverage counts
3+
# COV_EXCL_START
34
using SparseArrays
45

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

test/libraries/cusparse.jl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using CUDA.CUSPARSE
22

33
using LinearAlgebra
44
using SparseArrays
5-
using SparseArrays: nonzeroinds, getcolptr
5+
using SparseArrays: rowvals, nonzeroinds, getcolptr
66

77
@test CUSPARSE.version() isa VersionNumber
88

@@ -22,6 +22,7 @@ blockdim = 5
2222
@test ndims(d_x) == 1
2323
dense_d_x = CuVector(x)
2424
CUDA.@allowscalar begin
25+
@test sprint(show, d_x) == replace(sprint(show, x), "SparseVector{Float64, Int64}"=>"CUDA.CUSPARSE.CuSparseVector{Float64, Int32}", "sparsevec(["=>"sparsevec(Int32[")
2526
@test Array(d_x[:]) == x[:]
2627
@test d_x[firstindex(d_x)] == x[firstindex(x)]
2728
@test d_x[div(end, 2)] == x[div(end, 2)]
@@ -34,7 +35,13 @@ blockdim = 5
3435
@test nnz(d_x) == nnz(x)
3536
@test Array(nonzeros(d_x)) == nonzeros(x)
3637
@test Array(nonzeroinds(d_x)) == nonzeroinds(x)
38+
@test Array(rowvals(d_x)) == nonzeroinds(x)
3739
@test nnz(d_x) == length(nonzeros(d_x))
40+
d_y = copy(d_x)
41+
CUDA.unsafe_free!(d_y)
42+
x = sprand(m,0.2)
43+
d_x = CuSparseMatrixCSC{Float64}(x)
44+
@test size(d_x) == (m, 1)
3845
x = sprand(m,n,0.2)
3946
d_x = CuSparseMatrixCSC(x)
4047
@test CuSparseMatrixCSC(d_x) === d_x
@@ -74,6 +81,8 @@ blockdim = 5
7481
@test !ishermitian(d_x)
7582
@test_throws ArgumentError size(d_x,0)
7683
@test_throws ArgumentError CUSPARSE.CuSparseVector(x)
84+
d_y = copy(d_x)
85+
CUDA.unsafe_free!(d_y)
7786
y = sprand(k,n,0.2)
7887
d_y = CuSparseMatrixCSC(y)
7988
@test_throws ArgumentError copyto!(d_y,d_x)
@@ -111,7 +120,15 @@ blockdim = 5
111120
@test_throws ArgumentError copyto!(d_y,d_x)
112121
d_y = CuSparseMatrixCSR(d_y)
113122
d_x = CuSparseMatrixCSR(d_x)
123+
d_z = copy(d_x)
124+
CUDA.unsafe_free!(d_z)
114125
@test CuSparseMatrixCSR(d_x) === d_x
126+
@test reshape(d_x, :, :, 1, 1, 1) isa CuSparseArrayCSR
127+
@test_throws ArgumentError("Cannot repeat matrix dimensions of CuSparseCSR") repeat(d_x, 2, 1, 3)
128+
@test repeat(d_x, 1, 1, 3) isa CuSparseArrayCSR
129+
@test reshape(repeat(d_x, 1, 1, 3), size(d_x, 1), size(d_x, 2), 3, 1, 1) isa CuSparseArrayCSR
130+
# to hit the CuSparseArrayCSR path
131+
CUDA.unsafe_free!(repeat(d_x, 1, 1, 3))
115132
@test length(d_x) == m*n
116133
@test_throws ArgumentError copyto!(d_y,d_x)
117134
CUDA.@allowscalar begin
@@ -123,6 +140,8 @@ blockdim = 5
123140
d_y = CuSparseMatrixBSR(d_y, blockdim)
124141
d_x = CuSparseMatrixBSR(d_x, blockdim)
125142
@test CuSparseMatrixBSR(d_x) === d_x
143+
d_z = copy(d_x)
144+
CUDA.unsafe_free!(d_z)
126145
@test_throws ArgumentError copyto!(d_y,d_x)
127146
CUDA.@allowscalar begin
128147
@test d_y[1, 1] y[1, 1]

0 commit comments

Comments
 (0)