KernelAbstractions.jl
KernelAbstractions.jl copied to clipboard
Add backend lookup function based on input arguments
To eliminate code like https://github.com/SciML/DiffEqGPU.jl/blob/6c1886bf4e62a6293490d6c333a1302045a744d0/src/DiffEqGPU.jl#L369-L370, it would be nice if we could select the backend for the user automatically based on the input arguments provided. I propose an Auto() backend which can do this selection. With the fallback being CPU(), we'd select an appropriate GPU backend if any arguments contain things like CuArray/ROCArray, but would throw an error if both kinds are mixed (unlikely, but who knows, maybe someone has an NVidia+AMD machine).
I have punted on this in the past because:
- Launch configuration is device specific
- Array allocations come from the user
- Arbitrary nested structs
Good points!
- I wonder if we should also try to "solve" this by determining a good launch configuration based on occupancy calculations (which could be requested from the GPU backends by way of specifying a keyword like
:auto. - Some libraries (like DiffEqGPU) don't expose backend selection to the user, so the user must generally rely on dispatch within the library to select the right backend. I would argue that
Auto()makes us more idiomatic for such cases. - Yeah, I wasn't sure what to do about this. I feel like we could address this by first using Adapt to recursively check for matching types (and possibly do the replacement at that point), which could compile out for type-stable arguments.
I know that KA doesn't want to do too much that really should be left up to the user, but I feel like if we want to be a very thin abstraction layer, we should provide a way to "hide" things like backend and workgroupsize for users who want a "seamless" experience.
I think this is fixed with #320 ?