Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes
ngraph::op::v0::Constant Class Reference

Class for constants. More...

#include <constant.hpp>

Inheritance diagram for ngraph::op::v0::Constant:
Inheritance graph
[legend]
Collaboration diagram for ngraph::op::v0::Constant:
Collaboration graph
[legend]

Public Member Functions

const NodeTypeInfo & get_type_info () const override
 
 Constant (const std::shared_ptr< runtime::Tensor > &tensor)
 Initialize a constant from tensor. More...
 
template<typename T >
 Constant (const element::Type &type, Shape shape, const std::vector< T > &values)
 Constructs a tensor constant. More...
 
 Constant (const element::Type &type, const Shape &shape)
 Create unitialized constant.
 
template<class T , class = typename std::enable_if<std::is_fundamental<T>::value>::type>
 Constant (const element::Type &type, Shape shape, T value)
 Constructs a uniform tensor constant. More...
 
 Constant (const element::Type &type, Shape shape, const std::vector< std::string > &values)
 Constructs a tensor constant This constructor is mainly to support deserialization of constants. More...
 
 Constant (const element::Type &type, const Shape &shape, const void *data)
 Constructs a tensor constant with the supplied data. More...
 
 Constant (const Constant &other)
 
Constantoperator= (const Constant &)=delete
 
void validate_and_infer_types () override
 Verifies that attributes and inputs are consistent and computes output shapes and element types. Must be implemented by concrete child classes so that it can be run any number of times. More...
 
bool visit_attributes (AttributeVisitor &visitor) override
 
bool evaluate (const HostTensorVector &outputs, const HostTensorVector &inputs) const override
 
bool constant_fold (OutputVector &outputs, const OutputVector &inputs) override
 
Shape get_shape_val () const
 Returns the value of the constant node as a Shape object Can only be used on element::i64 nodes and interprets negative values as zeros.
 
Strides get_strides_val () const
 Returns the value of the constant node as a Strides object Can only be used on element::i64 nodes and interprets negative values as zeros.
 
Coordinate get_coordinate_val () const
 Returns the value of the constant node as a Coordinate object Can only be used on element::i64 nodes and interprets negative values as zeros.
 
CoordinateDiff get_coordinate_diff_val () const
 Returns the value of the constant node as a CoordinateDiff object Can only be used on element::i64 nodes.
 
AxisVector get_axis_vector_val () const
 Returns the value of the constant node as an AxisVector object Can only be used on element::i64 nodes and interprets negative values as zeros.
 
AxisSet get_axis_set_val () const
 Returns the value of the constant node as an AxisSet object Can only be used on element::i64 nodes and interprets negative values as zeros. Repeated values are allowed.
 
virtual std::shared_ptr< Nodeclone_with_new_inputs (const OutputVector &new_args) const override
 
std::vector< std::string > get_value_strings () const
 
template<typename T >
std::vector< T > get_vector () const
 
template<typename T >
std::vector< T > cast_vector () const
 Return the Constant's value as a vector cast to type T. More...
 
const void * get_data_ptr () const
 
template<typename T >
const T * get_data_ptr () const
 
template<element::Type_t ET>
const element_type_traits< ET >::value_type * get_data_ptr () const
 
bool get_all_data_elements_bitwise_identical () const
 
std::string convert_value_to_string (size_t index) const
 
- Public Member Functions inherited from ngraph::Node
void constructor_validate_and_infer_types ()
 
virtual bool visit_attributes (AttributeVisitor &)
 
virtual const op::AutoBroadcastSpec & get_autob () const
 
virtual bool evaluate (const HostTensorVector &output_values, const HostTensorVector &input_values) const
 Evaluates the op on input_values putting results in output_values. More...
 
virtual bool constant_fold (OutputVector &output_values, const OutputVector &inputs_values)
 
virtual OutputVector decompose_op () const
 Decomposes the FusedOp into a sub-graph consisting of core ngraph ops. More...
 
const char * get_type_name () const
 
void set_arguments (const NodeVector &arguments)
 Sets/replaces the arguments with new arguments.
 
void set_arguments (const OutputVector &arguments)
 Sets/replaces the arguments with new arguments.
 
void set_argument (size_t position, const Output< Node > &argument)
 Sets/replaces the arguments with new arguments.
 
void set_output_type (size_t i, const element::Type &element_type, const PartialShape &pshape)
 
void set_output_size (size_t output_size)
 Sets the number of outputs.
 
void revalidate_and_infer_types ()
 
