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

Namespaces

namespace  compute
 
namespace  pass
 
namespace  sinf
 
namespace  test
 
namespace  tinf
 

Data Structures

class  BuiltinOperatorMappingRule
 
class  BuiltinOptionsExtractor
 
class  BuiltinOptionsMappingRule
 
struct  CanonicalizePass
 Class to canoncalize CircleNodes. More...
 
class  CircleAbs
 ABS in Circle. More...
 
class  CircleAbsGraphBuilder
 
class  CircleAdd
 ADD in Circle. More...
 
class  CircleAddGraphBuilder
 
class  CircleAddN
 ADD_N in Circle. More...
 
class  CircleAddNGraphBuilder
 
class  CircleArgMax
 ARG_MAX in Circle. More...
 
class  CircleArgMaxGraphBuilder
 
class  CircleArgMin
 ARG_Min in Circle. More...
 
class  CircleArgMinGraphBuilder
 
class  CircleAveragePool2D
 AVERAGE_POOL_2D in Circle. More...
 
class  CircleAveragePool2DGraphBuilder
 
class  CircleBatchMatMul
 BATCH_MATMUL in Circle. More...
 
class  CircleBatchMatMulGraphBuilder
 
class  CircleBatchToSpaceND
 BATCH_TO_SPACE_ND in Circle. More...
 
class  CircleBatchToSpaceNDGraphBuilder
 
class  CircleBCQFullyConnected
 BCQ_FULLY_CONNECTED in Circle. More...
 
class  CircleBCQFullyConnectedGraphBuilder
 
class  CircleBCQGather
 BCQ_GATHER in Circle. More...
 
class  CircleBCQGatherGraphBuilder
 
class  CircleBidirectionalSequenceLSTM
 BIDIRECTIONAL_SEQUENCE_LSTM in Circle. More...
 
class  CircleBidirectionalSequenceLSTMGraphBuilder
 
class  CircleBidirectionalSequenceLSTMOut
 Virtual CIRCLEBIDIRECTIONAL_SEQUENCE_LSTM_OUT in Circle. More...
 
class  CircleBroadcastTo
 BroadcastTo in Circle. More...
 
class  CircleBroadcastToGraphBuilder
 
class  CircleCast
 CAST in Circle. More...
 
class  CircleCastGraphBuilder
 
class  CircleCeil
 CEIL in Circle. More...
 
class  CircleCeilGraphBuilder
 
class  CircleConcatenation
 CONCATENATION in Circle. More...
 
class  CircleConcatenationGraphBuilder
 
class  CircleConst
 Class to build tensor data. More...
 
class  CircleConstNodeBuilder
 Builder creates CircleConst node from Tensor with buffer. More...
 
class  CircleConv2D
 CONV_2D in Circle. More...
 
class  CircleConv2DGraphBuilder
 
class  CircleCos
 COS in Circle. More...
 
class  CircleCosGraphBuilder
 
class  CircleCumSum
 
class  CircleCumSumGraphBuilder
 
class  CircleCustom
 CUSTOM in Circle. More...
 
class  CircleCustomGraphBuilder
 
class  CircleCustomOut
 Virtual CIRCLECUSTOMOUT in Circle. More...
 
class  CircleDensify
 DENSIFY in Circle. More...
 
class  CircleDensifyGraphBuilder
 
class  CircleDepthToSpace
 DEPTH_TO_SPACE in Circle. More...
 
class  CircleDepthToSpaceGraphBuilder
 
class  CircleDepthwiseConv2D
 DEPTHWISE_CONV_2D in Circle. More...
 
class  CircleDepthwiseConv2DGraphBuilder
 
class  CircleDequantize
 DEQUANTIZE in Circle. More...
 
class  CircleDequantizeGraphBuilder
 
class  CircleDialect
 A singleton for Circle Dialect. More...
 
class  CircleDiv
 DIV in Circle. More...
 
class  CircleDivGraphBuilder
 
class  CircleElu
 ELU in Circle. More...
 
class  CircleEluGraphBuilder
 
class  CircleEqual
 EQUAL in Circle. More...
 
class  CircleEqualGraphBuilder
 
class  CircleExp
 EXP in Circle. More...
 
class  CircleExpandDims
 EXPAND_DIMS in Circle. More...
 
class  CircleExpandDimsGraphBuilder
 
class  CircleExpGraphBuilder
 
class  CircleExporter
 
class  CircleExporterImpl
 
class  CircleExportMetadata
 
class  CircleFakeQuant
 FAKE_QUANT in Circle. More...
 
class  CircleFakeQuantGraphBuilder
 
struct  CircleFileExpContract
 
class  CircleFill
 FILL in Circle. More...
 
class  CircleFillGraphBuilder
 
class  CircleFloor
 FLOOR in Circle. More...
 
class  CircleFloorDiv
 FLOOR_DIV in Circle. More...
 
class  CircleFloorDivGraphBuilder
 
class  CircleFloorGraphBuilder
 
class  CircleFloorMod
 FLOOR_MOD in Circle. More...
 
class  CircleFloorModGraphBuilder
 
class  CircleFullyConnected
 FULLY_CONNECTED in Circle. More...
 
class  CircleFullyConnectedGraphBuilder
 
class  CircleGather
 GATHER in Circle. More...
 
class  CircleGatherGraphBuilder
 
class  CircleGatherNd
 GATHER_ND in Circle. More...
 
class  CircleGatherNdGraphBuilder
 
class  CircleGelu
 GELU in Circle. More...
 
class  CircleGeluGraphBuilder
 
class  CircleGreater
 Greater in Circle. More...
 
class  CircleGreaterEqual
 GREATER EQUAL in Circle. More...
 
class  CircleGreaterEqualGraphBuilder
 
class  CircleGreaterGraphBuilder
 
class  CircleGRU
 GRU in Circle. More...
 
class  CircleGRUGraphBuilder
 
class  CircleHardSwish
 HardSwish in Circle. More...
 
class  CircleHardSwishGraphBuilder
 
class  CircleIf
 IF in Circle. More...
 
class  CircleIfGraphBuilder
 
class  CircleIfOut
 Virtual CIRCLEIFOUT in Circle. More...
 
class  CircleImportMetadata
 
class  CircleInput
 CircleNode used for Input of the Graph. More...
 
class  CircleInstanceNorm
 INSTANCE_NORM in Circle. More...
 
class  CircleInstanceNormGraphBuilder
 
class  CircleL2Normalize
 L2_NORMALIZATION in Circle. More...
 
class  CircleL2NormalizeGraphBuilder
 
class  CircleL2Pool2D
 L2_POOL_2D in Circle. More...
 
class  CircleL2Pool2DGraphBuilder
 
class  CircleLeakyRelu
 LEAKY_RELU in Circle. More...
 
class  CircleLeakyReluGraphBuilder
 
class  CircleLess
 LESS in Circle. More...
 
class  CircleLessEqual
 LESS_EQUAL in Circle. More...
 
class  CircleLessEqualGraphBuilder
 
class  CircleLessGraphBuilder
 
class  CircleLocalResponseNormalization
 LOCAL_RESPONSE_NORMALIZATION in Circle. More...
 
class  CircleLocalResponseNormalizationGraphBuilder
 
class  CircleLog
 LOG in Circle. More...
 
class  CircleLogGraphBuilder
 
class  CircleLogicalAnd
 LOGICAL_AND in Circle. More...
 
class  CircleLogicalAndGraphBuilder
 
class  CircleLogicalNot
 LOGICAL_NOT in Circle. More...
 
class  CircleLogicalNotGraphBuilder
 
class  CircleLogicalOr
 LOGICAL_OR in Circle. More...
 
class  CircleLogicalOrGraphBuilder
 
class  CircleLogistic
 LOGISTIC in Circle. More...
 
class  CircleLogisticGraphBuilder
 
class  CircleLogSoftmax
 LOG_SOFTMAX in Circle. More...
 
class  CircleLogSoftmaxGraphBuilder
 
class  CircleMatrixDiag
 MATRIX_DIAG in Circle. More...
 
class  CircleMatrixDiagGraphBuilder
 
class  CircleMatrixSetDiag
 MATRIX_SET_DIAG in Circle. More...
 
class  CircleMatrixSetDiagGraphBuilder
 
class  CircleMaximum
 MAXIMUM in Circle. More...
 
class  CircleMaximumGraphBuilder
 
class  CircleMaxPool2D
 MAX_POOL_2D in Circle. More...
 
class  CircleMaxPool2DGraphBuilder
 
class  CircleMean
 MEAN in Circle. More...
 
class  CircleMeanGraphBuilder
 
class  CircleMinimum
 MINIMUM in Circle. More...
 
class  CircleMinimumGraphBuilder
 
class  CircleMirrorPad
 MIRROR_PAD in Circle. More...
 
class  CircleMirrorPadGraphBuilder
 
class  CircleMul
 MUL in Circle. More...
 
class  CircleMulGraphBuilder
 
class  CircleNeg
 NEG in Circle. More...
 
class  CircleNegGraphBuilder
 
struct  CircleNode
 
class  CircleNodeExecutionPlan
 
struct  CircleNodeImpl
 
class  CircleNodeMixin
 
class  CircleNodeMixin< CircleNodeTrait::Bias >
 Mixin class for nodes that has a bias input. More...
 
class  CircleNodeMixin< CircleNodeTrait::FusedActFunc >
 
struct  CircleNodeMutableVisitor
 
struct  CircleNodeMutableVisitorBase
 
class  CircleNodeOrigin
 
class  CircleNodeSummaryBuilder
 
struct  CircleNodeVisitor
 
struct  CircleNodeVisitorBase
 
class  CircleNodeWithFEATURESSummaryBuilder
 
class  CircleNodeWithINPUTSummaryBuilder
 
class  CircleNodeWithReducerSummaryBuilder
 
class  CircleNodeWithXSummaryBuilder
 
class  CircleNodeWithXYSummaryBuilder
 
class  CircleNonMaxSuppressionV4
 NON_MAX_SUPPRESSION_V4 in Circle. More...
 
class  CircleNonMaxSuppressionV4GraphBuilder
 
class  CircleNonMaxSuppressionV4Out
 Virtual NONMAXSUPPRESSIONV4OUT in Circle. More...
 
class  CircleNonMaxSuppressionV5
 NON_MAX_SUPPRESSION_V5 in Circle. More...
 
class  CircleNonMaxSuppressionV5GraphBuilder
 
class  CircleNonMaxSuppressionV5Out
 Virtual NONMAXSUPPRESSIONV5OUT in Circle. More...
 
class  CircleNotEqual
 NOT EQUAL in Circle. More...
 
class  CircleNotEqualGraphBuilder
 
class  CircleOneHot
 ONEHOT in Circle. More...
 
class  CircleOneHotGraphBuilder
 
class  CircleOptimizer
 
class  CircleOutput
 CircleNode for Output of the Graph. More...
 
class  CircleOutputDummy
 Temporary DummyNode used with dangle CircleNode. More...
 
class  CircleOutputExclude
 CircleOutputExclude is used to specifying not exported nodes. More...
 
class  CirclePack
 PACK in Circle. More...
 
class  CirclePackGraphBuilder
 
class  CirclePad
 PAD in Circle. More...
 
class  CirclePadGraphBuilder
 
class  CirclePadV2
 PADV2 in Circle. More...
 
class  CirclePadV2GraphBuilder
 
class  CirclePow
 POW in Circle. More...
 
class  CirclePowGraphBuilder
 
class  CirclePRelu
 PRelu in Circle. More...
 
class  CirclePReluGraphBuilder
 
class  CircleQuantize
 QUANTIZE in Circle. More...
 
class  CircleQuantizeGraphBuilder
 
class  CircleQuantizer
 
struct  CircleQuantParam
 
class  CircleRange
 RANGE in Circle. More...
 
class  CircleRangeGraphBuilder
 
class  CircleRank
 RANK in Circle. More...
 
class  CircleRankGraphBuilder
 
class  CircleReader
 Loads Circle file and provides helpers to access attributes. More...
 
class  CircleReduceAny
 REDUCE_ANY in Circle. More...
 
class  CircleReduceAnyGraphBuilder
 
class  CircleReduceMax
 REDUCE_MAX in Circle. More...
 
class  CircleReduceMaxGraphBuilder
 
class  CircleReduceMin
 REDUCE_MIN in Circle. More...
 
class  CircleReduceMinGraphBuilder
 
class  CircleReduceProd
 REDUCE_PROD in Circle. More...
 
class  CircleReduceProdGraphBuilder
 
class  CircleRelu
 RELU in Circle. More...
 
class  CircleRelu0To1
 RELU_0_TO_1 in Circle. More...
 
class  CircleRelu0To1GraphBuilder
 
class  CircleRelu6
 RELU6 in Circle. More...
 
class  CircleRelu6GraphBuilder
 
class  CircleReluGraphBuilder
 
class  CircleReluN1To1
 RELU_N1_TO_1 in Circle. More...
 
class  CircleReluN1To1GraphBuilder
 
class  CircleReshape
 RESHAPE in Circle. More...
 
class  CircleReshapeGraphBuilder
 
class  CircleResizeBilinear
 RESIZE_BILINEAR in Circle. More...
 
class  CircleResizeBilinearGraphBuilder
 
class  CircleResizeNearestNeighbor
 RESIZE_NEAREST_NEIGHBOR in Circle. More...
 
class  CircleResizeNearestNeighborGraphBuilder
 
class  CircleReverseSequence
 REVERSE_SEQUENCE in Circle. More...
 
class  CircleReverseSequenceGraphBuilder
 
class  CircleReverseV2
 ReverseV2 in Circle. More...
 
class  CircleReverseV2GraphBuilder
 
class  CircleRmsNorm
 RMS_NORM in Circle. More...
 
class  CircleRmsNormGraphBuilder
 
class  CircleRoPE
 ROPE in Circle. More...
 
class  CircleRoPEGraphBuilder
 
class  CircleRound
 ROUND in Circle. More...
 
class  CircleRoundGraphBuilder
 
class  CircleRsqrt
 RSQRT in Circle. More...
 
class  CircleRsqrtGraphBuilder
 
class  CircleScatterNd
 SCATTER_ND in Circle. More...
 
class  CircleScatterNdGraphBuilder
 
class  CircleSegmentSum
 SEGMENT_SUM in Circle. More...
 
class  CircleSegmentSumGraphBuilder
 
class  CircleSelect
 SELECT in Circle. More...
 
class  CircleSelectGraphBuilder
 
class  CircleSelectV2
 SELECT_V2 in Circle. More...
 
class  CircleSelectV2GraphBuilder
 
class  CircleShape
 SHAPE in Circle. More...
 
class  CircleShapeGraphBuilder
 
class  CircleShapeInferencePass
 Pass to infer shape of circle nodes. More...
 
struct  CircleShapeInferenceRule
 
class  CircleSin
 SIN in Circle. More...
 
class  CircleSinGraphBuilder
 
class  CircleSlice
 SLICE in Circle. More...
 
class  CircleSliceGraphBuilder
 
class  CircleSoftmax
 SOFTMAX in Circle. More...
 
class  CircleSoftmaxGraphBuilder
 
class  CircleSpaceToBatchND
 SPACE_TO_BATCH_ND in Circle. More...
 
class  CircleSpaceToBatchNDGraphBuilder
 
class  CircleSpaceToDepth
 SPACE_TO_DEPTH in Circle. More...
 
class  CircleSpaceToDepthGraphBuilder
 
class  CircleSparseToDense
 SPARSE_TO_DENSE in Circle. More...
 
class  CircleSparseToDenseGraphBuilder
 
class  CircleSplit
 SPLIT in Circle. More...
 
class  CircleSplitGraphBuilder
 
class  CircleSplitOut
 Virtual CIRCLESPLITOUT in Circle. More...
 
class  CircleSplitV
 SPLIT_V in Circle. More...
 
class  CircleSplitVGraphBuilder
 
class  CircleSplitVOut
 Virtual CIRCLESPLITVOUT in Circle. More...
 
class  CircleSqrt
 SQRT in Circle. More...
 
class  CircleSqrtGraphBuilder
 
class  CircleSquare
 SQUARE in Circle. More...
 
class  CircleSquaredDifference
 SQUARED_DIFFERENCE in Circle. More...
 
class  CircleSquaredDifferenceGraphBuilder
 
class  CircleSquareGraphBuilder
 
class  CircleSqueeze
 SQUEEZE in Circle. More...
 
class  CircleSqueezeGraphBuilder
 
class  CircleStridedSlice
 STRIDED_SLICE in Circle. More...
 
class  CircleStridedSliceGraphBuilder
 
class  CircleSub
 SUB in Circle. More...
 
class  CircleSubGraphBuilder
 
class  CircleSum
 SUM in Circle. More...
 
class  CircleSumGraphBuilder
 
class  CircleSVDF
 SVDF in Circle. More...
 
class  CircleSVDFBuilder
 
class  CircleTanh
 TANH in Circle. More...
 
class  CircleTanhGraphBuilder
 
class  CircleTile
 TILE in Circle. More...
 
class  CircleTileGraphBuilder
 
class  CircleTopKV2
 TOPK_V2 in Circle. More...
 
class  CircleTopKV2GraphBuilder
 
class  CircleTopKV2Out
 Virtual CIRCLETOPKV2OUT in Circle. More...
 
class  CircleTranspose
 TRANSPOSE in Circle. More...
 
class  CircleTransposeConv
 TRANSPOSE_CONV in Circle. More...
 
class  CircleTransposeConvGraphBuilder
 
class  CircleTransposeGraphBuilder
 
class  CircleTypeInferencePass
 Pass to infer type of circle nodes. More...
 
struct  CircleTypeInferenceRule
 Type Inference Rule for CircleDialect. More...
 
class  CircleUnidirectionalSequenceLSTM
 UNIDIRECTIONAL_SEQUENCE_LSTM in Circle. More...
 
class  CircleUnidirectionalSequenceLSTMGraphBuilder
 
class  CircleUnique
 Unique in Circle. More...
 
class  CircleUniqueGraphBuilder
 
class  CircleUniqueOut
 Virtual CIRCLEUNIQUEOUT in Circle. More...
 
class  CircleUnpack
 UNPACK in Circle. More...
 
class  CircleUnpackGraphBuilder
 
class  CircleUnpackOut
 Virtual CIRCLEUNPACKOUT in Circle. More...
 
class  CircleVariable
 Virtual CircleVariable in Circle for 'variable' Tensor. More...
 
class  CircleWhere
 WHERE in Circle. More...
 
class  CircleWhereGraphBuilder
 
class  CircleWhile
 WHILE in Circle. More...
 
class  CircleWhileGraphBuilder
 
class  CircleWhileOut
 Virtual CIRCLEWHILEOUT in Circle. More...
 
class  CircleZerosLike
 ZEROS_LIKE in Circle. More...
 
class  CircleZerosLikeGraphBuilder
 
struct  CloneContext
 
class  CloneNode
 
class  CloneNodeLet
 
class  CloneNodeLet< CN::ABC >
 
class  CloneNodeLet< CN::DEF >
 
class  CloneNodeLet< CN::GHIJ >
 
class  CloneNodeLet< CN::KLMN >
 
class  CloneNodeLet< CN::OPQR >
 
class  CloneNodeLet< CN::STUV >
 
class  CloneNodeLet< CN::WXYZ >
 
class  CommonSubExpressionEliminationPass
 Pass to perform CSE (Common Sub-expression Elimination) More...
 
class  CommonSubExpressionEliminationTestGraph
 
class  ConnectNode
 
class  ConstantFoldingAddTestGraph
 
class  ConstantFoldingTestGraph
 
struct  ConvertNCHWToNHWCPass
 Class to convert NCHW Ops to NHWC. More...
 
struct  ConvertToFakeQuantizedModelPass
 Class to convert a quantized model to a fake-quantized fp32 model. More...
 
class  CopyQuantParamPass
 Pass to copy quantparam (scale, zerop) of a tensor to another tensor. More...
 
struct  DeadNodeQueryServiceImpl
 
struct  DecomposeHardSwishPass
 Class to decompose HardSwish to Add, Mul and Relu6. More...
 
struct  DecomposeSoftmaxPass
 Class to decompose Softmax into backend friendly structures. More...
 
class  Dilation
 
class  DimMetaData
 
class  DynamicBatchToSingleBatchPass
 Pass to convert dynamic batch to single batch. More...
 
struct  ExpandBroadcastConstPass
 Class to remove broadcasts of Const nodes. More...
 
struct  ExportContext
 
class  Filter
 
class  FixedArityNode
 Nodes with the fixed number of inputs. More...
 
struct  FoldAddV2Pass
 Class to fold AddV2 to a constant tensor. More...
 
struct  FoldCastPass
 Class to fold Cast to a constant tensor. More...
 
struct  FoldDensifyPass
 Class to Fold Densify if input is Sparse Constant. More...
 
struct  FoldDepthwiseConv2DPass
 Class to fold DepthwiseConv2D with constant input and filter into a constant tensor. More...
 
struct  FoldDequantizePass
 Class to fold Dequantize, which can be folded by constant inputs. More...
 
struct  FoldFullyConnectedPass
 Class to fold FullyConnected with constant input and filter into a constant tensor. More...
 
struct  FoldGatherPass
 Class to fold Gather to a constant tensor. More...
 
struct  FoldMulPass
 Class to fold Mul to a constant tensor. More...
 
struct  FoldReshapePass
 Class to fold Reshape to a constant tensor. More...
 
struct  FoldShapePass
 Class to fold Shape to a constant tensor. More...
 
struct  FoldSparseToDensePass
 Class to fold SparseToDense to a constant tensor. More...
 
struct  FoldSqueezePass
 Class to fold Squeeze to a constant tensor. More...
 
class  ForceQuantParamPass
 Pass to write quantparam (scale, zerop) to the specified tensors. More...
 
struct  ForwardReshapeToUnaryOpPass
 Class to Forward send Reshape after UnaryOp. More...
 
struct  ForwardTransposeOpPass
 Class to Forward Transpose Ops for further optimization. More...
 
struct  FuseActivationFunctionPass
 Class to fuse activation functions into preceding operators. More...
 
struct  FuseAddToFullyConnectedBiasPass
 Class to fuse Add to following FC bias. More...
 
struct  FuseAddWithConvPass
 Class to fuse CircleAdd into CircleConv2D. More...
 
struct  FuseAddWithFullyConnectedPass
 Class to fuse Add into FullyConnected. More...
 
struct  FuseAddWithTConvPass
 Class to fuse Add into CircleTransposeConv. More...
 
struct  FuseBatchNormWithConvPass
 Class to fuse Batch Normalization into CircleConv. More...
 
struct  FuseBatchNormWithDwConvPass
 Class to fuse Batch Normalization into CircleDepthWiseConv2D. More...
 
struct  FuseBatchNormWithTConvPass
 Class to fuse Batch Normalization into CircleTransposeConv. More...
 
struct  FuseBCQPass
 Class to fuse certain pattern of subgraph into CircleBCQFullyConnected or CircleBCQGather. More...
 
struct  FuseGeluPass
 Class to fuse certain pattern of subgraph into CircleGelu. More...
 
struct  FuseHorizontalFullyConnectedPass
 
struct  FuseInstanceNormPass
 Class to fuse certain pattern of subgraph into CircleInstanceNorm with auxiliary nodes. More...
 
struct  FuseMeanWithMeanPass
 Class to fuse two Mean operations follow one by one into one Mean with merge reduction indices. More...
 
struct  FuseMulToFullyConnectedWeightsPass
 Class to fuse Mul into following FullyConnected. More...
 
struct  FuseMulWithConvPass
 Class to fuse Mul operation with a preceding Conv. More...
 
struct  FuseMulWithDivPass
 Class to fuse Mul operation with a Div operation. More...
 
struct  FuseMulWithFullyConnectedPass
 Class to fuse Mul into CircleFullyConnected. More...
 
struct  FusePreActivationBatchNormPass
 Class to fuse batch normalization of pre-activation. More...
 
struct  FusePReluPass
 Class to fuse certain pattern of subgraph into CirclePRelu with auxiliary nodes. More...
 
struct  FuseRmsNormPass
 Class to fuse certain pattern of subgraph into CircleRmsNorm. More...
 
struct  FuseRoPEPass
 Class to fuse certain pattern of subgraph into CircleRoPE with auxiliary nodes. More...
 
struct  FuseRsqrtPass
 Class to fuse certain pattern of subgraph into CircleRsqrt. More...
 
struct  FuseSliceWithTConvPass
 Class to fuse Slice operation with a preceding TConv. More...
 
struct  FuseTransposeWithMeanPass
 Class to fuse Mean operation with a preceding Transpose. More...
 
class  GraphBuilder
 Base of general single output graph builder(e.g., Conv2DGraphBuilder) More...
 
struct  GraphBuilderBase
 Interface of convert circle::OperatorT to CircleNode. More...
 
class  GraphBuilderContext
 Class to store context to build loco graph IR from TensorFlow. More...
 
class  GraphBuilderMultiOutput
 Base of general multiple outputs graph builder(e.g., CircleIfGraphBuilder) More...
 
class  GraphBuilderRegistry
 Class to return graph builder for Circle nodes. More...
 
struct  GraphBuilderSource
 
class  Importer
 
class  ImporterEx
 
class  IndexNodeFinder
 
class  IndexTensorOutputs
 Set of Tensor Index of outputs of operators including graph input nodes. More...
 
struct  InsertQuantizeOpOnDTypeMismatch
 
struct  LayerInfo
 
class  Logger
 Logger Implementation. More...
 
class  LoggerConfig
 Logger Configuration. More...
 
struct  LoggingContext
 Global logging context. More...
 
struct  MakeBatchNormGammaPositivePass
 Class to make negative gamma of batchnorm to a small positive value (1e-10) This pass can change the execution result of the model. So, use it only when the impact is known to be acceptable. More...
 
class  Module
 Collection of 'loco::Graph's. More...
 
class  ModuleProgressReporter
 
class  NodeBuilderBase
 Creates nodes from given Tensor and context. More...
 
class  NodeFiller
 
class  NodeSummaryBuilder
 
class  NodeSummaryBuilderFactory
 
struct  OpCode
 
class  OperationExporterRule
 
struct  PartedModule
 PartedModule holds partitioned module and group name. More...
 
struct  PartedModules
 
struct  PartitionTable
 PartitionTable holds partition information. More...
 
class  Pass
 
struct  PGroup
 Partition Group with Partition Nodes of same group and I/Os nodes. More...
 
struct  PGroups
 
class  PhaseRunner
 
class  PhaseRunner< logo::PhaseStrategy::Restart >
 
class  PhaseRunner< logo::PhaseStrategy::Saturate >
 
struct  PNode
 Partition Node with CircleNode with group name. More...
 
class  ProgressReporter
 
struct  PropagateQParamBackwardPass
 Class to propagate quantization parameters of an operator's output to input. More...
 
struct  PropagateQParamForwardPass
 Class to propagate quantization parameters of an operator's input to output. More...
 
struct  QuantizeActivation
 Quantize non-const activation using recorded min/max values. More...
 
