Skip to content

Commit

Permalink
Add builtin sin, cos, sqrt pushforwards
Browse files Browse the repository at this point in the history
  • Loading branch information
vgvassilev committed Aug 21, 2024
1 parent 7621c9c commit e6cd81c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions include/clad/Differentiator/BuiltinDerivatives.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,36 @@ __builtin_expf_pushforward(float x, float d_x) {
return {__builtin_expf(x), __builtin_expf(x) * d_x};
}

CUDA_HOST_DEVICE inline ValueAndPushforward<float, float>
__builtin_sinf_pushforward(float x, float d_x) {
return {__builtin_sinf(x), __builtin_cosf(x) * d_x};
}

CUDA_HOST_DEVICE inline ValueAndPushforward<double, double>
__builtin_sin_pushforward(double x, double d_x) {
return {__builtin_sin(x), __builtin_cos(x) * d_x};
}

CUDA_HOST_DEVICE inline ValueAndPushforward<float, float>
__builtin_cosf_pushforward(float x, float d_x) {
return {__builtin_cosf(x), (-1) * __builtin_sinf(x) * d_x};
}

CUDA_HOST_DEVICE inline ValueAndPushforward<double, double>
__builtin_cos_pushforward(double x, double d_x) {
return {__builtin_cos(x), (-1) * __builtin_sin(x) * d_x};
}

CUDA_HOST_DEVICE inline ValueAndPushforward<float, float>
__builtin_sqrtf_pushforward(float x, float d_x) {
return {builtin_sqrtf(x), (((T)1) / (((T)2) * builtin_sqrtf(x))) * d_x};
}

CUDA_HOST_DEVICE inline ValueAndPushforward<double, double>
__builtin_sqrt_pushforward(double x, double d_x) {
return {builtin_sqrt(x), (((T)1) / (((T)2) * builtin_sqrt(x))) * d_x};
}

CUDA_HOST_DEVICE inline void __builtin_expf_pullback(float x, float* d_x) {
*d_x = __builtin_expf(x);
}
Expand Down

0 comments on commit e6cd81c

Please sign in to comment.