Data Structures | Public Types | Public Member Functions | Data Fields | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes
ngraph Class Reference

MatcherPass is a basic block for pattern based transformations. It describes pattern and action that is applied if pattern is matched. More...

#include <graph_rewrite.hpp>

Inheritance diagram for ngraph:
Inheritance graph
[legend]
Collaboration diagram for ngraph:
Collaboration graph
[legend]

Data Structures

class  AttributeAdapter< Coordinate >
 
class  AttributeAdapter< CoordinateDiff >
 
class  AttributeAdapter< element::Type >
 
class  AttributeAdapter< element::Type_t >
 
class  AttributeAdapter< NodeVector >
 
class  AttributeAdapter< op::AutoBroadcastSpec >
 
class  AttributeAdapter< op::AutoBroadcastType >
 
class  AttributeAdapter< op::BroadcastModeSpec >
 
class  AttributeAdapter< op::BroadcastType >
 
class  AttributeAdapter< op::EpsMode >
 
class  AttributeAdapter< op::LSTMWeightsFormat >
 
class  AttributeAdapter< op::PadMode >
 
class  AttributeAdapter< op::PadType >
 
class  AttributeAdapter< op::RecurrentSequenceDirection >
 
class  AttributeAdapter< op::RoundingType >
 
class  AttributeAdapter< op::TopKMode >
 
class  AttributeAdapter< op::TopKSortType >
 
class  AttributeAdapter< op::v0::DepthToSpace::DepthToSpaceMode >
 
class  AttributeAdapter< op::v0::Interpolate::InterpolateMode >
 
class  AttributeAdapter< op::v0::SpaceToDepth::SpaceToDepthMode >
 
class  AttributeAdapter< op::v1::BinaryConvolution::BinaryConvolutionMode >
 
class  AttributeAdapter< op::v1::NonMaxSuppression::BoxEncodingType >
 
class  AttributeAdapter< op::v1::Reverse::Mode >
 
class  AttributeAdapter< op::v3::NonMaxSuppression::BoxEncodingType >
 
class  AttributeAdapter< op::v3::ROIAlign::PoolingMode >
 
class  AttributeAdapter< op::v4::Interpolate::CoordinateTransformMode >
 
class  AttributeAdapter< op::v4::Interpolate::InterpolateMode >
 
class  AttributeAdapter< op::v4::Interpolate::NearestMode >
 
class  AttributeAdapter< op::v4::Interpolate::ShapeCalcMode >
 
class  AttributeAdapter< ParameterVector >
 
class  AttributeAdapter< PartialShape >
 
class  AttributeAdapter< reduction::Type >
 
class  AttributeAdapter< ResultVector >
 
class  AttributeAdapter< Shape >
 
class  AttributeAdapter< std::shared_ptr< Function > >
 
class  AttributeAdapter< std::shared_ptr< Node > >
 Visits a reference to a node that has been registered with the visitor. More...
 
class  AttributeAdapter< std::shared_ptr< op::TensorIterator::InputDescription > >
 
class  AttributeAdapter< std::shared_ptr< op::TensorIterator::OutputDescription > >
 
class  AttributeAdapter< std::shared_ptr< runtime::AlignedBuffer > >
 
class  AttributeAdapter< std::vector< std::shared_ptr< op::TensorIterator::InputDescription > > >
 
class  AttributeAdapter< std::vector< std::shared_ptr< op::TensorIterator::OutputDescription > > >
 
class  AttributeAdapter< Strides >
 
class  bfloat16
 
class  ConstString
 
class  Coordinate
 Coordinates for a tensor element. More...
 
class  CoordinateDiff
 A difference (signed) of tensor element coordinates. More...
 
class  Dimension
 Class representing a dimension, which may be dynamic (undetermined until runtime), in a shape or shape-like object. More...
 
struct  DiscreteTypeInfo
 
struct  element_type_traits
 
struct  element_type_traits< element::Type_t::bf16 >
 
struct  element_type_traits< element::Type_t::boolean >
 
struct  element_type_traits< element::Type_t::f16 >
 
struct  element_type_traits< element::Type_t::f32 >
 
struct  element_type_traits< element::Type_t::f64 >
 
struct  element_type_traits< element::Type_t::i16 >
 
struct  element_type_traits< element::Type_t::i32 >
 