struct  QuantizeBias
 QuantizeBias quantizes tensors for bias. More...
 
struct  QuantizeConstInputActivation
 
class  QuantizeDequantizeWeightsPass
 Pass to quantize weights. More...
 
class  QuantizeDequantizeWeightsWithGPTQPass
 Pass to quantize weights with GPTQ algorithm. More...
 
struct  QuantizedModelVerifier
 Class to verify quantized model. More...
 
struct  QuantizeOnnxDequantizeLinearPass
 Class to quantize ONNXDequantizeLinear operator. More...
 
class  QuantizeOnnxFakeQuantModelPass
 Pass to create a quantized graph from a graph fake-quantized on onnx. More...
 
struct  QuantizeOnnxQDQPass
 Class to quantize ONNX QuantizeLinear-DequantizeLinear operator. More...
 
class  QuantizePreCheckerPass
 Pass to verify the input model has the form acceptable by quantizer. More...
 
struct  QuantizeSpecialActivation
 Quantize non-const activaion using pre-defined scale/zp for special Ops. More...
 
struct  QuantizeWeights
 QuantizeWeights quantizes tensors for weights. More...
 
struct  QuantizeWeightsOnly
 QuantizeWeightsOnly quantizes tensors for weights. More...
 
class  QuantizeWeightsPass
 Pass to quantize weights. More...
 
class  QuantizeWithMinMaxPass
 Pass to quantize activation, weights, and bias. More...
 
struct  QuantizeWithPredecessorPass
 Class to quantize nodes using their predecessors' qparam. More...
 
struct  RemoveDuplicateConstPass
 Class to remove duplicate Const nodes. More...
 
struct  RemoveFakeQuantPass
 Class to Remove FakeQuant node. More...
 
struct  RemoveGatherGuardPass
 Class to remove Add+FloorMod guard ops of Gather. More...
 
struct  RemoveQDQForMixedPrecisionOpPass
 Class to remove QDQ pattern for mixed-precision Ops. More...
 
struct  RemoveQuantDequantSeqPass
 Class to Remove Quantize-Dequantize sequence. More...
 
struct  RemoveRedundantDequantizePass
 Class to remove redundant dequantize operations. More...
 
struct  RemoveRedundantQuantizePass
 Class to remove redundant quantize operations. More...
 
struct  RemoveRedundantReshapePass
 Class to remove redundant Reshape node into 1 Reshape node. More...
 
struct  RemoveRedundantTransposePass
 fuse or remove subsequent Transpose operators More...
 
struct  RemoveUnnecessaryAddPass
 Class to temove unnecessary(input and output are same) Add node. More...
 
struct  RemoveUnnecessaryCastPass
 Class to remove unnecessary Cast nodes. More...
 
struct  RemoveUnnecessaryReshapeNetPass
 Class to remove unnecessary Reshape nodes. More...
 
struct  RemoveUnnecessaryReshapePass
 Class to Remove Unnecessary(input shape and output shape same) Reshape node. More...
 
struct  RemoveUnnecessarySlicePass
 Class to Remove Unnecessary(input and output are same) Slice node. More...
 
struct  RemoveUnnecessarySplitPass
 Remove unnecessary Split OP. More...
 
struct  RemoveUnnecessaryStridedSlicePass
 Class to Remove Unnecessary(input and output are same) StridedSlice node. More...
 
struct  RemoveUnnecessaryTransposeNetPass
 
struct  ReplaceMulAddWithDepthwiseConvPass
 Class to replace channel-wise mul/add with CircleDepthwiseConv2D. More...
 
struct  ReplaceNonConstFCWithBatchMatMulPass
 Class to replace "FC with non-const weight" with Batched MatMul. More...
 
struct  ReplaceSubWithAddPass
 Class to Replace Sub With Add. More...
 
struct  ReplaceWithFCGeluFCPass
 Class to generate FC-Gelu-FC from a certain Op pattern. More...
 
class  RequantizePass
 Pass to re-quantize graph (ex: int8 -> uint8) More...
 
struct  ResolveCustomOpAddPass
 Class to resolve certain custom op of subgraph into add op in circle schema. More...
 
struct  ResolveCustomOpBatchMatMulPass
 Class to resolve certain custom op of subgraph into batchmatmul op in circle schema. More...
 
struct  ResolveCustomOpMatMulPass
 Class to resolve certain custom op of subgraph into matmul op in circle schema. More...
 
struct  ResolveCustomOpMaxPoolWithArgmaxPass
 Class to resolve custom op MaxPoolWithArgmax to subgraph with circle's MaxPool and ArgMax. More...
 
struct  ResolveCustomOpSplitVPass
 Class to resolve certain custom op of subgraph into splitv op in circle schema. More...
 
struct  ResolveFormerCustomOpPass
 Class to convert a custom operator to a built-in operator. More...
 
struct  SerializedGraphData
 
struct  SerializedModelData
 
struct  ShapeDescription
 
struct  ShuffleWeightTo16x1Float32Pass
 Class to convert weight format of FullyConnected to SHUFFLED16x1FLOAT32. More...
 
class  SparseIndexVector
 
class  Sparsifier
 
struct  SparsifyTensorPass
 Pass to sparsify tensor. More...
 
struct  SparsityParam
 
class  Stride
 
struct  SubGraphContext
 Record the information of T/F Lite SubGraph and its mapping to loco. More...
 
struct  SubstituteExpandDimsToReshapePass
 Class to substitute ExpandDims to single reshape node. More...
 
struct  SubstitutePackToReshapePass
 Class to Substitute Pack with 1 input to single reshape node. More...
 
struct  SubstitutePadV2ToPadPass
 Class to substitute PadV2 in certain condition to Pad. More...
 
struct  SubstituteSplitVToSplitPass
 Class to substitute certain SplitV to Split. More...
 
struct  SubstituteSqueezeToReshapePass
 Class to Substitute Squeeze to Reshape node for certain conditions. More...
 
struct  SubstituteStridedSliceToReshapePass
 Class to substitute Strided_Slice with certain condition to single reshape node. More...
 
struct  SubstituteTransposeToReshapePass
 Class to Substitute Transpose with certain input shape condition to single reshape node. More...
 
struct  TransformMinMaxToRelu6Pass
 Class to transform Maximum(Minimum(input, 6), 0) to Relu6. More...
 
struct  TransformMinReluToRelu6Pass
 Class to transform Relu(Minimum(input, 6)) to Relu6. More...
 
struct  TransformSqrtDivToRsqrtMulPass
 Class to transform Div(X,Sqrt(y)) to Mul(X,Rsqrt(y)) More...
 
class  TypedNodeBuilder
 Placeholder for builders of tensors with different types. More...
 
struct  TypeMapper
 TypeMapper maps between c++ primitive data type and loco::DataType. More...
 
struct  TypeMapper< float >
 
struct  TypeMapper< int16_t >
 
struct  TypeMapper< int32_t >
 
struct  TypeMapper< int64_t >
 
struct  TypeMapper< int8_t >
 
struct  TypeMapper< uint16_t >
 
struct  TypeMapper< uint32_t >
 
struct  TypeMapper< uint64_t >
 
struct  TypeMapper< uint8_t >
 
struct  UnrollUnidirectionalSequenceLSTMPass
 Class to Unroll UnidirectionalSequenceLSTM. More...
 
struct  UserSettings
 UserSettings provides user settings by key-value. More...
 
class  UserSettingsImpl
 
class  VariadicArityNode
 Nodes with the variadic inputs. More...
 
class  VectorWrapper
 Wrapper to use flatbuffers::Vector pointer as std::vector entity. More...
 
class  VerifyQuantizedBiasScale
 Verify the scale of quantized bias node. More...
 
class  VerifyQuantizedNodeChannelWiseGranularity
 
class  VerifyQuantizedNodeGranularity
 Verify the granualrity of quantized node. More...
 
class  VerifyQuantizedNodeLayerWiseGranularity
 
class  VerifyQuantizedNodeS16Type
 
class  VerifyQuantizedNodeType
 Verify the data type of quantized node. More...
 
class  VerifyQuantizedNodeTypeBase
 Verify using quantization type of a node and bias. More...
 
class  VerifyQuantizedNodeU8Type
 
struct  VirtualOutputDetector
 
struct  XpSepActFromTransposeConvPass
 Experimental Class to separate activation functions from TransposeConv. More...
 

Typedefs

using CircleTensorIndex = int32_t
 
using TensorIndex = int32_t
 
using OriginTable = std::map< uint32_t, std::shared_ptr< CircleNodeOrigin > >
 
using NodeName = std::string
 
using ExecutionPlanTable = std::map< uint32_t, std::vector< uint32_t > >
 
using LuciNodeTrait = CircleNodeTrait
 
template<LuciNodeTrait T>
using LuciNodeMixin = CircleNodeMixin< T >
 
using FormattedGraph = locop::FormattedGraphImpl< locop::Formatter::LinearV1 >
 
using MapNode2Clone = std::map< const CircleNode *, CircleNode * >
 
using GroupKey = std::string
 
using HessianMap = std::unordered_map< const luci::CircleNode *, std::vector< float > >
 
using LayerInfoMap = std::unordered_map< std::string, luci::LayerInfo >
 
using Phase = std::vector< std::unique_ptr< Pass > >
 
using CircleNodeID = uint32_t
 

Enumerations

enum class  NodeBuilderType { BUFFER }
 Tensor types which requires separated node. More...
 
enum class  FusedActFunc {
  UNDEFINED , NONE , RELU , RELU_N1_TO_1 ,
  RELU6 , TANH , SIGN_BIT
}
 
enum class  MirrorPadMode { UNDEFINED , REFLECT , SYMMETRIC }
 
enum class  Padding { UNDEFINED , SAME , VALID }
 
enum class  RoPEMode { UNDEFINED , GPT_NEOX , GPT_J }
 
enum class  CircleNodeTrait { FusedActFunc , Bias }
 enumeration of mixin class More...
 
enum class  CircleOpcode { CIRCLE_NODE , CIRCLE_VNODE }
 
enum class  ShapeStatus { UNDEFINED , NOSHAPE , VALID }
 ShapeStatus is to remember circle node shape status. More...
 
enum  DimensionType { DENSE , SPARSE_CSR }
 
enum  SparseIndexVectorType { NONE , I32 , U16 , U8 }
 
enum  QuantizationGranularity { LayerWise = 0 , ChannelWise = 1 }
 
enum  ActivationQType {
  MinMax , PreDefinedLogistic , PreDefinedTanh , PreDefinedSoftmax ,
  IntScale
}
 
enum class  CN {
  ABC , DEF , GHIJ , KLMN ,
  OPQR , STUV , WXYZ
}
 

Functions

circle::ActivationFunctionType to_circle_actfunc (luci::FusedActFunc func)
 
circle::TensorType to_circle_tensortype (loco::DataType type)
 
circle::MirrorPadMode to_circle_mirrorpadmode (luci::MirrorPadMode mode)
 
circle::RoPEMode to_circle_rope (luci::RoPEMode mode)
 
circle::FullyConnectedOptionsWeightsFormat to_circle_weightsformat (luci::CircleFullyConnected::WeightsFormat format)
 
circle::DimensionType to_circle_dimensiontype (luci::DimensionType type)
 
flatbuffers::Offset< void > to_circle_sparse_index_vector (flatbuffers::FlatBufferBuilder &fb, const SparseIndexVector &sparse_idx_vec)
 
circle::SparseIndexVector to_circle_sparse_index_vector_type (luci::SparseIndexVectorType type)
 
circle::BuiltinOperator circle_builtin_operator (const luci::CircleNode *node)
 
circle::BuiltinOptions circle_builtin_options (const luci::CircleNode *node)
 
std::string circle_custom_code (const luci::CircleNode *node)
 
flatbuffers::Offset< flatbuffers::Vector< uint8_t > > circle_custom_options (flatbuffers::FlatBufferBuilder &fb, const luci::CircleNode *node)
 
circle::Padding getOpPadding (const loco::Padding2D *pad, const loco::Stride< 2 > *stride, const ShapeDescription &ifm, const ShapeDescription &ofm)
 
circle::Padding getOpPadding (const luci::Padding pad)
 
void set_tensor_index (loco::Node *node, const CircleTensorIndex &tensor_id)
 
void clear_tensor_index (loco::Node *node)
 
CircleTensorIndex get_tensor_index (loco::Node *node)
 
bool check_size_limit (const flatbuffers::FlatBufferBuilder &fb, const uint64_t data_size)
 
std::vector< flatbuffers::Offset< circle::Metadata > > createCircleMetadataVector (flatbuffers::FlatBufferBuilder &builder, SerializedModelData &md)
 Create Metadata corresponding to model metadata.
 
void exportNodes (loco::Graph *g, flatbuffers::FlatBufferBuilder &builder, SerializedModelData &md, SerializedGraphData &gd)
 create Operators corresponding to model nodes
 
void prepareModelData (flatbuffers::FlatBufferBuilder &builder, SerializedModelData &md)
 one time preparation for SerializedModelData
 
void exportOpDefinedTensors (loco::Graph *g, flatbuffers::FlatBufferBuilder &builder, SerializedModelData &md, SerializedGraphData &gd)
 create Tensors corresponding to results of all nodes in graph
 
void clearExportInfo (loco::Graph *g)
 clear temporary export information annotated to graph nodes
 
const char * tensor_name (const circle::Tensor *tensor)
 
const circle::QuantizationParameters * tensor_quantization (const circle::Tensor *tensor)
 
loco::DataType luci_datatype (circle::TensorType type)
 
FusedActFunc luci_actfunc (const circle::ActivationFunctionType type)
 
Padding luci_padding (const circle::Padding padding)
 
MirrorPadMode luci_mirrorpad_mode (const circle::MirrorPadMode mode)
 
RoPEMode luci_rope_mode (const circle::RoPEMode mode)
 
luci::CircleFullyConnected::WeightsFormat luci_weights_format (const circle::FullyConnectedOptionsWeightsFormat weights_format)
 
std::unique_ptr< CircleQuantParamluci_quantparam (const circle::QuantizationParameters *quantization)
 
void copy_tensor_attributes (const circle::Tensor *tensor, CircleNode *node)
 Copy common tensor attributes such as name, type, etc. to node.
 
std::string fb_string2std_string (const flatbuffers::String *fb_str)
 
template<typename T >
VectorWrapper< T > wrap (const flatbuffers::Vector< T > *vec)
 
CircleVariablecreate_circlevariable (GraphBuilderContext *context, int32_t tensor_index)
 
DimensionType luci_dim_type (const circle::DimensionType dim_type)
 
SparseIndexVector luci_sparse_index_vector (const circle::SparseIndexVectorUnion &sparse_index_vector)
 
std::unique_ptr< CircleQuantParamluci_quantparam (const circle::QuantizationParametersT *quantization)
 
std::unique_ptr< SparsityParamluci_sparsityparam (const circle::SparsityParametersT *sparsity)
 
std::unique_ptr< SparsityParamluci_sparsityparam (const circle::SparsityParameters *sparparam)
 
 REGISTER_WRAPPER (flatbuffers::Offset< circle::SubGraph >)
 
 REGISTER_WRAPPER (flatbuffers::Offset< circle::Buffer >)
 
 REGISTER_WRAPPER (flatbuffers::Offset< circle::Tensor >)
 
 REGISTER_WRAPPER (flatbuffers::Offset< circle::Operator >)
 
 REGISTER_WRAPPER (flatbuffers::Offset< circle::OperatorCode >)
 
 REGISTER_WRAPPER (flatbuffers::Offset< circle::Metadata >)
 
 REGISTER_WRAPPER (int32_t)
 
 REGISTER_WRAPPER (uint8_t)
 
bool validate_batch_space_nd (const GraphBuilderBase::ValidateArgs &args)
 
bool validate_minmax (const GraphBuilderBase::ValidateArgs &args)
 
bool validate_reduce_minmax (const GraphBuilderBase::ValidateArgs &args)
 
void link (loco::GraphOutput *, CircleOutput *)
 Link GraphOutput with CircleOutput node.
 
void link (loco::GraphInput *, CircleInput *)
 Link GraphInput with CircleInput node.
 
CircleOutputoutput_node (loco::Graph *g, const loco::GraphOutputIndex &index)
 Find a CircleOutput node with a given output index.
 
CircleInputinput_node (loco::Graph *g, const loco::GraphInputIndex &index)
 Find a Pull node with a given input index.
 
void copy_quantparam (const luci::CircleNode *src, luci::CircleNode *dst)
 copy CircleQuantParam of src to dst
 
uint32_t size (loco::DataType data_type)
 Returns the size of the data type.
 
std::unique_ptr< Modulemake_module (void)
 
 INSTANTIATE (loco::DataType::S64)
 
 INSTANTIATE (loco::DataType::S32)
 
 INSTANTIATE (loco::DataType::S16)
 
 INSTANTIATE (loco::DataType::S8)
 
 INSTANTIATE (loco::DataType::S4)
 
 INSTANTIATE (loco::DataType::FLOAT32)
 
 INSTANTIATE (loco::DataType::U8)
 
 INSTANTIATE (loco::DataType::U4)
 
 INSTANTIATE (loco::DataType::BOOL)
 
 INSTANTIATE (loco::DataType::FLOAT16)
 
template<>
uint32_t CircleConst::size< loco::DataType::STRING > (void) const
 
template<>
void CircleConst::size< loco::DataType::STRING > (uint32_t l)
 
template<>
const std::string & CircleConst::at< loco::DataType::STRING > (uint32_t n) const
 
template<>
std::string & CircleConst::at< loco::DataType::STRING > (uint32_t n)
 
template<>
const std::string & CircleConst::scalar< loco::DataType::STRING > (void) const
 
template<>
std::string & CircleConst::scalar< loco::DataType::STRING > (void)
 
FormattedGraph fmt (loco::Graph *g)
 
void clone_connect (const luci::CircleNode *node, luci::CloneContext &clonecontext)
 Connect cloned node from input node.
 
PartedModules apply (Module *module, const PartitionTable &partition)
 Method to do paritioning from module and PartitionTable to produce PartedModules.
 
bool validate (luci::PartitionTable &partition)
 
std::string opcode_name (const CircleNode *node)
 
void remove_unused_inputoutputs (luci::PGroups *, const luci::Module *)
 This will remove unused inputs/outputs in each pgroup of pgroups.
 
void dump (std::ostream &os, const PNode *pnode)
 
void dump (std::ostream &os, const PGroup *pgroup)
 
void dump (std::ostream &os, const PGroups *pgroups)
 
std::unique_ptr< luci::PGroupsmerge_pgroups (const luci::PGroups *s_pgroups)
 This will merge pgroups with same group values in topological order.
 
std::unique_ptr< luci::PGroupsproduce_pgroups (const luci::Module *source, const luci::PartitionTable &partition)
 This will produce a PGroups from Module and PartitionTable.
 
luci::PartedModules produce_pmodules (const luci::PGroups *pgroups)
 This will produce list of luci::Module as PartedModules from pgroups.
 
void dump (std::ostream &os, const PartedModule *pmodule)
 
void dump (std::ostream &os, const PartedModules *pmodules)
 
void dynamic_batch_to_single_batch (luci::Module *)
 
template void SparsifyTensorPass::sparsify_tensor< loco::DataType::S32 > (luci::CircleConst *cop)
 
template void SparsifyTensorPass::sparsify_tensor< loco::DataType::S8 > (luci::CircleConst *cop)
 
template void SparsifyTensorPass::sparsify_tensor< loco::DataType::FLOAT32 > (luci::CircleConst *cop)
 
bool is_batchnorm_add (const luci::CircleAdd *add, luci::CircleMul *&mul, luci::CircleConst *&beta)
 Find Mul-Add pattern and return Mul and beta as BatchNorm.
 
bool is_batchnorm_add (const luci::CircleAdd *add)
 Find Mul-Add pattern.
 
bool is_batchnorm_mul (const luci::CircleMul *mul, luci::CircleNode *&pred_node, luci::CircleConst *&gamma)
 Find Const-Mul pattern and return Node and gamma as BatchNorm.
 
bool fuse_activation_function (luci::CircleNode *node)
 
bool fuse_sub_with_conv (luci::CircleSub *sub)
 
bool fuse_add_with_conv (luci::CircleAdd *add, std::vector< luci::CircleSub * > &sub_list)
 
bool fuse_mul_with_conv (luci::CircleMul *mul)
 
bool swap_mul_add (luci::CircleAdd *add, std::vector< luci::CircleMul * > &mul_list, std::vector< luci::CircleAdd * > &add_list)
 
bool to_compute (const Padding padding, compute::PaddingType &padding_type)
 
bool to_compute (const FusedActFunc act, compute::FusedActFunc &act_func)
 
template<typename T >
CircleConstcreate_const_node (loco::Graph *g, const loco::DataType dtype, const std::vector< uint32_t > &shape, const T value)
 
template<typename T >
luci::CircleConstcreate_const_node (loco::Graph *g, const loco::DataType dtype, const std::vector< uint32_t > &shape, const std::vector< T > &values)
 
std::vector< loco::Node * > inference_candidates (loco::Graph *g)
 Enumerate all the nodes whose shape/dtype should be inferenced to export graph.
 
LayerInfoMap layer_info_map (loco::Graph *g, std::vector< LayerInfo > &layers_info)
 
template<class ARG_TYPE_1 , class ARG_TYPE_2 >
NodeFiller< ARG_TYPE_1, ARG_TYPE_2 > fill (ARG_TYPE_1 **arg_1, ARG_TYPE_2 **arg_2)
 
bool is_same_shape (const luci::CircleNode *node, const loco::TensorShape &shape)
 
bool is_same_shape (const luci::CircleNode *node, const std::initializer_list< uint32_t > shape)
 
bool has_dynamic_shape (const loco::Node *node)
 
sparsity::TfLiteDimensionType to_tflite_sparsity (luci::DimensionType dt)
 
sparsity::TfLiteIntArrayto_tflite_sparsity (const luci::SparseIndexVector &data)
 
sparsity::TfLiteSparsity to_tflite_sparsity (const luci::SparsityParam *sp)
 
template<typename T >
sparsity::TfLiteIntArraymakeTfLiteArray (const std::vector< T > &data)
 
sparsity::TfLiteDimensionMetadatamakeTfLiteDimensionMetadata (const std::vector< luci::DimMetaData > &data)
 
void freeTfLiteSparsity (sparsity::TfLiteSparsity &tflsp)
 
bool in_array (const std::string &str, const std::vector< std::string > &array)
 
std::string to_string (const std::vector< std::string > &strings)
 
std::string to_lower_case (std::string s)
 
loco::DataType str_to_dtype (const std::string &str)
 
std::vector< loco::DataTypestr_vec_to_dtype_vec (std::vector< std::string > &vec)
 
QuantizationGranularity str_to_granularity (const std::string &str)
 
void propagate_concat_quantparam (luci::CircleConcatenation *concat)
 
void propagate_pad_v2_quantparam (luci::CirclePadV2 *pad_v2)
 
bool is_quantized (const CircleNode *node)
 
bool is_fp32 (const CircleNode *node)
 
uint8_t fp32_to_uint8_cast (float f)
 
void asymmetric_wquant_with_minmax_per_layer (CircleConst *node, float min, float max, float &scaling_factor, int64_t &zp, float &nudged_min, float &nudged_max)
 
void symmetric_wquant_with_minmax_per_layer (CircleConst *node, float min, float max, float &scaling_factor, float &nudged_min, float &nudged_max)
 
int32_t max_for_sym_quant (const loco::DataType &type)
 
void compute_sym_scale (float min, float max, float &scaling_factor, float &nudged_min, float &nudged_max, loco::DataType out_type)
 
void compute_asym_scale_zp (float min, float max, float &scaling_factor, int64_t &zp, float &nudged_min, float &nudged_max)
 
bool get_channel_dim_index (CircleConst *node, loco::TensorShape &dimension, int32_t &channel_dim_index)
 
uint32_t cal_offset (loco::TensorShape &dimension, uint32_t *indices)
 
ActivationQType activation_qtype (const CircleNode *node)
 
std::unique_ptr< CircleQuantParammake_predefined_qparam (ActivationQType qtype, loco::DataType dtype, CircleQuantParam *old_quant_param)
 
void set_int_scale (luci::CircleNode *node)
 
void quant_const (luci::CircleConst *node, loco::DataType quant_type)
 
void warn_accuracy_with_range (luci::CircleNode *n)
 
bool is_onnx_dequantize_linear (const luci::CircleCustom *node)
 
bool is_onnx_quantize_linear (const luci::CircleCustom *node)
 
std::unique_ptr< CircleQuantParammake_predefined_qparam (CircleNode *node, loco::DataType dtype)
 
bool has_execution_plan (const luci::CircleNode *circle_node)
 
void add_execution_plan (luci::CircleNode *circle_node, const luci::CircleNodeExecutionPlan &execution_plan)
 
luci::CircleNodeExecutionPlan get_execution_plan (const luci::CircleNode *circle_node)
 
bool has_node_id (const luci::CircleNode *circle_node)
 
void set_node_id (luci::CircleNode *circle_node, CircleNodeID id)
 
CircleNodeID get_node_id (const luci::CircleNode *circle_node)
 
std::shared_ptr< CircleNodeOriginsingle_origin (uint32_t id, const std::string &name)
 
std::shared_ptr< CircleNodeOrigincomposite_origin (const std::initializer_list< std::shared_ptr< CircleNodeOrigin > > origins)
 
std::shared_ptr< CircleNodeOrigincomposite_origin (const std::vector< std::shared_ptr< CircleNodeOrigin > > &origins)
 
void change_outputs (loco::Graph *, const std::vector< std::string > &)
 Change output to nodes with string name.
 
void copy_common_attributes (const luci::CircleNode *src, luci::CircleNode *dst)
 Copy common attributes of CircleNode from src to dst.
 
CircleNodeclone_node (const CircleNode *node, loco::Graph *graph)
 Return a new cloned CircleNode object with same attributes value of node to graph.
 
luci::CircleConstclone (luci::CircleConst *node)
 Return cloned object of CircleConst node.
 
ShapeDescription to_shape_description (const luci::CircleNode *node)
 
ShapeDescription to_shape_description (const loco::TensorShape &shape)
 
ShapeDescription to_shape_description (const loco::NodeShape &shape)
 
template<typename Permutation >
bool isNHWC (Permutation *perm)
 
template<>
bool isNHWC (loco::Permutation< loco::Domain::Feature > *perm)
 
template<>
bool isNHWC (loco::Permutation< loco::Domain::Filter > *perm)
 
bool validate (loco::Graph *)
 
bool validate_name (loco::Graph *)
 Return true if all nodes in graph have non empty name.
 
bool validate_unique_name (luci::Module *)
 Return true if all names in the Module are unique.
 
bool validate (luci::Module *)
 
bool validate_shape (loco::Graph *)
 
bool validate_shape (luci::Module *)
 
loco::NodeShape shape_get (const loco::Node *node)
 
bool shape_known (const loco::Node *node)
 
loco::DataType dtype_get (const loco::Node *node)
 
bool dtype_known (const loco::Node *node)
 

Detailed Description

@Note Methods in this file provides helper functions to reduce duplicate codes

Typedef Documentation

◆ CircleNodeID

using luci::CircleNodeID = typedef uint32_t

Definition at line 25 of file CircleNodeID.h.

◆ CircleTensorIndex

using luci::CircleTensorIndex = typedef int32_t

Definition at line 61 of file CircleExporterUtils.h.

◆ ExecutionPlanTable

using luci::ExecutionPlanTable = typedef std::map<uint32_t, std::vector<uint32_t> >

Definition at line 23 of file ExecutionPlanTable.h.

◆ FormattedGraph

◆ GroupKey

using luci::GroupKey = typedef std::string

Definition at line 32 of file PartitionIR.h.

◆ HessianMap

using luci::HessianMap = typedef std::unordered_map<const luci::CircleNode *, std::vector<float> >

Definition at line 31 of file QuantizeDequantizeWeightsWithGPTQPass.h.

◆ LayerInfoMap

using luci::LayerInfoMap = typedef std::unordered_map<std::string, luci::LayerInfo>

Definition at line 27 of file LayerInfoMap.h.

◆ LuciNodeMixin

template<LuciNodeTrait T>
using luci::LuciNodeMixin = typedef CircleNodeMixin<T>

Definition at line 29 of file LuciNodeMixins.h.

◆ LuciNodeTrait

Definition at line 27 of file LuciNodeMixins.h.

◆ MapNode2Clone

using luci::MapNode2Clone = typedef std::map<const CircleNode * , CircleNode * >
Note
MapNode2Clone is used as a map from original node to cloned node to find input of a cloned node

(Original) (Clone)

[A] [A'] | [B] | [B'] | | | | \ / \ / [C] [C']

From view of [C'] we need to find [A'] and [B']. We know [C] from [C'], then we can get from input of [C] as [A], [B] then [A]->[A'] and [B]->[B'] from the map.

Definition at line 42 of file ConnectNode.h.

◆ NodeName

using luci::NodeName = typedef std::string

Definition at line 35 of file CircleNodeDecl.h.

◆ OriginTable

using luci::OriginTable = typedef std::map<uint32_t, std::shared_ptr<CircleNodeOrigin> >

Definition at line 32 of file CircleImportMetadata.h.

◆ Phase

using luci::Phase = typedef std::vector<std::unique_ptr<Pass> >

Definition at line 29 of file ModulePhase.h.

◆ TensorIndex

using luci::TensorIndex = typedef int32_t

Definition at line 32 of file GraphBuilderContext.h.

Enumeration Type Documentation

◆ ActivationQType

Enumerator
MinMax 
PreDefinedLogistic 
PreDefinedTanh 
PreDefinedSoftmax 
IntScale 

Definition at line 72 of file QuantizationUtils.h.

73{
74 MinMax, // Quantize using recorded min/max
75 PreDefinedLogistic, // Quantize using pre-defined values
76 PreDefinedTanh, // Quantize using pre-defined values
77 PreDefinedSoftmax, // Quantize using pre-defined values
78 IntScale, // Round scale to a positive integer
79};
@ PreDefinedLogistic
@ PreDefinedSoftmax

◆ CircleNodeTrait

enum class luci::CircleNodeTrait
strong

enumeration of mixin class

Enumerator
FusedActFunc 
Bias 

Definition at line 31 of file CircleNodeMixins.h.

32{
34 Bias
35};

◆ CircleOpcode

enum class luci::CircleOpcode
strong
Enumerator
CIRCLE_NODE 
CIRCLE_VNODE 

Definition at line 23 of file CircleOpcode.h.

24{
25#define CIRCLE_NODE(OPCODE, CLASS) OPCODE,
26#define CIRCLE_VNODE CIRCLE_NODE
27#include "CircleNodes.lst"
28#undef CIRCLE_VNODE
29#undef CIRCLE_NODE
30};

◆ CN

enum class luci::CN
strong
Enumerator
ABC 
DEF 
GHIJ 
KLMN 
OPQR 
STUV 
WXYZ 

Definition at line 28 of file CircleCloneNode.h.

29{
30 ABC,
31 DEF,
32 GHIJ,
33 KLMN,
34 OPQR,
35 STUV,
36 WXYZ,
37};

◆ DimensionType

Enumerator
DENSE 
SPARSE_CSR 

Definition at line 28 of file SparsityParam.h.

29{
30 DENSE,
32};
@ SPARSE_CSR

◆ FusedActFunc

enum class luci::FusedActFunc
strong
Enumerator
UNDEFINED 
NONE 
RELU 
RELU_N1_TO_1 
RELU6 
TANH 
SIGN_BIT 

Definition at line 24 of file AttrFusedActFunc.h.

25{
26 UNDEFINED, // This is not defined by TFLite or Circle. This was added to
27 // prevent programming error.
28 NONE,
29 RELU,
30 RELU_N1_TO_1,
31 RELU6,
32 TANH,
33 SIGN_BIT
34};

◆ MirrorPadMode

enum class luci::MirrorPadMode
strong
Enumerator
UNDEFINED 
REFLECT 
SYMMETRIC 

Definition at line 23 of file AttrMirrorPadMode.h.

24{
25 UNDEFINED, // This is not defined by Circle. This was added to prevent programming error.
26
27 REFLECT,
29};

◆ NodeBuilderType

enum class luci::NodeBuilderType
strong

Tensor types which requires separated node.

Enumerator
BUFFER 

Definition at line 31 of file NodeBuilder.h.

32{
33 BUFFER,
34 // TODO Extend this struct here if needed to add new type of NodeBuilderBase
35};

◆ Padding

enum class luci::Padding
strong
Enumerator
UNDEFINED 
SAME 
VALID 

Definition at line 23 of file AttrPadding.h.

24{
25 UNDEFINED, // This is not defined by TFLite. This was added to prevent programming error.
26
27 SAME,
28 VALID,
29};

◆ QuantizationGranularity

Enumerator
LayerWise 
ChannelWise 

Definition at line 27 of file QuantizationParameters.h.

28{
29 LayerWise = 0,
30 ChannelWise = 1,
31};

◆ RoPEMode

enum class luci::RoPEMode
strong
Enumerator
UNDEFINED 
GPT_NEOX 
GPT_J 

Definition at line 23 of file AttrRoPEMode.h.

24{
25 UNDEFINED, // This is not defined by Circle. This was added to prevent programming error.
26
28 GPT_J,
29};

◆ ShapeStatus

enum class luci::ShapeStatus
strong

ShapeStatus is to remember circle node shape status.

Note
This is not an attribute from the file but inner status of a node. Shape with [] is scalar but sometimes it acts as dynamic shape.
Enumerator
UNDEFINED 
NOSHAPE 
VALID 

Definition at line 28 of file PropertyShapeStatus.h.

29{
30 UNDEFINED, // Shape status is undefined
31
32 NOSHAPE, // shape is unknown; to distinguish from scalar
33 VALID, // shape is valid
34};

◆ SparseIndexVectorType

Enumerator
NONE 
I32 
U16 
U8 

Definition at line 34 of file SparsityParam.h.

35{
36 NONE,
37 I32,
38 U16,
39 U8,
40};

Function Documentation

◆ activation_qtype()

ActivationQType luci::activation_qtype ( const CircleNode node)

Definition at line 300 of file QuantizationUtils.cpp.

301{
302 auto fused_act_node = dynamic_cast<const CircleNodeMixin<CircleNodeTrait::FusedActFunc> *>(node);
303 if (fused_act_node && fused_act_node->fusedActivationFunction() == FusedActFunc::TANH)
304 return ActivationQType::PreDefinedTanh;
305
306#define RETURN_INPUT_ACTIVATION_QTYPE(CLASS, INPUT) \
307 { \
308 auto n = loco::must_cast<const CLASS *>(node); \
309 auto input = loco::must_cast<CircleNode *>(n->INPUT()); \
310 return activation_qtype(input); \
311 }
312
313 switch (node->opcode())
314 {
315 case CircleOpcode::LOGISTIC:
316 return ActivationQType::PreDefinedLogistic;
317 case CircleOpcode::TANH:
318 return ActivationQType::PreDefinedTanh;
319 case CircleOpcode::SOFTMAX:
320 return ActivationQType::PreDefinedSoftmax;
321 case CircleOpcode::FLOOR:
322 case CircleOpcode::FLOOR_DIV:
323 case CircleOpcode::FLOOR_MOD:
324 case CircleOpcode::CEIL:
325 return ActivationQType::IntScale;
326 case CircleOpcode::GATHER:
328 case CircleOpcode::RESHAPE:
330 case CircleOpcode::TRANSPOSE:
332 case CircleOpcode::STRIDED_SLICE:
334 case CircleOpcode::SPLIT:
336 case CircleOpcode::CIRCLESPLITOUT:
338 case CircleOpcode::SPLIT_V:
340 case CircleOpcode::CIRCLESPLITVOUT:
342 case CircleOpcode::UNPACK:
344 case CircleOpcode::CIRCLEUNPACKOUT:
346 case CircleOpcode::QUANTIZE:
348 default:
349 break;
350 }
351
352#undef RETURN_INPUT_ACTIVATION_QTYPE
353
354 return ActivationQType::MinMax;
355}
#define RETURN_INPUT_ACTIVATION_QTYPE(CLASS, INPUT)
GATHER in Circle.
QUANTIZE in Circle.
RESHAPE in Circle.
SPLIT in Circle.
Definition CircleSplit.h:32
Virtual CIRCLESPLITOUT in Circle.
SPLIT_V in Circle.
Virtual CIRCLESPLITVOUT in Circle.
STRIDED_SLICE in Circle.
TRANSPOSE in Circle.
UNPACK in Circle.
Virtual CIRCLEUNPACKOUT in Circle.
virtual CircleOpcode opcode(void) const =0

References IntScale, MinMax, luci::CircleNode::opcode(), PreDefinedLogistic, PreDefinedSoftmax, PreDefinedTanh, RETURN_INPUT_ACTIVATION_QTYPE, and TANH.

Referenced by luci::QuantizeSpecialActivation::visit(), luci::QuantizeSpecialActivation::visit(), luci::QuantizeSpecialActivation::visit(), and luci::QuantizeSpecialActivation::visit().

◆ add_execution_plan()

void luci::add_execution_plan ( luci::CircleNode circle_node,
const luci::CircleNodeExecutionPlan execution_plan 
)

Definition at line 62 of file CircleNodeExecutionPlan.cpp.

64{
65 circle_node->annot<CircleExecutionPlanAnnotation>(nullptr);
66 circle_node->annot(std::make_unique<CircleExecutionPlanAnnotation>(execution_plan));
67}
const T * annot(void) const
Retrieve a stored annotation of type T.

References loco::AnnotatedItem< Annotation >::annot().

◆ apply()

PartedModules luci::apply ( Module module,
const PartitionTable partition 
)

Method to do paritioning from module and PartitionTable to produce PartedModules.

This will return Partitioned Modules object.

Definition at line 36 of file Partition.cpp.

37{
38 assert(source != nullptr);
39
40 LOGGER(l);
41
42 auto pgroups = produce_pgroups(source, partition);
43 INFO(l) << "--- Partition Graph (1)------------------------";
44 INFO(l) << pgroups.get();
45
46 auto mpgroups = merge_pgroups(pgroups.get());
47 INFO(l) << "--- Partition Graph (2)------------------------";
48 INFO(l) << mpgroups.get();
49
50 remove_unused_inputoutputs(mpgroups.get(), source);
51 INFO(l) << "--- Partition Graph (3)------------------------";
52 INFO(l) << mpgroups.get();
53
54 auto pmodules = produce_pmodules(mpgroups.get());
55 INFO(l) << "--- Modules -----------------------------------";
56 INFO(l) << &pmodules;
57
58 return pmodules;
59}
#define LOGGER(name)
Definition Log.h:65
#define INFO(name)
Definition Log.h:68
std::unique_ptr< luci::PGroups > produce_pgroups(const luci::Module *source, const luci::PartitionTable &partition)
This will produce a PGroups from Module and PartitionTable.
luci::PartedModules produce_pmodules(const luci::PGroups *pgroups)
This will produce list of luci::Module as PartedModules from pgroups.
std::unique_ptr< luci::PGroups > merge_pgroups(const luci::PGroups *s_pgroups)
This will merge pgroups with same group values in topological order.
void remove_unused_inputoutputs(luci::PGroups *pgroups, const luci::Module *source)
This will remove unused inputs/outputs in each pgroup of pgroups.

References INFO, LOGGER, merge_pgroups(), produce_pgroups(), produce_pmodules(), and remove_unused_inputoutputs().

Referenced by entry().

◆ asymmetric_wquant_with_minmax_per_layer()

void luci::asymmetric_wquant_with_minmax_per_layer ( CircleConst node,
float  min,
float  max,
float &  scaling_factor,
int64_t &  zp,
float &  nudged_min,
float &  nudged_max 
)

Definition at line 46 of file QuantizationUtils.cpp.

49{
50 const int32_t kMinScale = 0;
51 const int32_t kMaxScale = 255;
52
53 uint32_t size = node->size<loco::DataType::FLOAT32>();
54 compute_asym_scale_zp(min, max, scaling_factor, zp, nudged_min, nudged_max);
55 const float scaling_factor_inv = 1.0 / scaling_factor;
56 std::vector<int32_t> quantized_values(size);
57 for (uint32_t i = 0; i < size; ++i)
58 {
59 // clipping
60 auto data = node->at<loco::DataType::FLOAT32>(i);
61 data = data < nudged_min ? nudged_min : data;
62 data = data > nudged_max ? nudged_max : data;
63 quantized_values[i] =
64 static_cast<int32_t>(std::round((data - nudged_min) * scaling_factor_inv));
65 }
66
67 node->dtype(loco::DataType::U8); // change the type of tensor
68 node->size<loco::DataType::U8>(size); // resize tensor
69 for (uint32_t i = 0; i < size; ++i)
70 {
71 node->at<loco::DataType::U8>(i) = std::min(kMaxScale, std::max(kMinScale, quantized_values[i]));
72 }
73}
const loco::DataTypeImpl< DT >::Type & at(uint32_t n) const
uint32_t size(void) const
void compute_asym_scale_zp(float min, float max, float &scaling_factor, int64_t &zp, float &nudged_min, float &nudged_max)
int32_t size[5]
Definition Slice.cpp:35

References luci::CircleConst::at(), compute_asym_scale_zp(), flatbuffers::data(), luci::CircleConst::size(), and size.

Referenced by quant_const().

◆ cal_offset()

uint32_t luci::cal_offset ( loco::TensorShape dimension,
uint32_t *  indices 
)

Definition at line 287 of file QuantizationUtils.cpp.

288{
289 return indices[0] * dimension.dim(1).value() * dimension.dim(2).value() *
290 dimension.dim(3).value() +
291 indices[1] * dimension.dim(2).value() * dimension.dim(3).value() +
292 indices[2] * dimension.dim(3).value() + indices[3];
293}
uint32_t value(void) const
Return the value.
Definition Dimension.h:51
const Dimension & dim(uint32_t axis) const
Definition TensorShape.h:38

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

◆ change_outputs()

void luci::change_outputs ( loco::Graph graph,
const std::vector< std::string > &  new_outputs 
)

Change output to nodes with string name.

Note
Should match existing number of nodes and all names should exist. Will throw exception if failed.

Definition at line 48 of file ChangeOutputs.cpp.

49{
50 if (new_outputs.size() != graph->outputs()->size())
51 {
52 throw oops::UserExn("Change outputs failed: number of outputs should be ",
53 graph->outputs()->size());
54 }
55
56 std::map<std::string, luci::CircleNode *> named_nodes;
57
58 for (auto &node_name : new_outputs)
59 {
60 auto node = find_by_name(graph, node_name);
61 if (node == nullptr)
62 {
63 throw oops::UserExn("Change outputs failed: node not found: ", node_name);
64 }
65 named_nodes[node_name] = node;
66 }
67 // just to be sure
68 assert(graph->outputs()->size() == named_nodes.size());
69
70 for (uint32_t out = 0; out < graph->outputs()->size(); ++out)
71 {
72 auto output = luci::output_node(graph, out); // output is CircleOutput
73 assert(output != nullptr);
74
75 auto &node_name = new_outputs.at(out);
76 auto node = named_nodes[node_name];
77 assert(node != nullptr);
78
79 output->from(node);
80
81 // update GraphOutput shape, dtype to node
82 auto graph_out = graph->outputs()->at(out);
83 auto output_shape = std::make_unique<loco::TensorShape>();
84
85 output_shape->rank(node->rank());
86 for (uint32_t r = 0; r < node->rank(); ++r)
87 {
88 if (node->dim(r).known())
89 output_shape->dim(r).set(node->dim(r).value());
90 else
91 output_shape->dim(r).unset();
92 }
93 graph_out->shape(std::move(output_shape));
94 graph_out->dtype(node->dtype());
95 }
96}
Exception to user.
Definition UserExn.h:42
const luci_interpreter::RuntimeShape output_shape
CircleOutput * output_node(loco::Graph *g, const loco::GraphOutputIndex &index)
Find a CircleOutput node with a given output index.

References output_node(), output_shape, and size.

Referenced by entry().

◆ check_size_limit()

bool luci::check_size_limit ( const flatbuffers::FlatBufferBuilder fb,
const uint64_t  data_size 
)
inline

Definition at line 68 of file CircleExporterUtils.h.

69{
70 return FLATBUFFERS_SIZE_MAX < data_size + fb.GetSize();
71}
uoffset_t GetSize() const
The current size of the serialized buffer, counting from the end.
constexpr uint64_t FLATBUFFERS_SIZE_MAX

References FLATBUFFERS_SIZE_MAX, and flatbuffers::FlatBufferBuilder::GetSize().

◆ circle_builtin_operator()

circle::BuiltinOperator luci::circle_builtin_operator ( const luci::CircleNode node)

Definition at line 189 of file CircleExporterUtils.cpp.

190{
191 return node->accept(&BuiltinOperatorMappingRule::get());
192}
T accept(CircleNodeVisitorBase< T > *) const

References luci::CircleNode::accept(), and luci::BuiltinOperatorMappingRule::get().

Referenced by luci::OperationExporterRule::visit().

◆ circle_builtin_options()

circle::BuiltinOptions luci::circle_builtin_options ( const luci::CircleNode node)

Definition at line 194 of file CircleExporterUtils.cpp.

195{
196 if (auto cast = dynamic_cast<const luci::CircleCast *>(node))
197 {
198 return (cast->out_data_type() == loco::DataType::Unknown) ? circle::BuiltinOptions_NONE
199 : circle::BuiltinOptions_CastOptions;
200 }
201
202 return node->accept(&BuiltinOptionsMappingRule::get());
203}
CAST in Circle.
Definition CircleCast.h:32

References luci::CircleNode::accept(), and luci::BuiltinOptionsMappingRule::get().

Referenced by luci::OperationExporterRule::visit().

◆ circle_custom_code()

std::string luci::circle_custom_code ( const luci::CircleNode node)

Definition at line 205 of file CircleExporterUtils.cpp.

206{
207 if (auto custom_node = dynamic_cast<const luci::CircleCustom *>(node))
208 {
209 return custom_node->custom_code();
210 }
211
212 return "";
213}
CUSTOM in Circle.

Referenced by luci::OperationExporterRule::visit().

◆ circle_custom_options()

flatbuffers::Offset< flatbuffers::Vector< uint8_t > > luci::circle_custom_options ( flatbuffers::FlatBufferBuilder fb,
const luci::CircleNode node 
)

Definition at line 216 of file CircleExporterUtils.cpp.

217{
218 if (auto custom_node = dynamic_cast<const luci::CircleCustom *>(node))
219 {
220 std::vector<uint8_t> custom_options_vec{custom_node->custom_options().begin(),
221 custom_node->custom_options().end()};
222 return fb.CreateVector(custom_options_vec);
223 }
224
225 return 0;
226}
Offset< Vector< T > > CreateVector(const T *v, size_t len)
Serialize an array into a FlatBuffer vector.

References flatbuffers::FlatBufferBuilder::CreateVector().

Referenced by luci::OperationExporterRule::visit().

◆ CircleConst::at< loco::DataType::STRING >() [1/2]

template<>
std::string & luci::CircleConst::at< loco::DataType::STRING > ( uint32_t  n)

Definition at line 109 of file CircleConst.cpp.

110{
111 assert(dtype() == loco::DataType::STRING);
112 assert(n < _strings.size());
113 return _strings.at(n);
114}

◆ CircleConst::at< loco::DataType::STRING >() [2/2]

template<>
const std::string & luci::CircleConst::at< loco::DataType::STRING > ( uint32_t  n) const

Definition at line 102 of file CircleConst.cpp.

103{
104 assert(dtype() == loco::DataType::STRING);
105 assert(n < _strings.size());
106 return _strings.at(n);
107}

◆ CircleConst::scalar< loco::DataType::STRING >() [1/2]

template<>
std::string & luci::CircleConst::scalar< loco::DataType::STRING > ( void  )

Definition at line 123 of file CircleConst.cpp.

124{
125 assert(dtype() == loco::DataType::STRING);
126 assert(1 == _strings.size());
127 return _strings.at(0);
128}

◆ CircleConst::scalar< loco::DataType::STRING >() [2/2]

template<>
const std::string & luci::CircleConst::scalar< loco::DataType::STRING > ( void  ) const

Definition at line 116 of file CircleConst.cpp.

117{
118 assert(dtype() == loco::DataType::STRING);
119 assert(1 == _strings.size());
120 return _strings.at(0);
121}

◆ CircleConst::size< loco::DataType::STRING >() [1/2]

template<>
void luci::CircleConst::size< loco::DataType::STRING > ( uint32_t  l)

Definition at line 95 of file CircleConst.cpp.

96{
97 assert(dtype() == loco::DataType::STRING);
98 assert(_data.size() == 0);
99 _strings.resize(l);
100}

◆ CircleConst::size< loco::DataType::STRING >() [2/2]

template<>
uint32_t luci::CircleConst::size< loco::DataType::STRING > ( void  ) const

Definition at line 88 of file CircleConst.cpp.

89{
90 assert(dtype() == loco::DataType::STRING);
91 assert(_data.size() == 0);
92 return _strings.size();
93}

◆ clear_tensor_index()

void luci::clear_tensor_index ( loco::Node node)

Definition at line 314 of file CircleExporterUtils.cpp.

315{
316 if (node->annot<CircleTensorIndexAnnotation>() != nullptr)
317 node->annot<CircleTensorIndexAnnotation>(nullptr);
318}

References loco::AnnotatedItem< Annotation >::annot().

Referenced by clearExportInfo().

◆ clearExportInfo()

void luci::clearExportInfo ( loco::Graph g)

clear temporary export information annotated to graph nodes

Definition at line 724 of file CircleTensorExporter.cpp.

725{
726 auto nodes = g->nodes();
727 for (uint32_t n = 0; n < nodes->size(); ++n)
728 {
729 auto node = loco::must_cast<luci::CircleNode *>(nodes->at(n));
730 clear_tensor_index(node);
731 }
732}
void clear_tensor_index(loco::Node *node)

References clear_tensor_index().

◆ clone()

luci::CircleConst * luci::clone ( luci::CircleConst node)

Return cloned object of CircleConst node.

Definition at line 107 of file CircleConst.cpp.

108{
109 auto *cloned = clone_circleconst(node, node->graph());
110
111 copy_common_attributes(node, cloned);
112
113 return cloned;
114}
Graph * graph(void)
Definition Node.h:70
void copy_common_attributes(const luci::CircleNode *src, luci::CircleNode *dst)
Copy common attributes of CircleNode from src to dst.

References copy_common_attributes(), and loco::Node::graph().

Referenced by luci::CloneContext::emplace(), propagate_concat_quantparam(), and propagate_pad_v2_quantparam().

◆ clone_connect()

void luci::clone_connect ( const luci::CircleNode node,
luci::CloneContext clonecontext 
)

Connect cloned node from input node.

Definition at line 24 of file ConnectNode.cpp.

25{
26 ConnectNode cn(clonecontext);
27 node->accept(&cn);
28}

References luci::CircleNode::accept().

◆ clone_node()

luci::CircleNode * luci::clone_node ( const CircleNode node,
loco::Graph graph 
)

Return a new cloned CircleNode object with same attributes value of node to graph.

Note
Will return nullptr if clone has failed
Each visit implementation must copy node specific attributes.

Definition at line 70 of file CircleNodeClone.cpp.

71{
72 if (node == nullptr || graph == nullptr)
73 return nullptr;
74
75 CloneNode cn(graph);
76 auto cloned = node->accept(&cn);
77 if (cloned != nullptr)
78 copy_common_attributes(node, cloned);
79 return cloned;
80}

References luci::CircleNode::accept(), and copy_common_attributes().

◆ composite_origin() [1/2]

std::shared_ptr< CircleNodeOrigin > luci::composite_origin ( const std::initializer_list< std::shared_ptr< CircleNodeOrigin > >  origins)
Examples
/github/workspace/compiler/luci/pass/src/RemoveUnnecessaryTransposeNetPass.cpp.

Definition at line 126 of file CircleNodeOrigin.cpp.

127{
128 auto origin = std::make_shared<CompositeOrigin>(origins);
129
130 // For empty source, no need to create origin
131 if (origin->sources().empty())
132 return nullptr;
133
134 return origin;
135}

Referenced by luci::CircleImportMetadata::origin_table().

◆ composite_origin() [2/2]

std::shared_ptr< CircleNodeOrigin > luci::composite_origin ( const std::vector< std::shared_ptr< CircleNodeOrigin > > &  origins)

Definition at line 138 of file CircleNodeOrigin.cpp.

139{
140 auto origin = std::make_shared<CompositeOrigin>(origins);
141
142 // For empty source, no need to create origin
143 if (origin->sources().empty())
144 return nullptr;
145
146 return origin;
147}

◆ compute_asym_scale_zp()

void luci::compute_asym_scale_zp ( float  min,
float  max,
float &  scaling_factor,
int64_t &  zp,
float &  nudged_min,
float &  nudged_max 
)

Definition at line 150 of file QuantizationUtils.cpp.

152{
153 LOGGER(l);
154
155 assert(min <= max);
156 const int32_t kMinScale = 0;
157 const int32_t kMaxScale = 255;
158 const double qmin_double = kMinScale;
159 const double qmax_double = kMaxScale;
160 const double rmin = std::fmin(0, min);
161 const double rmax = std::fmax(0, max);
162
163 double scale = (rmax - rmin) / (qmax_double - qmin_double);
164 double zero_point_double = 0;
165 uint8_t nudged_zero_point = 0;
166 if (scale == 0)
167 {
168 WARN(l) << "The minimum and maximum values are the same." << std::endl;
169 if (min >= 0 && max >= 0)
170 zero_point_double = kMinScale;
171 else
172 zero_point_double = kMaxScale;
173 }
174 else
175 zero_point_double = qmin_double - rmin / scale;
176 if (min >= 0)
177 {
178 assert(min >= 0 && max >= 0);
179 nudged_zero_point = kMinScale;
180 scale = max / (qmax_double - qmin_double);
181 if (min > 0 && max > 0)
182 WARN(l) << "The minimum and maximum values are all positive." << std::endl;
183 }
184 else if (max < 0)
185 {
186 assert(min < 0 && max < 0);
187 nudged_zero_point = kMaxScale;
188 scale = -min / (qmax_double - qmin_double);
189 WARN(l) << "The minimum and maximum values are all negative." << std::endl;
190 }
191 else
192 {
193 assert(min < 0 && max >= 0);
194 nudged_zero_point = fp32_to_uint8_cast(std::round(zero_point_double));
195 }
196
197 // protect scale from being very low due to overflow
198 if (scale < 1e-5)
199 {
200 scale = 1e-5;
201 nudged_zero_point = fp32_to_uint8_cast(std::round(qmin_double - rmin / scale));
202 }
203
204 nudged_min = static_cast<float>((qmin_double - nudged_zero_point) * scale);
205 nudged_max = static_cast<float>((qmax_double - nudged_zero_point) * scale);
206
207 scaling_factor = scale;
208 zp = nudged_zero_point;
209}
#define WARN(name)
Definition Log.h:70
uint8_t fp32_to_uint8_cast(float f)

References fp32_to_uint8_cast(), LOGGER, and WARN.

Referenced by asymmetric_wquant_with_minmax_per_layer(), and luci::QuantizeActivation::visit().

◆ compute_sym_scale()

void luci::compute_sym_scale ( float  min,
float  max,
float &  scaling_factor,
float &  nudged_min,
float &  nudged_max,
loco::DataType  out_type 
)

Definition at line 116 of file QuantizationUtils.cpp.

118{
119 assert(min <= max);
120 assert(out_type == loco::DataType::S4 || out_type == loco::DataType::S8 ||
121 out_type == loco::DataType::S16);
122
123 const int32_t kMaxScale = max_for_sym_quant(out_type);
124 const int32_t kMinScale = -kMaxScale;
125 const double qmin_double = kMinScale;
126 const double qmax_double = kMaxScale;
127 const double rmin = std::fmin(0, min);
128 const double rmax = std::fmax(0, max);
129 double scale_factor_from_min_side{0};
130 double scale_factor_from_max_side{0};
131
132 if ((qmin_double * rmin) > 0)
133 scale_factor_from_min_side = rmin / qmin_double;
134
135 if ((qmax_double * rmax) > 0)
136 scale_factor_from_max_side = rmax / qmax_double;
137
138 scaling_factor = scale_factor_from_min_side > scale_factor_from_max_side
139 ? scale_factor_from_min_side
140 : scale_factor_from_max_side;
141
142 // protect scale from being very low to avoid overflow/underflow
143 const float kMinScalingFactor = (out_type == loco::DataType::S16) ? 1e-8 : 1e-5;
144 scaling_factor = std::max(scaling_factor, kMinScalingFactor);
145
146 nudged_min = static_cast<float>(qmin_double * scaling_factor);
147 nudged_max = static_cast<float>(qmax_double * scaling_factor);
148}
int32_t max_for_sym_quant(const loco::DataType &type)

References max_for_sym_quant().

Referenced by symmetric_wquant_with_minmax_per_layer(), and luci::QuantizeActivation::visit().

◆ copy_common_attributes()

void luci::copy_common_attributes ( const luci::CircleNode src,
luci::CircleNode dst 
)

Copy common attributes of CircleNode from src to dst.

Note
Attributes of specific node type like keep_dims() of CircleSum are not copied.

Definition at line 33 of file CircleNodeClone.cpp.

34{
35 assert(src != nullptr);
36 assert(dst != nullptr);
37
38 dst->name(src->name());
39 dst->dtype(src->dtype());
40
41 dst->rank(src->rank());
42 for (uint32_t i = 0; i < src->rank(); i++)
43 {
44 dst->dim(i) = src->dim(i);
45 }
46 dst->shape_status(src->shape_status());
47
48 // quantparam
49 copy_quantparam(src, dst);
50
51 // sparsity
52 const auto *sparsity = src->sparsityparam();
53 if (sparsity != nullptr)
54 {
55 auto sparam = std::make_unique<luci::SparsityParam>();
56 sparam->traversal_order = sparsity->traversal_order;
57 sparam->block_map = sparsity->block_map;
58 sparam->dim_metadata = sparsity->dim_metadata;
59
60 dst->sparsityparam(std::move(sparam));
61 }
62
63 // op version
64 dst->op_version(src->op_version());
65}
SparsityParam * sparsityparam(void) const
int32_t op_version(void) const
NodeName name(void) const
ShapeStatus shape_status(void) const

References copy_quantparam(), luci::CircleNode::name(), luci::CircleNode::op_version(), luci::CircleNode::shape_status(), and luci::CircleNode::sparsityparam().

Referenced by clone(), and clone_node().

◆ copy_quantparam()

void luci::copy_quantparam ( const luci::CircleNode src,
luci::CircleNode dst 
)

copy CircleQuantParam of src to dst

Definition at line 28 of file CircleQuantParam.cpp.

29{
30 auto q = src->quantparam();
31 if (q == nullptr)
32 dst->quantparam(nullptr);
33 else
34 {
35 auto qparam = std::make_unique<luci::CircleQuantParam>();
36 qparam->scale = q->scale;
37 qparam->zerop = q->zerop;
38 qparam->min = q->min;
39 qparam->max = q->max;
40 qparam->quantized_dimension = q->quantized_dimension;
41
42 dst->quantparam(std::move(qparam));
43 }
44}
CircleQuantParam * quantparam(void) const

References luci::CircleNode::quantparam().

Referenced by copy_common_attributes(), and luci::CopyQuantParamPass::run().

◆ copy_tensor_attributes()

void luci::copy_tensor_attributes ( const circle::Tensor *  tensor,
CircleNode node 
)

Copy common tensor attributes such as name, type, etc. to node.

Definition at line 272 of file CircleReader.cpp.

273{
274 assert(tensor != nullptr);
275
276 node->name(tensor_name(tensor));
277 node->dtype(luci_datatype(tensor->type()));
278
279 const auto tensor_shape_signature = wrap(tensor->shape_signature());
280 const auto tensor_shape = wrap(tensor->shape());
281 assert(tensor_shape_signature.size() == 0 ||
282 tensor_shape_signature.size() == tensor_shape.size());
283
284 const auto dims = tensor_shape; // in NHWC
285 node->rank(dims.size());
286 for (uint32_t r = 0; r < dims.size(); ++r)
287 {
288 if (tensor_shape_signature.size() > 0 && tensor_shape_signature.at(r) == -1)
289 node->dim(r).unset();
290 else
291 node->dim(r).set(dims[r]);
292 }
293
294 const auto quantization = tensor->quantization();
295 if (quantization != nullptr)
296 {
297 auto quantparam = luci_quantparam(quantization);
298 if (quantparam)
299 node->quantparam(std::move(quantparam));
300 }
301
302 const auto sparsity = tensor->sparsity();
303 if (sparsity != nullptr)
304 {
305 auto sparsityparam = luci_sparsityparam(sparsity);
306 if (sparsityparam)
307 node->sparsityparam(std::move(sparsityparam));
308 }
309}
std::unique_ptr< SparsityParam > luci_sparsityparam(const circle::SparsityParametersT *sparsity)
loco::DataType luci_datatype(circle::TensorType type)
const char * tensor_name(const circle::Tensor *tensor)

References luci_datatype(), luci_quantparam(), luci_sparsityparam(), luci::CircleNode::name(), luci::CircleNode::quantparam(), luci::CircleNode::sparsityparam(), tensor_name(), and wrap().

Referenced by luci::GraphBuilder::build(), luci::GraphBuilderMultiOutput::build(), luci::CircleWhileGraphBuilder::build(), luci_interpreter::CircleReferencingConstNodeBuilder::build(), luci::CircleConstNodeBuilder::build(), and create_circlevariable().

◆ create_circlevariable()

CircleVariable * luci::create_circlevariable ( GraphBuilderContext context,
int32_t  tensor_index 
)

Definition at line 48 of file CircleVariable.cpp.

49{
50 LOGGER(l);
51
52 auto graph = context->graph();
53 auto reader = context->reader();
54 const auto tensors = reader->tensors();
55 const auto variable_tensor = tensors[tensor_index];
56 assert(variable_tensor != nullptr);
57
58 if (not variable_tensor->is_variable())
59 {
60 // not a variable
61 return nullptr;
62 }
63 {
64 // check if there is no buffer as we don't support this for now
65 // TODO use buffer when this is enabled in Kernel
66 assert(reader->buffers()[variable_tensor->buffer()] != nullptr);
67 assert(reader->buffers()[variable_tensor->buffer()]->data() == nullptr);
68 }
69
70 auto variable_node = graph->nodes()->create<CircleVariable>();
71 copy_tensor_attributes(variable_tensor, variable_node);
72 variable_node->shape_status(luci::ShapeStatus::VALID);
73
74 INFO(l) << "[luci] NodeFinder variable node(" << tensor_index << ") -> " << variable_node << " "
75 << wrap(variable_tensor->shape()) << std::endl;
76
77 return variable_node;
78}
CircleTensors tensors() const
std::function< Ret(Arg)> wrap(Ret(*p)(Arg))
Convert a function pointer as a callable std::function.
Definition fipe.h:31
void copy_tensor_attributes(const circle::Tensor *tensor, CircleNode *node)
Copy common tensor attributes such as name, type, etc. to node.

References copy_tensor_attributes(), luci::GraphBuilderContext::graph(), INFO, LOGGER, luci::GraphBuilderContext::reader(), luci::CircleReader::tensors(), VALID, and wrap().

◆ create_const_node() [1/2]

template<typename T >
luci::CircleConst * luci::create_const_node ( loco::Graph g,
const loco::DataType  dtype,
const std::vector< uint32_t > &  shape,
const std::vector< T > &  values 
)

Definition at line 61 of file CreateCircleConst.h.

64{
65 auto node = g->nodes()->create<luci::CircleConst>();
66 node->dtype(dtype);
67 node->rank(shape.size());
68
69 uint32_t size = 1;
70 for (uint32_t i = 0; i < shape.size(); ++i)
71 {
72 node->dim(i) = shape.at(i);
73 size *= shape.at(i);
74 }
75 node->shape_status(luci::ShapeStatus::VALID);
76
77 node->size<TypeMapper<T>::get()>(size);
78 for (uint32_t i = 0; i < size; i++)
79 {
80 node->at<TypeMapper<T>::get()>(i) = values[i];
81 }
82
83 return node;
84}
Class to build tensor data.
Definition CircleConst.h:35

References luci::CircleConst::at(), size, and VALID.

◆ create_const_node() [2/2]

template<typename T >
CircleConst * luci::create_const_node ( loco::Graph g,
const loco::DataType  dtype,
const std::vector< uint32_t > &  shape,
const T  value 
)

Definition at line 33 of file CreateCircleConst.h.

35{
36 auto node = g->nodes()->create<CircleConst>();
37 node->dtype(dtype);
38 node->rank(shape.size());
39
40 uint32_t size = 1;
41 for (uint32_t i = 0; i < shape.size(); ++i)
42 {
43 node->dim(i) = shape.at(i);
44 size *= shape.at(i);
45 }
46 node->shape_status(ShapeStatus::VALID);
47
48 node->size<TypeMapper<T>::get()>(size);
49 for (uint32_t i = 0; i < size; i++)
50 {
51 node->at<TypeMapper<T>::get()>(i) = value;
52 }
53
54 return node;
55}

References luci::CircleConst::at(), size, and VALID.

◆ createCircleMetadataVector()

std::vector< flatbuffers::Offset< circle::Metadata > > luci::createCircleMetadataVector ( flatbuffers::FlatBufferBuilder builder,
luci::SerializedModelData md 
)

Create Metadata corresponding to model metadata.

Definition at line 129 of file CircleExportMetadata.cpp.

130{
131 std::vector<flatbuffers::Offset<circle::Metadata>> metadata_vec;
132
133 auto settings = luci::UserSettings::settings();
135 {
136 metadata_vec.emplace_back(
137 metadata_offset(builder, md, md._metadata.encoded_source_table(), "ONE_source_table"));
138
139 metadata_vec.emplace_back(
140 metadata_offset(builder, md, md._metadata.encoded_op_table(), "ONE_op_table"));
141 }
143 {
144 metadata_vec.emplace_back(metadata_offset(
145 builder, md, md._metadata.encoded_execution_plan_table(), "ONE_execution_plan_table"));
146 }
147 return metadata_vec;
148}
const std::vector< uint8_t > encoded_source_table(void)
const std::vector< uint8_t > encoded_op_table(void)
const std::vector< uint8_t > encoded_execution_plan_table(void)
CircleExportMetadata _metadata
static UserSettings * settings()

References luci::SerializedModelData::_metadata, luci::CircleExportMetadata::encoded_execution_plan_table(), luci::CircleExportMetadata::encoded_op_table(), luci::CircleExportMetadata::encoded_source_table(), luci::UserSettings::ExecutionPlanGen, luci::UserSettings::ProfilingDataGen, and luci::UserSettings::settings().

◆ dtype_get()

loco::DataType luci::dtype_get ( const loco::Node node)

Definition at line 22 of file CircleTypeInferenceHelper.cpp.

23{
24 assert(luci::dtype_known(node));
25 return loco::must_cast<const luci::CircleNode *>(node)->dtype();
26}
bool dtype_known(const loco::Node *node)

References dtype_known().

◆ dtype_known()

bool luci::dtype_known ( const loco::Node node)

Definition at line 28 of file CircleTypeInferenceHelper.cpp.

29{
30 return loco::must_cast<const luci::CircleNode *>(node)->dtype() != loco::DataType::Unknown;
31}

Referenced by dtype_get().

◆ dump() [1/5]

void luci::dump ( std::ostream &  os,
const PartedModule pmodule 
)

Definition at line 26 of file PartitionPModulesDump.cpp.

27{
28 os << "--- PartedModule: " << pmodule->group << std::endl;
29 os << luci::fmt(pmodule->module->graph());
30}
FormattedGraph fmt(loco::Graph *g)
Definition LogHelper.cpp:23
std::unique_ptr< Module > std::string group
Definition Partition.h:60

References fmt(), and luci::PartedModule::group.

◆ dump() [2/5]

void luci::dump ( std::ostream &  os,
const PartedModules pmodules 
)

Definition at line 32 of file PartitionPModulesDump.cpp.

33{
34 for (auto &pmodule : pmodules->pmodules)
35 {
36 dump(os, &pmodule);
37 }
38 os << std::endl;
39}
void dump(const coco::Op *op, int indent)
Definition Dump.cpp:177

References dump(), and luci::PartedModules::pmodules.

◆ dump() [3/5]

void luci::dump ( std::ostream &  os,
const PGroup pgroup 
)

Definition at line 32 of file PartitionIRDump.cpp.

33{
34 os << "--- PGroup: " << pgroup->group << std::endl;
35 os << "Input(s): [ ";
36 for (auto &node_in : pgroup->inputs)
37 os << node_in->name() << " ";
38 os << "]" << std::endl;
39 for (auto &pnode : pgroup->pnodes)
40 {
41 dump(os, pnode.get());
42 }
43 os << "Output(s): [ ";
44 for (auto &node_out : pgroup->outputs)
45 os << node_out->name() << " ";
46 os << "]" << std::endl;
47}
GroupKey group
Definition PartitionIR.h:53

References dump(), luci::PGroup::group, luci::PGroup::inputs, luci::PGroup::outputs, and luci::PGroup::pnodes.

◆ dump() [4/5]

void luci::dump ( std::ostream &  os,
const PGroups pgroups 
)

Definition at line 49 of file PartitionIRDump.cpp.

50{
51 for (auto &pgroup : pgroups->pgroups)
52 {
53 dump(os, pgroup.get());
54 }
55 os << "--- Node2Group items: " << std::endl;
56 for (auto it = pgroups->node2group.begin(); it != pgroups->node2group.end(); ++it)
57 {
58 auto node = it->first;
59 auto &group = it->second;
60 os << " Node: " << node << "(" << luci::opcode_name(node) << "," << node->name()
61 << "): " << group << std::endl;
62 }
63}
std::string opcode_name(const CircleNode *node)
std::map< const luci::CircleNode *, GroupKey > node2group
Definition PartitionIR.h:66

References dump(), luci::PGroups::node2group, opcode_name(), and luci::PGroups::pgroups.

◆ dump() [5/5]

void luci::dump ( std::ostream &  os,
const PNode pnode 
)

Definition at line 26 of file PartitionIRDump.cpp.

27{
28 os << "PNode: " << pnode->group << ", " << pnode->node << ":" << luci::opcode_name(pnode->node)
29 << ":" << pnode->node->name() << std::endl;
30}
const luci::CircleNode * node
Definition PartitionIR.h:41
GroupKey group
Definition PartitionIR.h:42

References luci::PNode::group, luci::CircleNode::name(), luci::PNode::node, and opcode_name().

Referenced by dump(), dump(), dump(), operator<<(), and operator<<().

◆ dynamic_batch_to_single_batch()

void luci::dynamic_batch_to_single_batch ( luci::Module m)

Definition at line 29 of file DynamicBatchToSingleBatch.cpp.

30{
31 assert(m); // FIX CALLER UNLESS
32
33 for (uint32_t i = 0; i < m->size(); i++)
34 {
35 auto g = m->graph(i);
36
37 logo::Phase phase;
38
39 phase.emplace_back(std::make_unique<luci::DynamicBatchToSingleBatchPass>());
40
41 // Needed to infer shapes of other nodes
42 phase.emplace_back(std::make_unique<luci::CircleShapeInferencePass>());
43
46 phase_runner.attach(&prog);
47 phase_runner.run(phase);
48 }
49}
std::vector< std::unique_ptr< Pass > > Phase
Definition Phase.h:31

References m, and logo::Saturate.

Referenced by entry().

◆ exportNodes()

void luci::exportNodes ( loco::Graph g,
flatbuffers::FlatBufferBuilder builder,
SerializedModelData md,
SerializedGraphData gd 
)

create Operators corresponding to model nodes

Parameters
nodescontainer with nodes
gdinformation about serializer parts of model

Definition at line 28 of file CircleOperationExporter.cpp.

30{
31 uint32_t node_position = 0;
32 for (auto node : loco::postorder_traversal(loco::output_nodes(g)))
33 {
34 ExportContext ctx{builder, md, gd};
35 OperationExporterRule exporter_rule{ctx};
36
37 auto circle_node = loco::must_cast<luci::CircleNode *>(node);
38 circle_node->accept(&exporter_rule);
39
40 const auto ops_size = gd._operators.size();
41
42 if (has_origin(circle_node) && ops_size != gd._operators.size())
43 {
44 const auto node_id = gd._operators.size() - 1;
45 for (auto source : get_origin(circle_node)->sources())
46 {
47 md._metadata.add_op_table(node_id, source->id());
48 }
49 }
50 if (has_execution_plan(circle_node))
51 {
52 // Add to node (in node_position) metadata vector with execution_plan information:
53 // order of execution, and offsets output tensors.
54 const auto execution_plan = get_execution_plan(circle_node);
55 std::vector<uint32_t> execution_plan_vector;
56 execution_plan_vector.push_back(execution_plan.order_in_plan());
57 for (auto offset : execution_plan.offsets())
58 {
59 execution_plan_vector.push_back(offset);
60 }
61 md._metadata.add_execution_plan_table(node_position, execution_plan_vector);
62 }
63
64 node_position++;
65 }
66}
void add_execution_plan_table(uint32_t node_id, const std::vector< uint32_t > &execution_plan_inform)
void add_op_table(uint32_t node_id, uint32_t source_id)
__global uchar * offset(const Image *img, int x, int y)
Definition helpers.h:540
bool has_execution_plan(const luci::CircleNode *circle_node)
luci::CircleNodeExecutionPlan get_execution_plan(const luci::CircleNode *circle_node)
std::vector< flatbuffers::Offset< circle::Operator > > _operators

References luci::SerializedModelData::_metadata, luci::SerializedGraphData::_operators, luci::CircleExportMetadata::add_execution_plan_table(), luci::CircleExportMetadata::add_op_table(), get_execution_plan(), has_execution_plan(), offset(), loco::output_nodes(), and loco::postorder_traversal().

◆ exportOpDefinedTensors()

void luci::exportOpDefinedTensors ( loco::Graph g,
flatbuffers::FlatBufferBuilder builder,
SerializedModelData md,
SerializedGraphData gd 
)

create Tensors corresponding to results of all nodes in graph

Parameters
computationalgraph
gdinformation about serialized parts of model

Definition at line 695 of file CircleTensorExporter.cpp.

697{
698 CircleTensorContext tensor_ctx;
699
700 // NOTE There may exist dangle CircleInput that is not visited with postorder_traversal()
701 // All dangle CircleOutput should be visited by postorder_traversal()
702 auto nodes = g->nodes();
703 for (uint32_t n = 0; n < nodes->size(); ++n)
704 {
705 auto node = dynamic_cast<luci::CircleInput *>(nodes->at(n));
706 if (node != nullptr)
707 allocateCircleTensor(node, tensor_ctx);
708 }
709
710 for (auto node : loco::postorder_traversal(loco::output_nodes(g)))
711 {
712 CircleNode *circle_node = loco::must_cast<luci::CircleNode *>(node);
713 if (dynamic_cast<const luci::CircleInput *>(circle_node) != nullptr)
714 continue;
715 allocateCircleTensor(circle_node, tensor_ctx);
716 }
717
718 for (const auto &tensor_info : tensor_ctx)
719 {
720 exportOpDefinedTensor(tensor_info, builder, md, gd);
721 }
722}
CircleNode used for Input of the Graph.
Definition CircleInput.h:36
void exportOpDefinedTensor(const TFLTensorInfo &info, FlatBufferBuilder &builder, SerializedModelData &gd)

References loco::output_nodes(), and loco::postorder_traversal().

◆ fb_string2std_string()

std::string luci::fb_string2std_string ( const flatbuffers::String fb_str)

Definition at line 311 of file CircleReader.cpp.

312{
313 return fb_str == nullptr ? "" : fb_str->str();
314}
std::string str() const

References flatbuffers::String::str().

Referenced by luci::CircleReader::name().

◆ fill()

template<class ARG_TYPE_1 , class ARG_TYPE_2 >
NodeFiller< ARG_TYPE_1, ARG_TYPE_2 > luci::fill ( ARG_TYPE_1 **  arg_1,
ARG_TYPE_2 **  arg_2 
)
inline

Definition at line 72 of file NodeFiller.h.

73{
74 return NodeFiller<ARG_TYPE_1, ARG_TYPE_2>{arg_1, arg_2};
75}

◆ fmt()

FormattedGraph luci::fmt ( loco::Graph g)

Definition at line 23 of file LogHelper.cpp.

24{
25 auto node_summary_builder = std::make_unique<NodeSummaryBuilderFactory>();
26 return std::move(locop::fmt<locop::LinearV1>(g).with(std::move(node_summary_builder)));
27}

Referenced by dump(), fme_apply::ProgressReporter::notify(), luci::ProgressReporter::notify(), luci::ModuleProgressReporter::notify(), fme_apply::ProgressReporter::notify(), luci::ProgressReporter::notify(), luci::ModuleProgressReporter::notify(), validate(), and validate_shape().

◆ fp32_to_uint8_cast()

uint8_t luci::fp32_to_uint8_cast ( float  f)

Definition at line 39 of file QuantizationUtils.cpp.

40{
41 assert(std::numeric_limits<uint8_t>::min() <= f);
42 assert(f <= std::numeric_limits<uint8_t>::max());
43 return static_cast<uint8_t>(f);
44}

Referenced by compute_asym_scale_zp().

◆ freeTfLiteSparsity()

void luci::freeTfLiteSparsity ( sparsity::TfLiteSparsity tflsp)

◆ fuse_activation_function()

bool luci::fuse_activation_function ( luci::CircleNode node)

Definition at line 27 of file FuseActivationFunctionPass.cpp.

28{
29 auto preds = loco::preds(node);
30 assert(preds.size() == 1);
31
32 auto pred_node = static_cast<luci::CircleNode *>(*preds.begin());
33 if (loco::succs(pred_node).size() != 1)
34 return false;
35
36 auto node_with_fused_act =
38 if (node_with_fused_act == nullptr)
39 return false;
40
41 // TODO remove this work-around
42 // This will skip fuse for concat as luci-interpreter doesn't support this yet
43 if (dynamic_cast<luci::CircleConcatenation *>(pred_node) != nullptr)
44 return false;
45 // TODO remove this work-around
46 // This will skip fuse for TransposeConv as backends does not support this yet
47 // NOTE remove this when XpSepActFromTransposeConvOpPass is removed
48 if (dynamic_cast<luci::CircleTransposeConv *>(pred_node) != nullptr)
49 return false;
50
51 auto fused_act = node_with_fused_act->fusedActivationFunction();
52
54
55 auto opcode = node->opcode();
56 if (opcode == luci::CircleOpcode::RELU)
57 {
58 if (fused_act == luci::FusedActFunc::NONE || fused_act == luci::FusedActFunc::RELU)
59 target_func = luci::FusedActFunc::RELU;
60 else if (fused_act == luci::FusedActFunc::RELU6)
61 target_func = luci::FusedActFunc::RELU6;
62 else
63 return false;
64 }
65 else if (opcode == luci::CircleOpcode::RELU6)
66 {
67 if (fused_act == luci::FusedActFunc::NONE || fused_act == luci::FusedActFunc::RELU ||
68 fused_act == luci::FusedActFunc::RELU6)
69 target_func = luci::FusedActFunc::RELU6;
70 else
71 return false;
72 }
73 else if (opcode == luci::CircleOpcode::RELU_N1_TO_1)
74 {
75 if (fused_act == luci::FusedActFunc::NONE || fused_act == luci::FusedActFunc::RELU_N1_TO_1)
77 else
78 return false;
79 }
80 else
81 return false;
82
83 node_with_fused_act->fusedActivationFunction(target_func);
84 luci::add_origin(pred_node, luci::get_origin(node));
85 loco::replace(node).with(pred_node);
86
87 node->drop();
88
89 return true;
90}
virtual void drop(void)=0
Drop all the reference of arguments.
void with(Node *into) const
Definition Node.cpp:66
CONCATENATION in Circle.
TRANSPOSE_CONV in Circle.
std::set< Node * > succs(const Node *node)
Enumerate all the successors of a given node.
Definition Node.cpp:46
std::set< Node * > preds(const Node *node)
Enumerate all the predecessors of a given node.
Definition Node.cpp:31
Subst< SubstQualifier::Default > replace(Node *node)
Definition Node.cpp:82

References loco::Node::drop(), NONE, luci::CircleNode::opcode(), loco::preds(), RELU, RELU6, RELU_N1_TO_1, loco::replace(), loco::succs(), UNDEFINED, and loco::Subst< SubstQualifier::Default >::with().

Referenced by luci::FuseActivationFunctionPass::run().

◆ fuse_add_with_conv()

bool luci::fuse_add_with_conv ( luci::CircleAdd add,
std::vector< luci::CircleSub * > &  sub_list 
)

Fuse ADD with the preceding CONV

BEFORE

  [Conv]  bias
     |

[Passable Op] (None, Max pool, Pad, etc) | [Add] beta

AFTER

  [Conv]  bias + beta
     |

[Passable Op]

A special case where SUB is newly inserted

BEFORE

        [Conv]  bias
     \   /
     [Add]
     /   \
        [Add]  beta

AFTER

        [Conv]  bias + beta
     \   /
     [Add]
     /   \

beta [Sub]

Returns
true if success

Definition at line 341 of file FusePreActivationBatchNormPass.cpp.

342{
343 auto x = dynamic_cast<luci::CircleConst *>(add->x());
344 auto y = dynamic_cast<luci::CircleConst *>(add->y());
345
346 luci::CircleNode *pred = nullptr;
347 luci::CircleConst *beta = nullptr;
348
349 if (x != nullptr && y == nullptr)
350 {
351 pred = loco::must_cast<luci::CircleNode *>(add->y());
352 beta = x;
353 }
354 else if (x == nullptr && y != nullptr)
355 {
356 pred = loco::must_cast<luci::CircleNode *>(add->x());
357 beta = y;
358 }
359 else
360 {
361 return false;
362 }
363
364 assert(beta->rank() == 1);
365
366 auto channel_size = beta->dim(0).value();
367 auto conv = get_backward_conv2d(pred, channel_size);
368
369 if (conv != nullptr)
370 {
371 if (!update_conv_bias_with_beta(conv, beta, true))
372 return false;
373
374 luci::add_origin(conv, luci::get_origin(add));
375 loco::replace(add).with(pred);
376 add->drop();
377
378 return true;
379 }
380 // A special case shown at the residual blocks of ResNetV2
381 // TODO: Handle this with get_backward_conv2d
382 else if (pred->opcode() == luci::CircleOpcode::ADD)
383 {
384 auto pred_add = loco::must_cast<luci::CircleAdd *>(pred);
385 conv = get_backward_conv2d(loco::must_cast<luci::CircleNode *>(pred_add->y()), channel_size);
386 if (conv == nullptr)
387 conv = get_backward_conv2d(loco::must_cast<luci::CircleNode *>(pred_add->x()), channel_size);
388
389 if (conv == nullptr)
390 return false;
391
392 if (!update_conv_bias_with_beta(conv, beta, true))
393 return false;
394
395 luci::add_origin(conv, luci::get_origin(add));
396
397 auto relu = *loco::succs(add).begin();
398 auto relu_node = loco::must_cast<luci::CircleRelu *>(relu);
399 assert(relu_node != nullptr);
400
401 loco::replace(add).with(pred);
402
403 add->drop();
404
405 sub_list.push_back(insert_sub(pred, beta));
406 luci::add_origin(sub_list.back(), luci::get_origin(add));
407
408 relu_node->features(pred);
409
410 return true;
411 }
412
413 return false;
414}
void conv(const nncc::core::ADT::feature::Shape &out_shape, nncc::core::ADT::feature::Accessor< OutputDType > &out_data, const nncc::core::ADT::feature::Shape &in_shape, const nncc::core::ADT::feature::Reader< InputDType > &in_data, const nncc::core::ADT::kernel::Shape &ker_shape, const nncc::core::ADT::kernel::Reader< KernelDType > &ker_data, const PadInfo &pad_info, const StrideInfo &stride_info)
Definition Conv2D.h:34

References luci::CircleNode::opcode(), loco::replace(), loco::succs(), and loco::Subst< SubstQualifier::Default >::with().

Referenced by luci::FusePreActivationBatchNormPass::run().

◆ fuse_mul_with_conv()

bool luci::fuse_mul_with_conv ( luci::CircleMul mul)

Fuse MUL with the next CONV

BEFORE

     [Mul]  gamma
       |
     [Relu]
      /  \

W1 [Conv] [Conv] W2

AFTER

          [Relu]
           /  \

gamma X W1 [Conv] [Conv] gamma X W2

Returns
true if success

Definition at line 433 of file FusePreActivationBatchNormPass.cpp.

434{
435 luci::CircleNode *pred_node = nullptr;
436 luci::CircleConst *gamma = nullptr;
437
438 if (!is_batchnorm_mul(mul, pred_node, gamma))
439 return false;
440
441 auto mul_succ = loco::succs(mul);
442 assert(mul_succ.size() == 1);
443
444 auto relu = loco::must_cast<luci::CircleRelu *>(*mul_succ.begin());
445
446 auto channel_size = gamma->dim(0).value();
447
448 bool fusable = true;
449 auto relu_succ = loco::succs(relu);
450 for (auto s : relu_succ)
451 {
452 auto conv = get_forward_conv2d(loco::must_cast<luci::CircleNode *>(s), channel_size);
453 if (conv == nullptr)
454 fusable = false;
455 }
456
457 if (fusable)
458 {
459 for (auto s : relu_succ)
460 {
461 // Find the next CONV
462 auto conv = get_forward_conv2d(loco::must_cast<luci::CircleNode *>(s), channel_size);
463
464 // Update CONV weights
465 update_conv_weights_with_gamma(conv, gamma);
466
467 // Update origin
468 // TODO need to remove const
469 luci::add_origin(const_cast<luci::CircleConv2D *>(conv),
470 luci::get_origin(loco::must_cast<luci::CircleNode *>(mul)));
471 }
472
473 loco::replace(mul).with(pred_node);
474 relu->features(pred_node);
475
476 mul->drop();
477
478 return true;
479 }
480
481 return false;
482}
CONV_2D in Circle.
void mul(const luci_interpreter::RuntimeShape &shape, const ArithmeticParams *params, const int16_t *input1_data, const int16_t *input2_data, int8_t *output_data)
bool is_batchnorm_mul(const luci::CircleMul *mul, luci::CircleNode *&pred_node, luci::CircleConst *&gamma)
Find Const-Mul pattern and return Node and gamma as BatchNorm.

References is_batchnorm_mul(), loco::replace(), loco::succs(), and loco::Subst< SubstQualifier::Default >::with().

Referenced by luci::FuseMulWithConvPass::run(), and luci::FusePreActivationBatchNormPass::run().

◆ fuse_sub_with_conv()

bool luci::fuse_sub_with_conv ( luci::CircleSub sub)

Fuse SUB with CONV

BEFORE

beta [Sub] | [Passable Op] [Conv] bias \ / [Add]

AFTER

[Passable Op]   [Conv] bias - beta
           \   /
           [Add]
Returns
true if success

Definition at line 272 of file FusePreActivationBatchNormPass.cpp.

273{
274 luci::CircleAdd *add = nullptr;
275 luci::CircleConv2D *conv = nullptr;
276 auto succs = loco::succs(sub);
277 if (succs.size() != 1)
278 return false;
279
280 add = get_forward_add(loco::must_cast<luci::CircleNode *>(*succs.begin()));
281 if (add == nullptr)
282 return false;
283
284 conv = dynamic_cast<luci::CircleConv2D *>(add->x());
285 if (conv == nullptr)
286 conv = dynamic_cast<luci::CircleConv2D *>(add->y());
287
288 if (conv == nullptr)
289 return false;
290
291 auto beta = loco::must_cast<luci::CircleConst *>(sub->y());
292 assert(beta != nullptr);
293 if (!update_conv_bias_with_beta(conv, beta, false))
294 return false;
295
296 luci::add_origin(conv, luci::get_origin(sub));
297
298 auto pred = sub->x();
299 loco::replace(sub).with(pred);
300
301 sub->drop();
302
303 return true;
304}
ADD in Circle.
Definition CircleAdd.h:34
loco::Node * x(void) const
Definition CircleSub.h:36
loco::Node * y(void) const
Definition CircleSub.h:39
void drop(void) final

References luci::FixedArityNode< N, Base >::drop(), loco::replace(), loco::succs(), loco::Subst< SubstQualifier::Default >::with(), luci::CircleSub::x(), and luci::CircleSub::y().

Referenced by luci::FusePreActivationBatchNormPass::run().

◆ get_channel_dim_index()

bool luci::get_channel_dim_index ( CircleConst node,
loco::TensorShape dimension,
int32_t &  channel_dim_index 
)

Definition at line 211 of file QuantizationUtils.cpp.

213{
214 auto succs = loco::succs(node);
215
216 // opcode is initialized to CIRCLEINPUT, because
217 // CIRCLEINPUT should never be the successor of any node
218 // (this is checked w/ the assert in the loop body)
219 luci::CircleOpcode opcode = luci::CircleOpcode::CIRCLEINPUT;
220 for (auto out : succs)
221 {
222 const auto circle_node = static_cast<CircleNode *>(out);
223 assert(circle_node->opcode() != luci::CircleOpcode::CIRCLEINPUT);
224
225 if (opcode == luci::CircleOpcode::CIRCLEINPUT)
226 {
227 opcode = circle_node->opcode();
228 }
229 else
230 {
231 // Node is used by multiple layers with different opcodes
232 // We do not care such cases
233 if (opcode != circle_node->opcode())
234 return false;
235 }
236 }
237
238 for (auto out : succs)
239 {
240 auto conv = dynamic_cast<CircleConv2D *>(out);
241 auto dw_conv = dynamic_cast<CircleDepthwiseConv2D *>(out);
242 auto tw_conv = dynamic_cast<CircleTransposeConv *>(out);
243 auto fc = dynamic_cast<CircleFullyConnected *>(out);
244
245 // Refer to https://github.com/Samsung/ONE/pull/2448.
246 if ((conv != nullptr && conv->filter() == node) ||
247 (tw_conv != nullptr && tw_conv->filter() == node)) // OHWI
248 {
249 assert(node->rank() == 4);
250 dimension.dim(0).set(node->dim(0).value());
251 dimension.dim(1).set(node->dim(1).value());
252 dimension.dim(2).set(node->dim(2).value());
253 dimension.dim(3).set(node->dim(3).value());
254 channel_dim_index = 0; // Set channel_dim_index based on "O"
255 return true;
256 }
257 else if (dw_conv != nullptr && dw_conv->filter() == node) // IHWC
258 {
259 assert(node->rank() == 4);
260 dimension.dim(0).set(node->dim(0).value());
261 dimension.dim(1).set(node->dim(1).value());
262 dimension.dim(2).set(node->dim(2).value());
263 dimension.dim(3).set(node->dim(3).value());
264 channel_dim_index = 3; // Set channel_dim_index based on "C"
265 return true;
266 }
267 else if (fc != nullptr && fc->weights() == node) // OI
268 {
269 assert(node->rank() == 2);
270 dimension.dim(0).set(node->dim(0).value());
271 dimension.dim(1).set(1); // Set FC layer like CONV
272 dimension.dim(2).set(1);
273 dimension.dim(3).set(node->dim(1).value());
274 channel_dim_index = 0; // Set channel_dim_index based on "O"
275 return true;
276 }
277 else
278 {
279 // node does not support channle-wise quantization
280 assert(false);
281 }
282 }
283
284 return false;
285}
void set(uint32_t value)
Definition Dimension.h:53

References loco::TensorShape::dim(), loco::Dimension::set(), and loco::succs().

◆ get_execution_plan()

luci::CircleNodeExecutionPlan luci::get_execution_plan ( const luci::CircleNode circle_node)

◆ get_node_id()

luci::CircleNodeID luci::get_node_id ( const luci::CircleNode circle_node)

Definition at line 65 of file CircleNodeID.cpp.

66{
67 if (!has_node_id(circle_node))
68 throw std::runtime_error("Cannot find CircleNodeID");
69
70 return circle_node->annot<CircleNodeIDAnnotation>()->node_id();
71}
bool has_node_id(const luci::CircleNode *circle_node)

References loco::AnnotatedItem< Annotation >::annot(), and has_node_id().

Referenced by minmax_embedder::Embedder::embed(), and onert::odc::Embedder::embed().

◆ get_tensor_index()

CircleTensorIndex luci::get_tensor_index ( loco::Node node)

Definition at line 320 of file CircleExporterUtils.cpp.

321{
322 assert(node->annot<CircleTensorIndexAnnotation>() != nullptr);
323 return node->annot<CircleTensorIndexAnnotation>()->index();
324}

References loco::AnnotatedItem< Annotation >::annot().

Referenced by luci::OperationExporterRule::visit().

◆ getOpPadding() [1/2]

circle::Padding luci::getOpPadding ( const loco::Padding2D pad,
const loco::Stride< 2 > *  stride,
const ShapeDescription ifm,
const ShapeDescription ofm 
)

Definition at line 249 of file CircleExporterUtils.cpp.

251{
252 // VALID padding
253 if (pad->top() == 0 && pad->bottom() == 0 && pad->left() == 0 && pad->right() == 0)
254 return circle::Padding_VALID;
255
256 // SAME padding
257 //
258 // For same padding, by definition, following equation should hold:
259 // O = floor((I - 1) / S) + 1
260 // where input size I, output size O, stride S
261 //
262 // NOTE input and output 'feature' map are shape of NHWC
263 bool same_padding_criterion_1 =
264 (static_cast<uint32_t>(ofm._dims[1]) == (ifm._dims[1] - 1) / stride->vertical() + 1) &&
265 (static_cast<uint32_t>(ofm._dims[2]) == (ifm._dims[2] - 1) / stride->horizontal() + 1);
266
267 // For same padding, rear padding is same or bigger than front padding by at most 1
268 bool same_padding_criterion_2 =
269 (pad->top() <= pad->bottom()) && (pad->bottom() <= pad->top() + 1) &&
270 (pad->left() <= pad->right()) && (pad->right() <= pad->left() + 1);
271
272 if (same_padding_criterion_1 && same_padding_criterion_2)
273 return circle::Padding_SAME;
274
275 INTERNAL_EXN("Unsupported padding criteria");
276}
#define INTERNAL_EXN(msg)
@ brief throw internal exception with message
Definition InternalExn.h:25
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
uint32_t horizontal(void) const
Definition Stride.h:40
uint32_t vertical(void) const
Definition Stride.h:36
std::vector< int32_t > _dims

References luci::ShapeDescription::_dims, loco::Padding2D::bottom(), INTERNAL_EXN, loco::Padding2D::left(), loco::Padding2D::right(), and loco::Padding2D::top().

Referenced by luci::BuiltinOptionsExtractor::visit(), luci::BuiltinOptionsExtractor::visit(), luci::BuiltinOptionsExtractor::visit(), luci::BuiltinOptionsExtractor::visit(), luci::BuiltinOptionsExtractor::visit(), and luci::BuiltinOptionsExtractor::visit().

◆ getOpPadding() [2/2]

circle::Padding luci::getOpPadding ( const luci::Padding  pad)

Definition at line 278 of file CircleExporterUtils.cpp.

279{
280 if (pad == luci::Padding::VALID)
281 return circle::Padding_VALID;
282 if (pad == luci::Padding::SAME)
283 return circle::Padding_SAME;
284
285 INTERNAL_EXN_V("Unsupported luci::Padding", oops::to_uint32(pad));
286}
#define INTERNAL_EXN_V(msg, val)
@ brief throw internal exception with message and value
Definition InternalExn.h:28
uint32_t to_uint32(T a)
Definition InternalExn.h:33

References INTERNAL_EXN_V, SAME, oops::to_uint32(), and VALID.

◆ has_dynamic_shape()

bool luci::has_dynamic_shape ( const loco::Node node)

Definition at line 62 of file Shape.cpp.

63{
64 const auto circle_node = loco::must_cast<const luci::CircleNode *>(node);
65 for (uint32_t i = 0; i < circle_node->rank(); ++i)
66 if (!circle_node->dim(i).known())
67 return true;
68 return false;
69}

Referenced by luci::ConvertNCHWToNHWCPass::run().

◆ has_execution_plan()

◆ has_node_id()

bool luci::has_node_id ( const luci::CircleNode circle_node)

Definition at line 54 of file CircleNodeID.cpp.

55{
56 return circle_node->annot<CircleNodeIDAnnotation>() != nullptr;
57}

References loco::AnnotatedItem< Annotation >::annot().

Referenced by minmax_embedder::Embedder::embed(), onert::odc::Embedder::embed(), and get_node_id().

◆ in_array()

bool luci::in_array ( const std::string &  str,
const std::vector< std::string > &  array 
)

Definition at line 24 of file Strings.cpp.

25{
26 return std::find(array.begin(), array.end(), str) != array.end();
27}

References flatbuffers::str.

◆ inference_candidates()

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

Enumerate all the nodes whose shape/dtype should be inferenced to export graph.

Definition at line 24 of file InferenceCandidates.cpp.

25{
27
28 for (auto node : loco::all_nodes(g))
29 {
30 // already included as candidate
31 if (std::find(candidates.begin(), candidates.end(), node) != candidates.end())
32 continue;
33
34 // As the node is not used for both graph output and multiple output operation,
35 // it cannot be candidate.
36 if (node->dialect()->service<DeadNodeQueryServiceImpl>()->isDeadNode(node))
37 continue;
38
39 candidates.emplace_back(node);
40 }
41
42 return candidates;
43}
std::vector< loco::Node * > postorder_traversal(const std::vector< loco::Node * > &roots)
Generate postorder traversal sequence starting from "roots".
Definition Algorithm.cpp:53
std::vector< Node * > output_nodes(Graph *)
Definition Graph.cpp:101
bool isDeadNode(loco::Node *node) final
Check if the node is dead node.

References loco::all_nodes(), loco::output_nodes(), and loco::postorder_traversal().

Referenced by luci::CircleTypeInferencePass::run(), and luci::CircleShapeInferencePass::run().

◆ input_node()

CircleInput * luci::input_node ( loco::Graph g,
const loco::GraphInputIndex index 
)

Find a Pull node with a given input index.

Definition at line 45 of file CircleNodes.cpp.

46{
47 for (uint32_t n = 0; n < g->nodes()->size(); ++n)
48 {
49 if (auto input = dynamic_cast<CircleInput *>(g->nodes()->at(n)))
50 {
51 if (input->indexed() && input->index() == index)
52 {
53 return input;
54 }
55 }
56 }
57 return nullptr;
58}

References size.

Referenced by luci::CircleWhileGraphBuilder::build(), luci::test::ExampleGraph< ExampleGraphType::CircleTranspose >::ExampleGraph(), luci::DynamicBatchToSingleBatchPass::run(), luci::sinf::Algorithm::visit(), and luci_interpreter::Interpreter::writeInputTensor().

◆ INSTANTIATE() [1/10]

luci::INSTANTIATE ( loco::DataType::BOOL  )

◆ INSTANTIATE() [2/10]

luci::INSTANTIATE ( loco::DataType::FLOAT16  )

◆ INSTANTIATE() [3/10]

luci::INSTANTIATE ( loco::DataType::FLOAT32  )

◆ INSTANTIATE() [4/10]

luci::INSTANTIATE ( loco::DataType::S16  )

◆ INSTANTIATE() [5/10]

luci::INSTANTIATE ( loco::DataType::S32  )

◆ INSTANTIATE() [6/10]

luci::INSTANTIATE ( loco::DataType::S4  )

◆ INSTANTIATE() [7/10]

luci::INSTANTIATE ( loco::DataType::S64  )

◆ INSTANTIATE() [8/10]

luci::INSTANTIATE ( loco::DataType::S8  )

◆ INSTANTIATE() [9/10]

luci::INSTANTIATE ( loco::DataType::U4  )

◆ INSTANTIATE() [10/10]

luci::INSTANTIATE ( loco::DataType::U8  )

◆ is_batchnorm_add() [1/2]

bool luci::is_batchnorm_add ( const luci::CircleAdd add)

Find Mul-Add pattern.

Definition at line 76 of file BatchNormPatternFinder.cpp.

77{
78 // for dummy mul and beta
79 luci::CircleMul *mul = nullptr;
80 luci::CircleConst *beta = nullptr;
81
82 return is_batchnorm_add(add, mul, beta);
83}
MUL in Circle.
Definition CircleMul.h:34
bool is_batchnorm_add(const luci::CircleAdd *add, luci::CircleMul *&mul, luci::CircleConst *&beta)
Find Mul-Add pattern and return Mul and beta as BatchNorm.

References is_batchnorm_add().

◆ is_batchnorm_add() [2/2]

bool luci::is_batchnorm_add ( const luci::CircleAdd add,
luci::CircleMul *&  mul,
luci::CircleConst *&  beta 
)

Find Mul-Add pattern and return Mul and beta as BatchNorm.

Definition at line 24 of file BatchNormPatternFinder.cpp.

25{
26 auto x = loco::must_cast<luci::CircleNode *>(add->x());
27 auto y = loco::must_cast<luci::CircleNode *>(add->y());
28
29 luci::CircleMul *pred = nullptr;
30 luci::CircleConst *constant = nullptr;
31
32 if (x->opcode() == luci::CircleOpcode::CIRCLECONST && y->opcode() == luci::CircleOpcode::MUL)
33 {
34 pred = loco::must_cast<luci::CircleMul *>(y);
35 constant = loco::must_cast<luci::CircleConst *>(x);
36 }
37 else if (x->opcode() == luci::CircleOpcode::MUL && y->opcode() == luci::CircleOpcode::CIRCLECONST)
38 {
39 pred = loco::must_cast<luci::CircleMul *>(x);
40 constant = loco::must_cast<luci::CircleConst *>(y);
41 }
42 else
43 {
44 return false;
45 }
46
47 uint32_t channel_dim = 0;
48
49 if (constant->rank() == 1)
50 {
51 channel_dim = constant->dim(0).value();
52 }
53 else if (constant->rank() == 4)
54 {
55 for (uint32_t i = 0; i < 3; i++)
56 {
57 if (constant->dim(i).value() != 1)
58 return false;
59 }
60 channel_dim = constant->dim(3).value();
61 }
62 else
63 {
64 return false;
65 }
66
67 // Assumption: Layout is channel-last
68 if (!(channel_dim == add->dim(add->rank() - 1)))
69 return false;
70
71 mul = pred;
72 beta = constant;
73 return true;
74}

Referenced by is_batchnorm_add(), and swap_mul_add().

◆ is_batchnorm_mul()

bool luci::is_batchnorm_mul ( const luci::CircleMul mul,
luci::CircleNode *&  pred_node,
luci::CircleConst *&  gamma 
)

Find Const-Mul pattern and return Node and gamma as BatchNorm.

Definition at line 85 of file BatchNormPatternFinder.cpp.

87{
88 auto x = dynamic_cast<luci::CircleConst *>(mul->x());
89 auto y = dynamic_cast<luci::CircleConst *>(mul->y());
90
91 luci::CircleNode *pred = nullptr;
92 luci::CircleConst *constant = nullptr;
93
94 if (x != nullptr && y == nullptr)
95 {
96 pred = loco::must_cast<luci::CircleNode *>(mul->y());
97 constant = x;
98 }
99 else if (x == nullptr && y != nullptr)
100 {
101 pred = loco::must_cast<luci::CircleNode *>(mul->x());
102 constant = y;
103 }
104 else
105 {
106 return false;
107 }
108
109 uint32_t channel_dim = 0;
110
111 if (constant->rank() == 1)
112 {
113 channel_dim = constant->dim(0).value();
114 }
115 else if (constant->rank() == 4)
116 {
117 for (uint32_t i = 0; i < 3; i++)
118 {
119 if (constant->dim(i).value() != 1)
120 return false;
121 }
122 channel_dim = constant->dim(3).value();
123 }
124 else
125 {
126 return false;
127 }
128
129 // Assumption: Layout is channel-last
130 if (!(channel_dim == mul->dim(mul->rank() - 1)))
131 return false;
132
133 pred_node = pred;
134 gamma = constant;
135 return true;
136}

Referenced by fuse_mul_with_conv(), and swap_mul_add().

◆ is_fp32()

bool luci::is_fp32 ( const CircleNode node)

Definition at line 37 of file QuantizationUtils.cpp.

37{ return node->dtype() == loco::DataType::FLOAT32; }

Referenced by luci::QuantizeActivation::visit().

◆ is_onnx_dequantize_linear()

bool luci::is_onnx_dequantize_linear ( const luci::CircleCustom node)

Definition at line 532 of file QuantizationUtils.cpp.

533{
534 if (node->numInputs() != 3)
535 return false;
536
537 if (node->numOutputs() != 1)
538 return false;
539
540 if (node->custom_code() != "ONNXDequantizeLinear")
541 return false;
542
543 return true;
544}
uint32_t numInputs(void) const
uint32_t numOutputs(void) const
const std::string & custom_code(void) const

References luci::CircleCustom::custom_code(), luci::CircleCustom::numInputs(), and luci::CircleCustom::numOutputs().

◆ is_onnx_quantize_linear()

bool luci::is_onnx_quantize_linear ( const luci::CircleCustom node)

Definition at line 546 of file QuantizationUtils.cpp.

547{
548 if (node->numInputs() != 3)
549 return false;
550
551 if (node->numOutputs() != 1)
552 return false;
553
554 if (node->custom_code() != "ONNXQuantizeLinear")
555 return false;
556
557 return true;
558}

References luci::CircleCustom::custom_code(), luci::CircleCustom::numInputs(), and luci::CircleCustom::numOutputs().

◆ is_quantized()

bool luci::is_quantized ( const CircleNode node)

Definition at line 28 of file QuantizationUtils.cpp.

29{
30 return node->quantparam() != nullptr &&
31 (node->dtype() == loco::DataType::U8 || // activation, weight (uint8 quant)
32 node->dtype() == loco::DataType::S16 || // activation, weight (int16 quant)
33 node->dtype() == loco::DataType::S32 || // bias (uint8 quant)
34 node->dtype() == loco::DataType::S64); // bias (int16 quant)
35}

References luci::CircleNode::quantparam().

Referenced by propagate_pad_v2_quantparam(), and luci::QuantizeOnnxFakeQuantModelPass::run().

◆ is_same_shape() [1/2]

bool luci::is_same_shape ( const luci::CircleNode node,
const loco::TensorShape shape 
)

Definition at line 22 of file Shape.cpp.

23{
24 if (node == nullptr)
25 return false;
26
28 return false;
29
30 if (node->rank() != shape.rank())
31 return false;
32
33 for (uint32_t i = 0; i < node->rank(); ++i)
34 {
35 if (node->dim(i).known() != shape.dim(i).known())
36 return false;
37
38 if (node->dim(i).value() != shape.dim(i).value())
39 return false;
40 }
41
42 return true;
43}
bool known(void) const
Return whether the value is known (or not)
Definition Dimension.h:47
uint32_t rank(void) const
Definition TensorShape.h:35

References loco::TensorShape::dim(), loco::Dimension::known(), loco::TensorShape::rank(), luci::CircleNode::shape_status(), VALID, and loco::Dimension::value().

Referenced by luci::CircleShapeInferencePass::run().

◆ is_same_shape() [2/2]

bool luci::is_same_shape ( const luci::CircleNode node,
const std::initializer_list< uint32_t >  shape 
)

Definition at line 45 of file Shape.cpp.

46{
47 if (node == nullptr)
48 return false;
49
50 if (node->rank() != shape.size())
51 return false;
52
53 uint32_t i = 0;
54 for (auto it = shape.begin(); it != shape.end(); ++it, ++i)
55 {
56 if (node->dim(i).value() != *it)
57 return false;
58 }
59 return true;
60}

◆ isNHWC() [1/3]

template<>
bool luci::isNHWC ( loco::Permutation< loco::Domain::Feature > *  perm)
inline

Definition at line 44 of file ShapeDescription.h.

45{
46 return perm->axis(loco::FeatureAxis::Count) == 0 && perm->axis(loco::FeatureAxis::Height) == 1 &&
47 perm->axis(loco::FeatureAxis::Width) == 2 && perm->axis(loco::FeatureAxis::Depth) == 3;
48}

References loco::Count, loco::Depth, loco::Height, and loco::Width.

◆ isNHWC() [2/3]

template<>
bool luci::isNHWC ( loco::Permutation< loco::Domain::Filter > *  perm)
inline

Definition at line 50 of file ShapeDescription.h.

51{
52 return perm->axis(loco::FilterAxis::Count) == 0 && perm->axis(loco::FilterAxis::Height) == 1 &&
53 perm->axis(loco::FilterAxis::Width) == 2 && perm->axis(loco::FilterAxis::Depth) == 3;
54}

References loco::Count, loco::Depth, loco::Height, and loco::Width.

◆ isNHWC() [3/3]

template<typename Permutation >
bool luci::isNHWC ( Permutation *  perm)
inline

◆ layer_info_map()

LayerInfoMap luci::layer_info_map ( loco::Graph g,
std::vector< LayerInfo > &  layers_info 
)

Definition at line 142 of file LayerInfoMap.cpp.

143{
144 LayerInfoMap info_by_name;
145
146 for (auto &&info : layers_info)
147 {
148 auto &name = info.name;
149 bool found = false;
150 for (auto node : loco::active_nodes(loco::output_nodes(g)))
151 {
152 auto cnode = loco::must_cast<luci::CircleNode *>(node);
153 if (cnode->opcode() == luci::CircleOpcode::CIRCLEOUTPUT)
154 continue;
155
156 if (cnode->name() == name)
157 {
158 // Check and add multiple-output node and its outputs to info_by_name
159 if (const auto multi_output = get_multi_output_node(cnode))
160 {
161 add_multi_output_node(info_by_name, info, multi_output);
162 found = true;
163 continue;
164 }
165
166 if (info_by_name.find(name) != info_by_name.end())
167 {
168 throw std::runtime_error("Duplicate layer name " + name +
169 ". Check layer names in the quantization configuration file.");
170 }
171
172 info_by_name[name] = info;
173 found = true;
174 continue;
175 }
176 }
177
178 if (not found)
179 throw std::runtime_error("No such layer named " + name +
180 ". Check layer names in the quantization configuration file.");
181 }
182
183 // TODO Check all names in layers_info exist in the info_by_name
184 // TODO Check names in info_by_name but not in layers_info are from virtual outputs
185
186 return info_by_name;
187}
volatile const char info[]
std::unordered_map< std::string, luci::LayerInfo > LayerInfoMap

References loco::active_nodes(), info, and loco::output_nodes().

Referenced by luci::QuantizeDequantizeWeightsPass::run(), luci::QuantizeDequantizeWeightsWithGPTQPass::run(), luci::QuantizeWithMinMaxPass::run(), and luci::QuantizedModelVerifier::verify().

◆ link() [1/2]

void luci::link ( loco::GraphInput input,
CircleInput node 
)

Link GraphInput with CircleInput node.

Definition at line 43 of file CircleNodes.cpp.

43{ node->index(input->index()); }
void index(const loco::GraphInputIndex &index)

References luci::CircleInput::index().

◆ link() [2/2]

void luci::link ( loco::GraphOutput output,
CircleOutput node 
)

Link GraphOutput with CircleOutput node.

Definition at line 26 of file CircleNodes.cpp.

26{ node->index(output->index()); }
void index(const loco::GraphOutputIndex &index)

References luci::CircleOutput::index().

Referenced by luci::test::TestGraph::TestGraph().

◆ luci_actfunc()

FusedActFunc luci::luci_actfunc ( const circle::ActivationFunctionType  type)

Definition at line 84 of file CircleReader.cpp.

85{
86 switch (type)
87 {
88 case circle::ActivationFunctionType::ActivationFunctionType_NONE:
90 case circle::ActivationFunctionType::ActivationFunctionType_RELU:
92 case circle::ActivationFunctionType::ActivationFunctionType_RELU_N1_TO_1:
94 case circle::ActivationFunctionType::ActivationFunctionType_RELU6:
96 case circle::ActivationFunctionType::ActivationFunctionType_TANH:
98 case circle::ActivationFunctionType::ActivationFunctionType_SIGN_BIT:
100 default:
101 break;
102 }
103 assert(false);
105}

References NONE, RELU, RELU6, RELU_N1_TO_1, SIGN_BIT, TANH, and UNDEFINED.

Referenced by luci_interpreter::configure_kernel_CircleConcatenation(), luci_interpreter::createConv2DParams(), luci_interpreter::createPoolParams(), luci_interpreter::kernels::evalTISOKernel(), and luci_interpreter::kernels::evalTISOQuantizedKernel().

◆ luci_datatype()

loco::DataType luci::luci_datatype ( circle::TensorType  type)

Definition at line 45 of file CircleReader.cpp.

46{
47 switch (type)
48 {
49 case circle::TensorType_FLOAT32:
50 return loco::DataType::FLOAT32;
51 case circle::TensorType_FLOAT16:
52 return loco::DataType::FLOAT16;
53 case circle::TensorType_INT32:
54 return loco::DataType::S32;
55 case circle::TensorType_UINT8:
56 return loco::DataType::U8;
57 case circle::TensorType_UINT4:
58 return loco::DataType::U4;
59 case circle::TensorType_INT64:
60 return loco::DataType::S64;
61 case circle::TensorType_STRING:
62 return loco::DataType::STRING;
63 case circle::TensorType_BOOL:
64 return loco::DataType::BOOL;
65 case circle::TensorType_INT16:
66 return loco::DataType::S16;
67 case circle::TensorType_COMPLEX64:
68 break;
69 case circle::TensorType_INT8:
70 return loco::DataType::S8;
71 case circle::TensorType_INT4:
72 return loco::DataType::S4;
73 case circle::TensorType_MXFP4:
74 return loco::DataType::MXFP4;
75 case circle::TensorType_MXINT8:
76 return loco::DataType::MXINT8;
77 default:
78 break;
79 }
80 assert(false);
81 return loco::DataType::Unknown;
82}

Referenced by luci::GraphBuilderMultiOutput::build(), luci::CircleConstNodeBuilder::build(), copy_tensor_attributes(), and luci_interpreter::Tensor::element_type().

◆ luci_dim_type()

DimensionType luci::luci_dim_type ( const circle::DimensionType  dim_type)

Definition at line 162 of file CircleReader.cpp.

163{
164 switch (dim_type)
165 {
166 case circle::DimensionType_DENSE:
167 return DimensionType::DENSE;
168 case circle::DimensionType_SPARSE_CSR:
169 return DimensionType::SPARSE_CSR;
170 default:
171 throw std::runtime_error("Invalid DimensionType");
172 }
173}

References DENSE, and SPARSE_CSR.

Referenced by luci_sparsityparam().

◆ luci_mirrorpad_mode()

MirrorPadMode luci::luci_mirrorpad_mode ( const circle::MirrorPadMode  mode)

Definition at line 120 of file CircleReader.cpp.

121{
122 switch (mode)
123 {
124 case circle::MirrorPadMode::MirrorPadMode_REFLECT:
125 return MirrorPadMode::REFLECT;
126 case circle::MirrorPadMode::MirrorPadMode_SYMMETRIC:
127 return MirrorPadMode::SYMMETRIC;
128 }
129 assert(false);
130 return MirrorPadMode::UNDEFINED;
131}

References REFLECT, SYMMETRIC, and UNDEFINED.

◆ luci_padding()

Padding luci::luci_padding ( const circle::Padding  padding)

Definition at line 107 of file CircleReader.cpp.

108{
109 switch (padding)
110 {
111 case circle::Padding::Padding_SAME:
112 return Padding::SAME;
113 case circle::Padding::Padding_VALID:
114 return Padding::VALID;
115 }
116 assert(false);
117 return Padding::UNDEFINED;
118}

References SAME, UNDEFINED, and VALID.

Referenced by luci_interpreter::computeConvPadding(), and luci_interpreter::createPoolParams().

◆ luci_quantparam() [1/2]

std::unique_ptr< CircleQuantParam > luci::luci_quantparam ( const circle::QuantizationParameters *  quantization)

Definition at line 230 of file CircleReader.cpp.

231{
232 // create temporary unpacked API object
233 assert(qparams != nullptr);
234 circle::QuantizationParametersT quantization;
235 qparams->UnPackTo(&quantization);
236
237 return luci_quantparam(&quantization);
238}
std::unique_ptr< CircleQuantParam > luci_quantparam(const circle::QuantizationParameters *quantization)

References luci_quantparam().

Referenced by copy_tensor_attributes(), and luci_quantparam().

◆ luci_quantparam() [2/2]

std::unique_ptr< CircleQuantParam > luci::luci_quantparam ( const circle::QuantizationParametersT *  quantization)

Definition at line 206 of file CircleReader.cpp.

207{
208 const auto &min = quantization->min;
209 const auto &max = quantization->max;
210 const auto &scale = quantization->scale;
211 const auto &zero_point = quantization->zero_point;
212 const auto &quantized_dimension = quantization->quantized_dimension;
213
214 if ((!min.empty() && !max.empty()) || (!scale.empty() && !zero_point.empty()))
215 {
216 auto quantparam = std::make_unique<CircleQuantParam>();
217
218 quantparam->min = min;
219 quantparam->max = max;
220 quantparam->scale = scale;
221 quantparam->zerop = zero_point;
222 quantparam->quantized_dimension = quantized_dimension;
223
224 return quantparam;
225 }
226
227 return nullptr;
228}

◆ luci_rope_mode()

RoPEMode luci::luci_rope_mode ( const circle::RoPEMode  mode)

Definition at line 133 of file CircleReader.cpp.

134{
135 switch (mode)
136 {
137 case circle::RoPEMode::RoPEMode_GPT_NEOX:
138 return RoPEMode::GPT_NEOX;
139 case circle::RoPEMode::RoPEMode_GPT_J:
140 return RoPEMode::GPT_J;
141 }
142 assert(false);
143 return RoPEMode::UNDEFINED;
144}

References GPT_J, GPT_NEOX, and UNDEFINED.

◆ luci_sparse_index_vector()

SparseIndexVector luci::luci_sparse_index_vector ( const circle::SparseIndexVectorUnion &  sparse_index_vector)

Definition at line 176 of file CircleReader.cpp.

177{
178 switch (sparse_index_vector.type)
179 {
180 case circle::SparseIndexVector_NONE:
181 return SparseIndexVector{SparseIndexVectorType::NONE, nullptr};
182 case circle::SparseIndexVector_Int32Vector:
183 {
184 const auto const_vec_ptr =
185 static_cast<const void *>(&(sparse_index_vector.AsInt32Vector()->values));
186 return SparseIndexVector{SparseIndexVectorType::I32, const_vec_ptr};
187 }
188 case circle::SparseIndexVector_Uint16Vector:
189 {
190 const auto const_vec_ptr =
191 static_cast<const void *>(&(sparse_index_vector.AsUint16Vector()->values));
192 return SparseIndexVector{SparseIndexVectorType::U16, const_vec_ptr};
193 }
194 case circle::SparseIndexVector_Uint8Vector:
195 {
196 const auto const_vec_ptr =
197 static_cast<const void *>(&(sparse_index_vector.AsUint8Vector()->values));
198 return SparseIndexVector{SparseIndexVectorType::U8, const_vec_ptr};
199 }
200 default:
201 throw std::runtime_error("Invalid SparseIndexVector type");
202 }
203}

References I32, NONE, U16, and U8.

Referenced by luci_sparsityparam().

◆ luci_sparsityparam() [1/2]

std::unique_ptr< SparsityParam > luci::luci_sparsityparam ( const circle::SparsityParameters *  sparparam)

Definition at line 262 of file CircleReader.cpp.

263{
264 // create temporary unpacked API object
265 assert(sparparam != nullptr);
266 circle::SparsityParametersT sparsity;
267 sparparam->UnPackTo(&sparsity);
268
270}

References luci_sparsityparam().

◆ luci_sparsityparam() [2/2]

std::unique_ptr< SparsityParam > luci::luci_sparsityparam ( const circle::SparsityParametersT *  sparsity)

Definition at line 240 of file CircleReader.cpp.

241{
242 assert(sparsity);
243 const auto &traversal_order = sparsity->traversal_order;
244 const auto &block_map = sparsity->block_map;
245 const auto &dim_metadata = sparsity->dim_metadata;
246
247 // TODO find a condition that should return nullptr
248 auto sparsityparam = std::make_unique<SparsityParam>();
249
250 sparsityparam->traversal_order = traversal_order;
251 sparsityparam->block_map = block_map;
252 for (const auto &dm : dim_metadata)
253 {
254 sparsityparam->dim_metadata.emplace_back(luci_dim_type(dm->format), dm->dense_size,
255 luci_sparse_index_vector(dm->array_segments),
256 luci_sparse_index_vector(dm->array_indices));
257 }
258
259 return sparsityparam;
260}
DimensionType luci_dim_type(const circle::DimensionType dim_type)
SparseIndexVector luci_sparse_index_vector(const circle::SparseIndexVectorUnion &sparse_index_vector)

References luci_dim_type(), and luci_sparse_index_vector().

Referenced by copy_tensor_attributes(), and luci_sparsityparam().

◆ luci_weights_format()

luci::CircleFullyConnected::WeightsFormat luci::luci_weights_format ( const circle::FullyConnectedOptionsWeightsFormat  weights_format)

Definition at line 147 of file CircleReader.cpp.

148{
149 switch (weights_format)
150 {
151 case circle::FullyConnectedOptionsWeightsFormat_DEFAULT:
153 case circle::FullyConnectedOptionsWeightsFormat_SHUFFLED4x16INT8:
155 case circle::FullyConnectedOptionsWeightsFormat_SHUFFLED16x1FLOAT32:
157 default:
158 throw std::runtime_error("Invalid FullyConnectedOptionsWeightsFormat");
159 }
160}

References luci::CircleFullyConnected::DEFAULT, luci::CircleFullyConnected::SHUFFLED16x1FLOAT32, and luci::CircleFullyConnected::SHUFFLED4x16INT8.

◆ make_module()

std::unique_ptr< Module > luci::make_module ( void  )

Definition at line 44 of file Module.cpp.

44{ return std::make_unique<Module>(); }

◆ make_predefined_qparam() [1/2]

std::unique_ptr< CircleQuantParam > luci::make_predefined_qparam ( ActivationQType  qtype,
loco::DataType  dtype,
CircleQuantParam old_quant_param 
)

Definition at line 357 of file QuantizationUtils.cpp.

360{
361 auto qparam = std::make_unique<CircleQuantParam>();
362
363 auto set_qparam = [&qparam, old_quant_param](float scale, int64_t zp) {
364 qparam->scale.emplace_back(scale);
365 qparam->zerop.emplace_back(zp);
366 qparam->min = old_quant_param->min;
367 qparam->max = old_quant_param->max;
368 };
369
370 switch (qtype)
371 {
372 case ActivationQType::PreDefinedLogistic:
373 if (dtype == loco::DataType::U8)
374 set_qparam(1.0f / 256.0f, 0);
375 else
376 {
377 assert(dtype == loco::DataType::S16);
378 set_qparam(1.0f / 32768.0f, 0);
379 }
380 break;
381 case ActivationQType::PreDefinedTanh:
382 if (dtype == loco::DataType::U8)
383 set_qparam(2.0f / 256.0f, 128);
384 else
385 {
386 assert(dtype == loco::DataType::S16);
387 set_qparam(1.0f / 32768.0f, 0);
388 }
389 break;
390 case ActivationQType::PreDefinedSoftmax:
391 if (dtype == loco::DataType::U8)
392 set_qparam(1.0f / 255.0f, 0);
393 else
394 {
395 assert(dtype == loco::DataType::S16);
396 set_qparam(1.0f / 32767.0f, 0);
397 }
398 break;
399 default:
400 throw std::runtime_error("Unsupported opcode with pre-defined qparam");
401 }
402 return qparam;
403}
std::vector< float > min
std::vector< float > max

References luci::CircleQuantParam::max, luci::CircleQuantParam::min, PreDefinedLogistic, PreDefinedSoftmax, and PreDefinedTanh.

Referenced by luci::QuantizeSpecialActivation::visit(), luci::QuantizeSpecialActivation::visit(), luci::QuantizeSpecialActivation::visit(), and luci::QuantizeSpecialActivation::visit().

◆ make_predefined_qparam() [2/2]

std::unique_ptr< CircleQuantParam > luci::make_predefined_qparam ( CircleNode node,
loco::DataType  dtype 
)

◆ makeTfLiteArray()

template<typename T >
sparsity::TfLiteIntArray * luci::makeTfLiteArray ( const std::vector< T > &  data)

Definition at line 268 of file SparsityFormatConverter.cpp.

269{
270 size_t cn = data.size();
271 size_t sz = 1 + data.size();
273 sp->size = cn;
274 for (size_t i = 0; i < cn; ++i)
275 {
276 sp->data[i] = data[i];
277 }
278 return sp;
279}

References sparsity::TfLiteIntArray::data, makeTfLiteArray(), and sparsity::TfLiteIntArray::size.

Referenced by makeTfLiteArray(), to_tflite_sparsity(), and to_tflite_sparsity().

◆ makeTfLiteDimensionMetadata()

sparsity::TfLiteDimensionMetadata * luci::makeTfLiteDimensionMetadata ( const std::vector< luci::DimMetaData > &  data)

Definition at line 282 of file SparsityFormatConverter.cpp.

283{
284 size_t cn = data.size();
286
287 for (size_t i = 0; i < cn; ++i)
288 {
289 tfldm[i].format = to_tflite_sparsity(data[i].format());
290 tfldm[i].dense_size = data[i].dense_size();
291 tfldm[i].array_segments = to_tflite_sparsity(data[i].array_segments());
292 tfldm[i].array_indices = to_tflite_sparsity(data[i].array_indices());
293 }
294
295 return tfldm;
296}
sparsity::TfLiteDimensionType to_tflite_sparsity(luci::DimensionType dt)

References sparsity::TfLiteDimensionMetadata::array_indices, sparsity::TfLiteDimensionMetadata::array_segments, sparsity::TfLiteDimensionMetadata::dense_size, sparsity::TfLiteDimensionMetadata::format, makeTfLiteDimensionMetadata(), and to_tflite_sparsity().

Referenced by makeTfLiteDimensionMetadata(), and to_tflite_sparsity().

◆ max_for_sym_quant()

int32_t luci::max_for_sym_quant ( const loco::DataType type)

Definition at line 104 of file QuantizationUtils.cpp.

105{
106 if (type == loco::DataType::S4)
107 return std::numeric_limits<int8_t>::max() >> 4;
108 else if (type == loco::DataType::S8)
109 return std::numeric_limits<int8_t>::max();
110 else if (type == loco::DataType::S16)
111 return std::numeric_limits<int16_t>::max();
112 else
113 throw std::runtime_error("Unsupported dtype for symmetric quantization");
114};

Referenced by compute_sym_scale().

◆ merge_pgroups()

std::unique_ptr< luci::PGroups > luci::merge_pgroups ( const luci::PGroups s_pgroups)

This will merge pgroups with same group values in topological order.

Definition at line 200 of file PartitionMerge.cpp.

201{
202 // Make a copy of pgroups to apply merge action
203 // Q) do we really need a copy?
204 auto d_pgroups = s_pgroups->make_copy();
205
206 // Merge partition graphs
207 // - This is initial implementation that works for limited networks
208 // - if A and B is same group -> if A is input of B -> ... -> merge B into A
209 auto &pgroups = d_pgroups->pgroups;
210 bool changed;
211 do
212 {
213 changed = false;
214 for (auto &pgroup_i : pgroups)
215 {
216 bool merged = false;
217 for (auto it = pgroups.begin(); it != pgroups.end(); ++it)
218 {
219 auto &pgroup = *it;
220
221 // skip if same object
222 if (pgroup->id == pgroup_i->id)
223 continue;
224 // skip if different group
225 if (pgroup->group != pgroup_i->group)
226 continue;
227 // skip if not connected
228 if (!is_input_of(pgroup_i.get(), pgroup.get()))
229 continue;
230 // skip if there are multiple inputs but inputs differ in group
231 if (!is_input_same(pgroup.get(), d_pgroups.get()))
232 continue;
233 // skip if pgroup has different group for other users of pgroup_i
234 if (!is_output_same(pgroup_i.get(), d_pgroups.get()))
235 continue;
236 // TODO add more condition may be needed
237
238 merge_into(pgroup.get(), pgroup_i.get());
239
240 auto eit = d_pgroups->id2pgroup.find(pgroup->id);
241 assert(eit != d_pgroups->id2pgroup.end());
242 d_pgroups->id2pgroup.erase(eit);
243
244 // remove merged pgroup from pgroups
245 pgroups.erase(it);
246
247 merged = true;
248 break;
249 }
250 if (merged)
251 {
252 changed = true;
253 break;
254 }
255 }
256 } while (changed);
257
258 return d_pgroups;
259}
std::unique_ptr< PGroups > make_copy(void) const
return a copy of PGroups

References luci::PGroup::group, luci::PGroup::id, luci::PGroups::make_copy(), and luci::PGroups::pgroups.

Referenced by apply().

◆ opcode_name()

std::string luci::opcode_name ( const CircleNode node)

Definition at line 66 of file CircleOpCode.cpp.

67{
68 QueryCircleName qcn;
69 auto cname = node->accept(&qcn);
70 if (cname != nullptr)
71 return std::string(cname);
72
73 QueryOpCode qoc;
74 auto opcode = node->accept(&qoc);
75 auto name = circle::EnumNameBuiltinOperator(opcode);
76 return std::string(name);
77}

References luci::CircleNode::accept().

Referenced by dump(), and dump().

◆ output_node()

CircleOutput * luci::output_node ( loco::Graph g,
const loco::GraphOutputIndex index 
)

Find a CircleOutput node with a given output index.

Definition at line 28 of file CircleNodes.cpp.

29{
30 for (uint32_t n = 0; n < g->nodes()->size(); ++n)
31 {
32 if (auto output = dynamic_cast<CircleOutput *>(g->nodes()->at(n)))
33 {
34 if (output->indexed() && output->index() == index)
35 {
36 return output;
37 }
38 }
39 }
40 return nullptr;
41}
CircleNode for Output of the Graph.

References size.

Referenced by change_outputs(), luci_interpreter::Interpreter::getOutputTensorSize(), luci_interpreter::Interpreter::readOutputTensor(), and luci::FuseBCQPass::run().

◆ prepareModelData()

void luci::prepareModelData ( FlatBufferBuilder builder,
SerializedModelData md 
)

one time preparation for SerializedModelData

Definition at line 681 of file CircleTensorExporter.cpp.

682{
683 md.clear();
684
685 // add one empty buffer
686 // note: this follows TFLite
687 // note: there's a comment in tflite fbs file
688 // - Note the 0th entry of this array must be an empty buffer (sentinel).
689 // - This is a convention so that tensors without a buffer can provide 0 as
690 // - their buffer.
691 md._empty_buffer = encodeOpBuffer(builder);
692 md._buffers.push_back(md._empty_buffer);
693}
flatbuffers::Offset< circle::Buffer > _empty_buffer
std::vector< flatbuffers::Offset< circle::Buffer > > _buffers

References luci::SerializedModelData::_buffers, luci::SerializedModelData::_empty_buffer, and luci::SerializedModelData::clear().

◆ produce_pgroups()

std::unique_ptr< luci::PGroups > luci::produce_pgroups ( const luci::Module source,
const luci::PartitionTable partition 
)

This will produce a PGroups from Module and PartitionTable.

Note
Each PGroup will hold one CircleNode and partition key value as group. Supports only single Graph in the Module for now.

Definition at line 225 of file PartitionPGroups.cpp.

227{
228 assert(source != nullptr);
229 // NOTE Only main graph (subgraph index 0) will be partitioned.
230 // Other subgraphs will follow the owner (IF/WHILE/...) group
231
232 LOGGER(l);
233
234 auto pgroups = std::make_unique<luci::PGroups>();
235
236 pgroups->default_group = partition.default_group;
237
238 // Create a PGroup per CircleNode: each PGroup will have one CircleNode
239 auto graph = source->graph();
240 auto nodes = graph->nodes();
241 for (uint32_t idx = 0; idx < nodes->size(); ++idx)
242 {
243 auto node = loco::must_cast<luci::CircleNode *>(nodes->at(idx));
244
245 // check if node is normal node that we are interested
246 if (check_allocate_partition(node))
247 {
248 auto group = group_from_partition(node, partition);
249
250 append(node, pgroups.get(), group, idx);
251 }
252 else
253 {
254 INFO(l) << "Skip Op: " << node->name() << std::endl;
255 // record as default group
256 pgroups->node2group[node] = partition.default_group;
257 }
258 }
259
260 return pgroups;
261}
loco::Graph * graph(void) const
provide main graph
Definition Module.cpp:32
std::string default_group
Definition Partition.h:43

References luci::PartitionTable::default_group, luci::PGroups::default_group, luci::Module::graph(), INFO, LOGGER, luci::CircleNode::name(), and luci::PGroups::node2group.

Referenced by apply().

◆ produce_pmodules()

luci::PartedModules luci::produce_pmodules ( const luci::PGroups pgroups)

This will produce list of luci::Module as PartedModules from pgroups.

Definition at line 375 of file PartitionPModules.cpp.

376{
377 LOGGER(l);
378
380
381 for (auto &pgroup : pgroups->pgroups)
382 {
384 pm.module = std::make_unique<luci::Module>();
385 pm.group = pgroup->group;
386
387 // the main graph for this module
388 auto graph = loco::make_graph();
389 auto graph_ptr = graph.get();
390
391 auto graph_name = make_name(pgroup.get());
392 graph->name(graph_name);
393
394 // Add main graph so that other subgraphs can be added inside build_graph
395 pm.module->add(std::move(graph));
396
397 INFO(l) << "--- Partition Graph build----------------------";
398 INFO(l) << "--- name: " << graph_name;
399 build_graph(pm, graph_ptr, pgroup.get());
400
401 pms.pmodules.emplace_back(std::move(pm));
402 }
403
404 return pms;
405}
std::unique_ptr< Graph > make_graph(void)
Definition Graph.cpp:131
PartedModule holds partitioned module and group name.
Definition Partition.h:57
std::vector< PartedModule > pmodules
Definition Partition.h:68

References luci::PartedModule::group, luci::PGroup::group, INFO, LOGGER, loco::make_graph(), luci::PGroups::pgroups, and luci::PartedModules::pmodules.

Referenced by apply().

◆ propagate_concat_quantparam()

void luci::propagate_concat_quantparam ( luci::CircleConcatenation concat)

BEFORE

   [CircleNode]             [CircleConst]
   (U8 qparam1)                 (FP32)
             \                    /
              \                  /
              [CircleConcatenation]
                  (U8 qparam2)

AFTER [CircleNode] [CircleConst] [CircleConst] <- Dead node (U8 qparam2) (U8 qparam2) (FP32) \ / \ / [CircleConcatenation] (U8 qparam2)

Definition at line 295 of file PropagateQParamBackwardPass.cpp.

296{
297 assert(concat->quantparam() != nullptr);
298
299 const auto num_inputs = concat->numValues();
300
301 // Quantize const inputs using their values if concat has fused act function
302 if (concat->fusedActivationFunction() != luci::FusedActFunc::NONE)
303 {
304 for (uint32_t i = 0; i < num_inputs; i++)
305 {
306 auto node = concat->arg(i);
307 auto const_node = dynamic_cast<luci::CircleConst *>(node);
308 if (const_node != nullptr)
309 {
310 auto new_const = luci::clone(const_node);
311 quant_const(new_const, concat->dtype());
312 concat->values(i, new_const);
313 }
314 }
315 return;
316 }
317
318 for (uint32_t i = 0; i < num_inputs; i++)
319 {
320 auto node = loco::must_cast<luci::CircleNode *>(concat->arg(i));
321
322 // Quantize constant values
323 if (node->opcode() == luci::CircleOpcode::CIRCLECONST)
324 {
325 luci::CircleConst *const_node = loco::must_cast<luci::CircleConst *>(node);
326
327 const auto concat_qparam = concat->quantparam();
328 assert(concat_qparam->scale.size() == 1);
329 const auto scaling_factor = concat_qparam->scale[0];
330 const auto zerop = concat_qparam->zerop[0];
331
332 auto new_const = luci::clone(const_node);
333 quant_const_values(new_const, scaling_factor, zerop, concat->dtype());
334 concat->values(i, new_const);
335 overwrite_quantparam(concat, new_const);
336 }
337 else
338 {
339 const auto succs = loco::succs(node);
340 if (succs.size() > 1)
341 continue;
342
343 // Non-const input must have been quantized
344 assert(node->quantparam() != nullptr);
345 overwrite_quantparam(concat, node);
346 }
347 }
348}
void concat(std::ostream &os, const std::string &sep, It beg, It end)
Definition String.h:31
void quant_const(luci::CircleConst *node, loco::DataType quant_type)
luci::CircleConst * clone(luci::CircleConst *node)
Return cloned object of CircleConst node.
TFConst * new_const(loco::Graph *graph, loco::TensorShape &tensor_shape, const loco::DataType &dtype)

References clone(), NONE, quant_const(), and loco::succs().

◆ propagate_pad_v2_quantparam()

void luci::propagate_pad_v2_quantparam ( luci::CirclePadV2 pad_v2)

BEFORE

   [CircleNode] [CircleConst] [CircleConst]
   (U8 qparam1)     (S32)       (FP32)
             \        |         /
              \       |        /
                [CirclePadV2]
                 (U8 qparam2)

AFTER (case 1)

By default qparam is propagated from output to inputs to meet backend requirements.

   [CircleNode] [CircleConst] [CircleConst]   [CircleConst] <- Dead node
   (U8 qparam2)     (S32)      (U8 qparam2)       (FP32)
             \        |         /
              \       |        /
                [CirclePadV2]
                 (U8 qparam2)

AFTER (case 2)

In case padded value is the lowest float value Qparam is propagated from input to output and constant.

This is a special case for optimization constructed pad, needed to guarantee that extremely large negative constant do not stretch output quantization range.

    [CircleNode] [CircleConst] [CircleConst]   [CircleConst] <- Dead node
    (U8 qparam1)     (S32)      (U8 qparam1)       (FP32)
              \        |         /
               \       |        /
                 [CirclePadV2]
                  (U8 qparam1)

Definition at line 385 of file PropagateQParamBackwardPass.cpp.

386{
387 if (ignore_pad_v2_const_quantization(pad_v2))
388 {
389 // propagate input quantization paramters from input to output and padding const value
390 auto pad_v2_input = loco::must_cast<luci::CircleNode *>(pad_v2->arg(0));
391 overwrite_quantparam(pad_v2_input, pad_v2);
392
393 auto const_value_node = loco::must_cast<luci::CircleConst *>(
394 pad_v2->arg(2)); // FIX ignore_pad_v2_const_quantization UNLESS
395 auto new_const = luci::clone(const_value_node);
396
397 const auto pad_v2_input_qparam = pad_v2_input->quantparam();
398 assert(pad_v2_input_qparam != nullptr);
399 assert(pad_v2_input_qparam->scale.size() == 1);
400 const auto scaling_factor = pad_v2_input_qparam->scale.at(0);
401 const auto zerop = pad_v2_input_qparam->zerop.at(0);
402
403 quant_const_values(new_const, scaling_factor, zerop, pad_v2->dtype());
404 overwrite_quantparam(pad_v2_input, new_const);
405 pad_v2->constant_values(new_const);
406 return;
407 }
408
409 // Propagate quantization paramters from output to inputs,
410 // to fit both input and counstant_value in one quant range.
411 auto quant_input = [pad_v2](void (CirclePadV2::*arg_setter)(loco::Node *), uint32_t arg) {
412 auto node = loco::must_cast<luci::CircleNode *>(pad_v2->arg(arg));
413
414 // Quantize constant values
415 if (node->opcode() == luci::CircleOpcode::CIRCLECONST)
416 {
417 luci::CircleConst *const_node = loco::must_cast<luci::CircleConst *>(node);
418 if (is_quantized(const_node))
419 return;
420
421 if (const_node->dtype() != loco::DataType::FLOAT32)
422 throw std::runtime_error("Unsupported data type for constant input of PadV2 Op");
423
424 const auto pad_v2_qparam = pad_v2->quantparam();
425 if (pad_v2_qparam == nullptr)
426 throw std::runtime_error("quantparam of PadV2 is not found during propagation");
427
428 assert(pad_v2_qparam->scale.size() == 1);
429 const auto scaling_factor = pad_v2_qparam->scale.at(0);
430 const auto zerop = pad_v2_qparam->zerop.at(0);
431
432 auto new_const = luci::clone(const_node);
433 quant_const_values(new_const, scaling_factor, zerop, pad_v2->dtype());
434 overwrite_quantparam(pad_v2, new_const);
435 (pad_v2->*arg_setter)(new_const);
436 }
437 else
438 {
439 const auto succs = loco::succs(node);
440 if (succs.size() > 1)
441 return;
442
443 // Non-const input must have been quantized
444 assert(node->quantparam() != nullptr);
445 overwrite_quantparam(pad_v2, node);
446 }
447 };
448
449 quant_input(&CirclePadV2::input, 0);
450 quant_input(&CirclePadV2::constant_values, 2);
451}
loco::Node * constant_values(void) const
Definition CirclePadV2.h:40
loco::Node * arg(uint32_t n) const final

References luci::FixedArityNode< N, Base >::arg(), clone(), luci::CirclePadV2::constant_values(), luci::CirclePadV2::input(), is_quantized(), luci::CircleNode::quantparam(), and loco::succs().

◆ quant_const()

void luci::quant_const ( luci::CircleConst node,
loco::DataType  quant_type 
)

Definition at line 418 of file QuantizationUtils.cpp.

419{
420 assert(node->dtype() == loco::DataType::FLOAT32);
421
422 float min = std::numeric_limits<float>::max();
423 float max = std::numeric_limits<float>::lowest();
424 for (uint32_t i = 0; i < node->size<loco::DataType::FLOAT32>(); i++)
425 {
426 auto data = node->at<loco::DataType::FLOAT32>(i);
427 min = data < min ? data : min;
428 max = data > max ? data : max;
429 }
430
431 float scaling_factor{0.0};
432 int64_t zp{0};
433 float nudged_min{0.0};
434 float nudged_max{0.0};
435
436 switch (quant_type)
437 {
438 case loco::DataType::U8:
439 asymmetric_wquant_with_minmax_per_layer(node, min, max, scaling_factor, zp, nudged_min,
440 nudged_max);
441 break;
442 case loco::DataType::S16:
443 symmetric_wquant_with_minmax_per_layer(node, min, max, scaling_factor, nudged_min,
444 nudged_max);
445 break;
446 default:
447 throw std::runtime_error("Unsupported data type");
448 }
449
450 auto quantparam = std::make_unique<luci::CircleQuantParam>();
451 quantparam->scale.push_back(scaling_factor);
452 quantparam->zerop.push_back(zp);
453 // Copy min and max values if it exists
454 if (node->quantparam())
455 {
456 quantparam->min = node->quantparam()->min;
457 quantparam->max = node->quantparam()->max;
458 }
459 node->quantparam(std::move(quantparam));
460}
void asymmetric_wquant_with_minmax_per_layer(CircleConst *node, float min, float max, float &scaling_factor, int64_t &zp, float &nudged_min, float &nudged_max)
void symmetric_wquant_with_minmax_per_layer(CircleConst *node, float min, float max, float &scaling_factor, float &nudged_min, float &nudged_max)

References asymmetric_wquant_with_minmax_per_layer(), luci::CircleConst::at(), flatbuffers::data(), luci::CircleQuantParam::max, luci::CircleQuantParam::min, luci::CircleNode::quantparam(), luci::CircleConst::size(), and symmetric_wquant_with_minmax_per_layer().

Referenced by propagate_concat_quantparam().

◆ REGISTER_WRAPPER() [1/8]

luci::REGISTER_WRAPPER ( flatbuffers::Offset< circle::Buffer >  )

◆ REGISTER_WRAPPER() [2/8]

luci::REGISTER_WRAPPER ( flatbuffers::Offset< circle::Metadata >  )

◆ REGISTER_WRAPPER() [3/8]

luci::REGISTER_WRAPPER ( flatbuffers::Offset< circle::Operator >  )

◆ REGISTER_WRAPPER() [4/8]

luci::REGISTER_WRAPPER ( flatbuffers::Offset< circle::OperatorCode >  )

◆ REGISTER_WRAPPER() [5/8]

luci::REGISTER_WRAPPER ( flatbuffers::Offset< circle::SubGraph >  )

◆ REGISTER_WRAPPER() [6/8]

luci::REGISTER_WRAPPER ( flatbuffers::Offset< circle::Tensor >  )

◆ REGISTER_WRAPPER() [7/8]

luci::REGISTER_WRAPPER ( int32_t  )

◆ REGISTER_WRAPPER() [8/8]

luci::REGISTER_WRAPPER ( uint8_t  )

◆ remove_unused_inputoutputs()

void luci::remove_unused_inputoutputs ( luci::PGroups pgroups,
const luci::Module source 
)

This will remove unused inputs/outputs in each pgroup of pgroups.

Definition at line 67 of file PartitionCleanup.cpp.

68{
69 assert(source != nullptr);
70 assert(pgroups != nullptr);
71
72 LOGGER(l);
73
74 INFO(l) << "--- Cleanup unused inputs/outputs";
75
76 // remove input within same pgroup
77 for (auto &pgroup : pgroups->pgroups)
78 {
79 bool changed;
80 do
81 {
82 changed = false;
83 for (auto it = pgroup->inputs.begin(); it != pgroup->inputs.end(); ++it)
84 {
85 auto input = *it;
86 if (pgroups->pgroup_of(input) == pgroup.get())
87 {
88 INFO(l) << " Cleanup input " << input->name() << " from group " << pgroup->group;
89 pgroup->inputs.erase(it);
90 changed = true;
91 break;
92 }
93 // NOTE CircleConst is one of input type, as they are registered as
94 // input to some node and then (should be) merged.
95 // Remove if this input is CircleConst
96 if (dynamic_cast<CircleConst *>(input) != nullptr)
97 {
98 INFO(l) << " Cleanup CircleConst " << input->name() << " from group " << pgroup->group;
99 pgroup->inputs.erase(it);
100 changed = true;
101 break;
102 }
103 }
104 } while (changed);
105 }
106
107 // remove unused output(s)
108 // 'used_outputs' will hold actual used outputs for all PGroups
109 CircleNodes used_outputs;
110
111 gather_graph_outputs(used_outputs, source);
112 gather_pgroups_outputs(used_outputs, pgroups);
113
114 for (auto &pgroup : pgroups->pgroups)
115 {
116 bool changed;
117 do
118 {
119 changed = false;
120 for (auto it = pgroup->outputs.begin(); it != pgroup->outputs.end(); ++it)
121 {
122 auto output = *it;
123 auto oit = std::find(used_outputs.begin(), used_outputs.end(), output);
124 if (oit == used_outputs.end())
125 {
126 INFO(l) << " Cleanup output " << output->name() << " from group " << pgroup->group;
127 pgroup->outputs.erase(it);
128 changed = true;
129 break;
130 }
131 }
132 } while (changed);
133 }
134}
const PGroup * pgroup_of(luci::CircleNode *node) const
return holding pgroup of node, nullptr if not found

References INFO, LOGGER, luci::PGroups::pgroup_of(), and luci::PGroups::pgroups.

Referenced by apply().

◆ set_int_scale()

void luci::set_int_scale ( luci::CircleNode node)

Definition at line 406 of file QuantizationUtils.cpp.

407{
408 assert(node); // FIX_CALLER_UNLESS
409
410 auto qparam = node->quantparam();
411 assert(qparam); // FIX_CALLER_UNLESS
412 assert(qparam->scale.size() == 1); // FIX_CALLER_UNLESS
413
414 auto fp_scale = qparam->scale[0];
415 qparam->scale[0] = fp_scale < 1 ? 1.0f : std::round(fp_scale);
416}

References luci::CircleNode::quantparam().

Referenced by luci::QuantizeSpecialActivation::visit(), luci::QuantizeSpecialActivation::visit(), luci::QuantizeSpecialActivation::visit(), and luci::QuantizeSpecialActivation::visit().

◆ set_node_id()

void luci::set_node_id ( luci::CircleNode circle_node,
luci::CircleNodeID  id 
)

Definition at line 59 of file CircleNodeID.cpp.

60{
61 circle_node->annot<CircleNodeIDAnnotation>(nullptr);
62 circle_node->annot(std::make_unique<CircleNodeIDAnnotation>(id));
63}

References loco::AnnotatedItem< Annotation >::annot().

◆ set_tensor_index()

void luci::set_tensor_index ( loco::Node node,
const CircleTensorIndex tensor_id 
)

Definition at line 308 of file CircleExporterUtils.cpp.

309{
310 assert(node->annot<CircleTensorIndexAnnotation>() == nullptr);
311 node->annot(std::make_unique<CircleTensorIndexAnnotation>(tensor_id));
312}

References loco::AnnotatedItem< Annotation >::annot().

◆ shape_get()

loco::NodeShape luci::shape_get ( const loco::Node node)

Definition at line 124 of file CircleShapeInferenceHelper.cpp.

125{
126 assert(luci::shape_known(node));
127 return loco::NodeShape{sinf::circle_shape(loco::must_cast<const luci::CircleNode *>(node))};
128}
bool shape_known(const loco::Node *node)

References luci::sinf::circle_shape(), and shape_known().

Referenced by luci::sinf::Algorithm::visit().

◆ shape_known()

bool luci::shape_known ( const loco::Node node)

Definition at line 130 of file CircleShapeInferenceHelper.cpp.

131{
132 return loco::must_cast<const luci::CircleNode *>(node)->shape_status() !=
134}

References UNDEFINED.

Referenced by shape_get().

◆ single_origin()

std::shared_ptr< CircleNodeOrigin > luci::single_origin ( uint32_t  id,
const std::string &  name 
)

Definition at line 120 of file CircleNodeOrigin.cpp.

121{
122 return std::make_shared<SingleOrigin>(id, name);
123}

Referenced by luci::CircleImportMetadata::origin_table().

◆ size()

uint32_t luci::size ( loco::DataType  data_type)
inline

Returns the size of the data type.

Note
luci saves S4, U4 in a single byte. The extra 4 bits in the MSB side are filled with sign bits.

Definition at line 31 of file DataTypeHelper.h.

32{
33 switch (data_type)
34 {
35 case loco::DataType::S4:
37 case loco::DataType::U4:
39 default:
40 return loco::size(data_type);
41 }
42}
uint32_t size(DataType data_type)
Returns the size of the data type.
C++ scalar type corresponding to each DataType.

References loco::size().

Referenced by luci_interpreter_pal::BroadcastTo(), mpqsolver::core::MAEMetric::compute(), circle_planner::ScratchpadHelperLinux::ComputeScratchpadSizeBatchMatMul(), entry(), luci_interpreter::getDataTypeSize(), circle_eval_diff::getEachByteSizeOf(), record_minmax::getTensorSize(), and circle_eval_diff::getTotalByteSizeOf().

◆ SparsifyTensorPass::sparsify_tensor< loco::DataType::FLOAT32 >()

template void luci::SparsifyTensorPass::sparsify_tensor< loco::DataType::FLOAT32 > ( luci::CircleConst cop)
extern

◆ SparsifyTensorPass::sparsify_tensor< loco::DataType::S32 >()

template void luci::SparsifyTensorPass::sparsify_tensor< loco::DataType::S32 > ( luci::CircleConst cop)
extern

◆ SparsifyTensorPass::sparsify_tensor< loco::DataType::S8 >()

template void luci::SparsifyTensorPass::sparsify_tensor< loco::DataType::S8 > ( luci::CircleConst cop)
extern

◆ str_to_dtype()

loco::DataType luci::str_to_dtype ( const std::string &  str)

Definition at line 47 of file Strings.cpp.

48{
49 if (to_lower_case(str).compare("uint4") == 0)
50 return loco::DataType::U4;
51 if (to_lower_case(str).compare("uint8") == 0)
52 return loco::DataType::U8;
53 if (to_lower_case(str).compare("uint16") == 0)
54 return loco::DataType::U16;
55 if (to_lower_case(str).compare("uint32") == 0)
56 return loco::DataType::U32;
57 if (to_lower_case(str).compare("uint64") == 0)
58 return loco::DataType::U64;
59
60 if (to_lower_case(str).compare("int4") == 0)
61 return loco::DataType::S4;
62 if (to_lower_case(str).compare("int8") == 0)
63 return loco::DataType::S8;
64 if (to_lower_case(str).compare("int16") == 0)
65 return loco::DataType::S16;
66 if (to_lower_case(str).compare("int32") == 0)
67 return loco::DataType::S32;
68 if (to_lower_case(str).compare("int64") == 0)
69 return loco::DataType::S64;
70
71 if (to_lower_case(str).compare("float16") == 0)
72 return loco::DataType::FLOAT16;
73 if (to_lower_case(str).compare("float32") == 0)
74 return loco::DataType::FLOAT32;
75 if (to_lower_case(str).compare("float64") == 0)
76 return loco::DataType::FLOAT64;
77
78 if (to_lower_case(str).compare("bool") == 0)
79 return loco::DataType::BOOL;
80
81 return loco::DataType::Unknown;
82}
std::string to_lower_case(std::string s)
Definition Strings.cpp:41

References flatbuffers::str, and to_lower_case().

◆ str_to_granularity()

QuantizationGranularity luci::str_to_granularity ( const std::string &  str)

Definition at line 93 of file Strings.cpp.

94{
95 if (to_lower_case(str).compare("layer") == 0)
96 return QuantizationGranularity::LayerWise;
97
98 if (to_lower_case(str).compare("channel") == 0)
99 return QuantizationGranularity::ChannelWise;
100
101 throw std::runtime_error("Quantization granularity must be either 'layer' or 'channel'");
102}

References ChannelWise, LayerWise, flatbuffers::str, and to_lower_case().

◆ str_vec_to_dtype_vec()

std::vector< loco::DataType > luci::str_vec_to_dtype_vec ( std::vector< std::string > &  vec)

Definition at line 85 of file Strings.cpp.

86{
87 std::vector<loco::DataType> res;
88 std::transform(vec.begin(), vec.end(), std::back_inserter(res),
89 [](std::string s) -> loco::DataType { return str_to_dtype(to_lower_case(s)); });
90 return res;
91}
DataType
"scalar" value type
Definition DataType.h:27

◆ swap_mul_add()

bool luci::swap_mul_add ( luci::CircleAdd add,
std::vector< luci::CircleMul * > &  mul_list,
std::vector< luci::CircleAdd * > &  add_list 
)

Swap MUL/ADD if they are from batch normalization

BEFORE [Mul] gamma | [Add + Relu] beta

AFTER [Add] beta/gamma | [Mul] gamma | [Relu]

Returns
true if success

Definition at line 499 of file FusePreActivationBatchNormPass.cpp.

501{
502 luci::CircleNode *pred_node = nullptr;
503 luci::CircleMul *mul = nullptr;
504 luci::CircleConst *beta = nullptr;
505 luci::CircleConst *gamma = nullptr;
506
507 if (!is_batchnorm_add(add, mul, beta))
508 return false;
509 if (add->fusedActivationFunction() != luci::FusedActFunc::RELU)
510 return false;
511
512 if (loco::succs(mul).size() != 1)
513 return false;
514
515 if (!is_batchnorm_mul(mul, pred_node, gamma))
516 return false;
517
518 if (beta->dtype() != loco::DataType::FLOAT32 || gamma->dtype() != loco::DataType::FLOAT32)
519 throw std::runtime_error("FusePreActivationBatchNormPass only supports Float32 model");
520
521 if (!is_non_negative(gamma))
522 return false;
523
524 // Insert Relu at the bottom
525 auto name = add->name();
526 assert(name.length() > 0);
527
528 auto relu = add->graph()->nodes()->create<luci::CircleRelu>();
529 relu->features(mul);
530 relu->name(name + "/Relu");
531 luci::add_origin(relu, luci::get_origin(add));
532 loco::replace(add).with(relu);
533
534 // Replace beta <- beta / gamma
535 if (add->x() == beta)
536 {
537 add->y(pred_node);
538 }
539 else
540 {
541 add->x(pred_node);
542 }
543 add->fusedActivationFunction(luci::FusedActFunc::NONE);
544 uint32_t size = beta->size<loco::DataType::FLOAT32>();
545 for (uint32_t i = 0; i < size; ++i)
546 {
547 auto b = beta->at<loco::DataType::FLOAT32>(i);
548 auto g = gamma->at<loco::DataType::FLOAT32>(i);
549 if (b == g)
550 {
551 beta->at<loco::DataType::FLOAT32>(i) = 1;
552 }
553 else
554 {
555 // If g is 0, we use a small value (empirically determined)
556 if (g == 0)
557 g = 1e-10;
558 beta->at<loco::DataType::FLOAT32>(i) = b / g;
559 }
560 }
561
562 if (mul->x() == gamma)
563 {
564 mul->y(add);
565 }
566 else
567 {
568 mul->x(add);
569 }
570
571 mul_list.push_back(mul);
572 add_list.push_back(add);
573
574 return true;
575}
RELU in Circle.
Definition CircleRelu.h:32

References luci::CircleConst::at(), is_batchnorm_add(), is_batchnorm_mul(), NONE, RELU, loco::replace(), luci::CircleConst::size(), size, loco::succs(), and loco::Subst< SubstQualifier::Default >::with().

Referenced by luci::FusePreActivationBatchNormPass::run().

◆ symmetric_wquant_with_minmax_per_layer()

void luci::symmetric_wquant_with_minmax_per_layer ( CircleConst node,
float  min,
float  max,
float &  scaling_factor,
float &  nudged_min,
float &  nudged_max 
)

Definition at line 75 of file QuantizationUtils.cpp.

78{
79 const int32_t kMaxScale = std::numeric_limits<int16_t>::max();
80 const int32_t kMinScale = -kMaxScale;
81
82 uint32_t size = node->size<loco::DataType::FLOAT32>();
83 compute_sym_scale(min, max, scaling_factor, nudged_min, nudged_max);
84 const float scaling_factor_inv = 1.0 / scaling_factor;
85 std::vector<int32_t> quantized_values(size);
86 for (uint32_t i = 0; i < size; ++i)
87 {
88 // clipping
89 auto data = node->at<loco::DataType::FLOAT32>(i);
90 data = data < nudged_min ? nudged_min : data;
91 data = data > nudged_max ? nudged_max : data;
92 quantized_values[i] = static_cast<int32_t>(std::round(data * scaling_factor_inv));
93 }
94
95 node->dtype(loco::DataType::S16); // change the type of tensor
96 node->size<loco::DataType::S16>(size); // resize tensor
97 for (uint32_t i = 0; i < size; ++i)
98 {
99 node->at<loco::DataType::S16>(i) =
100 std::min(kMaxScale, std::max(kMinScale, quantized_values[i]));
101 }
102}
void compute_sym_scale(float min, float max, float &scaling_factor, float &nudged_min, float &nudged_max, loco::DataType out_type)

References luci::CircleConst::at(), compute_sym_scale(), flatbuffers::data(), luci::CircleConst::size(), and size.

Referenced by quant_const().

◆ tensor_name()

const char * luci::tensor_name ( const circle::Tensor *  tensor)

Definition at line 29 of file CircleReader.cpp.

30{
31 assert(tensor != nullptr);
32
33 if (tensor->name() == nullptr || std::string(tensor->name()->c_str()).empty())
34 return "(noname)";
35
36 return tensor->name()->c_str();
37}

Referenced by luci::GraphBuilderMultiOutput::build(), luci::CircleWhileGraphBuilder::build(), copy_tensor_attributes(), luci::CircleOptimizer::sparsify(), luci::CircleCastGraphBuilder::validate(), luci::CircleGreaterGraphBuilder::validate(), and luci::CircleUnpackGraphBuilder::validate().

◆ tensor_quantization()

const circle::QuantizationParameters * luci::tensor_quantization ( const circle::Tensor *  tensor)

Definition at line 39 of file CircleReader.cpp.

40{
41 assert(tensor != nullptr);
42 return tensor->quantization();
43}

◆ to_circle_actfunc()

circle::ActivationFunctionType luci::to_circle_actfunc ( luci::FusedActFunc  func)

Definition at line 28 of file CircleExporterUtils.cpp.

29{
30 switch (func)
31 {
33 return circle::ActivationFunctionType_NONE;
35 return circle::ActivationFunctionType_RELU;
37 return circle::ActivationFunctionType_RELU_N1_TO_1;
39 return circle::ActivationFunctionType_RELU6;
41 return circle::ActivationFunctionType_TANH;
43 return circle::ActivationFunctionType_SIGN_BIT;
44 default:
45 INTERNAL_EXN_V("trying to convert unsupported luci::FusedActFunc", oops::to_uint32(func));
46 }
47}

References INTERNAL_EXN_V, NONE, RELU, RELU6, RELU_N1_TO_1, SIGN_BIT, TANH, and oops::to_uint32().

Referenced by luci::BuiltinOptionsExtractor::visit(), luci::BuiltinOptionsExtractor::visit(), luci::BuiltinOptionsExtractor::visit(), luci::BuiltinOptionsExtractor::visit(), luci::BuiltinOptionsExtractor::visit(), luci::BuiltinOptionsExtractor::visit(), luci::BuiltinOptionsExtractor::visit(), luci::BuiltinOptionsExtractor::visit(), luci::BuiltinOptionsExtractor::visit(), luci::BuiltinOptionsExtractor::visit(), luci::BuiltinOptionsExtractor::visit(), luci::BuiltinOptionsExtractor::visit(), luci::BuiltinOptionsExtractor::visit(), luci::BuiltinOptionsExtractor::visit(), luci::BuiltinOptionsExtractor::visit(), luci::BuiltinOptionsExtractor::visit(), luci::BuiltinOptionsExtractor::visit(), luci::BuiltinOptionsExtractor::visit(), and luci::BuiltinOptionsExtractor::visit().

◆ to_circle_dimensiontype()

circle::DimensionType luci::to_circle_dimensiontype ( luci::DimensionType  type)

Definition at line 132 of file CircleExporterUtils.cpp.

133{
134 switch (type)
135 {
137 return circle::DimensionType_DENSE;
139 return circle::DimensionType_SPARSE_CSR;
140 default:
141 INTERNAL_EXN_V("trying to convert unsupported luci::DimensionType", oops::to_uint32(type));
142 }
143}

References DENSE, INTERNAL_EXN_V, SPARSE_CSR, and oops::to_uint32().

◆ to_circle_mirrorpadmode()

circle::MirrorPadMode luci::to_circle_mirrorpadmode ( luci::MirrorPadMode  mode)

Definition at line 90 of file CircleExporterUtils.cpp.

91{
92 switch (mode)
93 {
95 return circle::MirrorPadMode::MirrorPadMode_REFLECT;
97 return circle::MirrorPadMode::MirrorPadMode_SYMMETRIC;
98 default:
99 INTERNAL_EXN_V("trying to convert unsupported luci::MirrorPadMode", oops::to_uint32(mode));
100 }
101}

References INTERNAL_EXN_V, REFLECT, SYMMETRIC, and oops::to_uint32().

Referenced by luci::BuiltinOptionsExtractor::visit().

◆ to_circle_rope()

circle::RoPEMode luci::to_circle_rope ( luci::RoPEMode  mode)

Definition at line 103 of file CircleExporterUtils.cpp.

104{
105 switch (mode)
106 {
108 return circle::RoPEMode::RoPEMode_GPT_NEOX;
110 return circle::RoPEMode::RoPEMode_GPT_J;
111 default:
112 INTERNAL_EXN_V("trying to convert unsupported luci::RoPEMode", oops::to_uint32(mode));
113 }
114}

References GPT_J, GPT_NEOX, INTERNAL_EXN_V, and oops::to_uint32().

Referenced by luci::BuiltinOptionsExtractor::visit().

◆ to_circle_sparse_index_vector()

flatbuffers::Offset< void > luci::to_circle_sparse_index_vector ( flatbuffers::FlatBufferBuilder fb,
const SparseIndexVector sparse_idx_vec 
)

Definition at line 145 of file CircleExporterUtils.cpp.

147{
148 auto type = sparse_idx_vec.type();
149 switch (type)
150 {
154 {
155 return circle::CreateInt32VectorDirect(fb, sparse_idx_vec.as_int32_vector()).Union();
156 }
158 {
159 return circle::CreateUint16VectorDirect(fb, sparse_idx_vec.as_uint16_vector()).Union();
160 }
162 {
163 return circle::CreateUint8VectorDirect(fb, sparse_idx_vec.as_uint8_vector()).Union();
164 }
165 default:
166 INTERNAL_EXN_V("trying to convert unsupported luci::SparseIndexVectorType",
167 oops::to_uint32(type));
168 }
169}
const std::vector< uint8_t > * as_uint8_vector(void) const
SparseIndexVectorType type(void) const
const std::vector< uint16_t > * as_uint16_vector(void) const
const std::vector< int32_t > * as_int32_vector(void) const

References luci::SparseIndexVector::as_int32_vector(), luci::SparseIndexVector::as_uint16_vector(), luci::SparseIndexVector::as_uint8_vector(), I32, INTERNAL_EXN_V, NONE, oops::to_uint32(), luci::SparseIndexVector::type(), U16, and U8.

◆ to_circle_sparse_index_vector_type()

circle::SparseIndexVector luci::to_circle_sparse_index_vector_type ( luci::SparseIndexVectorType  type)

Definition at line 171 of file CircleExporterUtils.cpp.

172{
173 switch (type)
174 {
176 return circle::SparseIndexVector_NONE;
178 return circle::SparseIndexVector_Int32Vector;
180 return circle::SparseIndexVector_Uint16Vector;
182 return circle::SparseIndexVector_Uint8Vector;
183 default:
184 INTERNAL_EXN_V("trying to convert unsupported luci::SparseIndexVectorType",
185 oops::to_uint32(type));
186 }
187}

References I32, INTERNAL_EXN_V, NONE, oops::to_uint32(), U16, and U8.

◆ to_circle_tensortype()

circle::TensorType luci::to_circle_tensortype ( loco::DataType  type)

Definition at line 49 of file CircleExporterUtils.cpp.

50{
51 switch (type)
52 {
53 case loco::DataType::U4:
54 return circle::TensorType_UINT4;
55 case loco::DataType::U8:
56 return circle::TensorType_UINT8;
57
58 case loco::DataType::S4:
59 return circle::TensorType_INT4;
60 case loco::DataType::S8:
61 return circle::TensorType_INT8;
62 case loco::DataType::S16:
63 return circle::TensorType_INT16;
64 case loco::DataType::S32:
65 return circle::TensorType_INT32;
66 case loco::DataType::S64:
67 return circle::TensorType_INT64;
68
69 case loco::DataType::FLOAT16:
70 return circle::TensorType_FLOAT16;
71 case loco::DataType::FLOAT32:
72 return circle::TensorType_FLOAT32;
73
74 case loco::DataType::BOOL:
75 return circle::TensorType_BOOL;
76
77 case loco::DataType::STRING:
78 return circle::TensorType_STRING;
79
80 case loco::DataType::MXFP4:
81 return circle::TensorType_MXFP4;
82 case loco::DataType::MXINT8:
83 return circle::TensorType_MXINT8;
84
85 default:
86 INTERNAL_EXN_V("failed to convert unsupported loco::DataType", oops::to_uint32(type));
87 }
88}

References INTERNAL_EXN_V, and oops::to_uint32().

Referenced by luci::BuiltinOptionsExtractor::visit(), luci::BuiltinOptionsExtractor::visit(), luci::BuiltinOptionsExtractor::visit(), luci::BuiltinOptionsExtractor::visit(), and luci::BuiltinOptionsExtractor::visit().

◆ to_circle_weightsformat()

circle::FullyConnectedOptionsWeightsFormat luci::to_circle_weightsformat ( luci::CircleFullyConnected::WeightsFormat  format)

Definition at line 117 of file CircleExporterUtils.cpp.

118{
119 switch (format)
120 {
122 return circle::FullyConnectedOptionsWeightsFormat_DEFAULT;
124 return circle::FullyConnectedOptionsWeightsFormat_SHUFFLED4x16INT8;
126 return circle::FullyConnectedOptionsWeightsFormat_SHUFFLED16x1FLOAT32;
127 default:
128 INTERNAL_EXN_V("trying to convert unsupported luci::WeightsFormat", oops::to_uint32(format));
129 }
130}

References luci::CircleFullyConnected::DEFAULT, INTERNAL_EXN_V, luci::CircleFullyConnected::SHUFFLED16x1FLOAT32, luci::CircleFullyConnected::SHUFFLED4x16INT8, and oops::to_uint32().

Referenced by luci::BuiltinOptionsExtractor::visit().

◆ to_compute() [1/2]

bool luci::to_compute ( const FusedActFunc  act,
compute::FusedActFunc act_func 
)

Definition at line 40 of file Compute.cpp.

41{
42 switch (act)
43 {
44 case FusedActFunc::NONE:
45 act_func = compute::FusedActFunc::NONE;
46 break;
47
48 case FusedActFunc::TANH:
49 act_func = compute::FusedActFunc::TANH;
50 break;
51
52 case FusedActFunc::RELU:
53 act_func = compute::FusedActFunc::RELU;
54 break;
55
56 case FusedActFunc::RELU_N1_TO_1:
57 act_func = compute::FusedActFunc::RELU_N1_TO_1;
58 break;
59
60 case FusedActFunc::RELU6:
61 act_func = compute::FusedActFunc::RELU6;
62 break;
63
64 default:
65 return false;
66 }
67 return true;
68}

References luci::compute::NONE, NONE, luci::compute::RELU, RELU, luci::compute::RELU6, RELU6, luci::compute::RELU_N1_TO_1, RELU_N1_TO_1, luci::compute::TANH, and TANH.

◆ to_compute() [2/2]

bool luci::to_compute ( const Padding  padding,
compute::PaddingType padding_type 
)

Definition at line 22 of file Compute.cpp.

23{
24 switch (padding)
25 {
26 case Padding::SAME:
27 padding_type = compute::PaddingType::kSame;
28 break;
29
30 case Padding::VALID:
31 padding_type = compute::PaddingType::kValid;
32 break;
33
34 default:
35 return false;
36 }
37 return true;
38}

References luci::compute::kSame, luci::compute::kValid, SAME, and VALID.

◆ to_lower_case()

std::string luci::to_lower_case ( std::string  s)

Definition at line 41 of file Strings.cpp.

42{
43 std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); });
44 return s;
45}

