Merge pull request #716 from Yangqing/dev
[platform/upstream/caffeonacl.git] / src / caffe / layers / hdf5_data_layer.cu
1 // Copyright 2014 BVLC and contributors.
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 namespace caffe {
19
20 template <typename Dtype>
21 Dtype HDF5DataLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
22       vector<Blob<Dtype>*>* top) {
23   const int batch_size = this->layer_param_.hdf5_data_param().batch_size();
24   const int data_count = (*top)[0]->count() / (*top)[0]->num();
25   const int label_data_count = (*top)[1]->count() / (*top)[1]->num();
26
27   for (int i = 0; i < batch_size; ++i, ++current_row_) {
28     if (current_row_ == data_blob_.num()) {
29       if (num_files_ > 1) {
30         current_file_ += 1;
31
32         if (current_file_ == num_files_) {
33           current_file_ = 0;
34           LOG(INFO) << "looping around to first file";
35         }
36
37         LoadHDF5FileData(hdf_filenames_[current_file_].c_str());
38       }
39       current_row_ = 0;
40     }
41     caffe_copy(data_count,
42         &data_blob_.cpu_data()[current_row_ * data_count],
43         &(*top)[0]->mutable_gpu_data()[i * data_count]);
44     caffe_copy(label_data_count,
45         &label_blob_.cpu_data()[current_row_ * label_data_count],
46         &(*top)[1]->mutable_gpu_data()[i * label_data_count]);
47   }
48   return Dtype(0.);
49 }
50
51 INSTANTIATE_CLASS(HDF5DataLayer);
52
53 }  // namespace caffe