-
-
Notifications
You must be signed in to change notification settings - Fork 122
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
Adding EnzymeRules #503
Comments
Not sure. It would be enlightening to have some other examples of rules for CUDA libraries before doing this.
I would want to hold off on this until it's known how the GPU stack plans on using Enzyme. If all those packages add EnzymeCore as a weak dep, then I'd rather not add it as a hard dep here. |
EnzymeCore is quite new, so there are few rules out there to point to as examples yet. But it's designed to be used similarly to ChainRulesCore. Where are ChainRulesCore rules defined for these CUDA libraries? Might make sense to define the EnzymeCore rules in the same place. One difference is that many ChainRules rules are intended to cover up language features not supported or poorly supported by Diffractor/Zygote, especially control flow and mutation, so the rules are often implemented on higher level functions with generic types, whereas Enzyme supports more language features so can be implemented at a lower level with more concrete types.
It can always be added as weak dep first and made a hard dep later to support older Julia versions. |
Perhaps surprisingly, nowhere. They're just defined against stdlib APIs and tested with GPU arrays. However, this doesn't really work with Enzyme because e.g. CPU BLAS and cuBLAS don't follow the same API. Thus I'm interested in how more straightforward libraries like cuBLAS and cuFFT will get rules: will they be defined at the CUDA wrapper level, or against the LinearAlgebra and AbstractFFT APIs respectively?
Yes, that's always the fallback. If a dependency of NNlib picks up EnzymeCore as a hard dep however (e.g. JuliaGPU/KernelAbstractions.jl#382), we might as well make it one too. |
Oh, I meant the kernels. But I think I answered my own question. The Lines 341 to 383 in acf87f5
Good question. It makes sense to define them in terms of the high-level API functions only if the following conditions are fulfilled:
Naively, I would guess defining rules at the level of LinearAlgebra, AbstractFFT, and NNLib would be sufficient, but specialized on |
I'm not sure. I would've agreed with your criteria and ideas on where to define rules, but then I see rules being defined for functions like A more concrete concern is where to place these rules with our current package extension structure. If EnzymeCore becomes a direct dep, then they can live in the existing GPU backend extensions. If it becomes a weak dep, we'd need to add another extension for each GPU backend just for the rules. Happy to accept PRs using either approach for now, but my inclination is to hold off on tagging until the dust settles there. |
Another data point: there's an open PR to add EnzymeCore as an extension to CUDA.jl with some basic forward-mode rules: JuliaGPU/CUDA.jl#1869 |
Yes, that's the main one I've been following to see what should be done on the NNlib side. |
See #536 for a conv example, adding these to the other layers would be incredibly valuable as well! |
Given that the conv, scatter, gather, and other rules are presently in place, I propose that this issue be closed and new issues for any unsupported functions be added? |
Motivation and description
On Slack, @ChrisRackauckas said that the functions defined in https://github.com/FluxML/NNlibCUDA.jl/tree/master/src/cudnn will need
EnzymeCore.EnzymeRules
overloads to work with Enzyme, since they use precompiled shipped binaries.Or would it be better to provide overloads for functions defined in https://github.com/JuliaGPU/CUDA.jl/tree/master/lib/cudnn?
Possible Implementation
This could be done on Julia v1.9 using an extension module and on pre-v1.9 the module could be loaded directly as described in https://pkgdocs.julialang.org/dev/creating-packages/#Transition-from-normal-dependency-to-extension, since EnzymeCore's sole dependency is Adapt, which is also a dependency here.
The text was updated successfully, but these errors were encountered: