-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcudnn_tanh_layer.cpp
46 lines (38 loc) · 1.29 KB
/
cudnn_tanh_layer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifdef USE_CUDNN
#include <algorithm>
#include <vector>
#include "caffe/layer.hpp"
#include "caffe/vision_layers.hpp"
namespace caffe {
template <typename Dtype>
void CuDNNTanHLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) {
TanHLayer<Dtype>::LayerSetUp(bottom, top);
// initialize cuDNN
CUDNN_CHECK(cudnnCreate(&handle_));
cudnn::createTensor4dDesc<Dtype>(&bottom_desc_);
cudnn::createTensor4dDesc<Dtype>(&top_desc_);
handles_setup_ = true;
}
template <typename Dtype>
void CuDNNTanHLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) {
TanHLayer<Dtype>::Reshape(bottom, top);
const int N = bottom[0]->num();
const int K = bottom[0]->channels();
const int H = bottom[0]->height();
const int W = bottom[0]->width();
cudnn::setTensor4dDesc<Dtype>(&bottom_desc_, N, K, H, W);
cudnn::setTensor4dDesc<Dtype>(&top_desc_, N, K, H, W);
}
template <typename Dtype>
CuDNNTanHLayer<Dtype>::~CuDNNTanHLayer() {
// Check that handles have been setup before destroying.
if (!handles_setup_) { return; }
cudnnDestroyTensorDescriptor(this->bottom_desc_);
cudnnDestroyTensorDescriptor(this->top_desc_);
cudnnDestroy(this->handle_);
}
INSTANTIATE_CLASS(CuDNNTanHLayer);
} // namespace caffe
#endif