Operation

Description

ATB Operation class.

This API class defines a series of APIs required for operator preparation and execution. You can execute operators by creating Operation objects.

Definition

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
class Operation {
public:
    Operation() = default;
    virtual ~Operation() = default;
    virtual std::string GetName() const = 0;
    virtual Status InferShape(const SVector<TensorDesc> &inTensorDescs, SVector<TensorDesc> &outTensorDescs) const = 0;
    virtual uint32_t GetInputNum() const = 0;
    virtual uint32_t GetOutputNum() const = 0;
    virtual Status Setup(const VariantPack &variantPack, uint64_t &workspaceSize, Context *context) = 0;
    virtual Status Execute(const VariantPack &variantPack, uint8_t *workspace, uint64_t workspaceSize, Context *context) = 0;
};

Parameters

Member

Description

GetName

Obtains the name of the created Operation.

InferShape

Infers the description of the output tensor based on the input tensor description.

  • inTensorDescs stores the SVector of the description information of all input tensors.
  • outTensorDescs stores the SVector of the description information of all output tensors.

If the execution is successful, NO_ERROR is returned. Other error codes indicate failures. For details, see ErrorType.

GetInputNum

Gets the number of input tensors of Op/GraphOp.

GetOutputNum

Gets the number of output tensors of Op/GraphOp.

Setup

Prepares for executing an Operation, such as calculating workspaceSize to be allocated during the Operation execution.

  • variantPack: input and output tensors.
  • workspaceSize: obtains the memory space to be allocated for Operation execution.
  • context: context where the preparation for Operation execution is located.

If the execution is successful, NO_ERROR is returned. Other error codes indicate failures. For details, see ErrorType.

Execute

Executes an Operation. The actual memory is allocated to the Operation based on the workspaceSize obtained in the Setup process, and the Operation is executed.

  • variantPack: input and output tensors.
  • workspace: memory address allocated for Operation execution.
  • workspaceSize: memory space to be allocated for Operation execution.
  • context: context where Operation execution is performed.

If the execution is successful, NO_ERROR is returned. Other error codes indicate failures. For details, see ErrorType.