piiswrong commented on a change in pull request #7442: contrib ctc interface 
changes, cudnn7 CTC, and gluon CTC
URL: https://github.com/apache/incubator-mxnet/pull/7442#discussion_r133883738
 
 

 ##########
 File path: src/operator/contrib/ctc_loss-inl.h
 ##########
 @@ -221,12 +315,139 @@ class CTCLossOp : public Operator {
     Tensor<xpu, 3, real_t> data_grad_computed =
         out_data[ctc_loss::kGrad].get<xpu, 3, real_t>(s);
 
-    Assign(data_grad, req[ctc_loss::kData],
-           broadcast<1>(output_grad, data_grad.shape_) * data_grad_computed);
+#if defined(__CUDACC__) && MXNET_USE_CUDNN == 1 && CUDNN_MAJOR >= 7
+    if (!param_.use_input_lengths && !exceed_cudnn_limit) {
+      cudnn_backward_extra(s, data_grad, output_grad, data_grad_computed);
+    } else {
+      baidu_backward_extra(req, data_grad, output_grad, data_grad_computed);
+    }
+#else
+    baidu_backward_extra(req, data_grad, output_grad, data_grad_computed);
+#endif
   }
 
  private:
   CTCLossParam param_;
+
+#if defined(__CUDACC__) && MXNET_USE_CUDNN == 1 && CUDNN_MAJOR >= 7
+  bool exceed_cudnn_limit;
+  cudnnDataType_t dtype_;
+  cudnnCTCLossDescriptor_t ctc_desc_;
+  cudnnTensorDescriptor_t prob_desc_, grad_desc_;
+
+  inline virtual void cudnn_forward(const OpContext &ctx,
+                                    mshadow::Stream<xpu>* s,
+                                    mshadow::Tensor<xpu, 3, real_t> data,
+                                    mshadow::Tensor<xpu, 1, real_t> costs,
+                                    mshadow::Tensor<xpu, 3, real_t> grad,
+                                    std::vector<int>* input_lengths,
+                                    std::vector<int>* label_lengths,
+                                    std::vector<int>* packed_labels,
+                                    int max_seq_len,
+                                    int batch_size,
+                                    int alphabet_size) {
+    using namespace mshadow;
+    // since the input is activation before softmax and cudnn ctc takes softmax
+    // apply softmax to inputs first.
+    Tensor<xpu, 3, real_t> prob(data.shape_);
+    mshadow::AllocSpace(&prob);
 
 Review comment:
   Dont alloc this way. Use ctx.requested
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to