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

Namespaces

namespace  onnx
 
namespace  test
 
namespace  tf
 

Data Structures

class  AddGraphBuilder
 GraphBuilder for Add node. More...
 
class  AvgPoolGraphBuilder
 
class  BiasAddGraphBuilder
 
struct  BinaryFunc
 
class  ConcatV2GraphBuilder
 
class  ConstantFoldAdd
 Constant folder for Const + Add -> Const. More...
 
class  ConstantFoldMul
 Constant folder for Const + Mul -> Const. More...
 
class  ConstantFoldPack
 Constant folder for Const + Pack -> Const. More...
 
class  ConstantFoldStridedSlice
 Constant folder for Const + StridedSlice -> Const. More...
 
class  ConstGraphBuilder
 
class  Conv2DBackpropInputGraphBuilder
 GraphBuilder for Conv2DBackpropInput node. More...
 
class  Conv2DGraphBuilder
 
class  DepthwiseConv2dNativeGraphBuilder
 GraphBuilder for DepthwiseConv2dNative node. More...
 
class  FakeQuantWithMinMaxVarsGraphBuilder
 GraphBuilder for FakeQuantWithMinMaxVars node. More...
 
class  FeatureShapeUpdater
 
class  FixedArityNode
 Nodes with the fixed number of inputs. More...
 
class  FuseBinaryIntoPreceding
 Fuse TFAdd, TFMul to preceding TFConv2D or TFDepthWiseConv2D. More...
 
class  FusedBatchNormGraphBuilder
 GraphBuilder for FusedBatchNorm node. More...
 
class  GraphBuilder
 Interface of convert TF NodeDef to loco::Node (e.g., Conv2DGraphBuilder) More...
 
class  GraphBuilderContext
 Class to store context to build loco graph IR from TensorFlow. More...
 
class  GraphBuilderRegistry
 Class to return graph builder for TF nodes. More...
 
struct  GraphBuilderSource
 
struct  GraphInputIndexAnnotation
 
class  GraphUpdate
 Interface to connect the graph. More...
 
class  IdentityGraphBuilder
 
class  Importer
 
class  Logger
 Logger Implementation. More...
 
class  LoggerConfig
 Logger Configuration. More...
 
struct  LoggingContext
 Global logging context. More...
 
class  MaximumGraphBuilder
 GraphBuilder for Maximum node. More...
 
class  MaxPoolGraphBuilder
 
class  MeanGraphBuilder
 GraphBuilder for Mean node. More...
 
struct  ModelSignature
 Class to store information to run a model. Normally this info comes from users via CLI params or configuration file. More...
 
class  MulGraphBuilder
 GraphBuilder for Mul node. More...
 
class  NodeDefTable
 Class to store and query tensorflow::NodeDef* with string name key. More...
 
class  PackGraphBuilder
 
class  Padding2DInference
 
class  PadGraphBuilder
 GraphBuilder for Pad node. More...
 
class  PlaceholderGraphBuilder
 GraphBuilder for Placeholder node. More...
 
class  PlaneInference
 
struct  PlaneShape
 
class  RealDivGraphBuilder
 GraphBuilder for RealDiv node. More...
 
class  Relu6GraphBuilder
 GraphBuilder for Relu6 node. More...
 
class  ReluGraphBuilder
 GraphBuilder for Relu node. More...
 
struct  RemoveTFIdentityNode
 Use the input of "TFIdentity" node instead. More...
 
class  ReshapeGraphBuilder
 GraphBuilder for Reshape node. More...
 
class  ResolveConstantShape
 Replace fully determined TFShape node into TFConst. More...
 
class  ResolveFusedBatchNorm
 Trasform TFFusedBatchNorm into TFAdd + TFRsqrt + TFMul + TFBatchNorm. More...
 
class  ResolveReshapeWildcardDim
 Determine wildcard dimension (denoted as -1) of Reshape's shape input if possible. More...
 
class  ResolveSquaredDifference
 Decompose TFSquaredDifference to TFSub, TFMul. More...
 
class  RsqrtGraphBuilder
 GraphBuilder for Rsqrt node. More...
 
class  ShapeGraphBuilder
 GraphBuilder for Shape node. More...
 
class  SoftmaxGraphBuilder
 GraphBuilder for Softmax node. More...
 
class  SqrtGraphBuilder
 GraphBuilder for Sqrt node. More...
 
class  SquaredDifferenceGraphBuilder
 GraphBuilder for SquaredDifference node. More...
 
