forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSigmoid.cu
More file actions
23 lines (20 loc) · 751 Bytes
/
Sigmoid.cu
File metadata and controls
23 lines (20 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <THCUNN/THCUNN.h>
#include <TH/THHalf.h>
#include <THC/THCNumerics.cuh>
#include <THC/THCApply.cuh>
template <typename T>
struct sigmoid_updateGradInput_functor {
__device__ __forceinline__ void operator()(T* gradInput, const T *output, const T *gradOutput) const {
*gradInput = *gradOutput * (1.f - *output) * (*output);
}
};
template <>
struct sigmoid_updateGradInput_functor<half> {
__device__ __forceinline__ void operator()(half* gradInput, const half *output, const half *gradOutput) const {
const float out = __half2float(*output);
const float go = __half2float(*gradOutput);
*gradInput = __float2half(go * (1.f - out) * out);
}
};
#include <THCUNN/generic/Sigmoid.cu>
#include <THC/THCGenerateFloatTypes.h>