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

Separate arguments for map! / broadcasting kernel #535

Open
wsmoses opened this issue May 25, 2024 · 1 comment
Open

Separate arguments for map! / broadcasting kernel #535

wsmoses opened this issue May 25, 2024 · 1 comment

Comments

@wsmoses
Copy link
Contributor

wsmoses commented May 25, 2024

This is part of ongoing work to make Enzyme + CUDA.jl work nicely from a user point of view.

cc @vchuravy

The implementation of map! (https://github.com/JuliaGPU/GPUArrays.jl/blob/ec9fe5b6f7522902e444c95a0c9248a4bc55d602/src/host/broadcast.jl#L120C46-L120C59) creates a broadcasted object which captures all of the arguments to map!. This is then passed to the kernel.

This makes things more difficult to successfully differentiate (as well as apply additional optimization to). Specifically if one of the arguments was non-differentiable (i.e. Const) and another argument was (i.e. Duplicated) then the resulting capturing variable would contain both differntiable and non-differentiable data (and any uses of it may potentially be activity-unstable). See https://enzyme.mit.edu/julia/stable/faq/#Activity-of-temporary-storage for a more thorough description as to how this presents difficulties.

Is it possible to have the implementation be something like:

function map_kernel(ctx, dest, nelem, args...)
   bc = Broadcast.instantiate(Broadcast.broadcasted(f, args...))
   ...
@maleadt
Copy link
Member

maleadt commented May 27, 2024

Is it possible to have the implementation be something like:

function map_kernel(ctx, dest, nelem, args...)
   bc = Broadcast.instantiate(Broadcast.broadcasted(f, args...))
   ...

No, Broadcast is a host-side abstraction that's not supported on-device.

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