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

Data Structures

class  AnnotatedItem
 
class  AvgPool2D
 2D Average Pooling More...
 
class  BiasAdd
 Produce a value of domain D from an input value (of domain D) and a bias. More...
 
class  BiasAdd< Domain::Feature >
 Add Feature and Bias along "depth" axis. More...
 
class  BiasAdd< Domain::Tensor >
 Add Tensor and Bias. More...
 
class  BiasDecode
 Create a "Tensor" from a "Bias". More...
 
class  BiasEncode
 Create a "Bias" from a "Tensor". More...
 
class  BiasShape
 Bias Shape. More...
 
class  CanonicalDialect
 A singleton for Canonical Dialect. More...
 
struct  CanonicalNode
 
struct  CanonicalNodeDef
 
struct  CanonicalNodeMutableVisitor
 
struct  CanonicalNodeMutableVisitorBase
 
struct  CanonicalNodeVisitor
 
struct  CanonicalNodeVisitorBase
 
struct  CanonicalShapeInferenceRule
 Shape inference rule for canonical dialect. More...
 
struct  CanonicalTypeInferenceRule
 Type Inference Rule for Canonical Dialect. More...
 
class  ConstGen
 Create a value from constant byte array. More...
 
class  Conv2D
 2D Spatial Convolution More...
 
struct  DataTypeImpl
 C++ scalar type corresponding to each DataType. More...
 
struct  DataTypeImpl< DataType::BOOL >
 
struct  DataTypeImpl< DataType::FLOAT16 >
 
struct  DataTypeImpl< DataType::FLOAT32 >
 
struct  DataTypeImpl< DataType::FLOAT64 >
 
struct  DataTypeImpl< DataType::S16 >
 
struct  DataTypeImpl< DataType::S32 >
 
struct  DataTypeImpl< DataType::S4 >
 
struct  DataTypeImpl< DataType::S64 >
 
struct  DataTypeImpl< DataType::S8 >
 
struct  DataTypeImpl< DataType::STRING >
 
struct  DataTypeImpl< DataType::U16 >
 
struct  DataTypeImpl< DataType::U32 >
 
struct  DataTypeImpl< DataType::U4 >
 
struct  DataTypeImpl< DataType::U64 >
 
struct  DataTypeImpl< DataType::U8 >
 
class  DepthwiseConv2D
 Depthwise 2D Convolution. More...
 
class  DepthwiseFilterDecode
 Create a tensor from a depthwise filter. More...
 
struct  DepthwiseFilterDecoder
 Describe how to build a tensor from a depthwise convolution filter. More...
 
class  DepthwiseFilterEncode
 Create a depthwise filter from a tensor. More...
 
struct  DepthwiseFilterEncoder
 Describe how to build a depthwise convolution filter from a tensor. More...
 
class  DepthwiseFilterIndex
 DepthwiseFilter Index. More...
 
class  DepthwiseFilterShape
 DepthwiseFilter Shape. More...
 
class  Dialect
 Dialect interface. More...
 
struct  DialectService
 Dialect Service interface. More...
 
class  Dimension
 The value of one dimension in a tensor shape. More...
 
class  EltwiseAdd
 Elementwise Add lhs and rhs. More...
 
class  EltwiseDiv
 Elementwise Div lhs and rhs. More...
 
class  EltwiseMax
 Elementwise Maximum of lhs and rhs. More...
 
class  EltwiseMul
 Elementwise Mul lhs and rhs. More...
 
class  EltwiseSqrt
 Elementwise Sqrt of input. More...
 
class  EltwiseSub
 Elementwise Sub lhs and rhs. More...
 
class  ErrorDetail
 The details of each error. More...
 
class  ErrorDetail< ErrorCategory::MissingArgument >
 The details of MissingArgument error. More...
 
struct  ErrorListener
 Error listener (with default implementation) More...
 
class  FeatureDecode
 Create a tensor from a feature map. More...
 
struct  FeatureDecoder
 Describe how to build a tensor from a (convolution) feature map. More...
 
class  FeatureEncode
 Create a feature map from a tensor. More...
 
struct  FeatureEncoder
 Decribe how to build a (convolution) feature map from a tensor. More...
 
class  FeatureIndex
 Feature Index. More...
 
class  FeatureShape
 Feature Map Shape. More...
 
class  FilterDecode
 Create a tensor from a filter. More...
 
struct  FilterDecoder
 Decribe how to build a a tensor from a filter. More...
 
class  FilterEncode
 Create a filter from a tensor. More...
 
struct  FilterEncoder
 Decribe how to build a (convolution) filter from a tensor. More...
 
class  FilterIndex
 Filter Index. More...
 
class  FilterShape
 Filter Shape. More...
 
struct  FixedArity
 
class  Forward
 Create a new value identical to its input. More...
 
class  Graph
 A neural network graph. More...
 
class  GraphInput
 Graph-level Input Metadata. More...
 
struct  GraphInputIndexQueryService
 
class  GraphOutput
 Graph-level Output Metadata. More...
 
struct  GraphOutputIndexQueryService
 
struct  IErrorListener
 Error listener interface. More...
 
class  MatMul
 Matrix Multiplication lhs and rhs. More...
 
class  MatrixDecode
 Create Tensor from Matrix. More...
 
struct  MatrixDecoder
 Describe how to build a tensor from a matrix. More...
 
class  MatrixEncode
 Create Matrix from Tensor. More...
 
struct  MatrixEncoder
 Decribe how to build a matrix from a tensor. More...
 
class  MatrixIndex
 Matrix Index. More...
 
class  MatrixShape
 Matrix Shape. More...
 
class  MaxPool2D
 2D Max Pooling More...
 
class  Mixin
 
class  Mixin< Trait::DataTyped >
 
class  Mixin< Trait::TensorShaped >
 
class  MultiDialectShapeInferenceRule
 Shape inference rule for multiple dialects. More...
 
class  MultiDialectTypeInferenceRule
 Type Inference Rule for multiple dialects. More...
 
class  NamedEntity
 Trait for elements with name. More...
 
class  Node
 Logical unit of computation. More...
 
struct  NodeAnnotation
 Extensible Node Metadata. More...
 
class  NodeMixin
 
class  NodeMixin< NodeTrait::DataType >
 
class  NodeMixin< NodeTrait::TensorShape >
 
class  NodePool
 
class  NodeShape
 
class  ObjectPool
 Object Pool. More...
 
class  Padding2D
 
class  PaddingND
 
class  Permutation
 
class  Permutation< Domain::DepthwiseFilter >
 Mapping between DepthwiseFilter/Tensor Axis. More...
 
class  Permutation< Domain::Feature >
 Mapping between Feature/Tensor Axis. More...
 
class  Permutation< Domain::Filter >
 Mapping between Filter/Tensor Axis. More...
 
class  Permutation< Domain::Matrix >
 Mapping between Matrix/Tensor Axis. More...
 
class  PermutingDecoder
 
class  PermutingDecoder< Domain::DepthwiseFilter >
 Permutation-based DepthwiseFilter-to-Tensor converter. More...
 
class  PermutingDecoder< Domain::Feature >
 
class  PermutingDecoder< Domain::Filter >
 Permutation-based Filter-to-Tensor converter. More...
 
class  PermutingDecoder< Domain::Matrix >
 Permutation-based Matrix-to-Tensor converter. More...
 
class  PermutingEncoder
 
class  PermutingEncoder< Domain::DepthwiseFilter >
 Permutation-based Tensor-to-DepthwiseFilter converter. More...
 
class  PermutingEncoder< Domain::Feature >
 
class  PermutingEncoder< Domain::Filter >
 Permutation-based Tensor-to-Filter converter. More...
 
class  PermutingEncoder< Domain::Matrix >
 Permutation-based Tensor-to-Matrix converter. More...
 
class  Pull
 Create a value from user data. More...
 
class  Push
 Make a value visible to user. More...
 
class  ReLU
 Create a new value that rectifies its input. More...
 
class  ReLU6
 Create a new value that rectifies its input capping the units at 6. More...
 
class  Reshape
 
class  Reshape< ReshapeType::Fixed >
 Reshape a tensor to another tensor whose shape is known at compile time. More...
 
struct  ShapeInference
 
struct  ShapeInferenceRule
 
class  ShapeInferenceSession
 
class  Softmax
 Computes softmax activations. More...
 
class  Softmax< Domain::Tensor >
 Computes softmax activations for Tensor domain. More...
 
class  Stride
 Stride configuration for N-dimensional spatial operations. More...
 
class  Stride< 2 >
 Stride configuration for 2D spatial operations. More...
 
class  Subst
 
class  Subst< SubstQualifier::Default >
 A helper for below "replace" helper. More...
 
class  Tanh
 Create a new value that rectifies its input by tanh. More...
 
class  TensorAxisSet
 
class  TensorBroadcast
 Duplicate elements along specified axes. More...
 
class  TensorConcat
 Concatenate two tensors. More...
 
class  TensorConstantPad
 Pads a tensor with constant value. More...
 
class  TensorReduce
 Computes ReduceFunc operations for Tensor domain. More...
 
class  TensorShape
 
class  TensorTranspose
 Permute an input. More...
 
class  TransposedConv2D
 2D Transposed Convolution More...
 
struct  TypeInference
 
struct  TypeInferenceRule
 
class  TypeInferenceSession
 
class  Use
 The edge between a node definition and its user. More...
 
class  Window
 ND Receptive Field Shape. More...
 
class  Window< 2 >
 2D Receptive Field Shape More...
 
struct  With
 

Typedefs

using GraphInputIndex = uint32_t
 
using GraphOutputIndex = uint32_t
 
using FixedReshape = Reshape< ReshapeType::Fixed >
 
using TensorSoftmax = Softmax< Domain::Tensor >
 
using TensorBiasAdd = BiasAdd< Domain::Tensor >
 
using FeatureBiasAdd = BiasAdd< Domain::Feature >
 
using TensorAxis = uint32_t
 
using TensorIndex = nncc::core::ADT::tensor::Index
 

Enumerations

enum class  CanonicalOpcode { CANONICAL_NODE }
 Canonical Node Opcode. More...
 
enum class  DataType {
  Unknown , U4 , U8 , U16 ,
  U32 , U64 , S4 , S8 ,
  S16 , S32 , S64 , FLOAT16 ,
  FLOAT32 , FLOAT64 , BOOL , STRING ,
  MXFP4 , MXINT8
}
 "scalar" value type More...
 
enum class  DepthwiseFilterAxis { Depth , Multiplier , Height , Width }
 
enum class  Domain {
  Unknown , Tensor , Feature , Filter ,
  DepthwiseFilter , Bias , Matrix
}
 Describe the kind of (N-dimensional) loco values. More...
 
enum class  FeatureAxis { Count , Depth , Height , Width }
 
enum class  FilterAxis { Count , Depth , Height , Width }
 
enum class  Trait { DataTyped , TensorShaped }
 
enum class  MatrixAxis { Height , Width }
 
enum class  SubstQualifier { Default }
 
enum class  NodeTrait { DataType , TensorShape }
 
enum class  ReshapeType { Fixed }
 
enum class  ReduceFunc { Mean }
 Reduce type functions. More...
 
enum class  ErrorCategory { MissingArgument }
 Possible error categories. More...
 

Functions

std::ostream & operator<< (std::ostream &os, const loco::FeatureShape &feature_shape)
 dump FeatureShape values to stream
 
std::ostream & operator<< (std::ostream &os, const loco::FilterShape &filter_shape)
 dump FilterShape values to stream
 
std::ostream & operator<< (std::ostream &os, const loco::TensorShape &tensor_shape)
 dump TensorShape values to stream
 
std::ostream & operator<< (std::ostream &os, const loco::Padding2D &pad)
 dump Padding2D values to stream
 
std::vector< loco::Node * > postorder_traversal (const std::vector< loco::Node * > &roots)
 Generate postorder traversal sequence starting from "roots".
 
std::set< loco::Node * > active_nodes (const std::vector< loco::Node * > &roots)
 Enumerate all the nodes required to compute "roots".
 
template<typename T , typename ARG >
_must_cast (ARG arg)
 
uint32_t size (DataType data_type)
 Returns the size of the data type.
 
bool operator== (const Dimension &, const Dimension &)
 Equality operator between two Dimensions.
 
bool operator== (const Dimension &, uint32_t)
 
bool operator== (uint32_t, const Dimension &)
 
Dimension make_dimension (void)
 Make an "unknown" dimension.
 
template<typename T >
must_cast (FeatureEncoder *node)
 A helper dynamic_cast that throws when failed.
 
template<typename T >
must_cast (const FeatureEncoder *node)
 
template<typename T >
must_cast (FeatureDecoder *node)
 
template<typename T >
must_cast (const FeatureDecoder *node)
 
template<typename T >
must_cast (FilterEncoder *node)
 A helper dynamic_cast that throws when failed.
 
template<typename T >
must_cast (const FilterEncoder *node)
 
std::vector< Node * > input_nodes (const Graph *)
 
std::vector< Node * > output_nodes (Graph *)
 
std::set< Node * > all_nodes (Graph *)
 Enumerate all the nodes in a given graph.
 
std::unique_ptr< Graphmake_graph (void)
 
std::set< Node * > preds (const Node *node)
 Enumerate all the predecessors of a given node.
 
std::set< Node * > succs (const Node *node)
 Enumerate all the successors of a given node.
 
Subst< SubstQualifier::Defaultreplace (Node *node)
 
template<typename T >
must_cast (Node *node)
 A helper dynamic_cast that throws when failed.
 
template<typename T >
must_cast (const Node *node)
 
void link (GraphOutput *, Push *push)
 
Pushpush_node (Graph *g, const GraphOutputIndex &index)
 Find a Push node with a given output index.
 
void link (GraphInput *, Pull *pull)
 
Pullpull_node (Graph *g, const GraphInputIndex &index)
 Find a Pull node with a given input index.
 
bool operator== (const NodeShape &lhs, const NodeShape &rhs)
 
uint32_t element_count (const loco::TensorShape *tensor_shape)
 Return the number of elements in a tensor of given shape.
 
bool operator== (const TensorShape &lhs, const TensorShape &rhs)
 '==' operator for TensorShape
 
bool valid (Graph *g, std::unique_ptr< ErrorListener > &&l=nullptr)
 Validate a loco graph.
 
ShapeInferenceSession apply (ShapeInferenceRule *r)
 
bool shape_known (const Node *node)
 
NodeShape shape_get (const Node *node)
 
void shape_erase (Node *node)
 
TypeInferenceSession apply (TypeInferenceRule *r)
 
bool dtype_known (const Node *node)
 
DataType dtype_get (const Node *node)
 
void dtype_erase (Node *node)
 
 INSTANTIATE (DataType::S32)
 
 INSTANTIATE (DataType::FLOAT32)
 
std::ostream & operator<< (std::ostream &os, const loco::Dimension &d)
 

Detailed Description

Push

Pull

ConstGen

TensorBroadcast

Typedef Documentation

◆ FeatureBiasAdd

Definition at line 829 of file Nodes.h.

◆ FixedReshape

Definition at line 523 of file Nodes.h.

◆ GraphInputIndex

using loco::GraphInputIndex = typedef uint32_t

Definition at line 25 of file GraphInputIndex.h.

◆ GraphOutputIndex

using loco::GraphOutputIndex = typedef uint32_t

Definition at line 25 of file GraphOutputIndex.h.

◆ TensorAxis

using loco::TensorAxis = typedef uint32_t

Definition at line 25 of file TensorAxis.h.

◆ TensorBiasAdd

Definition at line 806 of file Nodes.h.

◆ TensorIndex

Definition at line 26 of file TensorIndex.h.