struct  element_type_traits< element::Type_t::i64 >
 
struct  element_type_traits< element::Type_t::i8 >
 
struct  element_type_traits< element::Type_t::u1 >
 
struct  element_type_traits< element::Type_t::u16 >
 
struct  element_type_traits< element::Type_t::u32 >
 
struct  element_type_traits< element::Type_t::u64 >
 
struct  element_type_traits< element::Type_t::u8 >
 
class  EnumMask
 
class  EnumNames
 
class  Evaluator
 Execute handlers on a subgraph to compute values. More...
 
class  FactoryAttributeAdapter
 
class  FactoryRegistry
 Registry of factories that can construct objects derived from BASE_TYPE. More...
 
class  float16
 
class  Function
 A user-defined function. More...
 
class  Input
 
class  Input< const Node >
 A handle for one of a node's inputs. More...
 
class  Input< Node >
 A handle for one of a node's inputs. More...
 
class  Interval
 Interval arithmetic. More...
 
class  Logger
 
class  LogHelper
 
class  ngraph_error
 Base error for ngraph runtime errors. More...
 
class  Node
 
class  NodeValidationFailure
 
struct  NullLogger
 
class  OpSet
 Run-time opset information. More...
 
class  Output
 
class  Output< const Node >
 
class  Output< Node >
 A handle for one of a node's outputs. More...
 
class  PartialShape
 Class representing a shape that may be partially or totally dynamic. More...
 
struct  RawNodeOutput
 
class  Shape
 Shape for a tensor. More...
 
struct  SlicePlan
 
class  stopwatch
 
class  Strides
 Strides for a tensor. More...
 
class  unsupported_op
 
class  Variable
 
struct  VariableInfo
 
class  Variant
 
class  VariantImpl
 
class  VariantWrapper
 
class  VariantWrapper< int64_t >
 
class  VariantWrapper< std::string >
 

Public Types

enum  LOG_TYPE { _LOG_TYPE_ERROR, _LOG_TYPE_WARNING, _LOG_TYPE_INFO, _LOG_TYPE_DEBUG }
 
using HostTensor = runtime::HostTensor
 
using HostTensorPtr = std::shared_ptr< HostTensor >
 
using HostTensorVector = std::vector< HostTensorPtr >
 
using ResultVector = std::vector< std::shared_ptr< op::v0::Result > >
 
using NodeMap = std::unordered_map< ngraph::Node *, std::shared_ptr< ngraph::Node > >
 Alias useful for cloning.
 
using NodeTypeInfo = Node::type_info_t
 
using RawNodeOutputMap = std::map< RawNodeOutput, Output< Node > >
 
using ParameterVector = std::vector< std::shared_ptr< op::Parameter > >
 
using ResultVector = std::vector< std::shared_ptr< op::Result > >
 
using NodeVector = std::vector< std::shared_ptr< Node > >
 
using OutputVector = std::vector< Output< Node > >
 
using matcher_pass_callback = std::function< bool(ngraph::pattern::Matcher &m)>
 
using graph_rewrite_callback = std::function< bool(ngraph::pattern::Matcher &m)>
 
using recurrent_graph_rewrite_callback = std::function< bool(ngraph::pattern::RecurrentMatcher &m)>
 
using handler_callback = std::function< bool(const std::shared_ptr< Node > &node)>
 
using node_modifiers_t = std::function< void(const Node &node, std::vector< std::string > &attributes)>
 
using Rank = Dimension
 Alias for Dimension, used when the value represents the number of axes in a shape, rather than the size of one dimension in a shape. More...
 
using NodeExecutorTy = std::function< void(const std::vector< void * > &inputs, std::vector< void * > &outputs)>
 
using BuildNodeExecutor = std::function< NodeExecutorTy(const ngraph::Node *)>
 
using BuildNodeExecutorMap = std::unordered_map< std::type_index, BuildNodeExecutor >
 
using VariantTypeInfo = DiscreteTypeInfo
 

Public Member Functions

 Duration (const std::string &name, const std::string &category, const std::string &args="")
 
void stop ()
 stop the timer without writing the data to the log file. To write the data call the write method Calls to stop() are optional
 
void write ()
 write the log data to the log file for this event This funtion has an implicit stop() if stop() has not been previously called
 
 Duration (const Duration &)=delete
 
