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

mapreducedim! is not implemented for AnyROCArray Types #234

Closed
matinraayai opened this issue May 26, 2022 · 18 comments
Closed

mapreducedim! is not implemented for AnyROCArray Types #234

matinraayai opened this issue May 26, 2022 · 18 comments
Labels
arrays bug Something isn't working

Comments

@matinraayai
Copy link
Contributor

Hello,
GPUArray.mapreducedim! should be implemented for AnyROCArray instead of the more specific type of ROCArray. Is there a way for AnyROCArray to be adapted to ROCArray, so that this function is implemented for AnyROCArray?
Thanks

@jpsamaroo
Copy link
Member

As a stop-gap we can just convert to a dense ROCArray and then switch back the type after. @maleadt any recommendations?

@jpsamaroo jpsamaroo added bug Something isn't working arrays labels Jun 1, 2022
@maleadt
Copy link
Member

maleadt commented Jun 1, 2022

Why not implement mapreducedim! for AnyROCArray? Works for CUDA: https://github.com/JuliaGPU/CUDA.jl/blob/0060ea6f29b7dcfc5563dae868c11feb5d26281e/src/mapreduce.jl#L169-L171=, as these types are 'guaranteed' to work in a kernel.

@matinraayai
Copy link
Contributor Author

@maleadt should changing the function prototype to accept AnyROCArray work directly in theory?

@maleadt
Copy link
Member

maleadt commented Jun 3, 2022

I think so, but I'm not very familiar with AMDGPU.jl or it's mapreduce implementation. Try it out and see what breaks?

@matinraayai
Copy link
Contributor Author

@maleadt @jpsamaroo I've tried it before, but the problem is that the AMDGPU implementation queries the ROCm device associated with the ROCArray using its buffer field here:

agent = R.buf.agent

I have to look into it, but I don't think it will be as simple as changing the function prototype.

@maleadt
Copy link
Member

maleadt commented Jun 3, 2022

Then JuliaGPU/Adapt.jl#52 would probably be useful.

@matinraayai
Copy link
Contributor Author

@maleadt it looks good, but do you have an ETA on when it will merge?
Also it seems like the CUDA version also queries the current thread's device, which might not correspond to the actual device the array resides on. I think when merged, we can use this feature to fix bugs in both CUDA.jl and AMDGPU.jl.
https://github.com/JuliaGPU/CUDA.jl/blob/c1ef162c06d78c4b5cf31914fa1acf7db34eb7f5/src/mapreduce.jl#L174

@maleadt
Copy link
Member

maleadt commented Jun 8, 2022

No ETA on that change. You should probably use an agent function instead and define it on a couple of common wrappers, like oneAPI.jl does for its device function: https://github.com/JuliaGPU/oneAPI.jl/blob/9a43fb6fbf0ef20ffba34daef4b7ff44e7ed01c8/src/array.jl#L370-L371=

Also it seems like the CUDA version also queries the current thread's device, which might not correspond to the actual device the array resides on.

It's currently up to the user to make sure to use the correct array on its respective device. I don't think I'll make it automatic, since it's not clear what to do if multiple devices are involved. It's also possible to create arrays whose memory is accessible from other devices.

@matinraayai
Copy link
Contributor Author

@maleadt @jpsamaroo are SubArrays supposed to be a type of AnyROCArray or AnyCuArray? One thing I noticed is that this function doesn't get dispatched with a type of SubArray, backed by a ROCArray parent.

@maleadt
Copy link
Member

maleadt commented Jun 13, 2022

Ah yeah, we disabled those subtypes in Adapt.jl (which the Any* types are based on): https://github.com/JuliaGPU/Adapt.jl/blob/d9f852a61ee42258e543f5ff3b28e1f3abbb48bc/src/wrappers.jl#L86-L90=. That's because Adapt.jl used to be only used by CUDA.jl, where CuArray is used to encode views and reshapes (i..e, without using the array wrappers). Either we make it 'mandatory' for users of the Any* union types to handle SubArray/Reinterpret/Reshape themselves, or we should generalize Adapt.jl

@matinraayai
Copy link
Contributor Author

matinraayai commented Jun 14, 2022

@maleadt do CuSubArrays currently count as AnyCuArrays? Can I do the same thing CUDA.jl is doing to make AMDGPU support this type hierarchy? Ideally I want it in Adapt.jl because it seems useful but for now I need the workaround for our project.

@maleadt
Copy link
Member

maleadt commented Jun 14, 2022

There is no CuSubArray, CuArray itself is used to represent contiguous views (it encodes an offset argument for that), reshapes and reinterpretations. That would probably be useful for AMDGPU.jl too (because it simplifies dispatching to vendor libraries), but would be up to @jpsamaroo to decide.

@jpsamaroo
Copy link
Member

There is no CuSubArray, CuArray itself is used to represent contiguous views (it encodes an offset argument for that), reshapes and reinterpretations. That would probably be useful for AMDGPU.jl too (because it simplifies dispatching to vendor libraries), but would be up to @jpsamaroo to decide.

Yeah that sounds like the reasonable approach to me.

@matinraayai
Copy link
Contributor Author

@jpsamaroo @maleadt not sure I'm following. What exactly is the preferred course of action here?

@christophernhill
Copy link

@jpsamaroo and @maleadt could we do a quick zoom to sync up on this - I think its a quick fix.

@matinraayai
Copy link
Contributor Author

@jpsamaroo I've created a pull request for this:
#241
Let me know when your device detection code for AMDGPU is added to master so that I can modify my PR accordingly.
Thanks,
Matin

@pxl-th
Copy link
Member

pxl-th commented Dec 2, 2023

Mapreduce is now defined for AnyROCArray, feel free to re-open if you still have issues with it.

@pxl-th pxl-th closed this as completed Dec 2, 2023
@matinraayai
Copy link
Contributor Author

@pxl-th yes I think I implemented it myself and made the PR but forgot about this issue :D.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants