ONE - On-device Neural Engine
Loading...
Searching...
No Matches
opselector Namespace Reference

Data Structures

class  OpSelector
 

Enumerations

enum class  SelectType { ID , NAME }
 

Functions

bool exportModule (luci::Module *module, std::string &output_path)
 
template<>
std::vector< const luci::CircleNode * > OpSelector::select_by< SelectType::ID > (const std::vector< std::string > &comma_tokens)
 
template<>
std::vector< const luci::CircleNode * > OpSelector::select_by< SelectType::NAME > (const std::vector< std::string > &tokens)
 
template std::unique_ptr< luci::ModuleOpSelector::select_by< SelectType::ID > (const std::string &str)
 
template std::unique_ptr< luci::ModuleOpSelector::select_by< SelectType::NAME > (const std::string &str)
 

Enumeration Type Documentation

◆ SelectType

enum class opselector::SelectType
strong
Enumerator
ID 
NAME 

Definition at line 25 of file SelectType.h.

Function Documentation

◆ exportModule()

bool opselector::exportModule ( luci::Module module,
std::string &  output_path 
)

Definition at line 29 of file ModuleIO.cpp.

30{
31 luci::CircleExporter exporter;
32
33 luci::CircleFileExpContract contract(module, output_path);
34
35 if (!exporter.invoke(&contract))
36 {
37 std::cerr << "ERROR: Failed to export '" << output_path << "'" << std::endl;
38 return false;
39 }
40
41 return true;
42}
bool invoke(Contract *) const

References luci::CircleExporter::invoke().

Referenced by entry().

◆ OpSelector::select_by< SelectType::ID >() [1/2]

template std::unique_ptr< luci::Module > opselector::OpSelector::select_by< SelectType::ID > ( const std::string &  str)

◆ OpSelector::select_by< SelectType::ID >() [2/2]

template<>
std::vector< const luci::CircleNode * > opselector::OpSelector::select_by< SelectType::ID > ( const std::vector< std::string > &  comma_tokens)

Definition at line 265 of file OpSelector.cpp.

273{
274 std::vector<uint32_t> by_id;
275
276 for (const auto &comma_token : comma_tokens)
277 {
278 auto dash_tokens = ::split_into_vector(comma_token, '-');
279 if (not ::is_number(dash_tokens))
280 {
281 throw std::runtime_error{
282 "ERROR: To select operator by id, please use these args: [0-9], '-', ','"};
283 }
284
285 // Convert string into integer
286 std::vector<uint32_t> int_tokens;
287 try
288 {
289 std::transform(dash_tokens.begin(), dash_tokens.end(), std::back_inserter(int_tokens),
290 [](const std::string &str) { return static_cast<uint32_t>(std::stoi(str)); });
291 }
292 catch (const std::out_of_range &)
293 {
294 // Uf input is big integer like '123467891234', stoi throws this exception.
295 throw std::runtime_error{"ERROR: Argument is out of range."};
296 }
297 catch (...)
298 {
299 throw std::runtime_error{"ERROR: Unknown error"};
300 }
301
302 switch (int_tokens.size())
303 {
304 case 0: // inputs like "-"
305 {
306 throw std::runtime_error{"ERROR: Nothing was entered"};
307 }
308 case 1: // inputs like "1", "2"
309 {
310 by_id.push_back(int_tokens.at(0));
311 break;
312 }
313 case 2: // inputs like "1-2", "11-50"
314 {
315 for (uint32_t i = int_tokens.at(0); i <= int_tokens.at(1); i++)
316 {
317 by_id.push_back(i);
318 }
319 break;
320 }
321 default: // inputs like "1-2-3"
322 {
323 throw std::runtime_error{"ERROR: Too many '-' in str."};
324 }
325 }
326 }
327
328 loco::Graph *graph = _module->graph(0);
329 std::vector<const luci::CircleNode *> selected_nodes;
330
331 for (auto node : loco::all_nodes(graph))
332 {
333 auto cnode = loco::must_cast<const luci::CircleNode *>(node);
334
335 try
336 {
337 auto node_id = luci::get_node_id(cnode);
338 for (auto selected_id : by_id)
339 {
340 if (selected_id == node_id)
341 {
342 selected_nodes.emplace_back(cnode);
343 }
344 }
345 }
346 catch (const std::runtime_error &)
347 {
348 continue;
349 }
350 }
351
352 return selected_nodes;
353}
A neural network graph.
Definition Graph.h:161
std::set< Node * > all_nodes(Graph *)
Enumerate all the nodes in a given graph.
Definition Graph.cpp:59
CircleNodeID get_node_id(const luci::CircleNode *circle_node)

◆ OpSelector::select_by< SelectType::NAME >() [1/2]

template std::unique_ptr< luci::Module > opselector::OpSelector::select_by< SelectType::NAME > ( const std::string &  str)

◆ OpSelector::select_by< SelectType::NAME >() [2/2]

template<>
std::vector< const luci::CircleNode * > opselector::OpSelector::select_by< SelectType::NAME > ( const std::vector< std::string > &  tokens)

Definition at line 265 of file OpSelector.cpp.

358{
359 loco::Graph *graph = _module->graph(0);
360 std::vector<const luci::CircleNode *> selected_nodes;
361
362 for (auto node : loco::all_nodes(graph))
363 {
364 auto cnode = loco::must_cast<const luci::CircleNode *>(node);
365 std::string node_name = cnode->name();
366
367 for (const auto &selected_name : tokens)
368 if (selected_name.compare(node_name) == 0) // find the selected name
369 selected_nodes.emplace_back(cnode);
370 }
371
372 return selected_nodes;
373}