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

Fold into CuArrays #1

Open
MikeInnes opened this issue Sep 4, 2018 · 4 comments
Open

Fold into CuArrays #1

MikeInnes opened this issue Sep 4, 2018 · 4 comments

Comments

@MikeInnes
Copy link

CuArrays provides some machinery so that base functions (like sin or lgamma) can be replaced with their cudanative equivalents. With that this package could be folded into CuArrays and always "just work" for users, rather than having to load a new package for it. If you're up for it, happy to provide any clarification.

@xukai92
Copy link
Owner

xukai92 commented Sep 4, 2018

Hi @MikeInnes. Yes I'm up for it. Can you give me some hints on how to approach

@MikeInnes
Copy link
Author

MikeInnes commented Sep 5, 2018

The easiest thing is probably to use the @cufunc macro like so. This is really just defining a method for the cufunc function, like here where we define methods like cufunc(::typeof(Base.sin)) = CUDAnative.sin (the macro also does a replacement inside the definition you give it).

cufunc is called whenever broadcasting is used, so that will work automatically once you add that.

@xukai92
Copy link
Owner

xukai92 commented Feb 25, 2019

@MikeInnes I'm about to fold this package into CuArrays but still have a few questions that needs your help:

  1. As this also contains diff rules for digamma (which is missed in DiffRules.jl), I also need to submit a PR to DiffRules.jl. is it correct?
  2. Where should I put the codes like https://github.com/xukai92/CuGammaFuns.jl/blob/master/src/CuGammaFuns.jl#L13? Do I put it in CuArrays and do cufunc(::typeof(SpecialFunctions.lgamma)) = CuArrays.lgamma?
  3. Following 2, those codes are adapted from SpecialFunctions.jl, with only a few function calls inside pointed to CUDAnative's namespace, is there a way to not repeat codes there?

@MikeInnes
Copy link
Author

  1. A PR to DiffRules would probably be ideal. Short term you can also just define the rules in CuArrays (you'll need a rule for the GPU version as well anyway).
  2. Yup, that sounds right
  3. Unfortunately not, at the moment. The idea is to eventually have something Cassette-like to fix this stuff but for now we have to repeat everything (@cufunc automates this to some extent).

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