◆ TensorSoftmax

Definition at line 737 of file Nodes.h.

Enumeration Type Documentation

◆ CanonicalOpcode

enum class loco::CanonicalOpcode
strong

Canonical Node Opcode.

WARNING The order is subject to change. DO NOT serialize this value.

Enumerator
CANONICAL_NODE 

Definition at line 28 of file CanonicalOpcode.h.

29{
30#define CANONICAL_NODE(OPCODE, CLASS) OPCODE,
31#include "CanonicalNodes.lst"
32#undef CANONICAL_NODE
33};

◆ DataType

enum class loco::DataType
strong

"scalar" value type

Enumerator
Unknown 
U4 
U8 
U16 
U32 
U64 
S4 
S8 
S16 
S32 
S64 
FLOAT16 
FLOAT32 
FLOAT64 
BOOL 
STRING 
MXFP4 
MXINT8 

Definition at line 26 of file DataType.h.

27{
28 Unknown, // Unknown type (serves as a default value)
29
30 U4, // 4-bit unsigned integer
31 U8, // 8-bit unsigned integer
32 U16, // 16-bit unsigned integer
33 U32, // 32-bit unsigned integer
34 U64, // 64-bit unsigned integer
35
36 S4, // 4-bit signed integer
37 S8, // 8-bit signed integer
38 S16, // 16-bit signed integer
39 S32, // 32-bit signed integer
40 S64, // 64-bit signed integer
41
42 FLOAT16, // IEEE 16-bit floating-point
43 FLOAT32, // IEEE 32-bit floating-point
44 FLOAT64, // IEEE 64-bit floating-point
45
46 // WARNING the size of Bool may vary for NN frameworks
47 // TODO we need to find a way to resolve this issue
48 BOOL, // Boolean
49
50 // WARNING STRING is NOT fully supported yet
51 STRING, // String
52
53 // Microscaling data type
54 MXFP4,
55 MXINT8,
56};

◆ DepthwiseFilterAxis

enum class loco::DepthwiseFilterAxis
strong
Enumerator
Depth 
Multiplier 
Height 
Width 

Definition at line 23 of file DepthwiseFilterAxis.h.

◆ Domain

enum class loco::Domain
strong

Describe the kind of (N-dimensional) loco values.

loco is an intermediate representation for neural network compiler, which mainly focuses on N-dimensional values (usually referred to as Tensor).

There are several special cases for N-dimensional values according to its usage. For example, vision community often refers to 4D array as "FeatureMap".

It is definitely possible to represent all of these special cases using Tensor, but that scheme may introduces some confusion (e.g. NCHW vs NHWC issue).

loco distinguishes these special cases from Tensor in order to reduce such confusion.

This "Domain" enum class enumerates all of these special cases that loco supports.

Enumerator
Unknown 
Tensor 
Feature 
Filter 
DepthwiseFilter 
Bias 
Matrix 

Definition at line 39 of file Domain.h.

40{
41 Unknown,
42 Tensor,
43 Feature,
44 Filter, /* 2D Convolution Filter */
45 DepthwiseFilter, /* Depthwise 2D Convolution Filter */
46 Bias,
47 Matrix,
48 /* ... */
49};

◆ ErrorCategory

enum class loco::ErrorCategory
strong

Possible error categories.

This enum class enumerates all the possible validation failure reasons.

WARN DO NOT serialize this code. The tag value is subject to change.

Enumerator
MissingArgument 

Definition at line 34 of file Verifier.h.

35{
37 /* TO BE ADDED */
38};

◆ FeatureAxis

enum class loco::FeatureAxis
strong
Enumerator
Count 
Depth 
Height 
Width 

Definition at line 23 of file FeatureAxis.h.

24{
25 Count,
26 Depth,
27 Height,
28 Width
29};

◆ FilterAxis

enum class loco::FilterAxis
strong
Enumerator
Count 
Depth 
Height 
Width 

Definition at line 23 of file FilterAxis.h.

24{
25 Count,
26 Depth,
27 Height,
28 Width
29};

◆ MatrixAxis

enum class loco::MatrixAxis
strong
Enumerator
Height 
Width 

Definition at line 23 of file MatrixAxis.h.

24{
25 Height,
26 Width
27};

◆ NodeTrait

enum class loco::NodeTrait
strong
Enumerator
DataType 
TensorShape 

Definition at line 30 of file NodeMixins.h.

31{
33 // Nodes with TensorShape trait will provide the following methods:
34 // - rank()
35 // - rank(value)
36 // - dim()
37 // - dim(value)
38 // - shape({...})
40};
loco::DataType DataType

◆ ReduceFunc

enum class loco::ReduceFunc
strong

Reduce type functions.

Enumerator
Mean 

Definition at line 608 of file Nodes.h.

609{
610 Mean, // ReduceMean
611 // TODO Support other reduce operations
612};

◆ ReshapeType

enum class loco::ReshapeType
strong
Enumerator
Fixed 

Definition at line 489 of file Nodes.h.

490{
491 Fixed, // shape is known at compile time
492 // Add another type for a case when shape is not known at compile time
493};

◆ SubstQualifier

enum class loco::SubstQualifier
strong
Enumerator
Default 

Definition at line 43 of file Node.h.

44{
45 Default, // Replace all the occurrences as "Use" (by default)
46};

◆ Trait

enum class loco::Trait
strong
Enumerator
DataTyped 
TensorShaped 

Definition at line 39 of file Graph.h.

40{
41 // Any "DataTyped" class has the following methods
42 // - DataType dtype(void) const;
43 // - void dtype(const DataType &value);
45 // Any "TensorShaped" class has the following methods
46 // - const TensorShape *shape(void) const;
47 // - void shape(std::unique_ptr<TensorShape> &&);
48 // - void shape(std::initializer_list<Dimension> &&);
49 //
50 // TODO Rename NodeMixin::TensorShape as NodeMixin::NDShape
52};

Function Documentation

◆ _must_cast()

template<typename T , typename ARG >
T loco::_must_cast ( ARG  arg)

Definition at line 28 of file CastHelpers.h.

29{
30 auto cast_arg = dynamic_cast<T>(arg);
31 if (cast_arg == nullptr)
32 {
33 std::string msg = "loco::must_cast() failed to cast: ";
34 msg += typeid(T).name();
35 throw std::invalid_argument(msg.c_str());
36 }
37 return cast_arg;
38}

◆ active_nodes()

std::set< loco::Node * > loco::active_nodes ( const std::vector< loco::Node * > &  roots)

Enumerate all the nodes required to compute "roots".

Definition at line 112 of file Algorithm.cpp.

113{
114 // This implementation works but may be inefficient
115 //
116 // TODO Use efficient implementation if necessary
117 auto nodes = postorder_traversal(roots);
118 return std::set<loco::Node *>{nodes.begin(), nodes.end()};
119}
std::vector< loco::Node * > postorder_traversal(const std::vector< loco::Node * > &roots)
Generate postorder traversal sequence starting from "roots".
Definition Algorithm.cpp:53

References postorder_traversal().