Referenced by str_to_dtype(), and str_to_granularity().

◆ to_shape_description() [1/3]

ShapeDescription luci::to_shape_description ( const loco::NodeShape shape)

Definition at line 56 of file ShapeDescription.cpp.

57{
58 switch (shape.domain())
59 {
61 return to_shape_description(shape.as<loco::TensorShape>());
62 default:
63 break;
64 }
65
66 INTERNAL_EXN_V("Unsupported loco domain", oops::to_uint32(shape.domain()));
67}
ShapeType as(void) const
const Domain & domain(void) const
Definition NodeShape.h:48

References loco::NodeShape::as(), loco::NodeShape::domain(), INTERNAL_EXN_V, loco::Tensor, to_shape_description(), and oops::to_uint32().

◆ to_shape_description() [2/3]

ShapeDescription luci::to_shape_description ( const loco::TensorShape shape)

Definition at line 39 of file ShapeDescription.cpp.

40{
42
43 res._rank_known = true;
44
45 res._dims.resize(shape.rank());
46 for (uint32_t axis = 0; axis < shape.rank(); ++axis)
47 {
48 // All the dimensions SHOULD be known
49 assert(shape.dim(axis).known());
50 res._dims.at(axis) = shape.dim(axis).value();
51 }
52
53 return res;
54}