void delayed_validate_and_infer_types ()
 
virtual std::string description () const
 Get the string name for the type of the node, such as Add or Multiply. The class name, must not contain spaces as it is used for codegen. More...
 
const std::string & get_name () const
 Get the unique name of the node. More...
 
void set_friendly_name (const std::string &name)
 Sets a friendly name for a node. This does not overwrite the unique name of the node and is retrieved via get_friendly_name(). Used mainly for debugging. The friendly name may be set exactly once. More...
 
const std::string & get_friendly_name () const
 Gets the friendly name for a node. If no friendly name has been set via set_friendly_name then the node's unique name is returned. More...
 
virtual bool is_dynamic () const
 
size_t get_instance_id () const
 
virtual std::ostream & write_description (std::ostream &os, uint32_t depth=0) const
 Writes a description of a node to a stream. More...
 
const std::vector< std::shared_ptr< Node > > & get_control_dependencies () const
 Get control dependencies registered on the node.
 
const std::vector< Node * > & get_control_dependents () const
 Get nodes dependent on this node.
 
void add_control_dependency (std::shared_ptr< Node > node)
 This node cannot execute until node executes.
 
void remove_control_dependency (std::shared_ptr< Node > node)
 Remove the dependency of this node on node.
 
void clear_control_dependencies ()
 Remove all dependencies from this node.
 
void clear_control_dependents ()
 Remove this node as a dependency from all dependent nodes.
 
void add_node_control_dependencies (std::shared_ptr< Node > source_node)
 This node absorbs the control dependencies of source_node.
 
void add_node_control_dependents (std::shared_ptr< Node > source_node)
 This node becomes a dependent of every node dependent on source_node.
 
void transfer_control_dependents (std::shared_ptr< Node > replacement)
 This node's control dependencies are replaced by replacement.
 
size_t get_output_size () const
 Returns the number of outputs from the node.
 
const element::Type & get_output_element_type (size_t i) const
 Returns the element type for output i.
 
const element::Type & get_element_type () const
 Checks that there is exactly one output and returns its element type.
 
const Shapeget_output_shape (size_t i) const
 Returns the shape for output i.
 
const PartialShapeget_output_partial_shape (size_t i) const
 Returns the partial shape for output i.
 
Output< const Nodeget_default_output () const
 
Output< Nodeget_default_output ()
 
virtual size_t get_default_output_index () const
 Returns the output of the default output, or throws if there is none.
 
size_t no_default_index () const
 Throws no default.
 
const Shapeget_shape () const
 Checks that there is exactly one output and returns its shape.
 
descriptor::Tensor & get_output_tensor (size_t i) const
 Returns the tensor for output or input i.
 
descriptor::Tensor & get_input_tensor (size_t i) const
 
const std::string & get_output_tensor_name (size_t i) const
 Returns the tensor name for output i.
 
std::set< Input< Node > > get_output_target_inputs (size_t i) const
 
size_t get_input_size () const
 Returns the number of inputs for the op.
 
const element::Type & get_input_element_type (size_t i) const
 Returns the element type of input i.
 
const Shapeget_input_shape (size_t i) const
 Returns the shape of input i.
 
const PartialShapeget_input_partial_shape (size_t i) const
 Returns the partial shape of input i.
 
const std::string & get_input_tensor_name (size_t i) const
 Returns the tensor name for input i.
 
Nodeget_input_node_ptr (size_t index) const
 
std::shared_ptr< Nodeget_input_node_shared_ptr (size_t index) const
 
Output< Nodeget_input_source_output (size_t i) const
 
virtual std::shared_ptr< Nodeclone_with_new_inputs (const OutputVector &inputs) const =0
 
std::shared_ptr< Nodecopy_with_new_inputs (const OutputVector &new_args) const
 
std::shared_ptr< Nodecopy_with_new_inputs (const OutputVector &inputs, const std::vector< std::shared_ptr< Node >> &control_dependencies) const
 
bool has_same_type (std::shared_ptr< const Node > node) const
 True if this and node have one output with same element type and shape.
 
RTMap & get_rt_info ()
 
const RTMap & get_rt_info () const
 
const std::unordered_set< std::string > & get_provenance_tags () const
 
void add_provenance_tag (const std::string &tag)
 
template<typename T >
void add_provenance_tags (T tag_set)
 
void add_provenance_tags_above (const OutputVector &base, const std::unordered_set< std::string > &tag_set)
 Adds tag_set to this node and all intermediate nodes above base.
 