Referenced by fme_apply::check_patterns_valid(), fme_detect::EqualizePatternFinder::find(), moco::test::find_nodes_bytype(), luci::DeadNodeQueryServiceImpl::isDeadNode(), luci::layer_info_map(), mpqsolver::pattern::Q8LayerNormWithQ16VarianceResolver::resolve(), mpqsolver::pattern::Q8SoftmaxWithQ16SubExpResolver::resolve(), mpqsolver::bisection::BisectionSolver::run(), logo::RemoveDeadNodePass::run(), logo::RemoveDeadNodeWithQueryPass::run(), exo::FoldReshapeOfConstPass::run(), exo::FoldTransposeOfConstPass::run(), exo::FuseBiasAddPass::run(), exo::FuseInstanceNormPass::run(), exo::FuseReluPass::run(), exo::FuseRsqrtPass::run(), exo::FuseSquaredDifferencePass::run(), logo::SimplifyDomainConversionPass::run(), luci::CanonicalizePass::run(), luci::ConvertNCHWToNHWCPass::run(), luci::ConvertToFakeQuantizedModelPass::run(), luci::DecomposeHardSwishPass::run(), luci::DecomposeSoftmaxPass::run(), luci::ExpandBroadcastConstPass::run(), luci::FoldAddV2Pass::run(), luci::FoldCastPass::run(), luci::FoldDensifyPass::run(), luci::FoldDepthwiseConv2DPass::run(), luci::FoldDequantizePass::run(), luci::FoldFullyConnectedPass::run(), luci::FoldGatherPass::run(), luci::FoldMulPass::run(), luci::FoldReshapePass::run(), luci::FoldShapePass::run(), luci::FoldSparseToDensePass::run(), luci::FoldSqueezePass::run(), luci::ForwardReshapeToUnaryOpPass::run(), luci::ForwardTransposeOpPass::run(), luci::FuseActivationFunctionPass::run(), luci::FuseAddToFullyConnectedBiasPass::run(), luci::FuseAddWithConvPass::run(), luci::FuseAddWithFullyConnectedPass::run(), luci::FuseAddWithTConvPass::run(), luci::FuseBatchNormWithConvPass::run(), luci::FuseBatchNormWithDwConvPass::run(), luci::FuseBatchNormWithTConvPass::run(), luci::FuseGeluPass::run(), luci::FuseHorizontalFullyConnectedPass::run(), luci::FuseInstanceNormPass::run(), luci::FuseMeanWithMeanPass::run(), luci::FuseMulToFullyConnectedWeightsPass::run(), luci::FuseMulWithConvPass::run(), luci::FuseMulWithDivPass::run(), luci::FuseMulWithFullyConnectedPass::run(), luci::FusePreActivationBatchNormPass::run(), luci::FusePReluPass::run(), luci::FuseRmsNormPass::run(), luci::FuseRoPEPass::run(), luci::FuseRsqrtPass::run(), luci::FuseSliceWithTConvPass::run(), luci::FuseTransposeWithMeanPass::run(), luci::MakeBatchNormGammaPositivePass::run(), luci::PropagateQParamForwardPass::run(), luci::RemoveDuplicateConstPass::run(), luci::RemoveFakeQuantPass::run(), luci::RemoveGatherGuardPass::run(), luci::RemoveQuantDequantSeqPass::run(), luci::RemoveRedundantDequantizePass::run(), luci::RemoveRedundantReshapePass::run(), luci::RemoveRedundantTransposePass::run(), luci::RemoveUnnecessaryAddPass::run(), luci::RemoveUnnecessaryCastPass::run(), luci::RemoveUnnecessaryReshapeNetPass::run(), luci::RemoveUnnecessaryReshapePass::run(), luci::RemoveUnnecessarySlicePass::run(), luci::RemoveUnnecessarySplitPass::run(), luci::RemoveUnnecessaryStridedSlicePass::run(), luci::RemoveUnnecessaryTransposeNetPass::run(), luci::ReplaceMulAddWithDepthwiseConvPass::run(), luci::ReplaceNonConstFCWithBatchMatMulPass::run(), luci::ReplaceSubWithAddPass::run(), luci::ReplaceWithFCGeluFCPass::run(), luci::ResolveCustomOpAddPass::run(), luci::ResolveCustomOpBatchMatMulPass::run(), luci::ResolveCustomOpMatMulPass::run(), luci::ResolveCustomOpMaxPoolWithArgmaxPass::run(), luci::ResolveCustomOpSplitVPass::run(), luci::ResolveFormerCustomOpPass::run(), luci::ShuffleWeightTo16x1Float32Pass::run(), luci::SparsifyTensorPass::run(), luci::SubstituteExpandDimsToReshapePass::run(), luci::SubstitutePackToReshapePass::run(), luci::SubstitutePadV2ToPadPass::run(), luci::SubstituteSplitVToSplitPass::run(), luci::SubstituteSqueezeToReshapePass::run(), luci::SubstituteStridedSliceToReshapePass::run(), luci::SubstituteTransposeToReshapePass::run(), luci::TransformMinMaxToRelu6Pass::run(), luci::TransformMinReluToRelu6Pass::run(), luci::TransformSqrtDivToRsqrtMulPass::run(), luci::UnrollUnidirectionalSequenceLSTMPass::run(), luci::XpSepActFromTransposeConvPass::run(), luci::QuantizeOnnxDequantizeLinearPass::run(), luci::QuantizeOnnxQDQPass::run(), luci::QuantizeWithPredecessorPass::run(), exo::CanonicalNodeConverter< CanonicalType >::run(), exo::TensorBroadcastConverter::run(), exo::MergeConcatNodesPass::run(), fme_apply::FusePostScalePass::run(), fme_apply::FusePreScalePass::run(), luci::CommonSubExpressionEliminationPass::run(), luci::CopyQuantParamPass::run(), luci::ForceQuantParamPass::run(), luci::QuantizeDequantizeWeightsPass::run(), luci::QuantizeDequantizeWeightsWithGPTQPass::run(), luci::QuantizeOnnxFakeQuantModelPass::run(), luci::QuantizeWeightsPass::run(), luci::QuantizeWithMinMaxPass::run(), luci::RequantizePass::run(), luci::QuantizePreCheckerPass::run(), moco::tf::SimpleNodeTransform< ConcreteNode >::run(), moco::ConstantFoldAdd::run(), moco::ConstantFoldMul::run(), moco::ConstantFoldPack::run(), moco::ConstantFoldStridedSlice::run(), moco::FuseBinaryIntoPreceding::run(), moco::ResolveConstantShape::run(), moco::ResolveFusedBatchNorm::run(), moco::ResolveReshapeWildcardDim::run(), moco::ResolveSquaredDifference::run(), moco::SqueezeReduceNode::run(), luci::QuantizedModelVerifier::verify(), and q_implant::QImplant::write().

◆ all_nodes()

std::set< loco::Node * > loco::all_nodes ( loco::Graph g)

Enumerate all the nodes in a given graph.

NOTE This method returns std::set<Node *> unlike input_nodes and output_nodes.

Please use traverse algorithms that "Algorithm.h" provides (such as postorder_traversal) if order is relevant for implementation.

Definition at line 59 of file Graph.cpp.

60{
61 std::set<loco::Node *> res;
62
63 for (uint32_t n = 0; n < g->nodes()->size(); ++n)
64 {
65 res.insert(g->nodes()->at(n));
66 }
67
68 return res;
69}
int32_t size[5]
Definition Slice.cpp:35

References size.

Referenced by locop::FormattedGraphImpl< Formatter::LinearV1 >::dump(), luci::inference_candidates(), luci_interpreter::GraphLoader::loadOperators(), logo::RemoveDeadNodePass::run(), logo::RemoveDeadNodeWithQueryPass::run(), logo::RemoveForwardNodePass::run(), moco::RemoveTFIdentityNode::run(), luci::QuantizeWithMinMaxPass::run(), and q_implant::QImplant::write().

◆ apply() [1/2]

◆ apply() [2/2]

TypeInferenceSession loco::apply ( TypeInferenceRule r)
inline

Definition at line 99 of file TypeInference.h.

◆ dtype_erase()

void loco::dtype_erase ( Node node)
inline

Definition at line 110 of file TypeInference.h.

110{ TypeInference::erase(node); }

References loco::TypeInference::erase().

◆ dtype_get()

◆ dtype_known()

◆ element_count()

uint32_t loco::element_count ( const loco::TensorShape tensor_shape)

Return the number of elements in a tensor of given shape.

NOTE 1.

"volume" returns 1 if the rank is 0.

NOTE 2.

"caller" SHOULD pass a valid shape that has no unknown dimension.

  • The behavior of "volume" on invalid is undefined.

Definition at line 24 of file TensorShape.cpp.

25{
26 uint32_t res = 1;
27
28 for (uint32_t axis = 0; axis < tensor_shape->rank(); ++axis)
29 {
30 // Let's use "assert" here as "caller" is responsible for this check.
31 // Please refer to the header for details.
32 assert(tensor_shape->dim(axis).known());
33 res *= tensor_shape->dim(axis).value();
34 }
35
36 return res;
37}
uint32_t value(void) const
Return the value.
Definition Dimension.h:51
bool known(void) const
Return whether the value is known (or not)
Definition Dimension.h:47
const Dimension & dim(uint32_t axis) const
Definition TensorShape.h:38
uint32_t rank(void) const
Definition TensorShape.h:35

References loco::TensorShape::dim(), loco::Dimension::known(), loco::TensorShape::rank(), and loco::Dimension::value().

◆ input_nodes()

std::vector< Node * > loco::input_nodes ( const Graph g)

Definition at line 71 of file Graph.cpp.

72{
73 std::map<GraphInputIndex, loco::Node *> table;
74
75 for (uint32_t n = 0; n < g->nodes()->size(); ++n)
76 {
77 auto node = g->nodes()->at(n);
78
79 if (auto service = node->dialect()->service<GraphInputIndexQueryService>())
80 {
81 if (service->associated(node))
82 {
83 auto input_index = service->index(node);
84 assert(table.find(input_index) == table.end());
85 table[input_index] = node;
86 }
87 }
88 }
89
90 std::vector<loco::Node *> res;
91
92 for (uint32_t n = 0; n < g->inputs()->size(); ++n)
93 {
94 auto it = table.find(n);
95 res.emplace_back(it == table.end() ? nullptr : it->second);
96 }
97
98 return res;
99}

References size.

Referenced by mpqsolver::bisection::compute_depth(), record_minmax::DirectoryIterator::DirectoryIterator(), minmax_embedder::Embedder::embed(), onert::odc::Embedder::embed(), entry(), mpqsolver::core::H5FileDataProvider::H5FileDataProvider(), record_minmax::HDF5Iterator::HDF5Iterator(), luci_interpreter::GraphLoader::initInputOutputTensors(), luci::DeadNodeQueryServiceImpl::isDeadNode(), record_minmax::ListFileIterator::ListFileIterator(), record_minmax::RecordMinMax::profileData(), record_minmax::RecordMinMax::profileDataInParallel(), record_minmax::RandomIterator::RandomIterator(), mpqsolver::bisection::BisectionSolver::run(), luci::DynamicBatchToSingleBatchPass::run(), prunner::PModelsRunner::run(), dalgona::Dalgona::runAnalysisWithH5Input(), dalgona::Dalgona::runAnalysisWithRandomInput(), dalgona::PythonHooks::startNetworkExecution(), and InterpreterWrapper::writeInputTensor().

◆ INSTANTIATE() [1/2]

loco::INSTANTIATE ( DataType::FLOAT32  )

◆ INSTANTIATE() [2/2]

loco::INSTANTIATE ( DataType::S32  )

◆ link() [1/2]

void loco::link ( GraphInput input,
Pull pull 
)

Definition at line 160 of file Nodes.cpp.

160{ pull->index(input->index()); }
void index(const GraphInputIndex &index)
Definition Nodes.cpp:90

References loco::Pull::index().

◆ link() [2/2]

◆ make_dimension()

Dimension loco::make_dimension ( void  )

Make an "unknown" dimension.

Definition at line 30 of file Dimension.cpp.

30{ return Dimension{}; }
The value of one dimension in a tensor shape.
Definition Dimension.h:30

◆ make_graph()

◆ must_cast() [1/8]

template<typename T >
T loco::must_cast ( const FeatureDecoder node)

Definition at line 95 of file FeatureCodec.h.

96{
97 return _must_cast<T, const FeatureDecoder *>(node);
98}

◆ must_cast() [2/8]

template<typename T >
T loco::must_cast ( const FeatureEncoder node)

Definition at line 85 of file FeatureCodec.h.

86{
87 return _must_cast<T, const FeatureEncoder *>(node);
88}

◆ must_cast() [3/8]

template<typename T >
T loco::must_cast ( const FilterEncoder node)

Definition at line 69 of file FilterCodec.h.

70{
71 return _must_cast<T, const FilterEncoder *>(node);
72}

◆ must_cast() [4/8]

template<typename T >
T loco::must_cast ( const Node node)

Definition at line 151 of file Node.h.

151{ return _must_cast<T, const Node *>(node); }

◆ must_cast() [5/8]

template<typename T >
T loco::must_cast ( FeatureDecoder node)

Definition at line 90 of file FeatureCodec.h.

91{
92 return _must_cast<T, FeatureDecoder *>(node);
93}

◆ must_cast() [6/8]

template<typename T >
T loco::must_cast ( FeatureEncoder node)

A helper dynamic_cast that throws when failed.

Definition at line 80 of file FeatureCodec.h.

81{
82 return _must_cast<T, FeatureEncoder *>(node);
83}

◆ must_cast() [7/8]

template<typename T >
T loco::must_cast ( FilterEncoder node)

A helper dynamic_cast that throws when failed.

Definition at line 64 of file FilterCodec.h.

65{
66 return _must_cast<T, FilterEncoder *>(node);
67}

◆ must_cast() [8/8]

template<typename T >
T loco::must_cast ( Node node)

A helper dynamic_cast that throws when failed.

Definition at line 149 of file Node.h.

149{ return _must_cast<T, Node *>(node); }

◆ operator<<() [1/5]

std::ostream & loco::operator<< ( std::ostream &  os,
const loco::Dimension d 
)

Definition at line 22 of file FormattedTensorShape.cpp.

23{
24 os << (d.known() ? std::to_string(d.value()) : std::string{"?"});
25 return os;
26}

References loco::Dimension::known(), and loco::Dimension::value().

◆ operator<<() [2/5]

std::ostream & loco::operator<< ( std::ostream &  os,
const loco::FeatureShape feature_shape 
)

dump FeatureShape values to stream

Definition at line 22 of file LogHelper.cpp.

23{
24 os << "[" << feature_shape.count().value() << "," << feature_shape.height().value() << ","
25 << feature_shape.width().value() << "," << feature_shape.depth().value() << "]";
26 return os;
27}
const Dimension & depth(void) const
const Dimension & height(void) const
const Dimension & width(void) const
const Dimension & count(void) const

References loco::FeatureShape::count(), loco::FeatureShape::depth(), loco::FeatureShape::height(), loco::Dimension::value(), and loco::FeatureShape::width().

◆ operator<<() [3/5]

std::ostream & loco::operator<< ( std::ostream &  os,
const loco::FilterShape filter_shape 
)

dump FilterShape values to stream

Definition at line 29 of file LogHelper.cpp.

30{
31 os << "[" << filter_shape.height().value() << "," << filter_shape.width().value() << ","
32 << filter_shape.depth().value() << "," << filter_shape.count().value() << "]";
33 return os;
34}
const Dimension & count(void) const
Definition FilterShape.h:48
const Dimension & depth(void) const
Definition FilterShape.h:51
const Dimension & height(void) const
Definition FilterShape.h:54
const Dimension & width(void) const
Definition FilterShape.h:57

References loco::FilterShape::count(), loco::FilterShape::depth(), loco::FilterShape::height(), loco::Dimension::value(), and loco::FilterShape::width().

◆ operator<<() [4/5]

std::ostream & loco::operator<< ( std::ostream &  os,
const loco::Padding2D pad 
)

dump Padding2D values to stream

Definition at line 49 of file LogHelper.cpp.

50{
51 os << "[TLBR " << pad.top() << "," << pad.left() << "," << pad.bottom() << "," << pad.right()
52 << "]";
53
54 return os;
55}
uint32_t left(void) const
Definition Padding2D.h:49
uint32_t top(void) const
Definition Padding2D.h:41
uint32_t bottom(void) const
Definition Padding2D.h:45
uint32_t right(void) const
Definition Padding2D.h:53