class  SqueezeGraphBuilder
 GraphBuilder for Squeeze node. More...
 
class  SqueezeReduceNode
 If ReduceTypeOP don't keep dimensions, replace the ReduceTypeOp as new one to keep dimensions and insert TFSqueeze. More...
 
class  StopGradientGraphBuilder
 GraphBuilder for StopGradient node. More...
 
class  StridedSliceGraphBuilder
 
class  SubGraphBuilder
 GraphBuilder for Sub node. More...
 
class  SymbolTable
 Class to store and query loco::Node* with string name key. More...
 
class  TanhGraphBuilder
 GraphBuilder for Tanh node. More...
 
struct  TensorName
 
struct  TensorNameCompare
 To use TensorName as a key in std::map, this struct defines how to compare two TensorNames. More...
 
class  TensorPackEnumerator
 
class  TensorSliceEnumerator
 
class  TFAdd
 
class  TFAvgPool
 
class  TFBiasAdd
 
class  TFConcatV2
 
class  TFConst
 IR for tf.constant. More...
 
class  TFConv2D
 
class  TFConv2DBackpropInput
 
class  TFDepthwiseConv2dNative
 
class  TFDialect
 A singleton for TensorFlow Dialect. More...
 
class  TFFakeQuantWithMinMaxVars
 
class  TFFusedBatchNorm
 
class  TFIdentity
 
class  TFMaximum
 
class  TFMaxPool
 
class  TFMean
 
class  TFMul
 
struct  TFNode
 
struct  TFNodeImpl
 
struct  TFNodeMutableVisitor
 
struct  TFNodeMutableVisitorBase
 
struct  TFNodeVisitor
 
struct  TFNodeVisitorBase
 
class  TFPack
 
class  TFPad
 
class  TFPlaceholder
 IR for tf.placeholder. More...
 
class  TFPush
 Make a value visible to user. More...
 
class  TFRealDiv
 
class  TFRelu
 
class  TFRelu6
 
class  TFReshape
 
class  TFRsqrt
 
class  TFShape
 
struct  TFShapeInferenceRule
 Shape inference rule for TensorFlow dialect. More...
 
class  TFSoftmax
 
class  TFSqrt
 
class  TFSquaredDifference
 
class  TFSqueeze
 
class  TFStopGradient
 
class  TFStridedSlice
 
class  TFSub
 
class  TFTanh
 
struct  TFTypeInferenceRule
 Type Inference Rule for TFDialect. More...
 
class  UpdateQueue
 Class to store GraphUpdate objects. More...
 
class  VariadicArityNode
 Nodes with the variadic inputs. More...
 

Typedefs

using TFDataLayout = std::string
 
using NodeName = std::string
 
using TFPadding = std::string
 
using u32v_t = std::vector< uint32_t >
 
using TFStrides = std::vector< int64_t >
 
using TFKSize = std::vector< int64_t >
 

Enumerations

enum class  TFOpcode { TENSORFLOW_NODE }
 TensorFlow Node Opcode. More...
 

Functions

std::string str_toupper (std::string s)
 
template<typename T >
T * find_node_byname (loco::Graph *g, const char *name)
 find_node_byname() will return a node with type T with given name in graph g
 
bool indexed (const TFPlaceholder *node)
 
loco::GraphInputIndex index (const TFPlaceholder *node)
 
void index (TFPlaceholder *node, const loco::GraphInputIndex index)
 
loco::TensorShape tensor_shape (const TFPlaceholder *node)
 
TFPlaceholderplaceholder_node (loco::Graph *g, const loco::GraphInputIndex &idx)
 
TFPushpush_node (loco::Graph *g, const loco::GraphOutputIndex &index)
 Find a TFPush node with a given output index.
 
 INSTANTIATE (loco::DataType::S8)
 
 INSTANTIATE (loco::DataType::S32)
 
 INSTANTIATE (loco::DataType::FLOAT32)
 
TFConstnew_const (loco::Graph *graph, loco::TensorShape &tensor_shape, const loco::DataType &dtype)
 
template<>
int32_t scalar_from_const< int32_t > (const TFConst *tfconst)
 
template<>
float scalar_from_const< float > (const TFConst *tfconst)
 
bool valid_shape_for_constfold_binary_op (const loco::TensorShape &lhs, const loco::TensorShape &rhs)
 
template<>
void apply_binary< int32_t > (const moco::TFConst *x_const, const moco::TFConst *y_const, moco::TFConst *output_const, const moco::BinaryFunc &f)
 
template<>
void apply_binary< float > (const moco::TFConst *x_const, const moco::TFConst *y_const, moco::TFConst *output_const, const moco::BinaryFunc &f)
 
template<typename T >
scalar_from_const (const TFConst *tfconst)
 
template<>
int32_t scalar_from_const< int32_t > (const TFConst *tfconst)
 
template<>
float scalar_from_const< float > (const TFConst *tfconst)
 
template<typename T >
void apply_binary (const moco::TFConst *x_const, const moco::TFConst *y_const, moco::TFConst *output_const, const moco::BinaryFunc &f)
 
template<>
void apply_binary< int32_t > (const moco::TFConst *x_const, const moco::TFConst *y_const, moco::TFConst *output_const, const moco::BinaryFunc &f)
 
template<>
void apply_binary< float > (const moco::TFConst *x_const, const moco::TFConst *y_const, moco::TFConst *output_const, const moco::BinaryFunc &f)
 
template<typename DERIVED >
DERIVED * as (loco::Node *node)
 
loco::TensorShape broadcast_shape (const loco::TensorShape &x, const loco::TensorShape &y)
 
bool shape_inference_done (const loco::Node *node)
 Return true if node has shape inference data for checking shape inference is done or not.
 
loco::NodeShape node_shape (const loco::Node *node)
 
bool node_shape (const loco::Node *node, loco::NodeShape &nodeshape)
 
loco::TensorShape as_tensor_shape (const loco::FeatureShape &feature_shape, const TFDataLayout &data_layout)
 
loco::FeatureShape as_feature_shape (const loco::NodeShape &nodeshape, const TFDataLayout &data_layout)
 
PlaneShape make_plane_shape (const loco::FeatureShape &feature_shape)
 
FeatureShapeUpdater update (loco::FeatureShape &feature_shape)
 
loco::Stride< 2 > stride_of (const TFStrides &strides, const TFDataLayout &datalayout)
 
loco::Window< 2 > window_of (const TFKSize &ksize, const TFDataLayout &datalayout)
 
loco::Window< 2 > window_of (const loco::TensorShape &shape, const TFDataLayout &datalayout)
 

Typedef Documentation

◆ NodeName

using moco::NodeName = typedef std::string
Note
NodeName is string name of the Node without ':#' prefix like ':0' or ':1'

Definition at line 38 of file TFNodeDecl.h.

◆ TFDataLayout

using moco::TFDataLayout = typedef std::string

Definition at line 25 of file TFDataLayout.h.

◆ TFKSize

using moco::TFKSize = typedef std::vector<int64_t>

Definition at line 213 of file TFShapeInferenceHelper.h.

◆ TFPadding

using moco::TFPadding = typedef std::string

Definition at line 25 of file TFPadding.h.

◆ TFStrides

using moco::TFStrides = typedef std::vector<int64_t>

Definition at line 212 of file TFShapeInferenceHelper.h.

◆ u32v_t

typedef std::vector< uint32_t > moco::u32v_t

Definition at line 27 of file TensorPackEnumerator.h.

Enumeration Type Documentation

◆ TFOpcode

enum class moco::TFOpcode
strong

TensorFlow Node Opcode.

Enumerator
TENSORFLOW_NODE 

Definition at line 26 of file TFOpcode.h.

27{
28#define TENSORFLOW_NODE(OPCODE, CLASS) OPCODE,
29#include "TFNodes.lst"
30#undef TENSORFLOW_NODE
31};

Function Documentation

◆ apply_binary()

template<typename T >
void moco::apply_binary ( const moco::TFConst x_const,
const moco::TFConst y_const,
moco::TFConst output_const,
const moco::BinaryFunc f 
)

◆ apply_binary< float >() [1/2]

template<>
void moco::apply_binary< float > ( const moco::TFConst x_const,
const moco::TFConst y_const,
moco::TFConst output_const,
const moco::BinaryFunc f 
)

Definition at line 216 of file ConstantFoldHelper.cpp.

218{
219 auto x_shape = moco::tensor_shape(x_const);
220 auto y_shape = moco::tensor_shape(y_const);
221
222 if (y_shape.rank() == 0 || y_shape.rank() == 1)
223 {
224 auto rhs = scalar_from_const<float>(y_const);
225 apply_binary_f32(x_const, rhs, output_const, f);
226 }
227 else if (x_shape.rank() == 0 || x_shape.rank() == 1)
228 {
229 auto rhs = scalar_from_const<float>(x_const);
230 apply_binary_f32(y_const, rhs, output_const, f);
231 }
232 else
233 {
234 apply_binary_f32(x_const, y_const, output_const, f);
235 }
236}

