Dragon - C++ API
A Computation Graph Virtual Machine Based Deep Learning Framework
elu_op.h
Go to the documentation of this file.
1 
13 #ifndef DRAGON_OPERATORS_ACTIVATION_ELU_OP_H_
14 #define DRAGON_OPERATORS_ACTIVATION_ELU_OP_H_
15 
16 #include "core/operator.h"
17 
18 namespace dragon {
19 
20 template <class Context>
21 class EluOp : public Operator<Context> {
22  public:
23  EluOp(const OperatorDef& def, Workspace* ws)
24  : Operator<Context>(def, ws),
25  alpha_(OpArg<float>("alpha", 1.f)) {}
27 
28  void RunOnDevice() override;
29  template <typename T> void RunImpl();
30 
31  protected:
32  float alpha_;
33 };
34 
35 template <class Context>
36 class EluGradientOp : public Operator<Context> {
37  public:
38  EluGradientOp(const OperatorDef& def, Workspace* ws)
39  : Operator<Context>(def, ws),
40  alpha_(OpArg<float>("alpha", 1.f)) {}
42 
43  void RunOnDevice() override;
44  template <typename T> void RunImpl();
45 
46  protected:
47  float alpha_;
48 };
49 
50 #ifdef WITH_CUDNN
51 
52 #if CUDNN_VERSION_MIN(6, 0, 0)
53 
54 template <class Context>
55 class CuDNNEluOp final : public EluOp<Context> {
56 public:
57  CuDNNEluOp(const OperatorDef& def, Workspace* ws)
58  : EluOp<Context>(def, ws) {
59  CuDNNCreateTensorDesc(&input_desc_);
60  CUDNN_CHECK(cudnnCreateActivationDescriptor(&act_desc_));
61  CUDNN_CHECK(cudnnSetActivationDescriptor(
62  act_desc_,
63  CUDNN_ACTIVATION_ELU,
64  CUDNN_PROPAGATE_NAN,
65  this->alpha_
66  ));
67  }
69 
70  ~CuDNNEluOp() {
71  CuDNNDestroyTensorDesc(&input_desc_);
72  CUDNN_CHECK(cudnnDestroyActivationDescriptor(act_desc_));
73  }
74 
75  void RunOnDevice() override;
76  template <typename T> void RunImpl();
77 
78  protected:
79  cudnnTensorDescriptor_t input_desc_;
80  cudnnActivationDescriptor_t act_desc_;
81 };
82 
83 template <class Context>
84 class CuDNNEluGradientOp final : public EluGradientOp<Context> {
85  public:
86  CuDNNEluGradientOp(const OperatorDef& def, Workspace* ws)
87  : EluGradientOp<Context>(def, ws) {
88  CuDNNCreateTensorDesc(&input_desc_);
89  CUDNN_CHECK(cudnnCreateActivationDescriptor(&act_desc_));
90  CUDNN_CHECK(cudnnSetActivationDescriptor(
91  act_desc_,
92  CUDNN_ACTIVATION_ELU,
93  CUDNN_PROPAGATE_NAN,
94  this->alpha_
95  ));
96  }
98 
99  ~CuDNNEluGradientOp() {
100  CuDNNDestroyTensorDesc(&input_desc_);
101  CUDNN_CHECK(cudnnDestroyActivationDescriptor(act_desc_));
102  }
103 
104  void RunOnDevice() override;
105  template <typename T> void RunImpl();
106 
107  protected:
108  cudnnTensorDescriptor_t input_desc_;
109  cudnnActivationDescriptor_t act_desc_;
110 };
111 
112 #endif
113 
114 #endif // WITH_CUDNN
115 
116 } // namespace dragon
117 
118 #endif // DRAGON_OPERATORS_ACTIVATION_ELU_OP_H_
USE_OPERATOR_FUNCTIONS
Definition: elu_op.h:41
EluGradientOp(const OperatorDef &def, Workspace *ws)
Definition: elu_op.h:38
Definition: workspace.h:20
#define CUDNN_CHECK(condition)
Definition: cudnn_device.h:34
void RunOnDevice() override
Implement the detailed execution.
Definition: elu_op.cc:41
const OperatorDef & def() const
Return the stored def.
Definition: operator.h:114
void RunOnDevice() override
Implement the detailed execution.
Definition: elu_op.cc:20
Workspace * ws() const
Return the parent workspace.
Definition: operator.h:87
Definition: elu_op.h:21
Definition: elu_op.h:36
void CuDNNCreateTensorDesc(cudnnTensorDescriptor_t *desc)
Definition: cudnn_device.h:67
Definition: operator.h:149
#define OpArg
Definition: operator.h:235
#define USE_OPERATOR_FUNCTIONS
Definition: operator.h:261
USE_OPERATOR_FUNCTIONS
Definition: elu_op.h:26
void CuDNNDestroyTensorDesc(cudnnTensorDescriptor_t *desc)
Definition: cudnn_device.h:72
void RunImpl()
Definition: elu_op.cc:8
float alpha_
Definition: elu_op.h:32
float alpha_
Definition: elu_op.h:47
EluOp(const OperatorDef &def, Workspace *ws)
Definition: elu_op.h:23
void RunImpl()
Definition: elu_op.cc:28
Definition: common.h:41