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
12 changes: 12 additions & 0 deletions ext/ArrayInterfaceCUDAExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module ArrayInterfaceCUDAExt
using ArrayInterface
using CUDA
using CUDA.CUSOLVER
using CUDA.CUSPARSE
using LinearAlgebra

function ArrayInterface.lu_instance(A::CuMatrix{T}) where {T}
Expand All @@ -13,6 +14,17 @@ end

ArrayInterface.device(::Type{<:CUDA.CuArray}) = ArrayInterface.GPU()

# CUSPARSE arrays implement no `setindex!` at all, so the `true` default is wrong
# for them and callers guarding mutation with `can_setindex` hit a CanonicalIndexError.
const CuSparseArray = Union{
CUSPARSE.CuSparseVector,
CUSPARSE.CuSparseMatrixCSC,
CUSPARSE.CuSparseMatrixCSR,
CUSPARSE.CuSparseMatrixBSR,
CUSPARSE.CuSparseMatrixCOO,
}
ArrayInterface.can_setindex(::Type{<:CuSparseArray}) = false

function ArrayInterface.promote_eltype(
::Type{<:CUDA.CuArray{T, N, M}}, ::Type{T2}
) where {T, N, M, T2}
Expand Down
8 changes: 8 additions & 0 deletions test/gpu/cuda.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ lu_sparse = lu!(lu_inst_sparse, A_sparse)
#test that the resulting lu works
b = CuVector([1f0, 1f0])
@test CUDA.@allowscalar lu_sparse \ b == [1, 1]

# CUSPARSE arrays have no `setindex!`, so `can_setindex` must not claim they do
@test ArrayInterface.can_setindex(A_dense)
@test !ArrayInterface.can_setindex(A_sparse)
@test !ArrayInterface.can_setindex(CuSparseMatrixCSC(sparse(A_cpu)))
@test !ArrayInterface.can_setindex(CuSparseMatrixCOO(sparse(A_cpu)))
@test !ArrayInterface.can_setindex(CuSparseVector(sparsevec([1], [1.0f0], 2)))
@test_throws CanonicalIndexError A_sparse[1, 2] = 1.0f0
Loading