References luci::ShapeDescription::_dims, luci::ShapeDescription::_rank_known, loco::TensorShape::dim(), loco::Dimension::known(), loco::TensorShape::rank(), and loco::Dimension::value().

◆ to_shape_description() [3/3]

ShapeDescription luci::to_shape_description ( const luci::CircleNode node)

Definition at line 26 of file ShapeDescription.cpp.

27{
29
30 res._rank_known = true;
31
32 res._dims.resize(circle_node->rank());
33 for (uint32_t i = 0; i < circle_node->rank(); ++i)
34 res._dims.at(i) = circle_node->dim(i).known() ? circle_node->dim(i).value() : -1;
35
36 return res;
37}

References luci::ShapeDescription::_dims, and luci::ShapeDescription::_rank_known.

Referenced by to_shape_description().

◆ to_string()

std::string luci::to_string ( const std::vector< std::string > &  strings)

Definition at line 29 of file Strings.cpp.

30{
31 assert(!strings.empty());
32
33 std::string res;
34 for (unsigned int i = 0; i < strings.size() - 1; i++)
35 res += strings[i] + ", ";
36
37 res += strings[strings.size() - 1];
38 return res;
39}

◆ to_tflite_sparsity() [1/3]

sparsity::TfLiteIntArray * luci::to_tflite_sparsity ( const luci::SparseIndexVector data)

