Updated on 2022-03-13 GMT+08:00

IAITensor

Serves as the input and output of a model when the process function is used. This data type is defined in ai_tensor.h.

/**
* Tensor    Input and output data
*/
class IAITensor
{
public:
    IAITensor() {}
    virtual ~IAITensor() {};
    /*
    * @brief   Set parameters through AITensorDescription.
    * @param [in] tensor_desc   Tensor description
    * @return true: Initialization success
    * @return false: Initialization failure. The possible cause is that tensor_desc is inconsistent with the current tensor.
    */
    virtual bool Init(const AITensorDescription &tensor_desc) = 0;
   /*
    * @brief   Obtain the type name.
    */
    virtual const char* const GetTypeName() = 0;
    /*
    * @brief   Obtain the byte length after serialization.
    */
    virtual uint32_t ByteSizeLong() = 0;
    virtual void SetBufferAttr(void *data, int32_t size, bool isowner, bool is_support_mem_share) = 0;

    virtual bool IsSupportZerocpy() = 0;

#if defined( __ANDROID__) || defined(ANDROID)
        /*
        * @brief   Serialize data to the buffer for cross-process data interaction.
        * @param [in] buffer   Address of the buffer to which the data is serialized, allocated by the caller
        * @param [in] size   Size of the buffer to which the data is output
        * @return SUCCESS   Success
        *         FAILED: failure. If the tensor does not support cross-process, this API does not need to be implemented and a failure message is returned.
        */
        virtual AIStatus SerializeTo(void* buffer, const uint32_t size) = 0;

        /*
        * @brief   Deserialize data from the buffer to a tensor for cross-process data interaction.
        * @param [in] buffer  Size of the buffer to which the data is input
        * @param [in] size   Size of the buffer to which the data is input
        * @return SUCCESS   Success
        *         FAILED: failure. If the tensor does not support cross-process, this API does not need to be implemented and a failure message is returned.
        */
        virtual AIStatus DeserializeFrom(const void* buffer, const uint32_t size) = 0;
#endif
};