References scalar_from_const< float >().

◆ apply_binary< float >() [2/2]

template<>
void moco::apply_binary< float > ( const moco::TFConst x_const,
const moco::TFConst y_const,
moco::TFConst output_const,
const moco::BinaryFunc f 
)

Definition at line 216 of file ConstantFoldHelper.cpp.

218{
219 auto x_shape = moco::tensor_shape(x_const);
220 auto y_shape = moco::tensor_shape(y_const);
221
222 if (y_shape.rank() == 0 || y_shape.rank() == 1)
223 {
224 auto rhs = scalar_from_const<float>(y_const);
225 apply_binary_f32(x_const, rhs, output_const, f);
226 }
227 else if (x_shape.rank() == 0 || x_shape.rank() == 1)
228 {
229 auto rhs = scalar_from_const<float>(x_const);
230 apply_binary_f32(y_const, rhs, output_const, f);
231 }
232 else
233 {
234 apply_binary_f32(x_const, y_const, output_const, f);
235 }
236}

References scalar_from_const< float >().

◆ apply_binary< int32_t >() [1/2]

template<>
void moco::apply_binary< int32_t > ( const moco::TFConst x_const,
const moco::TFConst y_const,
moco::TFConst output_const,
const moco::BinaryFunc f 
)

Definition at line 193 of file ConstantFoldHelper.cpp.

195{
196 auto x_shape = moco::tensor_shape(x_const);
197 auto y_shape = moco::tensor_shape(y_const);
198
199 if (y_shape.rank() == 0 || y_shape.rank() == 1)
200 {
201 auto rhs = scalar_from_const<int32_t>(y_const);
202 apply_binary_s32(x_const, rhs, output_const, f);
203 }
204 else if (x_shape.rank() == 0 || x_shape.rank() == 1)
205 {
206 auto rhs = scalar_from_const<int32_t>(x_const);
207 apply_binary_s32(y_const, rhs, output_const, f);
208 }
209 else
210 {
211 apply_binary_f32(x_const, y_const, output_const, f);
212 }
213}

References scalar_from_const< int32_t >().

◆ apply_binary< int32_t >() [2/2]

template<>
void moco::apply_binary< int32_t > ( const moco::TFConst x_const,
const moco::TFConst y_const,
moco::TFConst output_const,
const moco::BinaryFunc f 
)

Definition at line 193 of file ConstantFoldHelper.cpp.

195{
196 auto x_shape = moco::tensor_shape(x_const);
197 auto y_shape = moco::tensor_shape(y_const);
198
199 if (y_shape.rank() == 0 || y_shape.rank() == 1)
200 {
201 auto rhs = scalar_from_const<int32_t>(y_const);
202 apply_binary_s32(x_const, rhs, output_const, f);
203 }
204 else if (x_shape.rank() == 0 || x_shape.rank() == 1)
205 {
206 auto rhs = scalar_from_const<int32_t>(x_const);
207 apply_binary_s32(y_const, rhs, output_const, f);
208 }
209 else
210 {
211 apply_binary_f32(x_const, y_const, output_const, f);
212 }
213}

References scalar_from_const< int32_t >().

◆ as()

template<typename DERIVED >
DERIVED * moco::as ( loco::Node node)

Definition at line 25 of file NodeAs.h.

25{ return dynamic_cast<DERIVED *>(node); }

◆ as_feature_shape()

loco::FeatureShape moco::as_feature_shape ( const loco::NodeShape nodeshape,
const TFDataLayout data_layout 
)

Definition at line 189 of file TFShapeInferenceHelper.cpp.

