-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathexp_layer.cu
More file actions
42 lines (35 loc) · 1.27 KB
/
exp_layer.cu
File metadata and controls
42 lines (35 loc) · 1.27 KB
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
#include <vector>
#include "caffe/layers/exp_layer.hpp"
#include "caffe/util/math_functions.hpp"
namespace caffe {
template <typename Dtype>
void ExpLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) {
const int count = bottom[0]->count();
const Dtype* bottom_data = bottom[0]->gpu_data();
Dtype* top_data = top[0]->mutable_gpu_data();
if (inner_scale_ == Dtype(1)) {
caffe_gpu_exp(count, bottom_data, top_data);
} else {
caffe_gpu_scale(count, inner_scale_, bottom_data, top_data);
caffe_gpu_exp(count, top_data, top_data);
}
if (outer_scale_ != Dtype(1)) {
caffe_gpu_scal(count, outer_scale_, top_data);
}
}
template <typename Dtype>
void ExpLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {
if (!propagate_down[0]) { return; }
const int count = bottom[0]->count();
const Dtype* top_data = top[0]->gpu_data();
const Dtype* top_diff = top[0]->gpu_diff();
Dtype* bottom_diff = bottom[0]->mutable_gpu_diff();
caffe_gpu_mul(count, top_data, top_diff, bottom_diff);
if (inner_scale_ != Dtype(1)) {
caffe_gpu_scal(count, inner_scale_, bottom_diff);
}
}
INSTANTIATE_LAYER_GPU_FUNCS(ExpLayer);
} // namespace caffe