singa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wan...@apache.org
Subject [1/5] incubator-singa git commit: SINGA-346 Update cudnn from V5 to V7
Date Tue, 24 Apr 2018 10:52:13 GMT
Repository: incubator-singa
Updated Branches:
  refs/heads/master 060e7dfe1 -> 9090160ed


SINGA-346 Update cudnn from V5 to V7

4 functions in v5 not present in v7:

'cudnnActivationBackward_v4',
'cudnnActivationForward_v4',
'cudnnSetPooling2dDescriptor_v4',
'cudnnSetFilter4dDescriptor_v4'

4 functions API changed in v7:

'cudnnSetConvolution2dDescriptor',
'cudnnSetRNNDescriptor',

'cudnnSetFilterNdDescriptor',  (int to const int)
'cudnnSetTensorNdDescriptor'.  (int to const int)


Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/c9f94714
Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/c9f94714
Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/c9f94714

Branch: refs/heads/master
Commit: c9f9471401d4698ae97218a5db795fb56b1998b2
Parents: 060e7df
Author: Wang Wei <dcswaw@nus.edu.sg>
Authored: Fri Apr 13 23:52:21 2018 +0800
Committer: Wang Wei <dcswaw@nus.edu.sg>
Committed: Fri Apr 13 23:52:57 2018 +0800

----------------------------------------------------------------------
 src/model/layer/cudnn_activation.cc  | 13 -------------
 src/model/layer/cudnn_convolution.cc | 13 +++----------
 src/model/layer/cudnn_pooling.cc     |  8 --------
 src/model/layer/cudnn_rnn.cc         |  4 ++--
 4 files changed, 5 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/c9f94714/src/model/layer/cudnn_activation.cc
----------------------------------------------------------------------
diff --git a/src/model/layer/cudnn_activation.cc b/src/model/layer/cudnn_activation.cc
index ff520b8..d1b2141 100644
--- a/src/model/layer/cudnn_activation.cc
+++ b/src/model/layer/cudnn_activation.cc
@@ -78,15 +78,9 @@ const Tensor CudnnActivation::Forward(int flag, const Tensor& input)
{
   output.device()->Exec([input, output, this](Context* ctx) {
     Block* inblock = input.block(), * outblock = output.block();
     float alpha = 1.0f, beta = 0.0f;
-#if CUDNN_MAJOR == 5
     CUDNN_CHECK(cudnnActivationForward(
         ctx->cudnn_handle, this->acti_desc_, &alpha, this->desc_,
         inblock->data(), &beta, this->desc_, outblock->mutable_data()));
-#elif CUDNN_MAJOR == 4
-    CUDNN_CHECK(cudnnActivationForward_v4(
-        ctx->cudnn_handle, this->acti_desc_, &alpha, this->desc_,
-        inblock->data(), &beta, this->desc_, outblock->mutable_data()));
-#endif
   }, {input.block()}, {output.block()});
   if (flag & kTrain) {
     if (cudnn_mode_ == CUDNN_ACTIVATION_SIGMOID ||
@@ -113,17 +107,10 @@ const std::pair<Tensor, vector<Tensor>> CudnnActivation::Backward(
     Block* dyblock = grad.block(), * dxblock = dx.block(),
            * yblock = inout.block(), * xblock = inout.block();
     float alpha = 1.0f, beta = 0.0f;
-#if CUDNN_MAJOR == 5
     CUDNN_CHECK(cudnnActivationBackward(
         ctx->cudnn_handle, this->acti_desc_, &alpha, this->desc_,
         yblock->data(), this->desc_, dyblock->data(), this->desc_,
         xblock->data(), &beta, this->desc_, dxblock->mutable_data()));
-#elif CUDNN_MAJOR == 4
-    CUDNN_CHECK(cudnnActivationBackward_v4(
-        ctx->cudnn_handle, this->acti_desc_, &alpha, this->desc_, yblock->data(),
-        this->desc_, dyblock->data(), this->desc_, xblock->data(), &beta,
-        this->desc_, dxblock->mutable_data()));
-#endif
   }, {grad.block(), inout.block()}, {dx.block()});
   return std::make_pair(dx, param_grad);
 }

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/c9f94714/src/model/layer/cudnn_convolution.cc
----------------------------------------------------------------------
diff --git a/src/model/layer/cudnn_convolution.cc b/src/model/layer/cudnn_convolution.cc
index 7d5e554..40c7d33 100644
--- a/src/model/layer/cudnn_convolution.cc
+++ b/src/model/layer/cudnn_convolution.cc
@@ -78,19 +78,11 @@ void CudnnConvolution::InitCudnn(const Tensor &input) {
                                            num_filters_, 1, 1));
   CUDNN_CHECK(cudnnSetConvolution2dDescriptor(conv_desc_, pad_h_, pad_w_,
                                               stride_h_, stride_w_, 1, 1,
-                                              CUDNN_CROSS_CORRELATION));
-#if CUDNN_MAJOR == 5
+                                              CUDNN_CROSS_CORRELATION, 
+                                              GetCudnnDataType(dtype)));
   CUDNN_CHECK(cudnnSetFilter4dDescriptor(filter_desc_, GetCudnnDataType(dtype),
                                          CUDNN_TENSOR_NCHW, num_filters_,
                                          channels_, kernel_h_, kernel_w_));