191{
192 if (nodeshape.domain() == loco::Domain::Feature)
193 return nodeshape.as<loco::FeatureShape>();
194
195 loco::FeatureShape feature_shape;
196
197 // only convert from tensor to feature
198 if (nodeshape.domain() != loco::Domain::Tensor)
199 {
200 INTERNAL_EXN("ShapeInference: Invalid shape information");
201 }
202
203 loco::TensorShape tensor_shape = nodeshape.as<loco::TensorShape>();
204
205 if (tensor_shape.rank() != 4)
206 {
207 INTERNAL_EXN("ShapeInference: Rank is not 4");
208 }
209
210 if (data_layout == "NHWC")
211 {
212 feature_shape.count() = tensor_shape.dim(0);
213 feature_shape.height() = tensor_shape.dim(1);
214 feature_shape.width() = tensor_shape.dim(2);
215 feature_shape.depth() = tensor_shape.dim(3);
216 }
217 else if (data_layout == "NCHW")
218 {
219 feature_shape.count() = tensor_shape.dim(0);
220 feature_shape.depth() = tensor_shape.dim(1);
221 feature_shape.height() = tensor_shape.dim(2);
222 feature_shape.width() = tensor_shape.dim(3);
223 }
224 else
225 {
226 // TODO support for other data_layout if needed
227 INTERNAL_EXN_V("ShapeInference: Unknown data_format", data_layout);
228 }
229
230 return feature_shape;
231}
#define INTERNAL_EXN(msg)
@ brief throw internal exception with message
Definition InternalExn.h:25
#define INTERNAL_EXN_V(msg, val)
@ brief throw internal exception with message and value
Definition InternalExn.h:28
Feature Map Shape.
ShapeType as(void) const
const Domain & domain(void) const
Definition NodeShape.h:48
const Dimension & dim(uint32_t axis) const
Definition TensorShape.h:38
uint32_t rank(void) const
Definition TensorShape.h:35

References loco::NodeShape::as(), loco::TensorShape::dim(), loco::NodeShape::domain(), loco::Feature, INTERNAL_EXN, INTERNAL_EXN_V, loco::TensorShape::rank(), and loco::Tensor.

◆ as_tensor_shape()

loco::TensorShape moco::as_tensor_shape ( const loco::FeatureShape feature_shape,
const TFDataLayout data_layout 
)

Definition at line 160 of file TFShapeInferenceHelper.cpp.

162{
163 loco::TensorShape tensor_shape;
164
165 tensor_shape.rank(4);
166 if (data_layout == "NHWC")
167 {
168 tensor_shape.dim(0) = feature_shape.count();
169 tensor_shape.dim(1) = feature_shape.height();
170 tensor_shape.dim(2) = feature_shape.width();
171 tensor_shape.dim(3) = feature_shape.depth();
172 }
173 else if (data_layout == "NCHW")
174 {
175 tensor_shape.dim(0) = feature_shape.count();
176 tensor_shape.dim(1) = feature_shape.depth();
177 tensor_shape.dim(2) = feature_shape.height();
178 tensor_shape.dim(3) = feature_shape.width();
179 }
180 else
181 {
182 // TODO support for other data_layout if needed
183 INTERNAL_EXN_V("ShapeInference: Unknown data_format", data_layout);
184 }
185
186 return tensor_shape;
187}
const Dimension & depth(void) const
const Dimension & height(void) const
const Dimension & width(void) const
const Dimension & count(void) const

References loco::FeatureShape::count(), loco::FeatureShape::depth(), loco::TensorShape::dim(), loco::FeatureShape::height(), INTERNAL_EXN_V, loco::TensorShape::rank(), and loco::FeatureShape::width().

◆ broadcast_shape()

loco::TensorShape moco::broadcast_shape ( const loco::TensorShape x,
const loco::TensorShape y 
)
Note
Helper for return broadcasted shape for binary operators having different shape for input x and y

Definition at line 125 of file TFShapeInferenceHelper.cpp.

126{
127 auto x_match = x;
128 auto y_match = y;
129
130 expand_rank(x_match, y_match);
131
132 auto output_shape = expand_dimension(x_match, y_match);
133
134 return output_shape;
135}
const luci_interpreter::RuntimeShape output_shape

References output_shape.

◆ find_node_byname()

template<typename T >
T * moco::find_node_byname ( loco::Graph g,
const char *  name 
)

find_node_byname() will return a node with type T with given name in graph g

Note
this uses simple linear search, but can speed up with better algorithms when needed.

Definition at line 34 of file GraphHelper.h.

35{
36 T *first_node = nullptr;
37 loco::Graph::NodeContext *nodes = g->nodes();
38 uint32_t count = nodes->size();
39
40 for (uint32_t i = 0; i < count; ++i)
41 {
42 auto tfnode = dynamic_cast<TFNode *>(nodes->at(i));
43 if (tfnode != nullptr)
44 {
45 if (tfnode->name() == name)
46 {
47 // if tfnode is NOT type of T then return will be nullptr
48 // this is OK cause the user wanted to get type T but it isn't
49 return dynamic_cast<T *>(tfnode);
50 }
51 }
52 }
53
54 return nullptr;
55}
T * at(uint32_t n) const
Access N-th object.
Definition ObjectPool.h:41
uint32_t size(void) const
Return the number of objects.
Definition ObjectPool.h:38