References loco::Padding2D::bottom(), loco::Padding2D::left(), loco::Padding2D::right(), and loco::Padding2D::top().

◆ operator<<() [5/5]

std::ostream & loco::operator<< ( std::ostream &  os,
const loco::TensorShape tensor_shape 
)

dump TensorShape values to stream

Definition at line 36 of file LogHelper.cpp.

37{
38 os << "[";
39 for (uint32_t r = 0; r < tensor_shape.rank(); ++r)
40 {
41 if (r)
42 os << ",";
43 os << tensor_shape.dim(r).value();
44 }
45 os << "]";
46 return os;
47}

References loco::TensorShape::dim(), loco::TensorShape::rank(), and loco::Dimension::value().

◆ operator==() [1/5]

bool loco::operator== ( const Dimension lhs,
const Dimension rhs 
)

Equality operator between two Dimensions.

Note
Refer to the definition of equality of dimemsion at https://www.tensorflow.org/api_docs/python/tf/Dimension#__eq__

Definition at line 22 of file Dimension.cpp.

23{
24 return lhs.known() && rhs.known() && lhs.value() == rhs.value();
25}

References loco::Dimension::known(), and loco::Dimension::value().

◆ operator==() [2/5]

bool loco::operator== ( const Dimension lhs,
uint32_t  rhs 
)

Definition at line 27 of file Dimension.cpp.

27{ return lhs.known() && lhs.value() == rhs; }

References loco::Dimension::known(), and loco::Dimension::value().

◆ operator==() [3/5]

bool loco::operator== ( const NodeShape lhs,
const NodeShape rhs 
)

Definition at line 214 of file NodeShape.cpp.

215{
216 if (lhs.domain() != rhs.domain())
217 return false;
218
219 switch (lhs.domain())
220 {
222 {
223 auto lhs_t = lhs.as<TensorShape>();
224 auto rhs_t = rhs.as<TensorShape>();
225 if (lhs_t.rank() != rhs_t.rank())
226 return false;
227 for (uint32_t axis = 0; axis < lhs_t.rank(); ++axis)
228 {
229 if (!(lhs_t.dim(axis) == rhs_t.dim(axis)))
230 return false;
231 }
232 return true;
233 }
234
236 {
237 auto lhs_f = lhs.as<FeatureShape>();
238 auto rhs_f = rhs.as<FeatureShape>();
239
240 return (lhs_f.count() == rhs_f.count() && lhs_f.depth() == rhs_f.depth() &&
241 lhs_f.height() == rhs_f.height() && lhs_f.width() == rhs_f.width());
242 }
243
245 {
246 auto lhs_f = lhs.as<FilterShape>();
247 auto rhs_f = rhs.as<FilterShape>();
248
249 return (lhs_f.count() == rhs_f.count() && lhs_f.depth() == rhs_f.depth() &&
250 lhs_f.height() == rhs_f.height() && lhs_f.width() == rhs_f.width());
251 }
252
254 {
255 auto lhs_f = lhs.as<DepthwiseFilterShape>();
256 auto rhs_f = rhs.as<DepthwiseFilterShape>();
257
258 return (lhs_f.multiplier() == rhs_f.multiplier() && lhs_f.depth() == rhs_f.depth() &&
259 lhs_f.height() == rhs_f.height() && lhs_f.width() == rhs_f.width());
260 }
261
263 {
264 auto lhs_f = lhs.as<BiasShape>();
265 auto rhs_f = rhs.as<BiasShape>();
266
267 return (lhs_f.length() == rhs_f.length());
268 }
269
271 {
272 auto lhs_f = lhs.as<MatrixShape>();
273 auto rhs_f = rhs.as<MatrixShape>();
274
275 return (lhs_f.height() == rhs_f.height() && lhs_f.width() == rhs_f.width());
276 }
277
278 default:
279 throw std::runtime_error("Not supported domain for NodeShape equality");
280 }
281 return false;
282}
ShapeType as(void) const
const Domain & domain(void) const
Definition NodeShape.h:48

References loco::NodeShape::as(), Bias, loco::FeatureShape::count(), loco::FilterShape::count(), loco::DepthwiseFilterShape::depth(), loco::FeatureShape::depth(), loco::FilterShape::depth(), DepthwiseFilter, loco::TensorShape::dim(), loco::NodeShape::domain(), Feature, Filter, loco::DepthwiseFilterShape::height(), loco::FeatureShape::height(), loco::FilterShape::height(), loco::MatrixShape::height(), loco::BiasShape::length(), Matrix, loco::DepthwiseFilterShape::multiplier(), loco::TensorShape::rank(), Tensor, loco::DepthwiseFilterShape::width(), loco::FeatureShape::width(), loco::FilterShape::width(), and loco::MatrixShape::width().

◆ operator==() [4/5]

bool loco::operator== ( const TensorShape lhs,
const TensorShape rhs 
)

'==' operator for TensorShape

Definition at line 44 of file TensorShape.cpp.

45{
46 if (lhs.rank() != rhs.rank())
47 return false;
48 for (uint32_t axis = 0; axis < lhs.rank(); ++axis)
49 {
50 if (!(lhs.dim(axis) == rhs.dim(axis)))
51 return false;
52 }
53 return true;
54}

References loco::TensorShape::dim(), and loco::TensorShape::rank().

◆ operator==() [5/5]

bool loco::operator== ( uint32_t  lhs,
const Dimension rhs 
)

Definition at line 28 of file Dimension.cpp.

28{ return rhs.known() && lhs == rhs.value(); }

References loco::Dimension::known(), and loco::Dimension::value().

◆ output_nodes()

std::vector< loco::Node * > loco::output_nodes ( loco::Graph g)

Definition at line 101 of file Graph.cpp.

102{
103 std::map<GraphOutputIndex, loco::Node *> table;
104
105 for (uint32_t n = 0; n < g->nodes()->size(); ++n)
106 {
107 auto node = g->nodes()->at(n);
108
109 if (auto service = node->dialect()->service<GraphOutputIndexQueryService>())
110 {
111 if (service->associated(node))
112 {
113 auto output_index = service->index(node);
114 assert(table.find(output_index) == table.end());
115 table[output_index] = node;
116 }
117 }
118 }
119
120 std::vector<loco::Node *> res;
121
122 for (uint32_t n = 0; n < g->outputs()->size(); ++n)
123 {
124 auto it = table.find(n);
125 res.emplace_back(it == table.end() ? nullptr : it->second);
126 }
127
128 return res;
129}

References size.

