Skip to content

Commit 63a4ec4

Browse files
committed
workaround take 2: manual CSR construction
CSC -> COO -> CSR and collect(CSR) is all broken on 12.0 Therefore, we go the full manual route now, constructing CSR from CSC(Transpose(A)) and compare element wise.
1 parent 73a6d26 commit 63a4ec4

1 file changed

Lines changed: 25 additions & 7 deletions

File tree

lib/cusparse/test/interfaces.jl

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,31 @@ nB = 2
338338

339339
rowmask_d = CuVector(rowmask)
340340
colmask_d = CuVector(colmask)
341-
@testset "type = $SparseMatrixType" for SparseMatrixType in (CuSparseMatrixCSC, CuSparseMatrixCSR)
342-
# CUDA 12.0 has a bug in CSC -> CSR conversion, so we go though COO
343-
dA_coo = CuSparseMatrixCOO(A)
344-
dA = SparseMatrixType(dA_coo)
345-
dS = dA[rowmask_d, colmask_d]
346-
@test dS isa SparseMatrixType
347-
@test S_cpu collect(dS)
341+
342+
# test slicing of CSC format
343+
A_csc = CuSparseMatrixCSC(A)
344+
S_csc = A_csc[rowmask_d, colmask_d]
345+
@test S_csc isa CuSparseMatrixCSC
346+
@test S_cpu collect(S_csc)
347+
348+
# test slicing of CSR format
349+
# Conversion between CSC and CSR is broken in many ways on CUDA 12.0,
350+
# therefore we construct the CSR matrix manually from the transposed CSC.
351+
Aᵀ_csc = CuSparseMatrixCSC(Transpose(A))
352+
A_csr = CuSparseMatrixCSR{eltype(A), Int32}(
353+
copy(Aᵀ_csc.colPtr), # rowPtr is the same as colPtr of the transposed CSC
354+
copy(Aᵀ_csc.rowVal), # colVal is the same as rowVal of the transposed CSC
355+
copy(Aᵀ_csc.nzVal), # nzVal is unchanged by transposition
356+
size(A)
357+
)
358+
# collect calls CSR→CSC conversion again which is broken, so we test on scalar level
359+
CUDA.@allowscalar for i in eachindex(A, A_csr)
360+
@test A[i] A_csr[i]
361+
end
362+
S_csr = A_csr[rowmask_d, colmask_d]
363+
@test S_csr isa CuSparseMatrixCSR
364+
CUDA.@allowscalar for i in eachindex(S_cpu, S_csr)
365+
@test S_cpu[i] S_csr[i]
348366
end
349367
end
350368
end

0 commit comments

Comments
 (0)