1 Star 0 Fork 4.9K

fish / docs

forked from OpenHarmony / docs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
plug-in.md 31.99 KB
一键复制 编辑 原始数据 按行查看 历史
NEEN 提交于 2021-03-12 17:59 . !197 Docs Update version 1.0.1

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.

For the data structure of ConfigInfo, ClientInfo, AlgorithmInfo, and DataInfo, see Table 2 in the SDK development guidelines.

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_PLUGIN_TYPE(-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.

1
https://gitee.com/fish_neil/docs.git
git@gitee.com:fish_neil/docs.git
fish_neil
docs
docs
master

搜索帮助