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

support ChainRulesCore inplaceability #2091

Merged
merged 3 commits into from
Sep 28, 2023
Merged

Conversation

piever
Copy link
Contributor

@piever piever commented Sep 25, 2023

ChainRulesCore has an opt-in trait is_inplaceable_destination to denote that an array supports in-place broadcasting (in particular a .+= b). This PR allows the ChainRules machinery to add derivatives in-place to CuArrays and avoid unnecessary allocations.

I only added the method for CuArrays because AFAIU wrapper types are handled by ChainRulesCore directly. Also, I didn't add the method for CUDA sparse arrays as it seemed to me that they do not support in-place broadcasting.

This requires one extra dependency (ChainRulesCore), but it is very lightweight and it was already a transitive dependency via AbstractFFTs.

@maleadt
Copy link
Member

maleadt commented Sep 26, 2023

Thanks! Shouldn't this be part of a package extension though?

@piever
Copy link
Contributor Author

piever commented Sep 26, 2023

Shouldn't this be part of a package extension though?

Ah yes, that makes sense. I've changed this to be loaded via extensions (I simply adapted the code from SpecialFunctions to be consistent).

@@ -67,4 +70,5 @@ UnsafeAtomicsLLVM = "0.1"
julia = "1.8"

[extras]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is necessary, but I saw it was done for SpecialFunctions, so I added it here for consistency.

@maleadt maleadt merged commit d38b507 into JuliaGPU:master Sep 28, 2023
1 check passed
@piever piever deleted the pv/inplaceable branch October 2, 2023 08:22
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

Successfully merging this pull request may close these issues.

None yet

2 participants