Duration & operator= (Duration const &)=delete
 
 ConstantFolding (const ngraph::BuildNodeExecutorMap &cfmap=ngraph::BuildNodeExecutorMap())
 
 ConvertFP32ToFP16 ()
 
 MatcherPass ()=default
 
 MatcherPass (const MatcherPass &)=delete
 
MatcherPass & operator= (const MatcherPass &)=delete
 
 MatcherPass (const std::string &name, const std::shared_ptr< pattern::Matcher > &m, const handler_callback &handler, const PassPropertyMask &property=PassProperty::CHANGE_DYNAMIC_STATE)
 
bool apply (std::shared_ptr< ngraph::Node > node)
 
template<typename T , class... Args>
std::shared_ptr< T > register_new_node (Args &&... args)
 
const std::vector< std::shared_ptr< ngraph::Node > > & get_new_nodes ()
 
void clear_new_nodes ()
 
std::shared_ptr< pattern::Matcher > get_matcher ()
 
 GraphRewrite ()=default
 
 GraphRewrite (const std::shared_ptr< MatcherPass > &pass)
 
template<typename T , class... Args>
std::shared_ptr< T > add_matcher (Args &&... args)
 
void add_matcher (const std::shared_ptr< pattern::Matcher > &m, const ngraph::graph_rewrite_callback &callback, const PassPropertyMask &property)
 
void add_matcher (const std::shared_ptr< pattern::Matcher > &m, const ngraph::graph_rewrite_callback &callback)
 
bool run_on_function (std::shared_ptr< ngraph::Function > f) override
 
 RecurrentGraphRewrite (size_t num_iters=10)
 
void add_matcher (const std::shared_ptr< pattern::RecurrentMatcher > &m, const ngraph::recurrent_graph_rewrite_callback &callback, const PassPropertyMask &property)
 
void add_matcher (const std::shared_ptr< pattern::RecurrentMatcher > &m, const ngraph::recurrent_graph_rewrite_callback &callback)
 
virtual bool run_on_function (std::shared_ptr< ngraph::Function > f)
 
 Manager ()
 
template<typename T , class... Args>
std::shared_ptr< T > register_pass (Args &&... args)
 
void run_passes (std::shared_ptr< Function >)
 
void set_pass_visualization (bool new_state)
 
void set_per_pass_validation (bool new_state)
 Set flag to enable/disable running Validate pass after executing each registered pass. More...
 
void set_callback (param_callback callback)
 Callback is a lambda function that can be used by registered transformations. The main purpose of this callback is to provide a way for plugins to disable/enable transformations. In some cases plugins may want not to execute some transformations. For example plugin can disable unpleasant decompositions because of performance reasons. Callback example: auto callback = [](const std::shared_ptr<const ngraph::Node> & node) -> bool { return std::dynamic_pointer_cast<const ngraph::opset3::DepthToSpace>(node) != nullptr; }; This callback returns true in case of DepthToSpace operation. So when execution DepthToSpace decomposition pass will check is this decomposition needed or plugin can execute this operation directly. And of course on transformation side we need to have a response for this callback. if (m_transformation_callback(batch_to_space)) { return false; }. More...
 
 PassConfig ()
 
const std::map< std::string, bool > & get_enables () const
 
void set_pass_enable (const std::string &name, bool enable)
 
bool get_pass_enable (const std::string &name) const
 
const std::map< std::string, bool > & get_pass_attributes () const
 
void set_pass_attribute (const std::string &name, bool enable)
 
bool get_pass_attribute (const std::string &name) const
 
 VisualizeTree (const std::string &file_name, node_modifiers_t nm=nullptr, bool dot_only=false)
 
bool run_on_function (std::shared_ptr< ngraph::Function >) override
 
void set_ops_to_details (const visualize_tree_ops_map_t &ops_map)
 
 AlignedBuffer (size_t byte_size, size_t alignment=64)
 
 AlignedBuffer ()
 
 AlignedBuffer (AlignedBuffer &&other)
 
AlignedBuffer & operator= (AlignedBuffer &&other)
 
size_t size () const
 
void * get_ptr (size_t offset) const
 
void * get_ptr ()
 
const void * get_ptr () const
 
template<typename T >
T * get_ptr ()
 
template<typename T >
const T * get_ptr () const
 
