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

#include <ListFileIterator.h>

Collaboration diagram for record_minmax::ListFileIterator:

Public Member Functions

 ListFileIterator (const std::string &input_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 32 of file ListFileIterator.h.

Constructor & Destructor Documentation

◆ ListFileIterator()

record_minmax::ListFileIterator::ListFileIterator ( const std::string &  input_path,
luci::Module module 
)

Definition at line 66 of file ListFileIterator.cpp.

67{
68 std::ifstream input_file(input_path);
69 if (input_file.fail())
70 throw std::runtime_error("Cannot open file \"" + input_path + "\".\n");
71
72 auto input_nodes = loco::input_nodes(module->graph());
73 for (auto input_node : input_nodes)
74 {
75 const auto cnode = loco::must_cast<const luci::CircleInput *>(input_node);
76 _input_nodes.emplace_back(cnode);
77 }
78
79 std::string record;
80 while (getline(input_file, record))
81 {
82 _lines.emplace_back(record);
83 }
84
85 if (_lines.size() == 0)
86 throw std::runtime_error("The input data file does not contain any record.");
87}
std::vector< Node * > input_nodes(const Graph *)
Definition Graph.cpp:71

References loco::input_nodes().

Member Function Documentation

◆ check_type_shape()

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

Implements record_minmax::DataSetIterator.

Definition at line 151 of file ListFileIterator.cpp.

151{ return false; }

◆ hasNext()

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

Implements record_minmax::DataSetIterator.

Definition at line 89 of file ListFileIterator.cpp.

89{ return _curr_idx < _lines.size(); }

◆ next()

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

Implements record_minmax::DataSetIterator.

Definition at line 91 of file ListFileIterator.cpp.

92{
93 const auto line = _lines.at(_curr_idx++);
94
95 const auto file_names = parse_line(line);
96
97 std::vector<DataBuffer> res;
98
99 // Space-separated input files are written in a single line
100 // This is the recommended way to write the list file
101 if (file_names.size() == _input_nodes.size())
102 {
103 for (uint32_t i = 0; i < file_names.size(); i++)
104 {
106 {
107 const auto file_name = file_names.at(i);
108 const auto input_node = _input_nodes.at(i);
109 const auto input_size = getTensorSize(input_node);
110
111 buf.data.resize(input_size);
112
113 readDataFromFile(file_name, buf.data, input_size);
114 }
115
116 res.emplace_back(buf);
117 }
118 }
119 else
120 {
121 // Must have a single file in one line (inputs are concatenated)
122 if (file_names.size() != 1)
123 throw std::runtime_error(
124 "Wrong number of inputs are given. Model has " + std::to_string(_input_nodes.size()) +
125 " inputs, but list file gives " + std::to_string(file_names.size()) + " inputs.");
126
127 // Read data from file to buffer
128 // Assumption: For a multi-input model, the binary file should have inputs concatenated in the
129 // same order with the input index.
130 // NOTE This is a legacy way to support multiple inputs.
132 {
133 // Get total input size
134 uint32_t total_input_size = 0;
135 for (auto input_node : _input_nodes)
136 {
137 total_input_size += getTensorSize(input_node);
138 }
139
140 buf.data.resize(total_input_size);
141
142 readDataFromFile(file_names.at(0), buf.data, total_input_size);
143 }
144
145 res.emplace_back(buf);
146 }
147
148 return res;
149}
CircleInput * input_node(loco::Graph *g, const loco::GraphInputIndex &index)
Find a Pull node with a given input index.
std::unique_ptr< ParsedTensor > parse_line(std::string &line)
Function to parse a line of test.info file Examples:
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 record_minmax::getTensorSize(), and record_minmax::readDataFromFile().


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