Skip to content

Commit 4a2526c

Browse files
committed
add allowed_setindex method for CUDA
1 parent 38765e5 commit 4a2526c

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

ext/QuantumToolboxCUDAExt.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ module QuantumToolboxCUDAExt
22

33
using QuantumToolbox
44
using QuantumToolbox: makeVal, getVal
5-
import QuantumToolbox: _sparse_similar, _convert_eltype_wordsize
6-
import CUDA: cu, CuArray, allowscalar, @allowscalar, has_cuda, AbstractCuArray
5+
import QuantumToolbox: _sparse_similar, _convert_eltype_wordsize, allowed_setindex!
6+
import CUDA: cu, CuArray, allowscalar, @allowscalar, has_cuda
77
import CUDA.CUSPARSE: CuSparseVector, CuSparseMatrixCSC, CuSparseMatrixCSR, AbstractCuSparseArray
88
import SparseArrays: SparseVector, SparseMatrixCSC, sparse, spzeros
99
import CUDA.Adapt: adapt
@@ -104,11 +104,11 @@ QuantumToolbox.to_dense(::Type{T}, A::AbstractCuSparseArray) where {T<:Number} =
104104

105105
QuantumToolbox._sparse_similar(A::CuSparseMatrixCSC, args...) = sparse(args..., fmt = :csc)
106106
QuantumToolbox._sparse_similar(A::CuSparseMatrixCSR, args...) = sparse(args..., fmt = :csr)
107-
_sparse_similar(A::CuSparseMatrixCSC, I::AbstractVector, J::AbstractVector, V::AbstractVector, m::Int, n::Int) =
107+
QuantumToolbox._sparse_similar(A::CuSparseMatrixCSC, I::AbstractVector, J::AbstractVector, V::AbstractVector, m::Int, n::Int) =
108108
CuSparseMatrixCSC(sparse(I, J, V, m, n))
109-
_sparse_similar(A::CuSparseMatrixCSC, m::Int, n::Int) = CuSparseMatrixCSC(spzeros(eltype(A), m, n))
110-
_sparse_similar(A::CuSparseMatrixCSR, I::AbstractVector, J::AbstractVector, V::AbstractVector, m::Int, n::Int) =
109+
QuantumToolbox._sparse_similar(A::CuSparseMatrixCSC, m::Int, n::Int) = CuSparseMatrixCSC(spzeros(eltype(A), m, n))
110+
QuantumToolbox._sparse_similar(A::CuSparseMatrixCSR, I::AbstractVector, J::AbstractVector, V::AbstractVector, m::Int, n::Int) =
111111
CuSparseMatrixCSR(sparse(I, J, V, m, n))
112-
_sparse_similar(A::CuSparseMatrixCSR, m::Int, n::Int) = CuSparseMatrixCSR(spzeros(eltype(A), m, n))
113-
allowed_setindex!(A::AbstractCuSparseArray, v, I...) = @allowscalar A[I...] = v
112+
QuantumToolbox._sparse_similar(A::CuSparseMatrixCSR, m::Int, n::Int) = CuSparseMatrixCSR(spzeros(eltype(A), m, n))
113+
QuantumToolbox.allowed_setindex!(A::AbstractCuSparseArray, v, I...) = @allowscalar A[I...] = v
114114
end

src/steadystate.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ function _steadystate_fourier(
397397
v0 = similar(L_0_mat, n_fourier * N)
398398
fill!(v0, zero(T))
399399
target_idx = n_max*N + 1
400-
allowed_setindex!(v0, weight, target_idx)
400+
QuantumToolbox.allowed_setindex!(v0, weight, target_idx)
401401

402402
(haskey(kwargs, :Pl) || haskey(kwargs, :Pr)) && error("The use of preconditioners must be defined in the solver.")
403403
if !isnothing(solver.Pl)

src/utilities.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,5 @@ _convert_eltype_wordsize(::Type{T}, ::Val{64}) where {T<:AbstractFloat} = Float6
200200
_convert_eltype_wordsize(::Type{T}, ::Val{32}) where {T<:AbstractFloat} = Float32
201201
_convert_eltype_wordsize(::Type{Complex{T}}, ::Val{64}) where {T<:Union{Int,AbstractFloat}} = ComplexF64
202202
_convert_eltype_wordsize(::Type{Complex{T}}, ::Val{32}) where {T<:Union{Int,AbstractFloat}} = ComplexF32
203+
204+
function allowed_setindex! end

0 commit comments

Comments
 (0)