template<typename T >
 operator T* ()
 
 HostTensor (const element::Type &element_type, const Shape &shape, void *memory_pointer, const std::string &name="")
 
 HostTensor (const element::Type &element_type, const Shape &shape, const std::string &name="")
 
 HostTensor (const element::Type &element_type, const PartialShape &partial_shape, const std::string &name="")
 
 HostTensor (const std::string &name="")
 
 HostTensor (const Output< Node > &)
 
 HostTensor (const std::shared_ptr< op::v0::Constant > &constant)
 
void initialize (const std::shared_ptr< op::v0::Constant > &constant)
 
void * get_data_ptr ()
 
const void * get_data_ptr () const
 
template<typename T >
T * get_data_ptr ()
 
template<typename T >
const T * get_data_ptr () const
 
template<element::Type_t ET>
element_type_traits< ET >::value_type * get_data_ptr ()
 
template<element::Type_t ET>
const element_type_traits< ET >::value_type * get_data_ptr () const
 
void write (const void *p, size_t n) override
 Write bytes directly into the tensor. More...
 
void read (void *p, size_t n) const override
 Read bytes directly from the tensor. More...
 
bool get_is_allocated () const
 
void set_element_type (const element::Type &element_type)
 Set the element type. Must be compatible with the current element type. More...
 
void set_shape (const Shape &shape)
 Set the actual shape of the tensor compatibly with the partial shape. More...
 
void set_unary (const HostTensorPtr &arg)
 Set the shape of a node from an input. More...
 
void set_broadcast (const op::AutoBroadcastSpec &autob, const HostTensorPtr &arg0, const HostTensorPtr &arg1)
 Set the shape of the tensor using broadcast rules. More...
 
void set_broadcast (const op::AutoBroadcastSpec &autob, const HostTensorPtr &arg0, const HostTensorPtr &arg1, const element::Type &element_type)
 Set the shape of the tensor using broadcast rules. More...
 

Data Fields

 NGRAPH_RTTI_DECLARATION
 
template class NGRAPH_API VariantImpl< int64_t >
 

Static Public Attributes

static bool s_provenance_enabled = getenv_bool("NGRAPH_PROVENANCE_ENABLE")
 

Protected Member Functions

void register_matcher (const std::shared_ptr< pattern::Matcher > &m, const ngraph::graph_rewrite_callback &callback, const PassPropertyMask &property=PassProperty::CHANGE_DYNAMIC_STATE)
 
template<typename T , class... Args>
std::shared_ptr< T > push_pass (Args &&... args)
 
void add_node_arguments (std::shared_ptr< Node > node, std::unordered_map< Node *, HeightMap > &height_maps, size_t &fake_node_ctr)
 
std::string add_attributes (std::shared_ptr< Node > node)
 
virtual std::string get_attributes (std::shared_ptr< Node > node)
 
virtual std::string get_node_name (std::shared_ptr< Node > node)
 
std::string get_constant_value (std::shared_ptr< Node > node, size_t max_elements=7)
 
void render () const
 

Protected Attributes

bool m_enable_shape_inference = false
 
std::vector< std::shared_ptr< ngraph::pass::MatcherPass > > m_matchers
 
param_callback m_transformation_callback
 
bool m_has_default_callback = true
 
std::vector< std::shared_ptr< PassBase > > m_pass_list
 
bool m_visualize = false
 
bool m_per_pass_validation = true
 
std::stringstream m_ss
 
std::set< std::shared_ptr< Node > > m_nodes_with_attributes
 
visualize_tree_ops_map_t m_ops_to_details
 
node_modifiers_t m_node_modifiers = nullptr
 
bool m_dot_only
 

Static Protected Attributes

static const int max_jump_distance
 

Detailed Description

MatcherPass is a basic block for pattern based transformations. It describes pattern and action that is applied if pattern is matched.

Allocates a block of memory on the specified alignment. The actual size of the allocated memory is larger than the requested size by the alignment, so allocating 1 byte on 64 byte alignment will allocate 65 bytes.

GraphRewrite is a container for MatcherPasses that allows to run them on Function in efficient way.

MatcherPass consists of Matcher and matcher_pass_callback that needs to be implemented and finally registered by using