Definition at line 237 of file SparsityFormatConverter.cpp.

238{
239 auto type = data.type();
240 switch (type)
241 {
243 {
244 std::vector<int32_t> empty;
245 return makeTfLiteArray(empty);
246 }
248 return makeTfLiteArray<int32_t>(*data.as_int32_vector());
250 return makeTfLiteArray<uint16_t>(*data.as_uint16_vector());
252 return makeTfLiteArray<uint8_t>(*data.as_uint8_vector());
253 default:
254 INTERNAL_EXN_V("unsupported SparseIndexVectorType", oops::to_uint32(type));
255 }
256}
sparsity::TfLiteIntArray * makeTfLiteArray(const std::vector< T > &data)

References I32, INTERNAL_EXN_V, makeTfLiteArray(), NONE, to_tflite_sparsity(), oops::to_uint32(), U16, and U8.

◆ to_tflite_sparsity() [2/3]

◆ to_tflite_sparsity() [3/3]

sparsity::TfLiteDimensionType luci::to_tflite_sparsity ( luci::DimensionType  dt)

Definition at line 225 of file SparsityFormatConverter.cpp.

226{
227 switch (dt)
228 {
230 return sparsity::TfLiteDimensionType::kTfLiteDimDense;
232 return sparsity::TfLiteDimensionType::kTfLiteDimSparseCSR;
233 }
234 return sparsity::TfLiteDimensionType::kTfLiteDimDense;
235}

