Operators#
Introduction#
An Operator defines the abstract computational logic for specific mathematical or logical operations. Operators provide the interface that enables Aidge to understand what computation needs to be performed, while backends provide the actual hardware-specific implementations.
Key characteristics:
Operation type: for example, an Add operator performs element-wise addition, a Conv operator performs a convolution.
Inputs and outputs: each operator specify how many inputs it expects, their data types (e.g., float, int), and their categories (e.g., data input, parameter input like weights or biases). It also defines what kind of output (or outputs) it produces.
Attributes: many operators have configurable parameters beyond their inputs, such as the kernel size for a convolution, the stride, padding, or whether to enable specific features. These are called attributes.
Input categories#
Operator input categories convey semantic information about the role of each input in the operator.
aidge_core.InputCategory.Data/aidge_core.InputCategory.OptionalData: differentiable tensor inputs representing activations or other runtime computational values.aidge_core.InputCategory.Param/aidge_core.InputCategory.OptionalParam: differentiable tensor inputs representing persistent learnable model parameters (typically weights or biases).These inputs are automatically materialized during graph construction by creating and connecting a dedicated Producer node by default. Additionally, the created Producer automatically gets an attribute Param set to true.
aidge_core.InputCategory.Attr/aidge_core.InputCategory.OptionalAttr: non-differentiable inputs representing structural or control information, such as dimensions, axes, shapes, lengths, masks, indices, or token ids.Attr inputs never participate in gradient propagation.
These inputs may alternatively be specified as constant operator attributes and are therefore generally optional. When both an input and an operator attribute are specified, the input value takes precedence.
Kind |
Example |
Differentiable |
Dynamic at runtime |
|---|---|---|---|
|
activation tensor |
yes |
yes |
|
weights |
yes |
yes |
|
axis, kernel size |
no |
usually no |
Attributes and properties#
Operators expose two categories of metadata:
Attributes are predefined instance variables declared by the operator definition. Their values are initialized during operator construction and may be modified throughout the operatorβs lifetime, subject to operator-specific constraints.
As mentioned above, when a corresponding
aidge_core.InputCategory.Attrinput is defined for an attribute and connected to a tensor or node, the input takes precedence and the attribute value is automatically updated during dimension forwarding.Operator attributes are stored in a StaticAttributes object, whose schema is fixed at compile time.
Note that in Aidge, Parameters are reserved for learnable parameters, typically weights and bias tensors.
Properties are static class variables shared by all instances of an operator type. They describe intrinsic characteristics, capabilities, constraints, or default behaviors of that operator class.
Properties are stored in a DynamicAttributes object.
Additionally, nodes may define their own annotations. Unlike operator attributes, node annotations can be introduced dynamically at runtime and are specific to individual node instances.
Node annotations are also stored in a DynamicAttributes object.
Note
The names StaticAttributes and DynamicAttributes refer to the storage model rather than the semantic role of the metadata. StaticAttributes stores a compile-time fixed tuple of predefined fields, whereas DynamicAttributes stores a mutable key-value map.
Concept |
Scope |
Storage |
Mutable |
Runtime-extensible |
|---|---|---|---|---|
Operator attribute |
|
|
Yes |
No |
Operator property |
|
|
Typically no |
Yes |
Node annotation |
|
|
Yes |
Yes |
Operator base class#
aidge_core.Operator is Aidgeβs base class for describing a mathematical operator. It does not make any assumption on the data coding.
- class aidge_core.Operator#
- __init__(self: aidge_core.aidge_core.Operator, type: str, inputs_category: collections.abc.Sequence[aidge_core.aidge_core.InputCategory], nb_out: SupportsInt | SupportsIndex) None#
- associate_input(self: aidge_core.aidge_core.Operator, inputIdx: SupportsInt | SupportsIndex, data: aidge_core.aidge_core.Data) None#
- backend(self: aidge_core.aidge_core.Operator) str#
- forward(*args, **kwargs)#
Overloaded function.
forward(self: aidge_core.aidge_core.Operator) -> None
forward(self: aidge_core.aidge_core.Operator, input: aidge_core.aidge_core.Data) -> list[aidge_core.aidge_core.Data]
forward(self: aidge_core.aidge_core.Operator, inputs: collections.abc.Sequence[aidge_core.aidge_core.Data]) -> list[aidge_core.aidge_core.Data]
- get_impl(self: aidge_core.aidge_core.Operator) aidge_core.aidge_core.OperatorImpl#
- get_nb_consumed_data(self: aidge_core.aidge_core.Operator, input_idx: SupportsInt | SupportsIndex) aidge_core.aidge_core.Elts_t#
- get_nb_produced_data(self: aidge_core.aidge_core.Operator, output_idx: SupportsInt | SupportsIndex) aidge_core.aidge_core.Elts_t#
- get_nb_required_data(self: aidge_core.aidge_core.Operator, input_idx: SupportsInt | SupportsIndex) aidge_core.aidge_core.Elts_t#
- get_nb_required_protected(self: aidge_core.aidge_core.Operator, input_idx: SupportsInt | SupportsIndex) aidge_core.aidge_core.Elts_t#
- get_raw_input(self: aidge_core.aidge_core.Operator, inputIdx: SupportsInt | SupportsIndex) aidge_core.aidge_core.Data#
- get_raw_output(self: aidge_core.aidge_core.Operator, outputIdx: SupportsInt | SupportsIndex) aidge_core.aidge_core.Data#
- get_required_memory(self: aidge_core.aidge_core.Operator, output_idx: SupportsInt | SupportsIndex, inputs_size: collections.abc.Sequence[SupportsInt | SupportsIndex]) aidge_core.aidge_core.Elts_t#
- input_category(*args, **kwargs)#
Overloaded function.
input_category(self: aidge_core.aidge_core.Operator) -> list[aidge_core.aidge_core.InputCategory]
Category of the inputs (Data or Param, optional or not). Data inputs exclude inputs expecting parameters (weights or bias).
- rtype:
list(InputCategory)
input_category(self: aidge_core.aidge_core.Operator, idx: typing.SupportsInt | typing.SupportsIndex) -> aidge_core.aidge_core.InputCategory
Category of a specific input (Data or Param, optional or not). Data inputs exclude inputs expecting parameters (weights or bias).
- rtype:
InputCategory
- is_atomic(self: aidge_core.aidge_core.Operator) bool#
- is_back_edge(self: aidge_core.aidge_core.Operator, input_index: SupportsInt | SupportsIndex) bool#
- is_optional_input(self: aidge_core.aidge_core.Operator, inputIdx: SupportsInt | SupportsIndex) bool#
- nb_inputs(self: aidge_core.aidge_core.Operator) int#
- nb_outputs(self: aidge_core.aidge_core.Operator) int#
- reset_consummer_producer(self: aidge_core.aidge_core.Operator) None#
- reset_input(self: aidge_core.aidge_core.Operator, inputIdx: SupportsInt | SupportsIndex) None#
- set_back_edges(self: aidge_core.aidge_core.Operator, input_indexes: collections.abc.Set[SupportsInt | SupportsIndex]) None#
- set_backend(*args, **kwargs)#
Overloaded function.
set_backend(self: aidge_core.aidge_core.Operator, name: str, device: typing.SupportsInt | typing.SupportsIndex = 0) -> None
set_backend(self: aidge_core.aidge_core.Operator, backends: collections.abc.Sequence[tuple[str, typing.SupportsInt | typing.SupportsIndex]], allow_default_impl: bool = True, check_available_specs: bool = False) -> tuple[str, int]
- set_dataformat(self: aidge_core.aidge_core.Operator, dataFormat: aidge_core.aidge_core.dformat) None#
- set_datatype(self: aidge_core.aidge_core.Operator, dataType: aidge_core.aidge_core.dtype) None#
- set_device(self: aidge_core.aidge_core.Operator, device: SupportsInt | SupportsIndex) None#
- set_impl(self: aidge_core.aidge_core.Operator, implementation: aidge_core.aidge_core.OperatorImpl) None#
- set_input(*args, **kwargs)#
Overloaded function.
set_input(self: aidge_core.aidge_core.Operator, inputIdx: typing.SupportsInt | typing.SupportsIndex, data: aidge_core.aidge_core.Data) -> None
set_input(self: aidge_core.aidge_core.Operator, inputIdx: typing.SupportsInt | typing.SupportsIndex, data: aidge_core.aidge_core.Data) -> None
- set_output(self: aidge_core.aidge_core.Operator, outputIdx: SupportsInt | SupportsIndex, data: aidge_core.aidge_core.Data) None#
- type(self: aidge_core.aidge_core.Operator) str#
- update_consummer_producer(self: aidge_core.aidge_core.Operator) None#
-
class Operator : public std::enable_shared_from_this<Operator>#
Base class for all operator types in the Aidge framework.
The
Operatorclass provides a foundation for implementing various operator types. Derived classes must implement specific behaviors for computation, attributes, and input/output handling.Subclassed by Aidge::OperatorROIs, Aidge::OperatorTensor
Public Functions
-
Operator() = delete#
Deleted default constructor.
-
inline Operator(const std::string &type, const std::vector<InputCategory> &inputsCategory, const IOIndex_t nbOut, const OperatorType operatorType = OperatorType::Data)#
Constructs an Operator instance.
- Parameters:
type β [in] The type of operator (e.g., βAddβ, βAveragePoolβ).
inputsCategory β [in] Categories of each input.
nbOut β [in] Number of outputs.
operatorType β [in] Type of operator (Data or Tensor).
-
inline Operator(const Operator &op)#
Copy constructor.
- Parameters:
op β [in] The operator to copy.
-
virtual ~Operator() noexcept#
Virtual destructor.
-
virtual std::shared_ptr<Operator> clone() const = 0#
Creates a clone of the current operator.
Derived classes must implement this method to provide a deep copy of the operator.
- Returns:
A shared pointer to the cloned operator.
-
inline virtual std::shared_ptr<Attributes> attributes() const#
Returns the attributes of the operator.
-
inline virtual DynamicAttributes &properties() const#
-
inline virtual std::shared_ptr<DynamicAttributes> annotations() const#
Get the currently associated Nodeβs attributes.
If no Node as be associated to the Operator, returns a
nullptr.Note
As Operators have only been tested with a single associated Node, only attributes of the first associated Node are returned. This should be updated.
- Returns:
Shared pointer to the Attributes of the associated Node.
Associates a shallow copy of the specified input data with the operator.
Derived classes must implement this method.
- Parameters:
inputIdx β [in] Index of the input to associate.
data β [in] Data to associate.
-
virtual void resetInput(const IOIndex_t inputIdx) = 0#
Resets the specified input.
Sets the specified input with a deep copy of the given data.
Derived classes must implement this method.
- Parameters:
inputIdx β [in] Index of the input to set.
data β [in] Data to set.
-
virtual std::shared_ptr<Data> getRawInput(const IOIndex_t inputIdx) const = 0#
Retrieves the raw input data for the specified index.
Sets the specified output with a deep copy of the given data.
Derived classes must implement this method.
- Parameters:
outputIdx β [in] Index of the output to set.
data β [in] Data to set.
-
virtual std::shared_ptr<Data> getRawOutput(const IOIndex_t outputIdx) const = 0#
Retrieves the raw output data for the specified index.
-
inline virtual std::string backend() const noexcept#
Returns the backend implementation name.
- Returns:
The name of the backend implementation.
-
virtual void setDevice(DeviceIdx_t device) = 0#
Sets the device.
- Parameters:
device β [in] Device index.
-
virtual void setBackend(const std::string &name, DeviceIdx_t device = 0) = 0#
Sets the backend implementation.
- Parameters:
name β [in] Name of the backend.
device β [in] Device index.
-
virtual std::pair<std::string, DeviceIdx_t> setBackend(const std::vector<std::pair<std::string, DeviceIdx_t>> &backends, bool allowDefaultImpl = true, bool checkAvailableSpecs = false) = 0#
Sets the backend implementation for multiple devices.
- Parameters:
backends β [in] A vector of backend and device index pairs.
allowDefaultImpl β [in] If true, allow using the default implementation if one exists, if no other backend is found.
checkAvailableSpecs β [in] If true, also check that there is a matching implementation spec in the backend.
-
virtual void setDataFormat(const DataFormat &dataFormat) const = 0#
-
virtual std::set<std::string> getAvailableBackends() const = 0#
Returns the available backend implementations.
Derived classes must implement this method.
- Returns:
A set of available backend names.
Set a new OperatorImpl to the Operator.
-
inline std::shared_ptr<OperatorImpl> getImpl() const noexcept#
Get the OperatorImpl of the Operator.
-
virtual Elts_t getNbRequiredData(const IOIndex_t inputIdx) const#
Minimum amount of data from a specific input for one computation pass.
- Parameters:
inputIdx β Index of the input analyzed.
- Returns:
Elts_t
-
virtual Elts_t getNbRequiredProtected(const IOIndex_t inputIdx) const#
-
virtual Elts_t getRequiredMemory(const IOIndex_t outputIdx, const std::vector<DimSize_t> &inputsSize) const#
-
virtual Elts_t getNbConsumedData(const IOIndex_t inputIdx) const#
Total amount of consumed data from a specific input.
- Parameters:
inputIdx β Index of the input analyzed.
- Returns:
Elts_t
-
virtual Elts_t getNbProducedData(const IOIndex_t outputIdx) const#
Total amount of produced data ready to be used on a specific output.
- Parameters:
outputIdx β Index of the output analyzed.
- Returns:
Elts_t
-
virtual void updateConsummerProducer()#
-
virtual void resetConsummerProducer()#
-
virtual void forward()#
-
virtual void backward()#
-
inline std::string type() const noexcept#
Returns the type of the operator.
- Returns:
The operator type as a string.
-
inline OperatorType operatorType() const noexcept#
Returns the type of the operator (Data or Tensor).
- Returns:
The operator type as an
OperatorTypeenum value.
-
inline std::vector<InputCategory> inputCategory() const#
Returns the categories of all inputs.
-
InputCategory inputCategory(IOIndex_t idx) const#
Returns the category of a specific input.
-
inline bool isOptionalInput(std::size_t inputIdx) const#
-
inline virtual bool isAtomic() const noexcept#
-
inline IOIndex_t nbInputs() const noexcept#
Returns the number of inputs.
-
inline IOIndex_t nbOutputs() const noexcept#
Returns the number of outputs.
-
inline void setBackEdges(const std::set<IOIndex_t> &backEdges)#
Sets the back edge input indexes for recurring operators.
- Parameters:
backEdges β [in] A set of input indexes representing back edges.
-
inline bool isBackEdge(IOIndex_t inputIdx) const#
Checks if a given input index is a back edge.
- Parameters:
inputIdx β [in] Index of the input to check.
- Returns:
True if the input index is a back edge, false otherwise.
Set the pointer of mOutput[outputIdx] to be equal to data. Warning this function should be use with great care as it may break the graph dataflow. You have been warned.
Public Static Attributes
-
static const std::pair<std::string, DeviceIdx_t> NoBackend#
-
Operator() = delete#
OperatorTensor base class#
aidge_core.OperatorTensor derives from the aidge_core.Operator base class and is the base class for any tensor-based operator.
- class aidge_core.OperatorTensor#
- __init__(self: aidge_core.aidge_core.OperatorTensor, type: str, inputs_category: collections.abc.Sequence[aidge_core.aidge_core.InputCategory], nb_out: SupportsInt | SupportsIndex) None#
- associate_input(self: aidge_core.aidge_core.Operator, inputIdx: SupportsInt | SupportsIndex, data: aidge_core.aidge_core.Data) None#
- backend(self: aidge_core.aidge_core.Operator) str#
- dims_forwarded(self: aidge_core.aidge_core.OperatorTensor) bool#
- forward(*args, **kwargs)#
Overloaded function.
forward(self: aidge_core.aidge_core.Operator) -> None
forward(self: aidge_core.aidge_core.Operator, input: aidge_core.aidge_core.Data) -> list[aidge_core.aidge_core.Data]
forward(self: aidge_core.aidge_core.Operator, inputs: collections.abc.Sequence[aidge_core.aidge_core.Data]) -> list[aidge_core.aidge_core.Data]
- forward_dims(self: aidge_core.aidge_core.OperatorTensor, allow_data_dependency: bool = False) bool#
- forward_dtype(self: aidge_core.aidge_core.OperatorTensor) bool#
- get_impl(self: aidge_core.aidge_core.Operator) aidge_core.aidge_core.OperatorImpl#
- get_input(self: aidge_core.aidge_core.OperatorTensor, inputIdx: SupportsInt | SupportsIndex) aidge_core.aidge_core.Tensor#
- get_inputs(self: aidge_core.aidge_core.OperatorTensor) list[aidge_core.aidge_core.Tensor]#
- get_nb_consumed_data(self: aidge_core.aidge_core.Operator, input_idx: SupportsInt | SupportsIndex) aidge_core.aidge_core.Elts_t#
- get_nb_produced_data(self: aidge_core.aidge_core.Operator, output_idx: SupportsInt | SupportsIndex) aidge_core.aidge_core.Elts_t#
- get_nb_required_data(self: aidge_core.aidge_core.Operator, input_idx: SupportsInt | SupportsIndex) aidge_core.aidge_core.Elts_t#
- get_nb_required_protected(self: aidge_core.aidge_core.Operator, input_idx: SupportsInt | SupportsIndex) aidge_core.aidge_core.Elts_t#
- get_output(self: aidge_core.aidge_core.OperatorTensor, outputIdx: SupportsInt | SupportsIndex) aidge_core.aidge_core.Tensor#
- get_outputs(self: aidge_core.aidge_core.OperatorTensor) list[aidge_core.aidge_core.Tensor]#
- get_raw_input(self: aidge_core.aidge_core.Operator, inputIdx: SupportsInt | SupportsIndex) aidge_core.aidge_core.Data#
- get_raw_output(self: aidge_core.aidge_core.Operator, outputIdx: SupportsInt | SupportsIndex) aidge_core.aidge_core.Data#
- get_required_memory(self: aidge_core.aidge_core.Operator, output_idx: SupportsInt | SupportsIndex, inputs_size: collections.abc.Sequence[SupportsInt | SupportsIndex]) aidge_core.aidge_core.Elts_t#
- get_required_spec(self: aidge_core.aidge_core.OperatorTensor) aidge_core.aidge_core.ImplSpec#
- input_category(*args, **kwargs)#
Overloaded function.
input_category(self: aidge_core.aidge_core.Operator) -> list[aidge_core.aidge_core.InputCategory]
Category of the inputs (Data or Param, optional or not). Data inputs exclude inputs expecting parameters (weights or bias).
- rtype:
list(InputCategory)
input_category(self: aidge_core.aidge_core.Operator, idx: typing.SupportsInt | typing.SupportsIndex) -> aidge_core.aidge_core.InputCategory
Category of a specific input (Data or Param, optional or not). Data inputs exclude inputs expecting parameters (weights or bias).
- rtype:
InputCategory
- is_atomic(self: aidge_core.aidge_core.Operator) bool#
- is_back_edge(self: aidge_core.aidge_core.Operator, input_index: SupportsInt | SupportsIndex) bool#
- is_optional_input(self: aidge_core.aidge_core.Operator, inputIdx: SupportsInt | SupportsIndex) bool#
- nb_inputs(self: aidge_core.aidge_core.Operator) int#
- nb_outputs(self: aidge_core.aidge_core.Operator) int#
- reset_consummer_producer(self: aidge_core.aidge_core.Operator) None#
- reset_input(self: aidge_core.aidge_core.Operator, inputIdx: SupportsInt | SupportsIndex) None#
- set_back_edges(self: aidge_core.aidge_core.Operator, input_indexes: collections.abc.Set[SupportsInt | SupportsIndex]) None#
- set_backend(*args, **kwargs)#
Overloaded function.
set_backend(self: aidge_core.aidge_core.Operator, name: str, device: typing.SupportsInt | typing.SupportsIndex = 0) -> None
set_backend(self: aidge_core.aidge_core.Operator, backends: collections.abc.Sequence[tuple[str, typing.SupportsInt | typing.SupportsIndex]], allow_default_impl: bool = True, check_available_specs: bool = False) -> tuple[str, int]
- set_dataformat(self: aidge_core.aidge_core.Operator, dataFormat: aidge_core.aidge_core.dformat) None#
- set_datatype(self: aidge_core.aidge_core.Operator, dataType: aidge_core.aidge_core.dtype) None#
- set_device(self: aidge_core.aidge_core.Operator, device: SupportsInt | SupportsIndex) None#
- set_impl(self: aidge_core.aidge_core.Operator, implementation: aidge_core.aidge_core.OperatorImpl) None#
- set_input(self: aidge_core.aidge_core.OperatorTensor, outputIdx: SupportsInt | SupportsIndex, data: aidge_core.aidge_core.Data) None#
- set_output(self: aidge_core.aidge_core.OperatorTensor, outputIdx: SupportsInt | SupportsIndex, data: aidge_core.aidge_core.Data) None#
- type(self: aidge_core.aidge_core.Operator) str#
- update_consummer_producer(self: aidge_core.aidge_core.Operator) None#
-
class OperatorTensor : public Aidge::Operator#
Base class for all operators that work with tensor inputs and outputs.
The
OperatorTensorclass provides an abstraction for operations on tensors with features such as input/output management, dimension handling, and receptive field computation.See also
Subclassed by Aidge::OperatorTensorWithImpl< WeightInterleaving_Op >, Aidge::OperatorTensorWithImpl< Slice_Op, Slice_OpImpl >, Aidge::OperatorTensorWithImpl< SVMRegressor_Op >, Aidge::OperatorTensorWithImpl< ReLU_Op >, Aidge::OperatorTensorWithImpl< Pop_Op, Pop_OpImpl >, Aidge::OperatorTensorWithImpl< Mul_Op >, Aidge::OperatorTensorWithImpl< AvgPooling_Op< DIM > >, Aidge::OperatorTensorWithImpl< Atan_Op >, Aidge::OperatorTensorWithImpl< Split_Op, Split_OpImpl >, Aidge::OperatorTensorWithImpl< Sin_Op >, Aidge::OperatorTensorWithImpl< NBitFlip_Op >, Aidge::OperatorTensorWithImpl< Ln_Op >, Aidge::OperatorTensorWithImpl< LeakyReLU_Op >, Aidge::OperatorTensorWithImpl< DepthToSpace_Op, DepthToSpace_OpImpl >, Aidge::OperatorTensorWithImpl< Cos_Op >, Aidge::OperatorTensorWithImpl< ConvDepthWise_Op< DIM > >, Aidge::OperatorTensorWithImpl< CentroidCropTransformation_Op >, Aidge::OperatorTensorWithImpl< BitShift_Op >, Aidge::OperatorTensorWithImpl< Sinh_Op >, Aidge::OperatorTensorWithImpl< Mod_Op >, Aidge::OperatorTensorWithImpl< Floor_Op >, Aidge::OperatorTensorWithImpl< Flatten_Op, Flatten_OpImpl >, Aidge::OperatorTensorWithImpl< FC_Op >, Aidge::OperatorTensorWithImpl< ConstantOfShape_Op, ConstantOfShape_OpImpl >, Aidge::OperatorTensorWithImpl< ColorSpaceTransformation_Op >, Aidge::OperatorTensorWithImpl< Ceil_Op >, Aidge::OperatorTensorWithImpl< CGPACT_Op >, Aidge::OperatorTensorWithImpl< ArgMax_Op >, Aidge::OperatorTensorWithImpl< Transpose_Op, TransposeImpl >, Aidge::OperatorTensorWithImpl< Sqrt_Op >, Aidge::OperatorTensorWithImpl< SliceExtractionTransformation_Op >, Aidge::OperatorTensorWithImpl< Pow_Op >, Aidge::OperatorTensorWithImpl< Min_Op >, Aidge::OperatorTensorWithImpl< MaxPooling_Op< DIM > >, Aidge::OperatorTensorWithImpl< Heaviside_Op >, Aidge::OperatorTensorWithImpl< Equal_Op >, Aidge::OperatorTensorWithImpl< DFT_Op >, Aidge::OperatorTensorWithImpl< Conv_Op< DIM > >, Aidge::OperatorTensorWithImpl< ComplexToInnerPair_Op, ComplexToInnerPair_OpImpl >, Aidge::OperatorTensorWithImpl< Reshape_Op, Reshape_OpImpl >, Aidge::OperatorTensorWithImpl< Not_Op >, Aidge::OperatorTensorWithImpl< GlobalAveragePooling_Op >, Aidge::OperatorTensorWithImpl< DropBlock_Op >, Aidge::OperatorTensorWithImpl< DoReFa_Op >, Aidge::OperatorTensorWithImpl< AffineTransformation_Op >, Aidge::OperatorTensorWithImpl< Unfold_Op< DIM >, Unfold_OpImpl< DIM > >, Aidge::OperatorTensorWithImpl< Tile_Op, Tile_OpImpl >, Aidge::OperatorTensorWithImpl< Shape_Op, Shape_OpImpl >, Aidge::OperatorTensorWithImpl< PadCropTransformation_Op >, Aidge::OperatorTensorWithImpl< Neg_Op >, Aidge::OperatorTensorWithImpl< ChannelExtractionTransformation_Op >, Aidge::OperatorTensorWithImpl< Sigmoid_Op >, Aidge::OperatorTensorWithImpl< Pad_Op >, Aidge::OperatorTensorWithImpl< Dropout_Op >, Aidge::OperatorTensorWithImpl< Cosh_Op >, Aidge::OperatorTensorWithImpl< STFT_Op >, Aidge::OperatorTensorWithImpl< InnerPairToComplex_Op, InnerPairToComplex_OpImpl >, Aidge::OperatorTensorWithImpl< Exp_Op >, Aidge::OperatorTensorWithImpl< CryptoHash_Op >, Aidge::OperatorTensorWithImpl< Sub_Op >, Aidge::OperatorTensorWithImpl< Squeeze_Op, Squeeze_OpImpl >, Aidge::OperatorTensorWithImpl< Reciprocal_Op >, Aidge::OperatorTensorWithImpl< Range_Op, Range_OpImpl >, Aidge::OperatorTensorWithImpl< Max_Op >, Aidge::OperatorTensorWithImpl< Less_Op >, Aidge::OperatorTensorWithImpl< GridSample_Op >, Aidge::OperatorTensorWithImpl< Tan_Op >, Aidge::OperatorTensorWithImpl< Softmax_Op >, Aidge::OperatorTensorWithImpl< MatMul_Op >, Aidge::OperatorTensorWithImpl< LogSoftmax_Op >, Aidge::OperatorTensorWithImpl< LayerNorm_Op >, Aidge::OperatorTensorWithImpl< GatherElements_Op, GatherElements_OpImpl >, Aidge::OperatorTensorWithImpl< FixedNBitFlipOp >, Aidge::OperatorTensorWithImpl< CompressionNoiseTransformation_Op >, Aidge::OperatorTensorWithImpl< Asin_Op >, Aidge::OperatorTensorWithImpl< Add_Op >, Aidge::OperatorTensorWithImpl< Abs_Op >, Aidge::OperatorTensorWithImpl< TrimTransformation_Op >, Aidge::OperatorTensorWithImpl< RescaleTransformation_Op >, Aidge::OperatorTensorWithImpl< Memorize_Op, Memorize_OpImpl >, Aidge::OperatorTensorWithImpl< Div_Op >, Aidge::OperatorTensorWithImpl< Clip_Op >, Aidge::OperatorTensorWithImpl< BatchNorm_Op< DIM > >, Aidge::OperatorTensorWithImpl< Tanh_Op >, Aidge::OperatorTensorWithImpl< Round_Op >, Aidge::OperatorTensorWithImpl< ResizeCropTransformation_Op >, Aidge::OperatorTensorWithImpl< ReduceSum_Op >, Aidge::OperatorTensorWithImpl< ReduceMin_Op >, Aidge::OperatorTensorWithImpl< ReduceMax_Op >, Aidge::OperatorTensorWithImpl< OneHot_Op >, Aidge::OperatorTensorWithImpl< HardSigmoid_Op >, Aidge::OperatorTensorWithImpl< FixedQ_Op >, Aidge::OperatorTensorWithImpl< Erf_Op >, Aidge::OperatorTensorWithImpl< Concat_Op, Concat_OpImpl >, Aidge::OperatorTensorWithImpl< Scatter_Op, Scatter_OpImpl >, Aidge::OperatorTensorWithImpl< BitErrorRate_Op >, Aidge::OperatorTensorWithImpl< Where_Op >, Aidge::OperatorTensorWithImpl< TopK_Op >, Aidge::OperatorTensorWithImpl< ShiftGELU_Op >, Aidge::OperatorTensorWithImpl< ScaleAdjust_Op >, Aidge::OperatorTensorWithImpl< NonZero_Op >, Aidge::OperatorTensorWithImpl< LSQ_Op >, Aidge::OperatorTensorWithImpl< Greater_Op >, Aidge::OperatorTensorWithImpl< ConnectedComponentLabeling_Op >, Aidge::OperatorTensorWithImpl< And_Op >, Aidge::OperatorTensorWithImpl< Sum_Op >, Aidge::OperatorTensorWithImpl< RangeAffineTransformation_Op >, Aidge::OperatorTensorWithImpl< InstanceNorm_Op >, Aidge::OperatorTensorWithImpl< Hardmax_Op >, Aidge::OperatorTensorWithImpl< Gather_Op, Gather_OpImpl >, Aidge::OperatorTensorWithImpl< Cast_Op, Cast_OpImpl >, Aidge::OperatorTensorWithImpl< CastLike_Op, CastLike_OpImpl >, Aidge::OperatorTensorWithImpl< Unsqueeze_Op, Unsqueeze_OpImpl >, Aidge::OperatorTensorWithImpl< TanhClamp_Op >, Aidge::OperatorTensorWithImpl< StackOp, StackOpImpl >, Aidge::OperatorTensorWithImpl< Resize_Op >, Aidge::OperatorTensorWithImpl< ReduceMean_Op >, Aidge::OperatorTensorWithImpl< LRN_Op >, Aidge::OperatorTensorWithImpl< Expand_Op >, Aidge::OperatorTensorWithImpl< ShiftMax_Op >, Aidge::OperatorTensorWithImpl< Select_Op, Select_OpImpl >, Aidge::OperatorTensorWithImpl< RandomNormalLike_Op >, Aidge::OperatorTensorWithImpl< Identity_Op, Identity_OpImpl >, Aidge::OperatorTensorWithImpl< ILayerNorm_Op >, Aidge::OperatorTensorWithImpl< Fold_Op< DIM > >, Aidge::OperatorTensorWithImpl< ConvTranspose_Op< DIM > >, Aidge::GenericOperator_Op, Aidge::MetaOperator_Op, Aidge::Move_Op, Aidge::OperatorTensorWithImpl< T, DEF_IMPL >, Aidge::Producer_Op
Public Functions
-
OperatorTensor() = delete#
-
OperatorTensor(const std::string &type, const std::vector<InputCategory> &inputsCategory, const IOIndex_t nbOut)#
Operator tensor constructor. This function is not meant to be called directly but by a derived class constructor every operator class derive from this class.
- Parameters:
type β [in] : type of operator (i.e. βAddβ, βAveragePoolβ,β¦)
inputsCategory β [in] : describes the type of each input.
nbOut β [in] : Number of tensors this operator will output
-
OperatorTensor(const OperatorTensor &other)#
Copy constructor.
- Parameters:
other β [in] Another
OperatorTensorinstance to copy.
-
~OperatorTensor()#
Destructor for the OperatorTensor class.
Associates an input tensor to the operator.
- Parameters:
inputIdx β [in] Index of the input to associate.
data β [in] Shared pointer to the data to associate.
-
virtual void resetInput(const IOIndex_t inputIdx) override#
Resets the input tensor at a given index.
- Parameters:
inputIdx β [in] Index of the input to reset.
Sets an input tensor for the operator.
- Parameters:
inputIdx β [in] Index of the input to set.
data β [in] Shared pointer to the data to set.
-
const std::shared_ptr<Tensor> &getInput(const IOIndex_t inputIdx) const#
Retrieves an input tensor.
- Parameters:
inputIdx β [in] Index of the input to retrieve.
- Returns:
Shared pointer to the input tensor.
-
virtual std::shared_ptr<Data> getRawInput(const IOIndex_t inputIdx) const final override#
Retrieves a raw input tensor.
- Parameters:
inputIdx β [in] Index of the input to retrieve.
- Returns:
Shared pointer to the raw input tensor.
Sets an output tensor for the operator.
- Parameters:
outputIdx β [in] Index of the output to set.
data β [in] Shared pointer to the data to set.
-
virtual const std::shared_ptr<Tensor> &getOutput(const IOIndex_t outputIdx) const#
Retrieves an output tensor.
- Parameters:
outputIdx β [in] Index of the output to retrieve.
- Returns:
Shared pointer to the output tensor.
-
virtual std::shared_ptr<Aidge::Data> getRawOutput(const Aidge::IOIndex_t outputIdx) const final override#
Retrieves a raw output tensor.
- Parameters:
outputIdx β [in] Index of the output to retrieve.
- Returns:
Shared pointer to the raw output tensor.
-
virtual std::vector<std::pair<std::vector<Aidge::DimSize_t>, std::vector<DimSize_t>>> computeReceptiveField(const std::vector<DimSize_t> &firstEltDims, const std::vector<DimSize_t> &outputDims, const IOIndex_t outputIdx = 0) const#
Computes the receptive field for a given output feature area.
- Parameters:
firstIdx β [in] First index of the output feature.
outputDims β [in] Dimensions of the output feature.
outputIdx β [in] Index of the output (default is 0).
- Returns:
Vector of pairs containing, for each data input tensor, the first index and dimensions of the feature area.
-
virtual bool forwardDims(bool allowDataDependency = false)#
Computes the dimensions of the operatorβs output tensor based on input sizes.
If the output dimensions depend on undefined inputs, this function returns false and enters TOKEN mode.
TOKEN mode ensures that all inputs and outputs of the graph the node belongs to are connected.
- Parameters:
allowDataDependency β [in] Flag to indicate if output dimensions depend on optional parameter tensors.
- Returns:
True if dimensions are successfully computed, false otherwise.
-
virtual bool forwardDType()#
Computes the data type of the operatorβs output tensor based on input data type.
For each operator inputs:
If input is an (optional) Param, the operator will forward
- Returns:
True if data types are successfully computed, false otherwise.
-
virtual bool dimsForwarded() const#
Checks if dimensions have been successfully forwarded.
- Returns:
True if dimensions are forwarded, false otherwise.
-
virtual void setDevice(DeviceIdx_t device) override#
Sets the device.
- Parameters:
device β [in] Device index.
-
virtual void setBackend(const std::string &name, DeviceIdx_t device = 0) override#
Sets the backend implementation.
- Parameters:
name β [in] Name of the backend.
device β [in] Device index.
-
virtual void setDataType(const DataType &dataType) const override#
Sets the data type of the operatorβs tensors.
Warning
Sets all outputs but only inputs of category
&InputCategory::Param
InputCategory::OptionnalParam
- Parameters:
dataType β Data type to set.
-
virtual void setDataFormat(const DataFormat &dataFormat) const override#
Sets the data format of the operatorβs tensors.
- Parameters:
dataFormat β Data format to set.
-
virtual void forward() override#
Executes the forward operation for the operator.
Set the pointer of mOutput[outputIdx] to be equal to data. Warning this function should be use with great care as it may break the graph dataflow. You have been warned.
-
OperatorTensor() = delete#
Generic Operator#
A generic tensor-based operator can be used to model any kind of mathematical operator that takes a defined number of inputs, produces a defined number of outputs and can have some attributes. It is possible to provide a function that produces the output tensors size w.r.t. the inputs size. It has a default consumer-producer model (require and consume all inputs full tensors and produces output full tensors).
This is the default operator used for unsupported ONNX operators when loading an ONNX model. While it obviously cannot be executed, a generic operator has still some usefulness:
It allows loading any graph even with unknown operators. It is possible to identify exactly all the missing operator types and their position in the graph;
It can be searched and manipulated with graph matching, allowing for example to replace it with alternative operators;
It can be scheduled and included in the graph static scheduling;
π§ A custom implementation may be provided in the future, even in pure Python, for rapid integration and prototyping.
- aidge_core.GenericOperator()#
GenericOperator(type: str, input_category: list[aidge_core.InputCategory], nb_out: int, name: str = '', **kwargs) -> aidge_core.aidge_core.Node
Creates a aidge_core.GenericOperatorOp with specified input and output counts.
- param type:
Type of the operator.
- type type:
str
- param inputCategory:
List of input categories.
- type inputCategory:
List[aidge_core.InputCategory]
- param nbOut:
Number of output tensors.
- type nbOut:
int
- param name:
Name of the operator, default=ββ
- type name:
str, Optional
- param kwargs:
Every kwargs provided will be interpreted as a :py:class: aidge_core.DynamicAttributes.
GenericOperator(type: str, nb_data: int, nb_param: int, nb_out: int, name: str = '', **kwargs) -> aidge_core.aidge_core.Node
Creates a aidge_core.GenericOperatorOp with specified input and output counts.
- param type:
Type of the operator.
- type type:
str
- param nbData:
Number of input data tensors.
- type nbData:
int
- param nbParam:
Number of parameter tensors.
- type nbParam:
int
- param nbOut:
Number of output tensors.
- type nbOut:
int
- param name:
Name of the operator, default=ββ
- type name:
str, Optional
- param kwargs:
Every kwargs provided will be interpreted as a :py:class: aidge_core.DynamicAttributes.
GenericOperator(type: str, op: aidge_core.aidge_core.OperatorTensor, name: str = '') -> aidge_core.aidge_core.Node
Creates a aidge_core.Node containing a aidge_core.GenericOperatorOp based on another aidge_core.Operator.
- Parameters:
type (str) β Type of the operator
op (aidge_core.Operator) β Existing operator to derive from.
name (str, Optional) β Name of the operator, default=ββ
-
std::shared_ptr<Node> Aidge::GenericOperator(const std::string &type, IOIndex_t nbData, IOIndex_t nbParam, IOIndex_t nbOut, const std::string &name = "")#
Creates a generic operator with specified input and output counts.
- Parameters:
type β [in] Type of the operator.
nbData β [in] Number of input data tensors.
nbParam β [in] Number of parameter tensors.
nbOut β [in] Number of output tensors.
name β [in] Optional name for the operator.
- Returns:
A shared pointer to the created operator node.
Creates a generic operator based on another operator.
- Parameters:
type β [in] Type of the generic operator.
op β [in] Existing operator to derive from.
name β [in] Optional name for the operator.
- Returns:
A shared pointer to the created operator node.
Meta Operator#
A meta-operator (or composite operator) is internally built from a sub-graph.
- aidge_core.meta_operator(type: str, graph: aidge_core.aidge_core.GraphView, forced_inputs_category: collections.abc.Sequence[aidge_core.aidge_core.InputCategory] = [], name: str = '') aidge_core.aidge_core.Node#
Helper function to create a MetaOperator node.
- Parameters:
type β The type of the meta-operator.
graph β The micro-graph defining the meta-operator.
forcedInputsCategory β Optional input categories to override default behavior.
name β Optional name for the operator.
- Returns:
A shared pointer to the created Node.
Building a new meta-operator is simple:
auto graph = Sequential({
Pad<2>(padding_dims, (!name.empty()) ? name + "_pad" : ""),
MaxPooling<2>(kernel_dims, (!name.empty()) ? name + "_maxpooling" : "", stride_dims, ceil_mode)
});
return MetaOperator("PaddedMaxPooling2D", graph, name);
You can use the aidge_core.expand_metaops to flatten the meta-operators in a graph.