Referenced by fme_apply::check_patterns_valid(), dalgona::PythonHooks::endNetworkExecution(), entry(), luci::exportNodes(), exo::circle_detail::exportOpDefinedTensors(), exo::tflite_detail::exportOpDefinedTensors(), luci::exportOpDefinedTensors(), fme_detect::EqualizePatternFinder::find(), logo::test::find_first_node_by_type(), moco::test::find_nodes_bytype(), luci::inference_candidates(), circle_eval_diff::MAEPrinter::init(), circle_eval_diff::MSEPrinter::init(), circle_eval_diff::MAPEPrinter::init(), circle_eval_diff::MPEIRPrinter::init(), circle_eval_diff::TopKMatchPrinter::init(), luci_interpreter::GraphLoader::initInputOutputTensors(), luci::DeadNodeQueryServiceImpl::isDeadNode(), luci::layer_info_map(), luci_interpreter::GraphLoader::loadOperators(), InterpreterWrapper::readOutputTensor(), mpqsolver::pattern::Q8LayerNormWithQ16VarianceResolver::resolve(), mpqsolver::pattern::Q8SoftmaxWithQ16SubExpResolver::resolve(), mpqsolver::bisection::BisectionSolver::run(), logo::RemoveDeadNodePass::run(), logo::RemoveDeadNodeWithQueryPass::run(), exo::FoldReshapeOfConstPass::run(), exo::FoldTransposeOfConstPass::run(), exo::FuseBiasAddPass::run(), exo::FuseInstanceNormPass::run(), exo::FuseReluPass::run(), exo::FuseRsqrtPass::run(), exo::FuseSquaredDifferencePass::run(), logo::SimplifyDomainConversionPass::run(), luci::CanonicalizePass::run(), luci::ConvertNCHWToNHWCPass::run(), luci::ConvertToFakeQuantizedModelPass::run(), luci::DecomposeHardSwishPass::run(), luci::DecomposeSoftmaxPass::run(), luci::ExpandBroadcastConstPass::run(), luci::FoldAddV2Pass::run(), luci::FoldCastPass::run(), luci::FoldDensifyPass::run(), luci::FoldDepthwiseConv2DPass::run(), luci::FoldDequantizePass::run(), luci::FoldFullyConnectedPass::run(), luci::FoldGatherPass::run(), luci::FoldMulPass::run(), luci::FoldReshapePass::run(), luci::FoldShapePass::run(), luci::FoldSparseToDensePass::run(), luci::FoldSqueezePass::run(), luci::ForwardReshapeToUnaryOpPass::run(), luci::ForwardTransposeOpPass::run(), luci::FuseActivationFunctionPass::run(), luci::FuseAddToFullyConnectedBiasPass::run(), luci::FuseAddWithConvPass::run(), luci::FuseAddWithFullyConnectedPass::run(), luci::FuseAddWithTConvPass::run(), luci::FuseBatchNormWithConvPass::run(), luci::FuseBatchNormWithDwConvPass::run(), luci::FuseBatchNormWithTConvPass::run(), luci::FuseGeluPass::run(), luci::FuseHorizontalFullyConnectedPass::run(), luci::FuseInstanceNormPass::run(), luci::FuseMeanWithMeanPass::run(), luci::FuseMulToFullyConnectedWeightsPass::run(), luci::FuseMulWithConvPass::run(), luci::FuseMulWithDivPass::run(), luci::FuseMulWithFullyConnectedPass::run(), luci::FusePreActivationBatchNormPass::run(), luci::FusePReluPass::run(), luci::FuseRmsNormPass::run(), luci::FuseRoPEPass::run(), luci::FuseRsqrtPass::run(), luci::FuseSliceWithTConvPass::run(), luci::FuseTransposeWithMeanPass::run(), luci::MakeBatchNormGammaPositivePass::run(), luci::PropagateQParamBackwardPass::run(), luci::PropagateQParamForwardPass::run(), luci::RemoveDuplicateConstPass::run(), luci::RemoveFakeQuantPass::run(), luci::RemoveGatherGuardPass::run(), luci::RemoveQDQForMixedPrecisionOpPass::run(), luci::RemoveQuantDequantSeqPass::run(), luci::RemoveRedundantDequantizePass::run(), luci::RemoveRedundantQuantizePass::run(), luci::RemoveRedundantReshapePass::run(), luci::RemoveRedundantTransposePass::run(), luci::RemoveUnnecessaryAddPass::run(), luci::RemoveUnnecessaryCastPass::run(), luci::RemoveUnnecessaryReshapeNetPass::run(), luci::RemoveUnnecessaryReshapePass::run(), luci::RemoveUnnecessarySlicePass::run(), luci::RemoveUnnecessarySplitPass::run(), luci::RemoveUnnecessaryStridedSlicePass::run(), luci::RemoveUnnecessaryTransposeNetPass::run(), luci::ReplaceMulAddWithDepthwiseConvPass::run(), luci::ReplaceNonConstFCWithBatchMatMulPass::run(), luci::ReplaceSubWithAddPass::run(), luci::ReplaceWithFCGeluFCPass::run(), luci::ResolveCustomOpAddPass::run(), luci::ResolveCustomOpBatchMatMulPass::run(), luci::ResolveCustomOpMatMulPass::run(), luci::ResolveCustomOpMaxPoolWithArgmaxPass::run(), luci::ResolveCustomOpSplitVPass::run(), luci::ResolveFormerCustomOpPass::run(), luci::ShuffleWeightTo16x1Float32Pass::run(), luci::SparsifyTensorPass::run(), luci::SubstituteExpandDimsToReshapePass::run(), luci::SubstitutePackToReshapePass::run(), luci::SubstitutePadV2ToPadPass::run(), luci::SubstituteSplitVToSplitPass::run(), luci::SubstituteSqueezeToReshapePass::run(), luci::SubstituteStridedSliceToReshapePass::run(), luci::SubstituteTransposeToReshapePass::run(), luci::TransformMinMaxToRelu6Pass::run(), luci::TransformMinReluToRelu6Pass::run(), luci::TransformSqrtDivToRsqrtMulPass::run(), luci::UnrollUnidirectionalSequenceLSTMPass::run(), luci::XpSepActFromTransposeConvPass::run(), luci::QuantizeOnnxDequantizeLinearPass::run(), luci::QuantizeOnnxQDQPass::run(), luci::QuantizeWithPredecessorPass::run(), exo::CanonicalNodeConverter< CanonicalType >::run(), exo::TensorBroadcastConverter::run(), exo::MergeConcatNodesPass::run(), fme_apply::InsertScaleShift::run(), fme_apply::FusePostScalePass::run(), fme_apply::FusePreScalePass::run(), luci::CommonSubExpressionEliminationPass::run(), luci::CopyQuantParamPass::run(), luci::ForceQuantParamPass::run(), luci::QuantizeDequantizeWeightsPass::run(), luci::QuantizeDequantizeWeightsWithGPTQPass::run(), luci::QuantizeOnnxFakeQuantModelPass::run(), luci::QuantizeWeightsPass::run(), luci::QuantizeWithMinMaxPass::run(), luci::RequantizePass::run(), luci::QuantizePreCheckerPass::run(), moco::tf::SimpleNodeTransform< ConcreteNode >::run(), logo::ConstantFoldingPass::run(), logo::ResolveDuplicateReshapePass::run(), logo::ResolveRedundantReshapePass::run(), moco::ConstantFoldAdd::run(), moco::ConstantFoldMul::run(), moco::ConstantFoldPack::run(), moco::ConstantFoldStridedSlice::run(), moco::FuseBinaryIntoPreceding::run(), moco::ResolveConstantShape::run(), moco::ResolveFusedBatchNorm::run(), moco::ResolveReshapeWildcardDim::run(), moco::ResolveSquaredDifference::run(), moco::SqueezeReduceNode::run(), luci::FuseBCQPass::run(), prunner::PModelsRunner::run(), prunner::PModelsRunner::save_outputs(), loco::ShapeInferenceSession::to(), loco::TypeInferenceSession::to(), luci::QuantizedModelVerifier::verify(), and q_implant::QImplant::write().

◆ postorder_traversal()

std::vector< loco::Node * > loco::postorder_traversal ( const std::vector< loco::Node * > &  roots)

Generate postorder traversal sequence starting from "roots".

HOW TO USE

for (auto node : postorder_traversal(...)) { ... node->do_something() ... }

Definition at line 53 of file Algorithm.cpp.

54{
55 std::vector<loco::Node *> res;
56
57 std::set<loco::Node *> visited_nodes;
58 std::stack<Frame> frames;
59
60 auto visited = [&visited_nodes](loco::Node *node) {
61 return visited_nodes.find(node) != visited_nodes.end();
62 };
63
64 // NOTE There is not much difference between "auto" and "auto &" as node is of "loco::Node *"
65 // type.
66 for (auto node : roots)
67 {
68 assert((node != nullptr) && "root is invalid");
69 frames.push(Frame{node});
70 }
71
72 while (!frames.empty())
73 {
74 auto &top_frame = frames.top();
75
76 if (top_frame.pos() == -1)
77 {
78 if (visited(top_frame.ptr()))
79 {
80 frames.pop();
81 continue;
82 }
83 visited_nodes.insert(top_frame.ptr());
84 }
85
86 top_frame.advance();
87
88 assert(top_frame.pos() >= 0);
89
90 if (top_frame.pos() < static_cast<int64_t>(top_frame.node().arity()))
91 {
92 // Let's visit the next argument
93 //
94 // NOTE "next" may be nullptr if a graph is under construction.
95 if (auto next = top_frame.node().arg(top_frame.pos()))
96 {
97 frames.push(Frame{next});
98 }
99 }
100 else
101 {
102 // Let's visit the current argument (all the arguments are already visited)
103 auto curr = top_frame.ptr();
104 res.emplace_back(curr);
105 frames.pop();
106 }
107 }
108
109 return res;
110}
Logical unit of computation.
Definition Node.h:54