References DENSE, SPARSE_CSR, and to_tflite_sparsity().

Referenced by makeTfLiteDimensionMetadata(), to_tflite_sparsity(), to_tflite_sparsity(), and to_tflite_sparsity().

◆ validate() [1/3]

bool luci::validate ( loco::Graph g)

Definition at line 322 of file Validate.cpp.

323{
324 if (!loco::valid(g))
325 return false;
326
327 if (!validate_shape_dtype(g))
328 return false;
329
330 if (!validate_multi_outs(g))
331 return false;
332
333 // TODO add more validation
334
335 return true;
336}
bool valid(Graph *g, std::unique_ptr< ErrorListener > &&l=nullptr)
Validate a loco graph.
Definition Verifier.cpp:100

References loco::valid().

◆ validate() [2/3]

bool luci::validate ( luci::Module module)

Definition at line 398 of file Validate.cpp.

399{
400 LOGGER(l);
401
402 INFO(l) << "--- validate Module -----------------------------------";
403
404 for (size_t g = 0; g < module->size(); ++g)
405 {
406 auto graph = module->graph(g);
407
408 INFO(l) << luci::fmt(graph) << std::endl;
409
410 if (!validate(graph))
411 {
412 std::cerr << "ERROR: Invalid circle model" << std::endl;
413 return false;
414 }
415 if (!validate_name(graph))
416 {
417 std::cerr << "ERROR: circle model has empty name" << std::endl;
418 return false;
419 }
420 }
421
422 if (!validate_unique_name(module))
423 {
424 std::cerr << "ERROR: circle model has duplicate names" << std::endl;
425 return false;
426 }
427
428 return true;
429}
bool validate_unique_name(luci::Module *)
Return true if all names in the Module are unique.
Definition Validate.cpp:357

References fmt(), INFO, LOGGER, validate_name(), and validate_unique_name().

◆ validate() [3/3]

bool luci::validate ( luci::PartitionTable partition)

Definition at line 28 of file PartitionValidate.cpp.

29{
30 if (partition.groups.size() == 0)
31 {
32 std::cerr << "There is no 'backends' information";
33 return false;
34 }
35 if (partition.default_group.empty())
36 {
37 std::cerr << "There is no 'default' backend information";
38 return false;
39 }
40 if (!pepper::is_one_of<std::string>(partition.default_group, partition.groups))
41 {
42 std::cerr << "'default' backend is not one of 'backends' item";
43 return false;
44 }
45 for (auto &byopcode : partition.byopcodes)
46 {
47 if (!pepper::is_one_of<std::string>(byopcode.second, partition.groups))
48 {
49 std::cerr << "OPCODE " << byopcode.first << " is not assigned to one of 'backends' items";
50 return false;
51 }
52 }
53 for (auto &byopname : partition.byopnames)
54 {
55 if (!pepper::is_one_of<std::string>(byopname.second, partition.groups))
56 {
57 std::cerr << "OPNAME " << byopname.first << " is not assigned to one of 'backends' items";
58 return false;
59 }
60 }
61 return true;
62}
std::vector< std::string > groups
Definition Partition.h:42

References luci::PartitionTable::byopcodes, luci::PartitionTable::byopnames, luci::PartitionTable::default_group, and luci::PartitionTable::groups.

Referenced by minmax_embedder::Embedder::embed(), onert::odc::Embedder::embed(), entry(), onert::odc::Quantizer::quantize(), mpqsolver::core::Quantizer::quantize(), and ReadModule().

◆ validate_batch_space_nd()

bool luci::validate_batch_space_nd ( const GraphBuilderBase::ValidateArgs args)

Definition at line 22 of file ValidateHelpers.cpp.

23{
24 const auto &inputs = args.op.inputs;
25 if (inputs.size() != 3)
26 return false;
27
28 // input 1 and 2 should have INT32/INT64 type
29 const auto tensors = args.reader.tensors();
30 const auto tensor_1 = tensors.at(inputs.at(1));
31 assert(tensor_1 != nullptr);
32 switch (tensor_1->type())
33 {
34 case circle::TensorType_INT32:
35 case circle::TensorType_INT64:
36 break;
37 default:
38 return false;
39 }
40 const auto tensor_2 = tensors.at(inputs.at(2));
41 assert(tensor_2 != nullptr);
42 switch (tensor_2->type())
43 {
44 case circle::TensorType_INT32:
45 case circle::TensorType_INT64:
46 break;
47 default:
48 return false;
49 }
50
51 // Only support input shape dimension 3 and 4 only
52 const auto tensor_0 = tensors.at(inputs.at(0));
53 assert(tensor_0 != nullptr);
54 const auto t_0_s = wrap(tensor_0->shape()).size();
55 if (t_0_s != 3 && t_0_s != 4)
56 return false;
57
58 // TODO check input shape
59
60 return true;
61}

References wrap().

Referenced by luci::CircleBatchToSpaceNDGraphBuilder::validate(), and luci::CircleSpaceToBatchNDGraphBuilder::validate().

◆ validate_minmax()

bool luci::validate_minmax ( const GraphBuilderBase::ValidateArgs args)

Definition at line 63 of file ValidateHelpers.cpp.

64{
65 const auto &inputs = args.op.inputs;
66 const auto &outputs = args.op.outputs;
67
68 if (inputs.size() != 2)
69 return false;
70
71 if (outputs.size() != 1)
72 return false;
73
74 const auto tensors = args.reader.tensors();
75 const auto tensor = tensors.at(inputs.at(0));
76 assert(tensor != nullptr);
77 switch (tensor->type())
78 {
79 case circle::TensorType_FLOAT16:
80 case circle::TensorType_FLOAT32:
81 case circle::TensorType_FLOAT64:
82 case circle::TensorType_INT16:
83 case circle::TensorType_INT32:
84 case circle::TensorType_INT64:
85 case circle::TensorType_UINT8:
86 break;
87 default:
88 return false;
89 }
90
91 assert(tensors[inputs.at(1)] != nullptr);
92 if (tensors[inputs.at(1)]->type() != tensor->type())
93 return false;
94
95 assert(tensors[outputs[0]] != nullptr);
96 if (tensors[outputs[0]]->type() != tensor->type())
97 return false;
98
99 return true;
100}

Referenced by luci::CircleMaximumGraphBuilder::validate(), and luci::CircleMinimumGraphBuilder::validate().

◆ validate_name()

bool luci::validate_name ( loco::Graph g)

Return true if all nodes in graph have non empty name.

Definition at line 338 of file Validate.cpp.

339{
340 auto nodes = g->nodes();
341 for (uint32_t n = 0; n < nodes->size(); ++n)
342 {
343 auto node = loco::must_cast<luci::CircleNode *>(nodes->at(n));
344 // skip virtual nodes
345 VirtualNodeDetector d;
346 if (node->accept(&d))
347 continue;
348
349 auto name = node->name();
350 if (name.empty())
351 return false;
352 }
353
354 return true;
355}

References luci::CircleNode::accept(), and luci::CircleNode::name().

Referenced by validate().

◆ validate_reduce_minmax()

bool luci::validate_reduce_minmax ( const GraphBuilderBase::ValidateArgs args)

Definition at line 102 of file ValidateHelpers.cpp.

103{
104 const auto &inputs = args.op.inputs;
105 const auto &outputs = args.op.outputs;
106
107 if (inputs.size() != 2)
108 return false;
109
110 if (outputs.size() != 1)
111 return false;
112
113 const auto tensors = args.reader.tensors();
114 const auto tensor_axis = tensors.at(inputs.at(1));
115 assert(tensor_axis != nullptr);
116 switch (tensor_axis->type())
117 {
118 case circle::TensorType_INT32:
119 case circle::TensorType_INT64:
120 break;
121 default:
122 return false;
123 }
124
125 return true;
126}

Referenced by luci::CircleReduceMaxGraphBuilder::validate(), and luci::CircleReduceMinGraphBuilder::validate().

◆ validate_shape() [1/2]

bool luci::validate_shape ( loco::Graph g)

Definition at line 311 of file Validate.cpp.

312{
313 if (!loco::valid(g))
314 return false;
315
316 if (!::validate_shape(g))
317 return false;
318
319 return true;
320}

References loco::valid(), and validate_shape().

Referenced by entry(), validate_shape(), and validate_shape().

◆ validate_shape() [2/2]

bool luci::validate_shape ( luci::Module module)

Definition at line 431 of file Validate.cpp.

432{
433 LOGGER(l);
434
435 INFO(l) << "--- validate shape of Module -----------------------------------";
436
437 for (size_t g = 0; g < module->size(); ++g)
438 {
439 auto graph = module->graph(g);
440
441 INFO(l) << luci::fmt(graph) << std::endl;
442
443 if (!validate_shape(graph))
444 {
445 std::cerr << "ERROR: Invalid circle model" << std::endl;
446 return false;
447 }
448 }
449
450 return true;
451}
bool validate_shape(loco::Graph *)
Definition Validate.cpp:311

References fmt(), INFO, LOGGER, and validate_shape().

◆ validate_unique_name()

bool luci::validate_unique_name ( luci::Module m)

Return true if all names in the Module are unique.

Note
CircleOutput may have duplicate name

Definition at line 357 of file Validate.cpp.

358{
359 LOGGER(l);
360
361 std::unordered_map<std::string, bool> names_col;
362
363 for (size_t g = 0; g < m->size(); ++g)
364 {
365 auto graph = m->graph(g);
366 auto nodes = graph->nodes();
367 for (uint32_t n = 0; n < nodes->size(); ++n)
368 {
369 auto node = loco::must_cast<luci::CircleNode *>(nodes->at(n));
370 // skip CircleOutput as it may have same name with from() node
371 auto output = dynamic_cast<luci::CircleOutput *>(node);
372 if (output != nullptr)
373 continue;
374 // skip virtual nodes
375 VirtualNodeDetector d;
376 if (node->accept(&d))
377 continue;
378
379 auto name = node->name();
380 INFO(l) << "Node: " << name << ", " << (uint32_t)(node->opcode()) << std::endl;
381 auto it = names_col.find(name);
382 if (it != names_col.end())
383 {
384 INFO(l) << "validate_unique_name: found duplicate " << name << ", " << graph->name()
385 << std::endl;
386 return false;
387 }
388
389 names_col[name] = true;
390 }
391 // There can exist same tensor name between different subgraphs.
392 names_col.clear();
393 }
394
395 return true;
396}

References luci::CircleNode::accept(), INFO, LOGGER, m, luci::CircleNode::name(), and luci::CircleNode::opcode().

Referenced by validate().

◆ warn_accuracy_with_range()

void luci::warn_accuracy_with_range ( luci::CircleNode n)

Definition at line 518 of file QuantizationUtils.cpp.

519{
520 LOGGER(l);
521 auto qp = n->quantparam();
522 auto k = qp->zerop.size();
523 for (uint32_t i = 0; i < k; i++)
524 {
525 if (warn_scale_zp(qp->scale[i], qp->zerop[i], n))
526 WARN(l) << "Quantization of " << i << "-th channel of " << n->name()
527 << "'s quantization may cause accuracy issues" << std::endl;
528 ;
529 }
530}
std::vector< int64_t > zerop

References LOGGER, luci::CircleNode::name(), luci::CircleNode::quantparam(), WARN, and luci::CircleQuantParam::zerop.

Referenced by luci::QuantizeWithMinMaxPass::run().

◆ wrap()

template<typename T >
VectorWrapper< T > luci::wrap ( const flatbuffers::Vector< T > *  vec)

Definition at line 82 of file CircleReader.h.

83{
84 return VectorWrapper<T>(vec);
85}
Wrapper to use flatbuffers::Vector pointer as std::vector entity.

Referenced by luci::CircleReader::buffers(), luci_interpreter::CircleReader::buffers(), luci_interpreter::CircleReferencingConstNodeBuilder::build(), luci::CircleConstNodeBuilder::build(), luci::CircleImportMetadata::CircleImportMetadata(), copy_tensor_attributes(), create_circlevariable(), luci_interpreter::Tensor::dim(), luci_interpreter::execute_kernel_CircleMean(), luci_interpreter::execute_kernel_CircleMirrorPad(), luci_interpreter::RuntimeGraph::getConstDataByTensor(), luci::CircleReader::inputs(), luci_interpreter::CircleReader::inputs(), luci::CircleReader::metadata(), luci_interpreter::CircleReader::metadata(), luci_interpreter::Tensor::num_dims(), luci_interpreter::Tensor::num_elements(), luci::CircleReader::num_subgraph(), luci_interpreter::CircleReader::num_subgraph(), luci::CircleReader::opcodes(), luci_interpreter::CircleReader::opcodes(), luci::CircleReader::operators(), luci_interpreter::CircleReader::operators(), luci::CircleReader::outputs(), luci_interpreter::CircleReader::outputs(), luci_interpreter::Tensor::tensor_shape(), luci::CircleReader::tensors(), luci_interpreter::CircleReader::tensors(), luci::CircleDepthwiseConv2DGraphBuilder::validate(), luci::CircleIfGraphBuilder::validate(), luci::CircleNonMaxSuppressionV4GraphBuilder::validate(), luci::CircleNonMaxSuppressionV5GraphBuilder::validate(), luci::CircleOneHotGraphBuilder::validate(), luci::CircleTransposeConvGraphBuilder::validate(), luci::CircleUnpackGraphBuilder::validate(), and validate_batch_space_nd().