Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Commit 3632db7

Browse files
committed
[MIOPEN] Optimization: reduce HIP module API calls in Reshape()
1 parent db0558d commit 3632db7

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

include/caffe/layers/cudnn_conv_layer.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class CuDNNConvolutionLayer : public ConvolutionLayer<Dtype> {
5959
mlopenTensorDescriptor_t bias_desc_;
6060
mlopenTensorDescriptor_t filter_desc_;
6161
vector<mlopenConvolutionDescriptor_t> conv_descs_;
62+
63+
int N_, C_, W_, H_;
6264
#endif
6365

6466
#ifdef USE_CUDNN

src/caffe/layers/cudnn_conv_layer.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ void CuDNNConvolutionLayer<Dtype>::LayerSetUp(
146146
#endif
147147
}
148148

149+
#ifdef USE_MIOPEN
150+
N_ = C_ = W_ = H_ = 0;
151+
#endif
152+
149153
handles_setup_ = true;
150154
}
151155

@@ -185,6 +189,25 @@ void CuDNNConvolutionLayer<Dtype>::Reshape(
185189
size_t workspace_limit_bytes = 8*1024*1024;
186190
#endif
187191

192+
#ifdef USE_MIOPEN
193+
bool doReshape = false;
194+
if ((N_ != this->num_) ||
195+
(C_ != this->channels_ / this->group_) ||
196+
(H_ != height) ||
197+
(W_ != width)) {
198+
doReshape = true;
199+
//LOG(INFO) << "doReshape\n";
200+
N_ = this->num_;
201+
C_ = this->channels_ / this->group_;
202+
H_ = height;
203+
W_ = width;
204+
} else {
205+
//LOG(INFO) << "NOT doReshape\n";
206+
}
207+
208+
if (doReshape) {
209+
#endif
210+
188211
for (int i = 0; i < bottom.size(); i++) {
189212
#ifdef USE_MIOPEN
190213
miopen::setTensor4dDesc<Dtype>(&bottom_descs_[i],
@@ -370,6 +393,10 @@ void CuDNNConvolutionLayer<Dtype>::Reshape(
370393
#endif
371394
}
372395

396+
#ifdef USE_MIOPEN
397+
} // if (doReshape)
398+
#endif
399+
373400
// reduce over all workspace sizes to get a maximum to allocate / reallocate
374401
size_t total_workspace_fwd = 0;
375402
size_t total_workspace_bwd_data = 0;

0 commit comments

Comments
 (0)