ONE - On-device Neural Engine
Loading...
Searching...
No Matches
opselector::OpSelector Class Referencefinal

#include <OpSelector.h>

Public Member Functions

 OpSelector (const luci::Module *module)
 
template<SelectType SELECT_TYPE>
std::unique_ptr< luci::Moduleselect_by (const std::string &str)
 

Detailed Description

Definition at line 31 of file OpSelector.h.

Constructor & Destructor Documentation

◆ OpSelector()

opselector::OpSelector::OpSelector ( const luci::Module module)

Definition at line 265 of file OpSelector.cpp.

265 : _module{module}
266{
267 // DO NOTHING
268}

Member Function Documentation

◆ select_by()

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

Definition at line 376 of file OpSelector.cpp.

377{
378 auto colon_tokens = ::split_into_vector(str, ',');
379 if (colon_tokens.empty())
380 {
381 throw std::runtime_error{"ERROR: Nothing was entered."};
382 }
383
384 auto selected_nodes = select_by<SELECT_TYPE>(colon_tokens);
385
386 // multiout node should be considered
387 IsMultiOutputNode multiout_visitor;
388 std::vector<const luci::CircleNode *> output_nodes;
389 for (const auto &node : selected_nodes)
390 {
391 if (node->accept(&multiout_visitor))
392 {
393 auto outputs = loco::succs(node);
394 for (auto &o : outputs)
395 {
396 output_nodes.push_back(dynamic_cast<luci::CircleNode *>(o));
397 }
398 }
399 }
400 selected_nodes.insert(selected_nodes.end(), output_nodes.begin(), output_nodes.end());
401
402 // TODO support two or more subgraphs
403 for (const auto &n : selected_nodes)
404 {
405 IsMultiGraphNode multigraph_visitor;
406 bool isMultiGraph = n->accept(&multigraph_visitor);
407 if (isMultiGraph)
408 {
409 throw std::runtime_error{"ERROR: If or While operator can't be selected."};
410 }
411 }
412
413 auto new_module = std::make_unique<luci::Module>();
414 new_module->add(::make_graph(selected_nodes));
415
416 return new_module;
417}
std::set< Node * > succs(const Node *node)
Enumerate all the successors of a given node.
Definition Node.cpp:46
std::vector< Node * > output_nodes(Graph *)
Definition Graph.cpp:101

References loco::succs().


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