ONE - On-device Neural Engine
Loading...
Searching...
No Matches
luci::FuseBCQPass Struct Referencefinal

Class to fuse certain pattern of subgraph into CircleBCQFullyConnected or CircleBCQGather. More...

#include <FuseBCQPass.h>

Collaboration diagram for luci::FuseBCQPass:

Public Member Functions

const char * name (void) const final
 
bool run (luci::Module *m) final
 
bool run (loco::Graph *g) final
 Run the pass.
 
- Public Member Functions inherited from logo::Pass
virtual ~Pass ()=default
 

Detailed Description

Class to fuse certain pattern of subgraph into CircleBCQFullyConnected or CircleBCQGather.

Definition at line 29 of file FuseBCQPass.h.

Member Function Documentation

◆ name()

const char * luci::FuseBCQPass::name ( void  ) const
inlinefinalvirtual

Reimplemented from logo::Pass.

Definition at line 31 of file FuseBCQPass.h.

31{ return "luci::FuseBCQPass"; }

◆ run() [1/2]

bool luci::FuseBCQPass::run ( loco::Graph graph)
finalvirtual

Run the pass.

Returns
false if there was nothing changed

Implements logo::Pass.

Definition at line 692 of file FuseBCQPass.cpp.

693{
694 // Do nothing for graph
695 return false;
696}

Referenced by package.infer.session::inference().

◆ run() [2/2]

bool luci::FuseBCQPass::run ( luci::Module m)
finalvirtual

Implements luci::Pass.

Definition at line 613 of file FuseBCQPass.cpp.

614{
615 bool changed = false;
616
617 const int32_t start_magicnum = -2e9 + 27;
618 const int32_t end_magicnum = 2e9 - 27;
619
620 loco::Graph *main_graph = m->graph(0);
621
622 luci::CircleConst *metadata_node = nullptr;
623 for (auto node : loco::output_nodes(main_graph))
624 {
625 auto output_node = loco::must_cast<luci::CircleOutput *>(node);
626
627 // Metadata node should be first output
628 if (output_node->index() != 0)
629 continue;
630
631 // Metadata should be constant and dtype should be S32
632 auto const_node = dynamic_cast<luci::CircleConst *>(output_node->from());
633 if (const_node == nullptr || const_node->dtype() != loco::DataType::S32)
634 continue;
635
636 // Metadata has at least four elements
637 const auto element_cnt = const_node->size<loco::DataType::S32>();
638 if (element_cnt < 4)
639 continue;
640
641 // Metadata has magic numbers at first and at last
642 const auto start_value = const_node->at<loco::DataType::S32>(0);
643 const auto end_value = const_node->at<loco::DataType::S32>(element_cnt - 1);
644 if (start_value == start_magicnum && end_value == end_magicnum)
645 {
646 metadata_node = const_node;
647 break;
648 }
649 }
650
651 if (metadata_node != nullptr)
652 {
653 const auto bcq_version = metadata_node->at<loco::DataType::S32>(1);
654 const auto original_output_cnt = metadata_node->at<loco::DataType::S32>(2);
655
656 if (bcq_version == 1)
657 {
658 const auto bundle_cnt = metadata_node->at<loco::DataType::S32>(3);
659
660 BCQFuser<1> fuser{original_output_cnt, bundle_cnt};
661 fuser.register_bcq_info(main_graph);
662
663 for (size_t g = 0; g < m->size(); ++g)
664 if (fuser.fuseBCQ(m->graph(g)))
665 changed = true;
666 }
667 else
668 {
669 LOGGER(l);
670 WARN(l) << "Not supported BCQ version is found." << std::endl;
671 }
672
673 // Remove all of BCQ information nodes iff there is no change
674 if (changed == false)
675 {
676 for (auto node : loco::output_nodes(main_graph))
677 {
678 auto output_node = loco::must_cast<luci::CircleOutput *>(node);
679 if (output_node->index() == 0 || (int)output_node->index() > original_output_cnt)
680 {
681 auto noOp = main_graph->nodes()->create<luci::CircleOutputExclude>();
682 output_node->from(noOp);
683 changed = true;
684 }
685 }
686 }
687 }
688
689 return changed;
690}
#define LOGGER(name)
Definition Log.h:65
A neural network graph.
Definition Graph.h:161
NodeContext * nodes(void)
Definition Graph.h:218
Derived * create(Args &&...args)
Definition NodePool.h:37
Class to build tensor data.
Definition CircleConst.h:35
const loco::DataTypeImpl< DT >::Type & at(uint32_t n) const
uint32_t size(void) const
CircleOutputExclude is used to specifying not exported nodes.
loco::Node * from(void) const
void index(const loco::GraphOutputIndex &index)
#define WARN(name)
Definition Log.h:70
std::vector< Node * > output_nodes(Graph *)
Definition Graph.cpp:101
CircleOutput * output_node(loco::Graph *g, const loco::GraphOutputIndex &index)
Find a CircleOutput node with a given output index.

References luci::CircleConst::at(), loco::NodePool::create(), luci::CircleOutput::from(), luci::CircleOutput::index(), LOGGER, m, loco::Graph::nodes(), luci::output_node(), loco::output_nodes(), luci::CircleConst::size(), and WARN.

Referenced by package.infer.session::inference().


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