Skip to content

Commit c7ac2d4

Browse files
authored
More tests/better coverage for CUSPARSE (#2663)
1 parent 3d42ca2 commit c7ac2d4

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/cusparse/broadcast.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ _getindex(arg, I, ptr) = Broadcast._broadcast_getindex(arg, I)
300300
## sparse broadcast implementation
301301

302302
# TODO: unify CSC/CSR kernels
303-
303+
## COV_EXCL_START
304304
# kernel to count the number of non-zeros in a row, to determine the row offsets
305305
function compute_offsets_kernel(::Type{<:CuSparseMatrixCSR}, offsets::AbstractVector{Ti},
306306
args...) where Ti
@@ -458,6 +458,7 @@ function sparse_to_dense_broadcast_kernel(::Type{<:CuSparseMatrixCSC}, f,
458458

459459
return
460460
end
461+
## COV_EXCL_STOP
461462

462463
function Broadcast.copy(bc::Broadcasted{<:Union{CuSparseVecStyle,CuSparseMatStyle}})
463464
# find the sparse inputs

test/libraries/cusparse.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ blockdim = 5
3535
@test nnz(d_x) == length(nonzeros(d_x))
3636
x = sprand(m,n,0.2)
3737
d_x = CuSparseMatrixCSC(x)
38+
@test CuSparseMatrixCSC(d_x) === d_x
3839
@test length(d_x) == m*n
3940
@test size(d_x) == (m,n)
4041
@test size(d_x,1) == m
@@ -76,15 +77,22 @@ blockdim = 5
7677
@test_throws ArgumentError copyto!(d_y,d_x)
7778
d_y = CuSparseMatrixCSR(d_y)
7879
d_x = CuSparseMatrixCSR(d_x)
80+
@test CuSparseMatrixCSR(d_x) === d_x
81+
@test length(d_x) == m*n
7982
@test_throws ArgumentError copyto!(d_y,d_x)
8083
CUDA.@allowscalar begin
8184
for i in 1:size(y, 1)
8285
@test d_y[i, :] y[i, :]
8386
end
87+
@test d_y[1, 1] y[1, 1]
8488
end
8589
d_y = CuSparseMatrixBSR(d_y, blockdim)
8690
d_x = CuSparseMatrixBSR(d_x, blockdim)
91+
@test CuSparseMatrixBSR(d_x) === d_x
8792
@test_throws ArgumentError copyto!(d_y,d_x)
93+
CUDA.@allowscalar begin
94+
@test d_y[1, 1] y[1, 1]
95+
end
8896
x = sprand(m,0.2)
8997
d_x = CuSparseVector(x)
9098
@test size(d_x, 1) == m
@@ -140,6 +148,7 @@ end
140148
@test collect(d_x) == collect(x)
141149
@test similar(d_x) isa CuSparseMatrixCSC{elty}
142150
@test similar(d_x, Float32) isa CuSparseMatrixCSC{Float32}
151+
@test similar(d_x, Float32, n, m) isa CuSparseMatrixCSC{Float32}
143152
end
144153

145154
@testset "CSR" begin
@@ -148,6 +157,7 @@ end
148157
@test collect(d_x) == collect(x)
149158
@test similar(d_x) isa CuSparseMatrixCSR{elty}
150159
@test similar(d_x, Float32) isa CuSparseMatrixCSR{Float32}
160+
@test similar(d_x, Float32, n, m) isa CuSparseMatrixCSR{Float32}
151161
end
152162

153163
@testset "BSR" begin
@@ -158,12 +168,13 @@ end
158168
@test similar(d_x, Float32) isa CuSparseMatrixBSR{Float32}
159169
end
160170

161-
@testset "BSR" begin
171+
@testset "COO" begin
162172
x = sprand(elty,m,n, 0.2)
163173
d_x = CuSparseMatrixCOO(x)
164174
@test collect(d_x) == collect(x)
165175
@test similar(d_x) isa CuSparseMatrixCOO{elty}
166176
@test similar(d_x, Float32) isa CuSparseMatrixCOO{Float32}
177+
@test similar(d_x, Float32, n, m) isa CuSparseMatrixCOO{Float32}
167178
end
168179
end
169180

0 commit comments

Comments
 (0)