- 
                Notifications
    You must be signed in to change notification settings 
- Fork 122
Open
Description
it sure would be nice if Unitful played better with CuArrays.  for example, currently, one cannot ustrip a CuArray and then assign to it:
julia> using Unitful, CUDA
julia> c = CuArray(zeros(3) * 1u"s")
3-element CuArray{Quantity{Float64, 𝐓, Unitful.FreeUnits{(s,), 𝐓, nothing}}, 1, CUDA.Mem.DeviceBuffer}:
 0.0 s
 0.0 s
 0.0 s
julia> ustrip(c)[1]=1   # innocuous warning about scalar indexing removed for succinctness
1
julia> c
3-element CuArray{Quantity{Float64, 𝐓, Unitful.FreeUnits{(s,), 𝐓, nothing}}, 1, CUDA.Mem.DeviceBuffer}:
 0.0 s
 0.0 s
 0.0 s
however, if i simply add a new method identical to this one but with CuArray, then it works fine:
julia> import Unitful: ustrip
julia> @inline ustrip(A::CuArray{Q}) where {Q <: Quantity} = reinterpret(Unitful.numtype(Q), A)
ustrip (generic function with 16 methods)
julia> ustrip(c)[1]=1
1
julia> c
3-element CuArray{Quantity{Float64, 𝐓, Unitful.FreeUnits{(s,), 𝐓, nothing}}, 1, CUDA.Mem.DeviceBuffer}:
 1.0 s
 0.0 s
 0.0 s
to be all inclusive, i think the right way to go here is just use AbstractArray.  then it'll work too for MtlArray, ROCArray, etc.
Originally posted by @bjarthur in #630 (comment)
Metadata
Metadata
Assignees
Labels
No labels