References loco::ObjectPool< T >::at(), and loco::ObjectPool< T >::size().

◆ index() [1/2]

loco::GraphInputIndex moco::index ( const TFPlaceholder node)

Definition at line 54 of file TFNode.cpp.

55{
56 assert(indexed(node));
57 return node->annot<GraphInputIndexAnnotation>()->index();
58}
const T * annot(void) const
Retrieve a stored annotation of type T.
bool indexed(const TFPlaceholder *node)
Definition TFNode.cpp:49
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54

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

Referenced by moco::ConstGraphBuilder::build(), index(), index(), moco::onnx::SymbolTable::name(), moco::TensorName::nodeName(), placeholder_node(), push_node(), tensor_shape(), moco::TFConcatV2::values(), moco::TFPack::values(), moco::TFConcatV2::values(), and moco::TFPack::values().

◆ index() [2/2]

void moco::index ( TFPlaceholder node,
const loco::GraphInputIndex  index 
)

Definition at line 60 of file TFNode.cpp.

61{
62 node->annot(std::make_unique<GraphInputIndexAnnotation>(index));
63}

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

◆ indexed()

bool moco::indexed ( const TFPlaceholder node)

Definition at line 49 of file TFNode.cpp.

50{
51 return (node->annot<GraphInputIndexAnnotation>() != nullptr);
52}

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

Referenced by index(), and placeholder_node().

◆ INSTANTIATE() [1/3]

moco::INSTANTIATE ( loco::DataType::FLOAT32  )

◆ INSTANTIATE() [2/3]

moco::INSTANTIATE ( loco::DataType::S32  )

◆ INSTANTIATE() [3/3]

moco::INSTANTIATE ( loco::DataType::S8  )

◆ make_plane_shape()

PlaneShape moco::make_plane_shape ( const loco::FeatureShape feature_shape)

Definition at line 238 of file TFShapeInferenceHelper.cpp.

239{
240 PlaneShape plane_shape;
241
242 plane_shape.height = feature_shape.height();
243 plane_shape.width = feature_shape.width();
244
245 return plane_shape;
246}

References loco::FeatureShape::height(), moco::PlaneShape::height, loco::FeatureShape::width(), and moco::PlaneShape::width.

◆ new_const()

TFConst * moco::new_const ( loco::Graph graph,
loco::TensorShape tensor_shape,
const loco::DataType dtype 
)

Definition at line 45 of file ConstantFoldHelper.cpp.

46{
47 assert(dtype == loco::DataType::S32 || dtype == loco::DataType::FLOAT32);
48
49 auto const_node = graph->nodes()->create<TFConst>();
50 const_node->dtype(dtype);
51 const_node->rank(tensor_shape.rank());
52
53 // Calc number of elements for target node and set shape
54 uint32_t num_elements = 1;
55 for (uint32_t r = 0; r < tensor_shape.rank(); r++)
56 {
57 const_node->dim(r) = tensor_shape.dim(r);
58 assert(const_node->dim(r).known());
59 num_elements = num_elements * const_node->dim(r).value();
60 }
61 if (dtype == loco::DataType::S32)
62 const_node->size<loco::DataType::S32>(num_elements);
63 else if (dtype == loco::DataType::FLOAT32)
64 const_node->size<loco::DataType::FLOAT32>(num_elements);
65
66 // give name for this node from address to be unique
67 std::ostringstream oss;
68 oss << "Const_" << (void *)const_node;
69 const_node->name(oss.str());
70
71 return const_node;
72}
IR for tf.constant.
Definition TFConst.h:67

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

◆ node_shape() [1/2]

loco::NodeShape moco::node_shape ( const loco::Node node)
Note
While in shape inference, Node maybe Canonical, TF dialect or other dialects This will provide common loco::NodeShape as shape information

Definition at line 142 of file TFShapeInferenceHelper.cpp.

143{
144 loco::NodeShape nodeshape; // default domain is Unknown
145
146 if (loco::shape_known(node))
147 {
148 nodeshape = loco::shape_get(node);
149 }
150
151 return nodeshape;
152}
bool shape_known(const Node *node)
NodeShape shape_get(const Node *node)

References loco::shape_get(), and loco::shape_known().

Referenced by node_shape().

◆ node_shape() [2/2]

