Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 53e6dac

Browse files
committedDec 10, 2015
Fix CuDNNConvolutionLayer for cuDNN v4
Add a macro to check the current cuDNN version
1 parent 5413860 commit 53e6dac

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed
 

‎include/caffe/util/cudnn.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#include "caffe/common.hpp"
88
#include "caffe/proto/caffe.pb.h"
99

10+
#define CUDNN_VERSION_MIN(major, minor, patch) \
11+
(CUDNN_VERSION >= (major * 1000 + minor * 100 + patch))
12+
1013
#define CUDNN_CHECK(condition) \
1114
do { \
1215
cudnnStatus_t status = condition; \

‎src/caffe/layers/cudnn_conv_layer.cu

+8
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,19 @@ void CuDNNConvolutionLayer<Dtype>::Forward_gpu(
3030
// Bias.
3131
if (this->bias_term_) {
3232
const Dtype* bias_data = this->blobs_[1]->gpu_data();
33+
#if CUDNN_VERSION_MIN(4, 0, 0)
34+
CUDNN_CHECK(cudnnAddTensor(handle_[g],
35+
cudnn::dataType<Dtype>::one,
36+
bias_desc_, bias_data + bias_offset_ * g,
37+
cudnn::dataType<Dtype>::one,
38+
top_descs_[i], top_data + top_offset_ * g));
39+
#else
3340
CUDNN_CHECK(cudnnAddTensor(handle_[g], CUDNN_ADD_SAME_C,
3441
cudnn::dataType<Dtype>::one,
3542
bias_desc_, bias_data + bias_offset_ * g,
3643
cudnn::dataType<Dtype>::one,
3744
top_descs_[i], top_data + top_offset_ * g));
45+
#endif
3846
}
3947
}
4048

0 commit comments

Comments
 (0)
Please sign in to comment.