Merge pull request #497 from jeffdonahue/fix-backward-interface
[platform/upstream/caffeonacl.git] / src / caffe / layers / hdf5_output_layer.cu
1 // Copyright 2014 BVLC and contributors.
2
3 #include <vector>
4
5 #include "hdf5.h"
6 #include "hdf5_hl.h"
7
8 #include "caffe/blob.hpp"
9 #include "caffe/common.hpp"
10 #include "caffe/layer.hpp"
11 #include "caffe/util/io.hpp"
12 #include "caffe/vision_layers.hpp"
13
14 namespace caffe {
15 using std::vector;
16
17 template <typename Dtype>
18 Dtype HDF5OutputLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
19       vector<Blob<Dtype>*>* top) {
20   CHECK_GE(bottom.size(), 2);
21   CHECK_EQ(bottom[0]->num(), bottom[1]->num());
22   data_blob_.Reshape(bottom[0]->num(), bottom[0]->channels(),
23                      bottom[0]->height(), bottom[0]->width());
24   label_blob_.Reshape(bottom[1]->num(), bottom[1]->channels(),
25                      bottom[1]->height(), bottom[1]->width());
26   const int data_datum_dim = bottom[0]->count() / bottom[0]->num();
27   const int label_datum_dim = bottom[1]->count() / bottom[1]->num();
28
29   for (int i = 0; i < bottom[0]->num(); ++i) {
30     CUDA_CHECK(cudaMemcpy(&data_blob_.mutable_cpu_data()[i * data_datum_dim],
31            &bottom[0]->gpu_data()[i * data_datum_dim],
32            sizeof(Dtype) * data_datum_dim, cudaMemcpyDeviceToHost));
33     CUDA_CHECK(cudaMemcpy(&label_blob_.mutable_cpu_data()[i * label_datum_dim],
34            &bottom[1]->gpu_data()[i * label_datum_dim],
35            sizeof(Dtype) * label_datum_dim, cudaMemcpyDeviceToHost));
36   }
37   SaveBlobs();
38   return Dtype(0.);
39 }
40
41 template <typename Dtype>
42 void HDF5OutputLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,
43       const vector<bool>& propagate_down, vector<Blob<Dtype>*>* bottom) {
44   return;
45 }
46
47 INSTANTIATE_CLASS(HDF5OutputLayer);
48
49 }  // namespace caffe