bool moco::node_shape ( const loco::Node node,
loco::NodeShape nodeshape 
)

Definition at line 154 of file TFShapeInferenceHelper.cpp.

155{
156 nodeshape = node_shape(node);
157 return (nodeshape.domain() != loco::Domain::Unknown);
158}
loco::NodeShape node_shape(const loco::Node *node)

References loco::NodeShape::domain(), node_shape(), and loco::Unknown.

◆ placeholder_node()

TFPlaceholder * moco::placeholder_node ( loco::Graph g,
const loco::GraphInputIndex idx 
)

Definition at line 84 of file TFNode.cpp.

85{
86 for (uint32_t n = 0; n < g->nodes()->size(); ++n)
87 {
88 if (auto tfplaceholder = dynamic_cast<TFPlaceholder *>(g->nodes()->at(n)))
89 {
90 if (indexed(tfplaceholder) && index(tfplaceholder) == idx)
91 {
92 return tfplaceholder;
93 }
94 }
95 }
96 return nullptr;
97}
IR for tf.placeholder.
int32_t size[5]
Definition Slice.cpp:35

References index(), indexed(), and size.

Referenced by moco::PlaceholderGraphBuilder::build().

◆ push_node()

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

Find a TFPush node with a given output index.

Definition at line 121 of file TFNode.cpp.

122{
123 for (uint32_t n = 0; n < g->nodes()->size(); ++n)
124 {
125 if (auto tfpush = dynamic_cast<TFPush *>(g->nodes()->at(n)))
126 {
127 if (tfpush->indexed() && tfpush->index() == index)
128 {
129 return tfpush;
130 }
131 }
132 }
133 return nullptr;
134}
Make a value visible to user.
Definition TFPush.h:42

References index(), and size.

◆ scalar_from_const()

template<typename T >
T moco::scalar_from_const ( const TFConst tfconst)

◆ scalar_from_const< float >() [1/2]

template<>
float moco::scalar_from_const< float > ( const TFConst tfconst)

Definition at line 86 of file ConstantFoldHelper.cpp.

87{
88 assert(tfconst->rank() == 0 || tfconst->rank() == 1);
89 assert(tfconst->dtype() == loco::DataType::FLOAT32);
90 return tfconst->at<loco::DataType::FLOAT32>(0);
91}
const loco::DataTypeImpl< DT >::Type & at(uint32_t n) const
Definition TFConst.cpp:38

References moco::TFConst::at().

Referenced by apply_binary< float >().

◆ scalar_from_const< float >() [2/2]

template<>
float moco::scalar_from_const< float > ( const TFConst tfconst)

Definition at line 86 of file ConstantFoldHelper.cpp.

87{
88 assert(tfconst->rank() == 0 || tfconst->rank() == 1);
89 assert(tfconst->dtype() == loco::DataType::FLOAT32);
90 return tfconst->at<loco::DataType::FLOAT32>(0);
91}

References moco::TFConst::at().

Referenced by apply_binary< float >().

◆ scalar_from_const< int32_t >() [1/2]

template<>
int32_t moco::scalar_from_const< int32_t > ( const TFConst tfconst)

Definition at line 79 of file ConstantFoldHelper.cpp.

80{
81 assert(tfconst->rank() == 0 || tfconst->rank() == 1);
82 assert(tfconst->dtype() == loco::DataType::S32);
83 return tfconst->at<loco::DataType::S32>(0);
84}

References moco::TFConst::at().

Referenced by apply_binary< int32_t >().

◆ scalar_from_const< int32_t >() [2/2]

template<>
int32_t moco::scalar_from_const< int32_t > ( const TFConst tfconst)

Definition at line 79 of file ConstantFoldHelper.cpp.

80{
81 assert(tfconst->rank() == 0 || tfconst->rank() == 1);
82 assert(tfconst->dtype() == loco::DataType::S32);
83 return tfconst->at<loco::DataType::S32>(0);
84}

References moco::TFConst::at().

Referenced by apply_binary< int32_t >().

◆ shape_inference_done()

bool moco::shape_inference_done ( const loco::Node node)

Return true if node has shape inference data for checking shape inference is done or not.

Note
Will be deprecated in near future

◆ str_toupper()

std::string moco::str_toupper ( std::string  s)

Definition at line 27 of file Convert.cpp.

28{
29 // from https://en.cppreference.com/w/cpp/string/byte/toupper
30 std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::toupper(c); });
31 return s;
32}