-#elif CUDNN_MAJOR == 4
-  CUDNN_CHECK(cudnnSetFilter4dDescriptor_v4(
-      filter_desc_, GetCudnnDataType(dtype), CUDNN_TENSOR_NCHW, num_filters_,
-      channels_, kernel_h_, kernel_w_));
-#else
-  LOG(FATAL) << "Not supported CUDNN version = " << CUDNN_MAJOR;
-#endif
-
   if (prefer_ == "fastest" || prefer_ == "limited_workspace" ||
       prefer_ == "no_workspace") {
     cudnnConvolutionFwdPreference_t fwd_pref;
@@ -115,6 +107,7 @@ void CudnnConvolution::InitCudnn(const Tensor &input) {
     CUDNN_CHECK(cudnnGetConvolutionBackwardFilterAlgorithm(
         ctx->cudnn_handle, x_desc_, y_desc_, conv_desc_, filter_desc_,
         bwd_filt_pref, workspace_byte_limit_, &bp_filter_alg_));
+    # deprecated in cudnn v7
     CUDNN_CHECK(cudnnGetConvolutionBackwardDataAlgorithm(
         ctx->cudnn_handle, filter_desc_, y_desc_, conv_desc_, x_desc_,
         bwd_data_pref, workspace_byte_limit_, &bp_data_alg_));

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/c9f94714/src/model/layer/cudnn_pooling.cc
----------------------------------------------------------------------
diff --git a/src/model/layer/cudnn_pooling.cc b/src/model/layer/cudnn_pooling.cc
index 364242e..be480d7 100644
--- a/src/model/layer/cudnn_pooling.cc
+++ b/src/model/layer/cudnn_pooling.cc
@@ -65,17 +65,9 @@ void CudnnPooling::InitCudnn(const Tensor &input) {
   else
     LOG(FATAL) << "Not implemented!";
 
-#if CUDNN_MAJOR == 5
   CUDNN_CHECK(cudnnSetPooling2dDescriptor(pool_desc_, pool_method, nan_prop_,
                                           kernel_h_, kernel_w_, pad_h_, pad_w_,
                                           stride_h_, stride_w_));
-#elif CUDNN_MAJOR == 4
-  CUDNN_CHECK(cudnnSetPooling2dDescriptor_v4(pool_desc_, pool_method, nan_prop_,
-                                             kernel_h_, kernel_w_, pad_h_,
-                                             pad_w_, stride_h_, stride_w_));
-#else
-  LOG(FATAL) << "Not supported CUDNN version = " << CUDNN_MAJOR;
-#endif
   has_init_cudnn_ = true;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/c9f94714/src/model/layer/cudnn_rnn.cc
----------------------------------------------------------------------
diff --git a/src/model/layer/cudnn_rnn.cc b/src/model/layer/cudnn_rnn.cc
index 62c6355..fb5fee0 100644
--- a/src/model/layer/cudnn_rnn.cc
+++ b/src/model/layer/cudnn_rnn.cc
@@ -144,9 +144,9 @@ void CudnnRNN::SetRNNDescriptor(shared_ptr<Device> dev) {
     rnn_mode = CUDNN_RNN_TANH;
   else if (rnn_mode_ == "gru")
     rnn_mode = CUDNN_GRU;
-  CUDNN_CHECK(cudnnSetRNNDescriptor(rnn_desc_, hidden_size_, num_stacks_,
+  CUDNN_CHECK(cudnnSetRNNDescriptor(ctx->cudnn_handle, rnn_desc_, hidden_size_, num_stacks_,
                                     dropout_desc_, input_mode, direction,
-                                    rnn_mode, dtype_));
+                                    rnn_mode, CUDNN_RNN_ALGO_STANDARD, dtype_));
 
   size_t weight_size;
   CUDNN_CHECK(cudnnGetRNNParamsSize(ctx->cudnn_handle, rnn_desc_, x_descs_[0],


Mime
View raw message