void remove_provenance_tag (const std::string &tag)
 
void add_provenance_group_member (const std::shared_ptr< Node > &node)
 Add node to additional nodes that receive tags.
 
void remove_provenance_group_member (const std::shared_ptr< Node > &node)
 Remove node to additional nodes that receive tags.
 
void replace_provenance_group_member (const std::shared_ptr< Node > &current_node, const std::shared_ptr< Node > &replacement_node)
 Replace current_node with replacement_node and transfer tags.
 
const std::set< std::shared_ptr< Node > > & get_provenance_group_members () const
 
std::shared_ptr< Nodeadd_provenance_group_members_above (const OutputVector &base)
 Add all nodes between this node and nodes in base as additional nodes to receive provenance tags.
 
void merge_provenance_tags_from (const std::shared_ptr< const Node > &source)
 
void transfer_provenance_tags (const std::shared_ptr< Node > &replacement)
 Transfer provenance tags to replacement.
 
NodeVector get_users (bool check_is_used=false) const
 Get all the nodes that uses the current node.
 
virtual size_t get_version () const
 
virtual std::shared_ptr< Nodeget_default_value () const
 
bool operator< (const Node &other) const
 Use instance ids for comparison instead of memory addresses to improve determinism.
 
std::vector< Input< Node > > inputs ()
 
std::vector< Input< const Node > > inputs () const
 
std::vector< Output< Node > > input_values () const
 
std::vector< Output< Node > > outputs ()
 
std::vector< Output< const Node > > outputs () const
 
Input< Nodeinput (size_t input_index)
 
Input< const Nodeinput (size_t input_index) const
 
Output< Nodeinput_value (size_t input_index) const
 
Output< Nodeoutput (size_t output_index)
 
Output< const Nodeoutput (size_t output_index) const
 
void set_op_annotations (std::shared_ptr< ngraph::op::util::OpAnnotations > op_annotations)
 
std::shared_ptr< ngraph::op::util::OpAnnotationsget_op_annotations () const
 
virtual bool match_value (pattern::Matcher *matcher, const Output< Node > &pattern_value, const Output< Node > &graph_value)
 
virtual bool match_node (pattern::Matcher *matcher, const Output< Node > &graph_value)
 

Static Public Member Functions

template<typename T >
static std::shared_ptr< op::v0::Constantcreate (const element::Type &type, Shape shape, const std::vector< T > values)
 Wrapper around constructing a shared_ptr of a Constant. More...
 
template<typename T >
static std::shared_ptr< op::v0::Constantcreate (const element::Type &type, Shape shape, std::initializer_list< T > values)
 Wrapper around constructing a shared_ptr of a Constant. More...
 

Static Public Attributes

static constexpr NodeTypeInfo type_info {"Constant", 0}
 

Protected Member Functions

void * allocate_buffer ()
 Allocate a buffer and return a pointer to it.
 
void * get_data_ptr_nc ()
 
template<element::Type_t ET>
element_type_traits< ET >::value_type * get_data_ptr_nc ()
 
 Constant (const OutputVector &args)
 
virtual void infer_element_type ()
 
template<typename T >
void write_values (const std::vector< T > &values)
 
template<typename T , typename U >
void write_buffer (void *target, const std::vector< U > &source, size_t count)
 
template<typename T >
void write_to_buffer (const element::Type &target_type, const Shape &, const std::vector< T > &source, void *target, size_t target_element_count)
 
bool are_all_data_elements_bitwise_identical () const
 
- Protected Member Functions inherited from ngraph::op::Op
 Op (const OutputVector &arguments)
 
- Protected Member Functions inherited from ngraph::Node
 Node ()=default
 Construct an unitialized Node.
 
 Node (const Node &)
 Copying a node.
 
Nodeoperator= (const Node &)
 Assignment operator.
 
 Node (size_t output_size)
 Construct an unitialized Node. More...
 
 Node (const OutputVector &arguments, size_t output_size=1)
 Constructor for Node subclasses that have metaclasses. More...
 
void safe_delete (NodeVector &nodes, bool recurse)
 Moves nodes that would be deleted from inputs to nodes to avoid stack overflows on deep networks.
 
void set_input_is_relevant_to_shape (size_t i, bool relevant=true)
 Marks an input as being relevant or irrelevant to the output shapes of this node. More...
 
void set_input_is_relevant_to_value (size_t i, bool relevant=true)
 Marks an input as being relevant or irrelevant to the output values of this node. More...
 