Referenced by moco::AvgPoolGraphBuilder::build(), moco::Conv2DGraphBuilder::build(), moco::MaxPoolGraphBuilder::build(), moco::Conv2DBackpropInputGraphBuilder::build(), moco::DepthwiseConv2dNativeGraphBuilder::build(), and moco::DepthwiseConv2dNativeGraphBuilder::validate().

◆ stride_of()

loco::Stride< 2 > moco::stride_of ( const TFStrides strides,
const TFDataLayout datalayout 
)

Definition at line 283 of file TFShapeInferenceHelper.cpp.

284{
285 loco::Stride<2> stride;
286
287 auto data_layout = as_data_layout(datalayout);
288 if (data_layout == DataLayout::NHWC)
289 {
290 stride.vertical(strides[1]);
291 stride.horizontal(strides[2]);
292 }
293 else if (data_layout == DataLayout::NCHW)
294 {
295 stride.vertical(strides[2]);
296 stride.horizontal(strides[3]);
297 }
298 else
299 {
300 // TODO add more datalayout supports if needed
301 INTERNAL_EXN("ShapeInference: Unknown data_format");
302 }
303
304 return stride;
305}
Stride configuration for N-dimensional spatial operations.
Definition Stride.h:28

References INTERNAL_EXN.

◆ tensor_shape()

loco::TensorShape moco::tensor_shape ( const TFPlaceholder node)

Definition at line 65 of file TFNode.cpp.

66{
67 assert(node != nullptr);
68
70
71 uint32_t rank = node->rank();
72 shape.rank(rank);
73 for (uint32_t index = 0; index < rank; ++index)
74 {
75 if (node->dim(index).known())
76 shape.dim(index) = node->dim(index).value();
77 else
78 shape.dim(index).unset();
79 }
80
81 return shape;
82}
void unset(void)
Definition Dimension.h:59

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

◆ update()

◆ valid_shape_for_constfold_binary_op()

bool moco::valid_shape_for_constfold_binary_op ( const loco::TensorShape lhs,
const loco::TensorShape rhs 
)
Note
Check if it is valid to run Constant folding for binary operations as-of current implementation. That is currently we support for element-wise or one of the input is scalar. TODO Support other shapes of binary operation

Definition at line 93 of file ConstantFoldHelper.cpp.

94{
95 // scalar
96 if (lhs.rank() == 0 || rhs.rank() == 0)
97 return true;
98
99 // same as scalar
100 if (lhs.rank() == 1 && lhs.dim(0).value() == 1)
101 return true;
102 if (rhs.rank() == 1 && rhs.dim(0).value() == 1)
103 return true;
104
105 // for elementwise binary operation
106 return ::same_shape(&lhs, &rhs);
107}
uint32_t value(void) const
Return the value.
Definition Dimension.h:51

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

◆ window_of() [1/2]

loco::Window< 2 > moco::window_of ( const loco::TensorShape shape,
const TFDataLayout datalayout 
)

Definition at line 331 of file TFShapeInferenceHelper.cpp.

332{
333 loco::Window<2> window;
334
335 if (datalayout == "HWIO")
336 {
337 window.vertical(shape.dim(0).value());
338 window.horizontal(shape.dim(1).value());
339 }
340 else if (datalayout == "HWCM")
341 {
342 window.vertical(shape.dim(0).value());
343 window.horizontal(shape.dim(1).value());
344 }
345 else
346 {
347 // TODO add more datalayout supports if needed
348 INTERNAL_EXN_V("ShapeInference: Unknown data_format", datalayout);
349 }
350
351 return window;
352}
ND Receptive Field Shape.
Definition Window.h:30

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

◆ window_of() [2/2]

loco::Window< 2 > moco::window_of ( const TFKSize ksize,
const TFDataLayout datalayout 
)

Definition at line 307 of file TFShapeInferenceHelper.cpp.

308{
309 loco::Window<2> window;
310
311 auto data_layout = as_data_layout(datalayout);
312 if (data_layout == DataLayout::NHWC)
313 {
314 window.vertical(ksize[1]);
315 window.horizontal(ksize[2]);
316 }
317 else if (data_layout == DataLayout::NCHW)
318 {
319 window.vertical(ksize[2]);
320 window.horizontal(ksize[3]);
321 }
322 else
323 {
324 // TODO add more datalayout supports if needed
325 INTERNAL_EXN("ShapeInference: Unknown data_format");
326 }
327
328 return window;
329}

References INTERNAL_EXN.