ONE - On-device Neural Engine
Loading...
Searching...
No Matches
record_minmax::DirectoryIterator Class Referencefinal

#include <DirectoryIterator.h>

Collaboration diagram for record_minmax::DirectoryIterator:

Public Member Functions

 DirectoryIterator (const std::string &dir_path, luci::Module *module)
 
bool hasNext () const override
 
std::vector< DataBuffernext () override
 
bool check_type_shape () const override
 
- Public Member Functions inherited from record_minmax::DataSetIterator
virtual ~DataSetIterator ()=default
 

Detailed Description

Definition at line 33 of file DirectoryIterator.h.

Constructor & Destructor Documentation

◆ DirectoryIterator()

record_minmax::DirectoryIterator::DirectoryIterator ( const std::string &  dir_path,
luci::Module module 
)

Definition at line 32 of file DirectoryIterator.cpp.

33 : _dir_path(dir_path)
34{
35 auto dir = opendir(dir_path.c_str());
36 if (not dir)
37 throw std::runtime_error("Cannot open directory. Please check \"" + _dir_path +
38 "\" is a directory.\n");
39
40 dirent *entry = nullptr;
41 while ((entry = readdir(dir)))
42 {
43 if (entry->d_type != DT_REG)
44 continue;
45
46 _entries.emplace_back(entry);
47 }
48
49 auto input_nodes = loco::input_nodes(module->graph());
50 for (auto input_node : input_nodes)
51 {
52 const auto cnode = loco::must_cast<const luci::CircleInput *>(input_node);
53 _input_nodes.emplace_back(cnode);
54 }
55}
int entry(const int argc, char **argv)
Definition Driver.cpp:53
std::vector< Node * > input_nodes(const Graph *)
Definition Graph.cpp:71

References entry(), and loco::input_nodes().

Member Function Documentation

◆ check_type_shape()

bool record_minmax::DirectoryIterator::check_type_shape ( ) const
overridevirtual

Implements record_minmax::DataSetIterator.

Definition at line 100 of file DirectoryIterator.cpp.

100{ return false; }

◆ hasNext()

bool record_minmax::DirectoryIterator::hasNext ( ) const
overridevirtual

Implements record_minmax::DataSetIterator.

Definition at line 57 of file DirectoryIterator.cpp.

57{ return _curr_idx < _entries.size(); }

◆ next()

std::vector< DataBuffer > record_minmax::DirectoryIterator::next ( )
overridevirtual

Implements record_minmax::DataSetIterator.

Definition at line 59 of file DirectoryIterator.cpp.

60{
61 auto entry = _entries.at(_curr_idx++);
62 assert(entry); // FIX_ME_UNLESS
63
64 // Get total input size
65 uint32_t total_input_size = 0;
66 for (auto input : _input_nodes)
67 {
68 const auto *input_node = loco::must_cast<const luci::CircleInput *>(input);
69 total_input_size += getTensorSize(input_node);
70 }
71
72 const std::string filename = entry->d_name;
73
74 // Read data from file to buffer
75 // Assumption: For a multi-input model, the binary file should have inputs concatenated in the
76 // same order with the input index.
77 std::vector<char> input_data(total_input_size);
78 readDataFromFile(_dir_path + "/" + filename, input_data, total_input_size);
79
80 std::vector<DataBuffer> res;
81
82 uint32_t offset = 0;
83 for (auto input_node : _input_nodes)
84 {
86
87 const auto input_size = getTensorSize(input_node);
88
89 buf.data.resize(input_size);
90 memcpy(buf.data.data(), input_data.data() + offset, input_size);
91
92 offset += input_size;
93
94 res.emplace_back(buf);
95 }
96
97 return res;
98}
__global uchar * offset(const Image *img, int x, int y)
Definition helpers.h:540
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.
size_t getTensorSize(const luci::CircleNode *node)
Definition Utils.cpp:57
void readDataFromFile(const std::string &filename, std::vector< char > &data, size_t data_size)
Definition Utils.cpp:65
std::vector< char > DataBuffer

References entry(), record_minmax::getTensorSize(), offset(), and record_minmax::readDataFromFile().


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