Back-merge documentation updates from master
[platform/upstream/caffeonacl.git] / src / caffe / layers / hdf5_data_layer.cu
1 // Copyright Sergey Karayev 2014
2 /*
3 TODO:
4 - only load parts of the file, in accordance with a prototxt param "max_mem"
5 */
6
7 #include <stdint.h>
8 #include <string>
9 #include <vector>
10
11 #include "hdf5.h"
12 #include "hdf5_hl.h"
13
14 #include "caffe/layer.hpp"
15 #include "caffe/util/io.hpp"
16 #include "caffe/vision_layers.hpp"
17
18 using std::string;
19
20 namespace caffe {
21
22 template <typename Dtype>
23 void HDF5DataLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
24       vector<Blob<Dtype>*>* top) {
25   const int batchsize = this->layer_param_.batchsize();
26   for (int i = 0; i < batchsize; ++i, ++current_row) {
27     if (current_row == data_dims[0]) {
28       current_row = 0;
29     }
30
31     CUDA_CHECK(cudaMemcpy(
32             &(*top)[0]->mutable_gpu_data()[i * data_dims[1]],
33             &(data.get()[current_row * data_dims[1]]),
34             sizeof(Dtype) * data_dims[1],
35             cudaMemcpyHostToDevice));
36
37     CUDA_CHECK(cudaMemcpy(
38             &(*top)[1]->mutable_gpu_data()[i * label_dims[1]],
39             &(label.get()[current_row * label_dims[1]]),
40             sizeof(Dtype) * label_dims[1],
41             cudaMemcpyHostToDevice));
42   }
43 }
44
45 template <typename Dtype>
46 Dtype HDF5DataLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,
47       const bool propagate_down, vector<Blob<Dtype>*>* bottom) {
48   return Dtype(0.);
49 }
50
51 INSTANTIATE_CLASS(HDF5DataLayer);
52
53 }  // namespace caffe