LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
io_data_buffer.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.
26 
27 #ifndef LBANN_IO_BUFFER_HPP_INCLUDED
28 #define LBANN_IO_BUFFER_HPP_INCLUDED
29 
31 
32 namespace lbann {
33 
34 template <typename TensorDataType>
36 {
37 public:
39 
42  using AbsDistMatrixType = El::AbstractDistMatrix<TensorDataType>;
43 
45 
46 public:
50  std::map<data_field_type, std::unique_ptr<AbsDistMatrixType>> m_input_buffers;
51  std::atomic<bool> m_fetch_data_in_background;
52  std::future<void> m_data_fetch_future;
54  El::Matrix<El::Int> m_indices_fetched_per_mb;
55 
57  : m_num_samples_fetched(0), m_fetch_data_in_background(false)
58  {
59  m_input_buffers.clear();
60  }
61 
62  data_buffer(const data_buffer& other)
63  : m_num_samples_fetched(other.m_num_samples_fetched)
64  {
65  m_fetch_data_in_background.store(other.m_fetch_data_in_background);
66  m_input_buffers.clear();
67  // m_input_buffers.reserve(other.m_input_buffers.size());
68  // for (const auto& ptr : other.m_input_buffers) {
69  // m_input_buffers.emplace_back(ptr ? ptr->Copy() : nullptr);
70  // }
71  }
73  {
74  m_num_samples_fetched = other.m_num_samples_fetched;
75  m_fetch_data_in_background.store(other.m_fetch_data_in_background);
76  m_input_buffers.clear();
77  // m_input_buffers.reserve(other.m_input_buffers.size());
78  // for (const auto& ptr : other.m_input_buffers) {
79  // m_input_buffers.emplace_back(ptr ? ptr->Copy() : nullptr);
80  // }
81  return *this;
82  }
83  data_buffer* copy() const { return new data_buffer(*this); }
84 
86  template <class Archive>
87  void serialize(Archive& ar);
88 
92  lbann_comm* comm);
93 
95  {
96  m_fetch_data_in_background = flag;
97  }
98 
100  {
102  }
103 
107  const El::Matrix<El::Int>* get_sample_indices_fetched_per_mb() const
108  {
109  return &m_indices_fetched_per_mb;
110  }
111  El::Matrix<El::Int>* get_sample_indices_fetched_per_mb()
112  {
113  return &m_indices_fetched_per_mb;
114  }
115 
117 
118  void set_data_fetch_future(std::future<void> future)
119  {
120  m_data_fetch_future = std::move(future);
121  }
122 
123  std::future<void> get_data_fetch_future()
124  {
125  return std::move(m_data_fetch_future);
126  }
127 };
128 
129 } // namespace lbann
130 
131 #endif // LBANN_IO_BUFFER_HPP_INCLUDED
El::Matrix< El::Int > * get_sample_indices_fetched_per_mb()
void serialize(Archive &ar)
std::map< data_field_type, std::unique_ptr< AbsDistMatrixType > > m_input_buffers
void set_data_fetch_future(std::future< void > future)
void set_fetch_data_in_background(bool flag)
data_buffer & operator=(const data_buffer &other)
data_buffer * copy() const
El::Matrix< El::Int > m_indices_fetched_per_mb
1-D Matrix of which indices were fetched in this mini-batch
void initialize_buffer_for_data_field(data_field_type const data_field, lbann_comm *comm)
Create a data parallel distributed matrix to hold the input data for the field.
data_buffer(lbann_comm *comm)
std::atomic< bool > m_fetch_data_in_background
data_buffer(const data_buffer &other)
El::AbstractDistMatrix< TensorDataType > AbsDistMatrixType
The tensor type expected in this object.
std::string data_field_type
std::future< void > m_data_fetch_future
bool is_data_fetched_in_background() const
std::future< void > get_data_fetch_future()
const El::Matrix< El::Int > * get_sample_indices_fetched_per_mb() const