forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sqrt.cu
33 lines (27 loc) · 812 Bytes
/
Sqrt.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <THCUNN/THCUNN.h>
#include <TH/THHalf.h>
#include <THCUNN/THCHalfAutoNumerics.cuh>
#include <THC/THCApply.cuh>
template <typename T>
struct sqrtupdateOutput_functor
{
const T bias;
sqrtupdateOutput_functor(T bias_)
: bias(bias_)
{}
__device__ void operator()(T *output, const T *input) const
{
*output = sqrt(*input + bias);
}
};
template <typename T>
struct sqrtupdateGradInput_functor
{
sqrtupdateGradInput_functor() {}
__device__ void operator()(T *gradInput, const T *output, const T *gradOutput) const
{
*gradInput = (THCNumerics<T>::eq(*output,ScalarConvert<float, T>::to(0.0f))) ? ScalarConvert<float, T>::to(0.0f) : ((ScalarConvert<float, T>::to(0.5f) * *gradOutput) / *output);
}
};
#include <THCUNN/generic/Sqrt.cu>
#include <THC/THCGenerateFloatTypes.h>