Skip to content

Conversation

@Lucky-Lodhi2004
Copy link

I made changes for only one derivative i.e. exp_pushforward. Changes for other derivatives can be made after discussing from maintainers.

Users can redefine builtin derivatives after my changes.

 ~/repos/llvm-project/build/bin/clang++ -std=c++17 -I ./include/ -fplugin=./build/lib/clad.so example.cpp -o example
./example
The code is: 
void differentiable_code_grad(double x, double *_d_x) {
    {
        double _r0 = 0.;
        _r0 += 1 * clad::custom_derivatives::std::exp_pushforward(x, 1.).pushforward;
        *_d_x += _r0;
    }
}

Changes

Added control macro for the definition of std::exp_pushforward.
here

// 2.1 exp, expf, expl
// Allow disabling built-in derivative if user-defined derivative provided.
#ifndef CLAD_NO_BUILTIN_EXP
template <typename T, typename dT>
CUDA_HOST_DEVICE ValueAndPushforward<T, dT> exp_pushforward(T x, dT d_x) {
  return {::std::exp(x), ::std::exp(x) * d_x};
}
#endif

and here:

#ifndef CLAD_NO_BUILTIN_EXP
using std::exp_pushforward;  //disable built-in exp derivative
#endif

Similar macro for all the functions can be used (if maintainers approve).

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.

1 participant