LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
data_reader_merge_samples.hpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2023, Lawrence Livermore National Security, LLC.
3 // Produced at the Lawrence Livermore National Laboratory.
4 // Written by the LBANN Research Team (B. Van Essen, et al.) listed in
5 // the CONTRIBUTORS file. <lbann-dev@llnl.gov>
6 //
7 // LLNL-CODE-697807.
8 // All rights reserved.
9 //
10 // This file is part of LBANN: Livermore Big Artificial Neural Network
11 // Toolkit. For details, see http://software.llnl.gov/LBANN or
12 // https://github.com/LLNL/LBANN.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "Licensee"); you
15 // may not use this file except in compliance with the License. You may
16 // obtain a copy of the License at:
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
23 // implied. See the License for the specific language governing
24 // permissions and limitations under the license.
25 //
26 // data_reader_merge_samples.hpp .cpp - Merge samples from multiple data readers
28 
29 #ifndef LBANN_DATA_READER_MERGE_SAMPLES_HPP
30 #define LBANN_DATA_READER_MERGE_SAMPLES_HPP
31 
32 #include "compound_data_reader.hpp"
33 
34 namespace lbann {
35 
41 {
42 public:
43  data_reader_merge_samples(std::vector<generic_data_reader*> data_readers,
44  bool shuffle = true);
47  ~data_reader_merge_samples() override;
48  data_reader_merge_samples* copy() const override
49  {
50  return new data_reader_merge_samples(*this);
51  }
52 
53  std::string get_type() const override { return "data_reader_merge_samples"; }
54 
56  void load() override;
57 
58  int get_num_labels() const override
59  {
60  return m_data_readers[0]->get_num_labels();
61  }
62  int get_num_responses() const override
63  {
64  return m_data_readers[0]->get_num_responses();
65  }
66  int get_linearized_data_size() const override
67  {
68  return m_data_readers[0]->get_linearized_data_size();
69  }
70  int get_linearized_label_size() const override
71  {
72  return m_data_readers[0]->get_linearized_label_size();
73  }
74  int get_linearized_response_size() const override
75  {
76  return m_data_readers[0]->get_linearized_response_size();
77  }
78  const std::vector<El::Int> get_data_dims() const override
79  {
80  return m_data_readers[0]->get_data_dims();
81  }
82 
84  const std::vector<int>& get_num_samples_psum() { return m_num_samples_psum; }
85 
86 protected:
87  bool fetch_datum(CPUMat& X, int data_id, int mb_idx) override;
88  bool fetch_label(CPUMat& Y, int data_id, int mb_idx) override;
89  bool fetch_response(CPUMat& Y, int data_id, int mb_idx) override;
90 
92  std::vector<int> m_num_samples_psum;
93 
95  void setup_indices(int num_samples);
96 
98  size_t compute_num_samples_psum();
99 
101  void sanity_check_for_consistency(int num_labels,
102  int data_size,
103  int label_size,
104  const std::vector<El::Int>& data_dims);
105 };
106 
107 } // namespace lbann
108 
109 #endif // LBANN_DATA_READER_MERGE_SAMPLES_HPP
int get_linearized_label_size() const override
Get the linearized size (i.e. number of elements) in a label.
data_reader_merge_samples(std::vector< generic_data_reader *> data_readers, bool shuffle=true)
data_reader_merge_samples * copy() const override
std::vector< int > m_num_samples_psum
Partial sums of the number of samples in each reader.
bool fetch_datum(CPUMat &X, int data_id, int mb_idx) override
int get_num_labels() const override
Return the number of labels (classes) in this dataset.
El::Matrix< DataType, El::Device::CPU > CPUMat
Definition: base.hpp:116
int get_linearized_response_size() const override
Get the linearized size (i.e. number of elements) in a response.
void setup_indices(int num_samples)
code common to both load() and load_using_data_store()
int get_linearized_data_size() const override
Get the linearized size (i.e. number of elements) in a sample.
size_t compute_num_samples_psum()
code common to both load() and load_using_data_store()
bool fetch_label(CPUMat &Y, int data_id, int mb_idx) override
void sanity_check_for_consistency(int num_labels, int data_size, int label_size, const std::vector< El::Int > &data_dims)
code common to both load() and load_using_data_store()
bool fetch_response(CPUMat &Y, int data_id, int mb_idx) override
const std::vector< int > & get_num_samples_psum()
support for data store functionality
const std::vector< El::Int > get_data_dims() const override
Get the dimensions of the data.
int get_num_responses() const override
Return the number of responses in this dataset.
data_reader_merge_samples & operator=(const data_reader_merge_samples &)
std::vector< generic_data_reader * > m_data_readers
List of readers providing data.
void load() override
Load subsidiary data readers.