See also
register_matcher. MatcherPass can be executed on node within
apply method. To run matcher pass on Function use GraphRewrite. In addition MatcherPass provides a way for adding new operations into GraphRewrite execution queue. That means that operations that were created inside transformation callback can be added for matching. To register node use
register_new_node method. GraphRewrite automatically takes registered nodes and put them to execution queue. If multiple nodes were register make sure that they were registered in topological order. Note: when implementing pattern for Matcher make sure that root node is an operation from opset or has ngraph::pattern::op::WrapType. That will help GraphRewrite to execute matcher passes more efficient.

Graph rewrite pass is used for matcher passes execution on Function. To register MatcherPass use

See also
add_matcher<T>(args) method where T is a MatcherPass class. As a default algorithm graph rewrite pass traverse Function in topological order and applies registered matcher passes for each node. But if all registered matcher passes have type based root node in Matcher pattern then efficient mechanism is used to execute them. Matcher pattern root is type based if it's operation from opset or pattern::op::WrapType. Note: when implementing pattern for Matcher make sure that root node is an operation from opset or has ngraph::pattern::op::WrapType. That will help GraphRewrite to execute matcher passes more efficient.

Member Typedef Documentation

◆ Rank

using ngraph::Rank = Dimension

Alias for Dimension, used when the value represents the number of axes in a shape, rather than the size of one dimension in a shape.

XXX: THIS TYPE IS EXPERIMENTAL AND THE ENTIRE DESIGN IS SUBJECT TO CHANGE.

Member Function Documentation

◆ read()

void ngraph::read ( void *  p,
size_t  n 
) const
override

Read bytes directly from the tensor.

Parameters
pPointer to destination for data
nNumber of bytes to read, must be integral number of elements.

◆ set_broadcast() [1/2]

void ngraph::set_broadcast ( const op::AutoBroadcastSpec &  autob,
const HostTensorPtr &  arg0,
const HostTensorPtr &  arg1 
)

Set the shape of the tensor using broadcast rules.

Parameters
autobThe broadcast mode
arg0The first argument
arg1The second argument

◆ set_broadcast() [2/2]

void ngraph::set_broadcast ( const op::AutoBroadcastSpec &  autob,
const HostTensorPtr &  arg0,
const HostTensorPtr &  arg1,
const element::Type element_type 
)

Set the shape of the tensor using broadcast rules.

Parameters
autobThe broadcast mode
arg0The first argument
arg1The second argument
element_typeThe output element type

◆ set_callback()

void ngraph::set_callback ( param_callback  callback)
inline

Callback is a lambda function that can be used by registered transformations. The main purpose of this callback is to provide a way for plugins to disable/enable transformations. In some cases plugins may want not to execute some transformations. For example plugin can disable unpleasant decompositions because of performance reasons. Callback example: auto callback = [](const std::shared_ptr<const ngraph::Node> & node) -> bool { return std::dynamic_pointer_cast<const ngraph::opset3::DepthToSpace>(node) != nullptr; }; This callback returns true in case of DepthToSpace operation. So when execution DepthToSpace decomposition pass will check is this decomposition needed or plugin can execute this operation directly. And of course on transformation side we need to have a response for this callback. if (m_transformation_callback(batch_to_space)) { return false; }.

Parameters
callbacklamda function that returns true in case if node is supported by plugin and transformation is not needed

◆ set_element_type()

void ngraph::set_element_type ( const element::Type element_type)

Set the element type. Must be compatible with the current element type.

Parameters
element_typeThe element type

◆ set_per_pass_validation()

void ngraph::set_per_pass_validation ( bool  new_state)
inline

Set flag to enable/disable running Validate pass after executing each registered pass.

Parameters
new_stateValue "true" enables Validate pass run; "false", otherwise

◆ set_shape()

void ngraph::set_shape ( const Shape &  shape)

Set the actual shape of the tensor compatibly with the partial shape.

Parameters
shapeThe shape being set

◆ set_unary()

void ngraph::set_unary ( const HostTensorPtr &  arg)

Set the shape of a node from an input.

Parameters
argThe input argument

◆ write()

void ngraph::write ( const void *  p,
size_t  n 
)
override

Write bytes directly into the tensor.

Parameters
pPointer to source of data
nNumber of bytes to write, must be integral number of elements.

Field Documentation

◆ m_transformation_callback

param_callback ngraph::m_transformation_callback
protected
Initial value:
= [](const std::shared_ptr<const Node>&) -> bool {
return false;
}

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