Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method to get information on computing device? #44

Open
findmyway opened this issue May 10, 2022 · 3 comments
Open

Method to get information on computing device? #44

findmyway opened this issue May 10, 2022 · 3 comments

Comments

@findmyway
Copy link

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

@oschulz
Copy link
Collaborator

oschulz commented May 10, 2022

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?

@findmyway
Copy link
Author

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.

@oschulz oschulz changed the title Support Base.parent? Support Base.parent(::ElasticArray) to get information on computing device? May 10, 2022
@oschulz
Copy link
Collaborator

oschulz commented May 10, 2022

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 oschulz reopened this May 10, 2022
@oschulz oschulz changed the title Support Base.parent(::ElasticArray) to get information on computing device? Method to get information on computing device? May 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants