开源鸿蒙 Plug-in

  • 2022-08-09
  • 浏览 (675)

Plug-in

The AI engine framework has defined a set of algorithm plug-in access specifications. Each plug-in needs to implement specified APIs to implement functions such as obtaining the plug-in version information and algorithm inference type, executing synchronous and asynchronous algorithms, loading algorithm plug-ins, uninstalling algorithm plug-ins, setting algorithm configuration information, and obtaining specified algorithm configuration information. Specifically, implement the SyncProcess API for the synchronous algorithm and the AsyncProcess API for the asynchronous algorithm.

Table 1 describes the IPlugin APIs.

Table 1 IPlugin APIs

API

Description

Parameters

const long long GetVersion() const;

Function: Obtains the plug-in version information.

Return value: version number (long long)

-

const char *GetInferMode() const;

Function: Obtains the algorithm inference type.

Return value: SYNC or ASYNC

-

int SyncProcess(IRequest *request, IResponse *&response);

Function: Executes a synchronous algorithm.

Return value: Returns 0 if the operation is successful; returns a non-zero value otherwise.

request: Passes the request content to the algorithm plug-in over the data channel between the engine server and the plug-in. This parameter must not be null.

response: Receives the synchronous algorithm execution result returned by the algorithm plug-in over the data channel between the engine server and the plug-in. This parameter must not be null.

int AsyncProcess(IRequest *request, IPluginAlgorithmCallback *callback);

Function: Executes an asynchronous algorithm.

Return value: Returns 0 if the operation is successful; returns a non-zero value otherwise.

request: Passes the request content to the algorithm plug-in over the data channel between the engine server and the plug-in. This parameter must not be null.

callback: Returns the asynchronous algorithm execution result to the engine server. This parameter must not be null.

int Prepare(long long transactionId, const DataInfo &inputInfo, DataInfo &outputInfo);

Function: Loads an algorithm plug-in.

Return value: Returns 0 if the operation is successful; returns a non-zero value otherwise.

transactionId: Indicates the transaction ID, which is used to identify the client and session. This parameter must not be null.

inputInfo: Indicates input information specified for algorithm plug-in loading. This parameter can be null.

outputInfo: Indicates output information in the return result of algorithm plug-in loading. This parameter can be null.

int Release(bool isFullUnload, long long transactionId, const DataInfo &inputInfo);

Function: Uninstalls an algorithm plug-in.

Return value: Returns 0 if the operation is successful; returns a non-zero value otherwise.

isFullUnload: Indicates whether a plug-in is called by only one client. A plug-in can be uninstalled only when it is called by only one client. This parameter must not be null.

transactionId: Indicates the transaction ID, which is used to identify the client and session. This parameter must not be null.

inputInfo: Indicates input information specified for algorithm plug-in uninstallation. This parameter can be null.

int SetOption(int optionType, const DataInfo &inputInfo);

Function: Sets configuration items. You can use this API to pass algorithm’s extended information to plug-ins.

Return value: Returns 0 if the operation is successful; returns a non-zero value otherwise.

optionType: Indicates the algorithm for obtaining the configuration item information. An algorithm plug-in can use this parameter as needed. This parameter must not be null.

inputInfo: Indicates algorithm parameter information. An algorithm plug-in can use this parameter as needed. This parameter can be null.

int GetOption(int optionType, const DataInfo &inputInfo, DataInfo &outputInfo);

Function: Obtains configuration item information based on the specified optionType and inputInfo.

Return value: Returns 0 if the operation is successful; returns a non-zero value otherwise.

optionType: Indicates the algorithm for obtaining the configuration item information. This parameter must not be null.

inputInfo: Indicates input information specified for obtaining configuration item information of the algorithm. This parameter can be null.

outputInfo: Indicates the configuration item information in the return result. This parameter can be null.

Algorithm plug-in APIs including Prepare, SyncProcess, AsyncProcess, Release, SetOption, and GetOption are in 1:1 mapping with the client APIs including AieClientPrepare, AieClientSyncProcess, AieClientAsyncProcess, AieClientRelease, AieClientSetOption, and AieClientGetOption. The GetInferMode API is used to return the algorithm execution type, which can be synchronous or asynchronous.

Table 2 describes the IPluginCallback APIs.

Table 2 IPluginCallback APIs

API

Description

Parameters

void OnEvent(PluginEvent event, IResponse *response);

Function: Returns the asynchronous algorithm execution result.

event: Enumerates the algorithm execution result. The value can be ON_PLUGIN_SUCCEED or ON_PLUGIN_FAIL.

response: Encapsulates the algorithm execution result.

The Request and Response classes define the requests and responses used for communication between the AI engine server and algorithm plug-ins. A request encapsulates the request content and input data of the caller. The plug-in returns the calculation result to the AI engine server through a response.

Table 3 describes the attributes of the Request class.

Table 3 Attributes of the Request class

Name

Description

Default Value

innerSequenceId

Type: long long

Function: reserved

0

requestId

Type: int

Function: Indicates the request sequence, which is used to bind the return result.

0

operationId

Type: int

Function: reserved

0

transactionId

Type: long long

Function: Indicates the transaction ID, which is the combination of clientId and sessionId.

0

algoPluginType

Type: int

Function: Indicates the algorithm type ID allocated by the AI engine framework based on the plug-in loading sequence.

0

msg

Type: DataInfo

Function: Stores the input parameters for calling the algorithm API.

.data = nullptr

.length = 0

Table 4 describes the attributes of the Response class.

Table 4 Attributes of the Response class

Name

Description

Default Value

innerSequenceId

Type: long long

Function: reserved

0

requestId

Type: int

Function: Indicates the request sequence, which is used to bind the return result.

0

retCode_

Type: int

Function: Indicates the inference result code of the asynchronous algorithm.

0

retDesc

Type: string

Function: reserved

-

transactionId

Type: long long

Function: Indicates the transaction ID, which is the combination of clientId and sessionId.

0

algoPluginType

Type: int

Function: Indicates the algorithm type ID allocated by the AI engine framework based on the plug-in loading sequence.

INVALID_ALGO_PLUGINTYPE(-1)

result

Type: DataInfo

Function: Stores the inference result of the asynchronous algorithm.

.data = nullptr

.length = 0

For details about the development process, see the development example for the KWS plug-in.

你可能感兴趣的文章

开源鸿蒙 Subsystems

开源鸿蒙 KWS Configuration File

开源鸿蒙 KWS Plug-in

开源鸿蒙 KWS SDK

开源鸿蒙 Development Examples

开源鸿蒙 Configuration File

开源鸿蒙 SDK

开源鸿蒙 Development Guidelines

开源鸿蒙 Development Environment

开源鸿蒙 AI Engine Framework

0  赞