blob: 8c0e6f881a3491b12bf0f871881ae421f100981e (
plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#include "THCUNN.h"
#include "THCHalf.h"
#include "THCHalfAutoNumerics.cuh"
template <typename T>
struct LeakyReLUUpdateOutput
{
const T negval_;
LeakyReLUUpdateOutput(T negval)
: negval_(negval)
{}
__device__ __forceinline__ void operator()(T *out, T *in)
{
T x = *in;
*out = (x > 0) ? x : x * negval_;
}
};
// in-place variant
template <typename T>
struct LeakyReLUUpdateOutputIP
{
const T negval_;
LeakyReLUUpdateOutputIP(T negval)
: negval_(negval)
{}
__device__ __forceinline__ void operator()(T *x)
{
*x = (*x > 0) ? *x : negval_ * (*x);
}
};
template <typename T>
struct LeakyReLUUpdateGradInput
{
const T negval_;
LeakyReLUUpdateGradInput(T negval)
: negval_(negval)
{}
__device__ __forceinline__ void operator()(
T* gradInput,
T* input,
T* gradOutput) const
{
*gradInput = (*input > 0) ? *gradOutput : (*gradOutput) * negval_;
}
};
template <typename T>
struct LeakyReLUUpdateGradInputIP
{
const T negval_;
LeakyReLUUpdateGradInputIP(T negval)
: negval_(negval)
{}
__device__ __forceinline__ void operator()(
T* gradOutput,
T* input) const
{
*gradOutput = (*input > 0) ? *gradOutput : (*gradOutput) * negval_;
}
};
#include "generic/LeakyReLU.cu"
#include "THCGenerateFloatTypes.h"
|