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

Method to get information on computing device?

Open findmyway opened this issue 3 years ago • 3 comments

The result of Base.parent fallbacks to the default implementation of AbstractArray. It would be better to add return .data instead, I guess?

findmyway avatar May 10 '22 04:05 findmyway

Hi @findmyway we had a specialization of parent in the past, but we weren't happy with it in the end (#24). The recommended way to get EA.data is now vec(EA).

Do you have a use case that needs to use parent in a generic fashion instead of vec?

oschulz avatar May 10 '22 06:05 oschulz

I see. Thanks for the link.

Yes, I'd like to detect whether the underlying data structure is on CPU or GPU. I thought parent is the straightforward API for it. Though vec works here, it's not general enough. This means I need to explicitly add a dependency to ElasticArrays and add a specilized dispatch for it.

Closing this due to duplication.

findmyway avatar May 10 '22 06:05 findmyway

Yes, I'd like to detect whether the underlying data structure is on CPU or GPU.

Oh, that's a good point! I contributed a function get_device to KernelAbstractions somewhat recently to do that, and it does indeed use parent as it's generic fallback mechanism. It was the best way @vchuravy and me found to handle custom array types in a generic fashion, but it's reach is limited.

It would be nice if we had a lightweight API somewhere to get the primary backing storage type of objects: KernelAbstractions is too heavy for ElasticArrays to depend on and I don't think KernelAbstractions will accept ElasticArrays as a dependency. So there's no clean way to specialize get_device for ElasticArray.

And @colinxs discovered that defining parent(A::ElasticArray) = A.data causes trouble with linear algebra operations.

@vchuravy do you think we could establish a lightweight package with an API to get the primary backing array type of objects, or get it into some existing lightweight package, so that KernelAbstractions.get_device doesn't have to use parent, which is a bit clunky anyway? Maybe such a function could to into Adapt.jl? Or maybe we could establish a very lightweight package AbstractComputingDevices that only defines CPU and get_device?

oschulz avatar May 10 '22 07:05 oschulz