ONE - On-device Neural Engine
Loading...
Searching...
No Matches
circle_eval_diff::DirectoryLoader Class Referencefinal

#include <InputDataLoader.h>

Collaboration diagram for circle_eval_diff::DirectoryLoader:

Public Member Functions

 DirectoryLoader (const std::string &dir_path, const std::vector< loco::Node * > &input_nodes)
 
uint32_t size (void) const final
 
Data get (uint32_t data_idx) const final
 
- Public Member Functions inherited from circle_eval_diff::InputDataLoader
virtual ~InputDataLoader ()=default
 

Additional Inherited Members

- Public Types inherited from circle_eval_diff::InputDataLoader
using Data = std::vector< Tensor >
 

Detailed Description

Definition at line 78 of file InputDataLoader.h.

Constructor & Destructor Documentation

◆ DirectoryLoader()

circle_eval_diff::DirectoryLoader::DirectoryLoader ( const std::string &  dir_path,
const std::vector< loco::Node * > &  input_nodes 
)

Definition at line 158 of file InputDataLoader.cpp.

160 : _input_nodes{input_nodes}
161{
162 DIR *dir = opendir(dir_path.c_str());
163 if (not dir)
164 {
165 throw std::runtime_error("Cannot open directory \"" + dir_path + "\".");
166 }
167
168 struct dirent *entry = nullptr;
169 const auto input_total_bytes = getTotalByteSizeOf(input_nodes);
170 while ((entry = readdir(dir)))
171 {
172 // Skip if the entry is not a regular file
173 if (entry->d_type != DT_REG)
174 continue;
175
176 _data_paths.push_back(dir_path + "/" + entry->d_name);
177 }
178
179 closedir(dir);
180}
int entry(const int argc, char **argv)
Definition Driver.cpp:53
size_t getTotalByteSizeOf(const std::vector< loco::Node * > &nodes)
std::vector< Node * > input_nodes(const Graph *)
Definition Graph.cpp:71

References circle_eval_diff::DIR, entry(), and circle_eval_diff::getTotalByteSizeOf().

Member Function Documentation

◆ get()

InputDataLoader::Data circle_eval_diff::DirectoryLoader::get ( uint32_t  data_idx) const
finalvirtual

Implements circle_eval_diff::InputDataLoader.

Definition at line 184 of file InputDataLoader.cpp.

185{
186 // Read raw data
187 const auto input_total_bytes = getTotalByteSizeOf(_input_nodes);
188 std::vector<char> input_data(input_total_bytes);
189 const auto raw_data_path = _data_paths.at(data_idx);
190 std::ifstream fs(raw_data_path, std::ifstream::binary);
191
192 if (fs.fail())
193 {
194 throw std::runtime_error("Cannot open file \"" + raw_data_path + "\".");
195 }
196 if (fs.read(input_data.data(), input_total_bytes).fail())
197 {
198 throw std::runtime_error("Failed to read raw data from file \"" + raw_data_path + "\".");
199 }
200
201 // Make Tensor from raw data
202 auto input_data_cur = input_data.data();
203
204 Data data;
205 data.resize(_input_nodes.size());
206 std::vector<size_t> input_bytes = getEachByteSizeOf(_input_nodes);
207 for (uint32_t index = 0; index < _input_nodes.size(); index++)
208 {
209 const auto input_node = loco::must_cast<const luci::CircleInput *>(_input_nodes.at(index));
210 auto &tensor = data.at(index);
211 tensor = *createEmptyTensor(input_node).get();
212 auto buffer = tensor.buffer();
213 std::memcpy(buffer, input_data_cur, input_bytes.at(index));
214 input_data_cur += input_bytes.at(index);
215 }
216
217 return data;
218}
std::vector< size_t > getEachByteSizeOf(const std::vector< loco::Node * > &nodes)
std::shared_ptr< Tensor > createEmptyTensor(const luci::CircleNode *node)
Definition Tensor.cpp:90
list input_data
Definition infer.py:29
CircleInput * input_node(loco::Graph *g, const loco::GraphInputIndex &index)
Find a Pull node with a given input index.
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54

References circle_eval_diff::createEmptyTensor(), circle_eval_diff::getEachByteSizeOf(), and circle_eval_diff::getTotalByteSizeOf().

◆ size()

uint32_t circle_eval_diff::DirectoryLoader::size ( void  ) const
finalvirtual

Implements circle_eval_diff::InputDataLoader.

Definition at line 182 of file InputDataLoader.cpp.

182{ return _data_paths.size(); }

The documentation for this class was generated from the following files: