Dragon - C++ API
A Computation Graph Virtual Machine Based Deep Learning Framework
sigmoid_op.h
Go to the documentation of this file.
1 
13 #ifndef DRAGON_OPERATORS_ACTIVATION_SIGMOID_OP_HPP
14 #define DRAGON_OPERATORS_ACTIVATION_SIGMOID_OP_HPP
15 
16 #include "core/operator.h"
17 
18 namespace dragon {
19 
20 template <class Context>
21 class SigmoidOp : public Operator<Context> {
22  public:
25 
26  void RunOnDevice() override;
27  template <typename T> void RunImpl();
28 };
29 
30 template <class Context>
31 class SigmoidGradientOp : public Operator<Context> {
32  public:
35 
36  void RunOnDevice() override;
37  template <typename T> void RunImpl();
38 };
39 
40 #ifdef WITH_CUDNN
41 
42 template <class Context>
43 class CuDNNSigmoidOp final : public SigmoidOp<Context> {
44 public:
45  CuDNNSigmoidOp(const OperatorDef& def, Workspace* ws)
46  : SigmoidOp<Context>(def, ws) {
48  CUDNN_CHECK(cudnnCreateActivationDescriptor(&act_desc_));
49  CUDNN_CHECK(cudnnSetActivationDescriptor(
50  act_desc_,
51  CUDNN_ACTIVATION_SIGMOID,
52  CUDNN_PROPAGATE_NAN, 0
53  ));
54  }
56 
59  CUDNN_CHECK(cudnnDestroyActivationDescriptor(act_desc_));
60  }
61 
62  void RunOnDevice() override;
63  template <typename T> void RunImpl();
64 
65  protected:
66  cudnnTensorDescriptor_t input_desc_;
67  cudnnActivationDescriptor_t act_desc_;
68 };
69 
70 template <class Context>
71 class CuDNNSigmoidGradientOp final : public SigmoidGradientOp<Context> {
72  public:
73  CuDNNSigmoidGradientOp(const OperatorDef& def, Workspace* ws)
74  : SigmoidGradientOp<Context>(def, ws) {
75  CUDNN_CHECK(cudnnCreateTensorDescriptor(&input_desc_));
76  CUDNN_CHECK(cudnnCreateActivationDescriptor(&act_desc_));
77  CUDNN_CHECK(cudnnSetActivationDescriptor(
78  act_desc_,
79  CUDNN_ACTIVATION_SIGMOID,
80  CUDNN_PROPAGATE_NAN, 0
81  ));
82  }
84 
86  CUDNN_CHECK(cudnnDestroyTensorDescriptor(input_desc_));
87  CUDNN_CHECK(cudnnDestroyActivationDescriptor(act_desc_));
88  }
89 
90  void RunOnDevice() override;
91  template <typename T> void RunImpl();
92 
93  protected:
94  cudnnTensorDescriptor_t input_desc_;
95  cudnnActivationDescriptor_t act_desc_;
96 };
97 
98 #endif // WITH_CUDNN
99 
100 } // namespace dragon
101 
102 #endif // DRAGON_OPERATORS_ACTIVATION_SIGMOID_OP_HPP
void RunImpl()
Definition: cudnn_sigmoid_op.cc:43
void RunImpl()
Definition: cudnn_sigmoid_op.cc:8
Definition: workspace.h:20
Definition: sigmoid_op.h:43
SIMPLE_CTOR_DTOR(SigmoidGradientOp)
void RunOnDevice() override
Implement the detailed execution.
Definition: sigmoid_op.cc:36
#define CUDNN_CHECK(condition)
Definition: cudnn_device.h:34
cudnnTensorDescriptor_t input_desc_
Definition: sigmoid_op.h:94
void RunOnDevice() override
Implement the detailed execution.
Definition: cudnn_sigmoid_op.cc:35
const OperatorDef & def() const
Return the stored def.
Definition: operator.h:114
Workspace * ws() const
Return the parent workspace.
Definition: operator.h:87
USE_OPERATOR_FUNCTIONS
Definition: sigmoid_op.h:83
CuDNNSigmoidOp(const OperatorDef &def, Workspace *ws)
Definition: sigmoid_op.h:45
void CuDNNCreateTensorDesc(cudnnTensorDescriptor_t *desc)
Definition: cudnn_device.h:67
Definition: operator.h:149
void RunImpl()
Definition: sigmoid_op.cc:23
Definition: sigmoid_op.h:31
CuDNNSigmoidGradientOp(const OperatorDef &def, Workspace *ws)
Definition: sigmoid_op.h:73
cudnnTensorDescriptor_t input_desc_
Definition: sigmoid_op.h:66
Definition: sigmoid_op.h:71
void CuDNNDestroyTensorDesc(cudnnTensorDescriptor_t *desc)
Definition: cudnn_device.h:72
cudnnActivationDescriptor_t act_desc_
Definition: sigmoid_op.h:95
Definition: sigmoid_op.h:21
void RunImpl()
Definition: sigmoid_op.cc:8
~CuDNNSigmoidGradientOp()
Definition: sigmoid_op.h:85
void RunOnDevice() override
Implement the detailed execution.
Definition: cudnn_sigmoid_op.cc:75
USE_OPERATOR_FUNCTIONS
Definition: sigmoid_op.h:55
cudnnActivationDescriptor_t act_desc_
Definition: sigmoid_op.h:67
SIMPLE_CTOR_DTOR(SigmoidOp)
~CuDNNSigmoidOp()
Definition: sigmoid_op.h:57
Definition: common.h:41
void RunOnDevice() override
Implement the detailed execution.
Definition: sigmoid_op.cc:15
USE_OPERATOR_FUNCTIONS
Definition: sigmoid_op.h:34
USE_OPERATOR_FUNCTIONS
Definition: sigmoid_op.h:24