Adding a function to get device from array (type)?
Created by: oschulz
It would be nice to have a function that returns a KernelAbstractions.jl device given an array (type), e.g.
get_device(A::AbstractArray) = get_device(typeof(A))
get_device(::Type{<:AbstractArray}) = CPUDevice()
get_device(T::Type{<:AbstractGPUArray}) = throw(ArgumentError("NoKernelAbstractions.Device type defined for arrays of type $(T.name.name)"))
get_device(::Type{<:CuArray}) = CUDADevice()
get_device(::Type{<:AbstractCuSparseArray}) = CUDADevice()
get_device(::Type{<:ROCArray}) = ROCDevice()
so that users can write device-agnostic code like
function foo(A::AbstractArray)
A = ones(1024, 1024)
device = KernelAbstractions.get_device(A)
kernel = mul2(device, 16)
event = kernel(A, ndrange=size(A))
...
Would that fit into the KernelAbstractions concept?