ExponentialUtilities.jl icon indicating copy to clipboard operation
ExponentialUtilities.jl copied to clipboard

GPU-Friendly `inplace_add!`

Open SBuercklin opened this issue 2 years ago • 3 comments

inplace_add! as currently implemented uses scalar indexing to update the diagonal of an array. Since CuArrays disallow scalar indexing outside the REPL, this method breaks in practice.

The current implementation, reproduced from here

@inline function inplace_add!(A,B::UniformScaling) # Called from generated code
    s = B.λ
    @inbounds for i in diagind(A)
        A[i] += s
    end
end

SBuercklin avatar Jun 02 '22 14:06 SBuercklin

Thanks for the report. Indeed, one thing we really need to get up and running on this repo is GPU tests.

ChrisRackauckas avatar Jun 02 '22 14:06 ChrisRackauckas

I think this might be the only ExponentialUtilities.jl change needed.

https://github.com/JuliaGPU/CUDA.jl/pull/1532 solves the ldiv! with LU decomposition

We also need LinearAlgebra.opnorm1(::CuMatrix) which is straightforward to get something that works, but not obvious to me how to get something that's low/non-allocating

SBuercklin avatar Jun 02 '22 15:06 SBuercklin

For diagonal, we do this in diffeq: https://github.com/SciML/OrdinaryDiffEq.jl/blob/v6.14.0/src/derivative_utils.jl#L447-L457

@YingboMa might have ideas for opnorm1.

ChrisRackauckas avatar Jun 02 '22 15:06 ChrisRackauckas