ONE - On-device Neural Engine
Loading...
Searching...
No Matches
nnkit::support::tftestinfo Namespace Reference

Data Structures

class  ParsedTensor
 Class to store tensor information parsed from test.info file under moco/test/tf. More...
 

Enumerations

enum class  DataType { FLOAT32 }
 Supported Data Types. More...
 

Functions

std::vector< std::unique_ptr< ParsedTensor > > parse (const char *info_path)
 Function to parse test.info.
 
std::unique_ptr< ParsedTensorparse_line (std::string &line)
 Function to parse a line of test.info file Examples:
 

Enumeration Type Documentation

◆ DataType

Supported Data Types.

Enumerator
FLOAT32 

Definition at line 38 of file ParsedTensor.h.

39{
40 FLOAT32, // IEEE 32-bit floating point
41 /* To be added */
42};

Function Documentation

◆ parse()

std::vector< std::unique_ptr< ParsedTensor > > nnkit::support::tftestinfo::parse ( const char *  info_path)

Function to parse test.info.

Definition at line 204 of file TensorInfoParser.cpp.

205{
206 std::ifstream infile;
207 infile.open(info_path);
208
209 if (infile.fail())
210 {
211 throw oops::UserExn("Fail to open file", "path", info_path);
212 }
213
214 std::vector<std::unique_ptr<ParsedTensor>> tensors;
215
216 std::string line;
217 while (std::getline(infile, line))
218 {
219 auto tensor = parse_line(line);
220 if (tensor)
221 tensors.emplace_back(std::move(tensor));
222 }
223
224 return tensors;
225}
Exception to user.
Definition UserExn.h:42

References parse_line().

Referenced by nnkit::support::moco::tf::Backend::Backend(), nnkit::support::tf::Backend::Backend(), and main().

◆ parse_line()

std::unique_ptr< ParsedTensor > nnkit::support::tftestinfo::parse_line ( std::string &  line)

Function to parse a line of test.info file Examples:

  • "input, in/placeholder_32:0, TF_INT32, [3, 4, 2, 3]"
  • "output, result:0, TF_FLOAT, []"

Definition at line 143 of file TensorInfoParser.cpp.

144{
145 // parsed data
147 std::string name;
148 TF_DataType dtype;
149 std::vector<int32_t> shape;
150
151 remove_comment(line);
152
153 if (line.length() == 0) // empty line or line with comment
154 return nullptr;
155
156 std::string tok, trimmed, dim;
157
158 std::istringstream line_stream(line);
159
160 CHECK_NOT_NULL(std::getline(line_stream, tok, ',')); // kind
161 kind = get_kind(trim(tok));
162
163 CHECK_NOT_NULL(std::getline(line_stream, tok, ',')); // tensor name
164 trimmed = trim(tok);
165 if (!validate_name(trimmed))
166 throw oops::UserExn("Tensor name in wrong format", "name", tok);
167 name.assign(trimmed);
168
169 CHECK_NOT_NULL(std::getline(line_stream, tok, ',')); // data type
170 dtype = get_dtype(trim(tok));
171
172 CHECK_NOT_NULL(std::getline(line_stream, tok, '[')); // start of shape
173 trimmed = trim(tok);
174 if (trimmed.length())
175 throw oops::UserExn("Unknown token between data type and shape", "token", tok);
176
177 CHECK_NOT_NULL(std::getline(line_stream, tok, ']'));
178
179 std::istringstream shape_stream(tok);
180
181 bool first = true;
182 while (std::getline(shape_stream, dim, ',')) // each dim
183 {
184 dim = trim(dim);
185
186 if (first && dim.length() == 0)
187 continue; // scalar
188 first = false;
189
190 if (dim.length() == 0)
191 throw oops::UserExn("Empty dim in shape", "shape", tok);
192
193 if (!validate_num(dim))
194 throw oops::UserExn("Dim in shape must be a number", "dim", dim);
195
196 shape.emplace_back(std::stoi(dim));
197 }
198
199 return std::make_unique<ParsedTensor>(kind, name, dtype, shape);
200}
#define CHECK_NOT_NULL(x)
DataType
Supported Data Types.

References CHECK_NOT_NULL.

Referenced by parse().