Static Protected Member Functions

static constexpr size_t host_alignment ()
 

Protected Attributes

element::Type m_element_type
 
Shape m_shape {}
 
std::shared_ptr< runtime::AlignedBuffer > m_data
 
bool m_all_elements_bitwise_identical
 

Additional Inherited Members

- Public Types inherited from ngraph::Node
using type_info_t = DiscreteTypeInfo
 
using RTMap = std::map< std::string, std::shared_ptr< Variant > >
 
- Data Fields inherited from ngraph::Node
std::unordered_set< descriptor::Tensor * > liveness_new_list
 
std::unordered_set< descriptor::Tensor * > liveness_free_list
 

Detailed Description

Class for constants.

Constructor & Destructor Documentation

◆ Constant() [1/5]

ngraph::op::v0::Constant::Constant ( const std::shared_ptr< runtime::Tensor > &  tensor)

Initialize a constant from tensor.

Parameters
tensorThe tensor with data

◆ Constant() [2/5]

template<typename T >
ngraph::op::v0::Constant::Constant ( const element::Type type,
Shape  shape,
const std::vector< T > &  values 
)
inline

Constructs a tensor constant.

Parameters
typeThe element type of the tensor constant.
shapeThe shape of the tensor constant.
valuesA vector of literals for initializing the tensor constant. The size of values must match the size of the shape.

◆ Constant() [3/5]

template<class T , class = typename std::enable_if<std::is_fundamental<T>::value>::type>
ngraph::op::v0::Constant::Constant ( const element::Type type,
Shape  shape,
value 
)
inline

Constructs a uniform tensor constant.

Parameters
typeThe element type of the tensor constant.
shapeThe shape of the tensor constant.
valueA scalar for initializing the uniform tensor constant. The value is broadcast to the specified shape.

◆ Constant() [4/5]

ngraph::op::v0::Constant::Constant ( const element::Type type,
Shape  shape,
const std::vector< std::string > &  values 
)

Constructs a tensor constant This constructor is mainly to support deserialization of constants.

Parameters
typeThe element type of the tensor constant.
shapeThe shape of the tensor constant.
valuesA list of string values to use as the constant data.

◆ Constant() [5/5]

ngraph::op::v0::Constant::Constant ( const element::Type type,
const Shape &  shape,
const void *  data 
)

Constructs a tensor constant with the supplied data.

Parameters
typeThe element type of the tensor constant.
shapeThe shape of the tensor constant.
dataA void* to constant data.

Member Function Documentation

◆ cast_vector()

template<typename T >
std::vector<T> ngraph::op::v0::Constant::cast_vector ( ) const
inline

Return the Constant's value as a vector cast to type T.

Template Parameters
TType to which data vector's entries will be cast.
Returns
Constant's data vector.

◆ create() [1/2]

template<typename T >
static std::shared_ptr<op::v0::Constant> ngraph::op::v0::Constant::create ( const element::Type type,
Shape  shape,
const std::vector< T >  values 
)
inlinestatic

Wrapper around constructing a shared_ptr of a Constant.

Parameters
typeThe element type of the tensor constant.
shapeThe shape of the tensor constant.
valuesA vector of values to use as the constant data.

◆ create() [2/2]

template<typename T >
static std::shared_ptr<op::v0::Constant> ngraph::op::v0::Constant::create ( const element::Type type,
Shape  shape,
std::initializer_list< T >  values 
)
inlinestatic

Wrapper around constructing a shared_ptr of a Constant.

Parameters
typeThe element type of the tensor constant.
shapeThe shape of the tensor constant.
valuesAn initializer_list of values to use as the constant data.

◆ get_type_info()

const NodeTypeInfo& ngraph::op::v0::Constant::get_type_info ( ) const
inlineoverridevirtual

Returns the NodeTypeInfo for the node's class. During transition to type_info, returns a dummy type_info for Node if the class has not been updated yet.

Implements ngraph::Node.

◆ get_value_strings()

std::vector<std::string> ngraph::op::v0::Constant::get_value_strings ( ) const
Returns
The initialization literals for the tensor constant.

◆ validate_and_infer_types()

void ngraph::op::v0::Constant::validate_and_infer_types ( )
inlineoverridevirtual

Verifies that attributes and inputs are consistent and computes output shapes and element types. Must be implemented by concrete child classes so that it can be run any number of times.

Throws if the node is invalid.

Reimplemented from ngraph::Node.


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