Referenced by active_nodes(), locop::FormattedGraphImpl< Formatter::LinearV1 >::dump(), luci::exportNodes(), exo::circle_detail::exportOpDefinedTensors(), exo::tflite_detail::exportOpDefinedTensors(), luci::exportOpDefinedTensors(), logo::test::find_first_node_by_type(), locomotiv::Session::infer(), luci::inference_candidates(), luci_interpreter::GraphLoader::loadOperators(), luci::ConvertNCHWToNHWCPass::run(), luci::PropagateQParamBackwardPass::run(), luci::RemoveQDQForMixedPrecisionOpPass::run(), luci::RemoveRedundantQuantizePass::run(), fme_apply::InsertScaleShift::run(), logo::ConstantFoldingPass::run(), logo::ResolveDuplicateReshapePass::run(), logo::ResolveRedundantReshapePass::run(), loco::ShapeInferenceSession::to(), and loco::TypeInferenceSession::to().

◆ preds()

std::set< Node * > loco::preds ( const Node node)

Enumerate all the predecessors of a given node.

Definition at line 31 of file Node.cpp.

32{
33 std::set<Node *> res;
34
35 for (uint32_t n = 0; n < node->arity(); ++n)
36 {
37 if (auto pred = node->arg(n))
38 {
39 res.insert(pred);
40 }
41 }
42
43 return res;
44}
virtual Node * arg(uint32_t N) const =0
Access N-th argument node.
virtual uint32_t arity(void) const =0
Return the number of arguments.

References loco::Node::arg(), and loco::Node::arity().

Referenced by luci::fuse_activation_function().

◆ pull_node()

Pull * loco::pull_node ( Graph g,
const GraphInputIndex index 
)

Find a Pull node with a given input index.

Definition at line 162 of file Nodes.cpp.

163{
164 for (uint32_t n = 0; n < g->nodes()->size(); ++n)
165 {
166 if (auto pull = dynamic_cast<Pull *>(g->nodes()->at(n)))
167 {
168 if (pull->indexed() && pull->index() == index)
169 {
170 return pull;
171 }
172 }
173 }
174 return nullptr;
175}
Create a value from user data.
Definition Nodes.h:96

References size.

Referenced by exo::circle_detail::registerGraphIOName(), exo::tflite_detail::registerGraphIOName(), and locomotiv::Session::set_input().

◆ push_node()

Push * loco::push_node ( Graph g,
const GraphOutputIndex index 
)

Find a Push node with a given output index.

Definition at line 67 of file Nodes.cpp.

68{
69 for (uint32_t n = 0; n < g->nodes()->size(); ++n)
70 {
71 if (auto push = dynamic_cast<Push *>(g->nodes()->at(n)))
72 {
73 if (push->indexed() && push->index() == index)
74 {
75 return push;
76 }
77 }
78 }
79 return nullptr;
80}
Make a value visible to user.
Definition Nodes.h:53

References size.

Referenced by exo::circle_detail::registerGraphIOName(), and exo::tflite_detail::registerGraphIOName().

◆ replace()

◆ shape_erase()

void loco::shape_erase ( Node node)
inline

Definition at line 62 of file ShapeInference.h.

62{ ShapeInference::erase(node); }

References loco::ShapeInference::erase().

◆ shape_get()

◆ shape_known()

◆ size()

uint32_t loco::size ( DataType  data_type)
inline

Returns the size of the data type.

Note
If you need the size at compile time, use sizeof(typename DataTypeImpl<DT>::Type).

Definition at line 134 of file DataTypeTraits.h.

135{
136 switch (data_type)
137 {
138 case DataType::S4:
139 throw std::runtime_error("S4 type is not supported by loco::size");
140 case DataType::S8:
142 case DataType::U4:
143 throw std::runtime_error("U4 type is not supported by loco::size");
144 case DataType::U8:
146 case DataType::S16:
148 case DataType::U16:
150 case DataType::S32:
152 case DataType::U32:
154 case DataType::S64:
156 case DataType::U64:
158 case DataType::FLOAT16:
160 case DataType::FLOAT32:
162 case DataType::FLOAT64:
164 case DataType::BOOL:
166 case DataType::STRING:
167 // STRING is variable length. Cannot decide size by type
168 throw std::runtime_error("Invalid size call with STRING type");
169 default:
170 // TODO Support remaining data types.
171 assert(false);
172 return UINT32_MAX; // Avoid compiler warning.
173 }
174}
C++ scalar type corresponding to each DataType.

Referenced by luci::size().

◆ succs()

◆ valid()

bool loco::valid ( Graph g,
std::unique_ptr< ErrorListener > &&  l = nullptr 
)

Validate a loco graph.

"valid" returns true if a given graph has no error.

NOTE Given a valid(non-null) listener, "valid" notifies error details to the listener.

Definition at line 100 of file Verifier.cpp.

101{
102 class ErrorCounter final : public ErrorListener
103 {
104 public:
105 uint32_t count(void) const { return _count; }
106
107 public:
108 void notify(const ErrorDetail<ErrorCategory::MissingArgument> &) { _count += 1; }
109
110 private:
111 uint32_t _count = 0;
112 };
113
114 ErrorCounter counter;
115 graph_verifier(g).enroll(&counter).enroll(std::move(l)).run();
116 return counter.count() == 0;
117}
Error listener (with default implementation)
Definition Verifier.h:83
void notify(const ErrorDetail< ErrorCategory::MissingArgument > &) override
Definition Verifier.h:86

Referenced by loco::Permutation< Domain::DepthwiseFilter >::axis(), loco::Permutation< Domain::DepthwiseFilter >::axis(), loco::Permutation< Domain::Feature >::axis(), loco::Permutation< Domain::Feature >::axis(), loco::Permutation< Domain::Filter >::axis(), loco::Permutation< Domain::Filter >::axis(), loco::Permutation< Domain::Matrix >::axis(), loco::Permutation< Domain::Matrix >::axis(), loco::Permutation< Domain::DepthwiseFilter >::mapped(), loco::Permutation< Domain::Feature >::mapped(), loco::Permutation< Domain::Filter >::mapped(), loco::Permutation< Domain::Matrix >::mapped(), loco::PermutingDecoder< Domain::DepthwiseFilter >::shape(), loco::PermutingDecoder< Domain::Feature >::shape(), loco::PermutingDecoder< Domain::Filter >::shape(), loco::PermutingDecoder< Domain::Matrix >::shape(), loco::PermutingEncoder< Domain::Feature >::shape(), loco::PermutingEncoder< Domain::Filter >::shape(), loco::PermutingEncoder< Domain::DepthwiseFilter >::shape(), loco::PermutingEncoder< Domain::Matrix >::shape(), mir2loco::Transformer::transform(), luci::validate(), luci::validate_shape(), loco::PermutingEncoder< Domain::DepthwiseFilter >::value(), loco::PermutingEncoder< Domain::Feature >::value(), loco::PermutingEncoder< Domain::Filter >::value(), loco::PermutingEncoder< Domain::Matrix >::value(), loco::PermutingDecoder< Domain::Feature >::value(), loco::PermutingDecoder< Domain::Filter >::value(), loco::PermutingDecoder< Domain::DepthwiseFilter >::value(), and loco::PermutingDecoder< Domain::Matrix >::value().