Dragon - C++ API
A Computation Graph Virtual Machine Based Deep Learning Framework
conv_transpose_op.h
Go to the documentation of this file.
1 
13 #ifndef DRAGON_OPERATORS_VISION_CONV_TRANSPOSE_OP_H_
14 #define DRAGON_OPERATORS_VISION_CONV_TRANSPOSE_OP_H_
15 
17 
18 namespace dragon {
19 
20 template <class Context>
22  : public ConvOpBase<Context> {
23  public:
25  const OperatorDef& def,
26  Workspace* ws)
27  : ConvOpBase<Context>(def, ws) { Setup(2); }
30 
31  bool Transposed() override { return true; }
32  bool HasBias() override { return XSize() > 2; }
33 
34  void RunOnDevice() override;
35  template <typename T> void RunImpl();
36 
37  protected:
39  vector<string> dynamic_dsize;
40 };
41 
42 template <class Context>
44  : public ConvTranspose2dOp<Context> {
45  public:
47  const OperatorDef& def,
48  Workspace* ws)
49  : ConvTranspose2dOp<Context>(def, ws) {}
52 
53  bool HasBias() override {
54  return Y(2)->name() != "NULL";
55  }
56 
57  void RunOnDevice() override;
58  template <typename T> void RunImpl();
59 };
60 
61 #ifdef WITH_CUDNN
62 
63 template <class Context>
65  : public ConvTranspose2dOp<Context> {
66  public:
68  const OperatorDef& def,
69  Workspace* ws)
70  : ConvTranspose2dOp<Context>(def, ws),
72  TENSOR_CORE_AVAILABLE() ? 1 : 0
73  ) {
74 #if CUDNN_VERSION_MIN(7, 0, 0)
75  cudnn_group_ = 1;
76 #else
78 #endif
83  CUDNN_CHECK(cudnnCreateFilterDescriptor(&filter_desc_));
84  CUDNN_CHECK(cudnnCreateConvolutionDescriptor(&conv_desc_));
85  if (data_format() == "NCHW") format_ = CUDNN_TENSOR_NCHW;
86  else if (data_format() == "NHWC") format_ = CUDNN_TENSOR_NHWC;
87  }
90 
96  CUDNN_CHECK(cudnnDestroyFilterDescriptor(filter_desc_));
97  CUDNN_CHECK(cudnnDestroyConvolutionDescriptor(conv_desc_));
98  }
99 
100  void SetConvDescFromInputs();
101 
102  void RunOnDevice() override;
103  template <typename T> void ResetDesc();
104  template <typename T> void RunImpl();
105 
106  protected:
107  cudnnDataType_t compute_type_;
108  cudnnTensorFormat_t format_;
109  cudnnConvolutionBwdDataAlgo_t fwd_algo_;
110  cudnnTensorDescriptor_t input_desc_, output_desc_;
111  cudnnTensorDescriptor_t bias_desc_, output2b_desc_;
112  cudnnConvolutionDescriptor_t conv_desc_;
113  cudnnFilterDescriptor_t filter_desc_;
117 };
118 
119 template <class Context>
121  : public ConvTranspose2dGradientOp<Context> {
122 public:
124  const OperatorDef& def,
125  Workspace* ws)
126  : ConvTranspose2dGradientOp<Context>(def, ws),
128  TENSOR_CORE_AVAILABLE() ? 1 : 0
129  ) {
130 #if CUDNN_VERSION_MIN(7, 0, 0)
131  cudnn_group_ = 1;
132 #else
134 #endif
139  CUDNN_CHECK(cudnnCreateFilterDescriptor(&filter_desc_));
140  CUDNN_CHECK(cudnnCreateConvolutionDescriptor(&conv_desc_));
141  if (data_format() == "NCHW") format_ = CUDNN_TENSOR_NCHW;
142  else if (data_format() == "NHWC") format_ = CUDNN_TENSOR_NHWC;
143  }
146 
152  CUDNN_CHECK(cudnnDestroyFilterDescriptor(filter_desc_));
153  CUDNN_CHECK(cudnnDestroyConvolutionDescriptor(conv_desc_));
154  }
155 
156  void SetConvDescFromInputs();
157 
158  void RunOnDevice() override;
159  template <typename T> void ResetDesc();
160  template <typename T> void RunImpl();
161 
162  protected:
163  cudnnDataType_t compute_type_;
164  cudnnTensorFormat_t format_;
165  cudnnConvolutionBwdFilterAlgo_t bwd_filter_algo_;
166  cudnnConvolutionFwdAlgo_t bwd_data_algo_;
167  cudnnTensorDescriptor_t input_desc_, output_desc_;
168  cudnnTensorDescriptor_t bias_desc_, input2b_desc_;
169  cudnnConvolutionDescriptor_t conv_desc_;
170  cudnnFilterDescriptor_t filter_desc_;
174 };
175 
176 #endif // WITH_CUDNN
177 
178 } // namespace dragon
179 
180 #endif // DRAGON_OPERATORS_VISION_CONV_TRANSPOSE_OP_H_
USE_OPERATOR_FUNCTIONS
Definition: conv_transpose_op.h:28
USE_CONVOLUTION_FUNCTIONS
Definition: conv_transpose_op.h:89
size_t fwd_data_size_
Definition: conv_transpose_op.h:114
vector< string > dynamic_dsize
Definition: conv_transpose_op.h:39
USE_CONVOLUTION_FUNCTIONS
Definition: conv_transpose_op.h:51
cudnnTensorDescriptor_t input_desc_
Definition: conv_transpose_op.h:110
vec64_t output_dims_
Definition: conv_transpose_op.h:173
Definition: workspace.h:20
cudnnTensorDescriptor_t bias_desc_
Definition: conv_transpose_op.h:111
int64_t enable_tensor_core_
Definition: conv_transpose_op.h:172
void RunImpl()
Definition: cudnn_conv2d_transpose_op.cc:401
cudnnTensorFormat_t format_
Definition: conv_transpose_op.h:108
ConvTranspose2dOp(const OperatorDef &def, Workspace *ws)
Definition: conv_transpose_op.h:24
bool TENSOR_CORE_AVAILABLE()
Definition: cuda_device.h:154
int64_t group_
Definition: conv_op_base.h:47
#define CUDNN_CHECK(condition)
Definition: cudnn_device.h:34
Definition: conv_transpose_op.h:120
cudnnTensorDescriptor_t output2b_desc_
Definition: conv_transpose_op.h:111
const string & data_format() const
Return the data format.
Definition: operator.h:79
const OperatorDef & def() const
Return the stored def.
Definition: operator.h:114
Workspace * ws() const
Return the parent workspace.
Definition: operator.h:87
void SetConvDescFromInputs()
Definition: cudnn_conv2d_transpose_op.cc:13
void RunOnDevice() override
Implement the detailed execution.
Definition: conv2d_transpose_op.cc:24
void SetConvDescFromInputs()
Definition: cudnn_conv2d_transpose_op.cc:224
cudnnDataType_t compute_type_
Definition: conv_transpose_op.h:107
CuDNNConvTranspose2dOp(const OperatorDef &def, Workspace *ws)
Definition: conv_transpose_op.h:67
void CuDNNCreateTensorDesc(cudnnTensorDescriptor_t *desc)
Definition: cudnn_device.h:67
int64_t enable_tensor_core_
Definition: conv_transpose_op.h:115
cudnnConvolutionFwdAlgo_t bwd_data_algo_
Definition: conv_transpose_op.h:166
cudnnTensorDescriptor_t output_desc_
Definition: conv_transpose_op.h:167
cudnnTensorDescriptor_t bias_desc_
Definition: conv_transpose_op.h:168
void RunOnDevice() override
Implement the detailed execution.
Definition: cudnn_conv2d_transpose_op.cc:209
cudnnDataType_t compute_type_
Definition: conv_transpose_op.h:163
int XSize()
Return the number of inputs.
Definition: operator.h:46
cudnnConvolutionDescriptor_t conv_desc_
Definition: conv_transpose_op.h:112
void RunImpl()
Definition: cudnn_conv2d_transpose_op.cc:169
void ResetDesc()
Definition: cudnn_conv2d_transpose_op.cc:71
void Setup(int num_axes)
Definition: conv_op_base.cc:248
void RunOnDevice() override
Implement the detailed execution.
Definition: conv2d_transpose_op.cc:63
std::vector< int64_t > vec64_t
Definition: types.h:25
vec32_t static_dsize
Definition: conv_transpose_op.h:38
CuDNNConvTranspose2dGradientOp(const OperatorDef &def, Workspace *ws)
Definition: conv_transpose_op.h:123
cudnnTensorFormat_t format_
Definition: conv_transpose_op.h:164
int64_t cudnn_group_
Definition: conv_transpose_op.h:172
cudnnTensorDescriptor_t input_desc_
Definition: conv_transpose_op.h:167
cudnnTensorDescriptor_t input2b_desc_
Definition: conv_transpose_op.h:168
Definition: conv_transpose_op.h:43
vec64_t filter_dims_
Definition: conv_transpose_op.h:116
bool HasBias() override
Definition: conv_transpose_op.h:32
USE_OPERATOR_FUNCTIONS
Definition: conv_transpose_op.h:88
void RunOnDevice() override
Implement the detailed execution.
Definition: cudnn_conv2d_transpose_op.cc:459
USE_CONVOLUTION_FUNCTIONS
Definition: conv_transpose_op.h:145
size_t bwd_filter_size_
Definition: conv_transpose_op.h:171
void ResetDesc()
Definition: cudnn_conv2d_transpose_op.cc:282
cudnnConvolutionBwdDataAlgo_t fwd_algo_
Definition: conv_transpose_op.h:109
vec64_t output_dims_
Definition: conv_transpose_op.h:116
USE_CONVOLUTION_FUNCTIONS
Definition: conv_transpose_op.h:29
void RunImpl()
Definition: conv2d_transpose_op.cc:40
void CuDNNDestroyTensorDesc(cudnnTensorDescriptor_t *desc)
Definition: cudnn_device.h:72
USE_OPERATOR_FUNCTIONS
Definition: conv_transpose_op.h:50
ConvTranspose2dGradientOp(const OperatorDef &def, Workspace *ws)
Definition: conv_transpose_op.h:46
cudnnFilterDescriptor_t filter_desc_
Definition: conv_transpose_op.h:170
~CuDNNConvTranspose2dOp()
Definition: conv_transpose_op.h:91
cudnnFilterDescriptor_t filter_desc_
Definition: conv_transpose_op.h:113
bool Transposed() override
Definition: conv_transpose_op.h:31
Definition: conv_transpose_op.h:64
bool HasBias() override
Definition: conv_transpose_op.h:53
int64_t cudnn_group_
Definition: conv_transpose_op.h:115
size_t bwd_data_size_
Definition: conv_transpose_op.h:171
cudnnConvolutionBwdFilterAlgo_t bwd_filter_algo_
Definition: conv_transpose_op.h:165
Tensor * Y(int i)
Return the specified output tensor.
Definition: operator.cc:55
std::vector< int > vec32_t
Definition: types.h:24
USE_OPERATOR_FUNCTIONS
Definition: conv_transpose_op.h:144
cudnnTensorDescriptor_t output_desc_
Definition: conv_transpose_op.h:110
const string & name() const
Return the tensor name.
Definition: tensor.h:69
Definition: common.h:41
Definition: conv_transpose_op.h:21
vec64_t filter_dims_
Definition: conv_transpose_op.h:173
~CuDNNConvTranspose2dGradientOp()
Definition: conv_transpose_op.h:147
void RunImpl()
Definition: conv2d_transpose_op.cc:8
cudnnConvolutionDescriptor_t conv_desc_
Definition: conv_transpose_op.h:169
Definition: conv_op_base.h:23