未验证 提交 b23a4c5a 编写于 作者: O openharmony_ci 提交者: Gitee

!20448 翻译已完成20206+19996+19744+19800+19766+19789+19759+19685+19481+19629+19480+19020+19000

Merge pull request !20448 from shawn_he/19000-d
...@@ -3,42 +3,25 @@ ...@@ -3,42 +3,25 @@
## Basic Concepts ## Basic Concepts
The inter-process communication (IPC) and remote procedure call (RPC) mechanisms are used to implement cross-process communication. The difference between them lies in that IPC uses the Binder driver to implement cross-process communication within a device, whereas RPC uses the DSoftBus driver to implement cross-process communication across devices. Inter-process communication (IPC) and remote procedure call (RPC) are used to implement cross-process communication. IPC uses the Binder driver to implement cross-process communication within a device, whereas RPC uses the DSoftBus driver to implement cross-process communication across devices. Cross-process communication is required because each process has its own independent resources and memory space and one process is not allowed to access the resources and memory space of other processes.
The reason why cross-process communication is needed is that each process has its own independent resources and memory space and one process is not allowed to access the resources and memory space of other processes. IPC and RPC usually use the client-server model, where the client (service requester, that is, the process that requests a service) obtains the proxy of the server (service provider, that is, the process that provides the service) and uses the proxy to read and write data to implement data communication across processes. More specifically, the client constructs a proxy object of the server. The proxy object has the same functions as the server. To access a certain API of the server, you only need to access the corresponding API in the proxy object. The proxy object sends the request to the server, and the server processes the received request and returns the processing result to the proxy object through the driver. Then, the proxy object forwards the processing result to the client. The server registers system abilities (SAs) with the system ability manager (SAMgr), which manages the SAs and provides APIs for clients. To communicate with a specific SA, the client must obtain the proxy of the SA from SAMgr. > **NOTE**
> The applications in the stage model cannot use IPC or RPC directly, and must use the following capabilities to implement related service scenarios:
>- [Background services](../application-models/background-services.md): use IPC to implement service invocation across processes.
>- [Multi-device collaboration](../application-models/hop-multi-device-collaboration.md): uses RPC to call remote interfaces and transfer data.
In the following sections, proxy represents the service requester, and stub represents the service provider.
![IPC&RPC communication mechanisms](figures/IPC_RPC_communication.PNG) ## Implementation Principles
IPC and RPC usually use the client-server model, where the client (service requester, that is, the process that requests a service) obtains the proxy of the server (service provider, that is, the process that provides the service) and uses the proxy to read and write data to implement data communication across processes. More specifically, the client constructs a proxy object of the server. The proxy object has the same functions as the server. To access a certain API of the server, you only need to access the corresponding API in the proxy object. The proxy object sends the request to the server, and the server processes the received request and returns the processing result to the proxy object through the driver. Then, the proxy object forwards the processing result to the client. The server registers system abilities (SAs) with the system ability manager (SAMgr), which manages the SAs and provides APIs for clients. To communicate with a specific SA, the client must obtain the proxy of the SA from SAMgr. In the following sections, proxy represents the service requester, and stub represents the service provider.
## Constraints ![IPC & RPC communication mechanisms] (figures/IPC_RPC_communication.PNG)
- During cross-process communication within a single device, the maximum amount of data to be transmitted is about 1 MB. If the amount of data to be transmitted exceeds this limit, use the [anonymous shared memory](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis/js-apis-rpc.md#ashmem8).
- Subscription to death notifications of anonymous stub objects (not registered with SAMgr) is prohibited in RPC.
- During cross-process communication across processes, a proxy object cannot be passed back to the device that hosts the stub object pointed by the proxy object. That is, the proxy object pointing to the stub object of the remote device cannot be passed across processes twice on the local device.
## **Recommendations**
First, compile an API class and define message codes in the API class for both communication parties to identify operations. Unimplemented APIs are allowed in the API class because it must be inherited by both communication parties and its inheritance classes cannot be abstract classes. When inheriting the API class, both communication parties must implement the unimplemented APIs, so as to make sure that the inheritance classes are not abstract classes.
Then, implement the API class specific to the stub, and override the **AsObject** and **OnRemoteRequest** APIs. In addition, compile the proxy to implement the APIs in the API class and override the **AsObject** API. You can also encapsulate an additional API for calling **SendRequest** to send data to the peer.
After the preceding operations are done, register a system ability (SA) with SAMgr. Note that the registration should be completed in the process that hosts the stub. Then, obtain the proxy from SAMgr as needed to implement cross-process communication with the stub.
Related steps are as follows:
- Implementing the API class: Inherit **IRemoteBroker**, define message codes, and declare APIs that are not implemented in the API class. ## Constraints
- Implementing the service provider (stub): Inherit **IRemoteStub** or **RemoteObject**, and override the **AsObject** and **OnRemoteRequest** APIs.
- Implementing the service requester (proxy): Inherit **IRemoteProxy** or **RemoteProxy**, override the **AsObject** API, and encapsulate the required API to call **SendRequest**.
- Registering the SA: Apply for a unique ID for the SA, and register the SA with SAMgr.
- Obtaining the SA: Obtain the proxy based on the SA ID and device ID, and use the proxy to communicate with the remote end.
- A maximum of 1 MB data can be transferred in cross-process communication on a single device. If the amount of data to be transmitted is larger than 1 MB, use [anonymous shared memory](../reference/apis/js-apis-rpc.md#ashmem8).
## Related Modules - Subscription to death notifications of anonymous stub objects (not registered with SAMgr) is prohibited in RPC.
[Distributed Ability Manager Service Framework](https://gitee.com/openharmony/ability_dmsfwk) - During cross-process communication across processes, a proxy object cannot be passed back to the device that hosts the stub object pointed by the proxy object. That is, the proxy object pointing to the stub object of the remote device cannot be passed across processes twice on the local device.
...@@ -3592,7 +3592,7 @@ Sets the audio device for a call. This API uses an asynchronous callback to retu ...@@ -3592,7 +3592,7 @@ Sets the audio device for a call. This API uses an asynchronous callback to retu
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------- | ---- | ---------- | | -------- | ---------------------------- | ---- | ---------- |
| device | [AudioDevice](#audiodevice8) | Yes | Audio device.| | device | [AudioDevice](#audiodevice10) | Yes | Audio device.|
| callback | AsyncCallback<void> | Yes | Callback used to return the result.| | callback | AsyncCallback<void> | Yes | Callback used to return the result.|
**Error codes** **Error codes**
...@@ -3611,17 +3611,64 @@ For details about the following error codes, see [Telephony Error Codes](../../r ...@@ -3611,17 +3611,64 @@ For details about the following error codes, see [Telephony Error Codes](../../r
**Example** **Example**
```js ```js
call.setAudioDevice(1, (err) => { let audioDevice={
deviceType: 1
}
call.setAudioDevice(audioDevice, (err) => {
console.log(`callback: err->${JSON.stringify(err)}`); console.log(`callback: err->${JSON.stringify(err)}`);
}); });
``` ```
## call.setAudioDevice<sup>10+</sup>
setAudioDevice\(device: AudioDevice): Promise\<void\>
Sets the audio device for a call. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permission**: ohos.permission.SET_TELEPHONY_STATE
**System capability**: SystemCapability.Telephony.CallManager
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------- | ---- | ---------- |
| device | [AudioDevice](#audiodevice10) | Yes | Audio device.|
**Error codes**
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
| 201 | Permission denied. |
| 202 | Non-system applications use system APIs. |
| 401 | Parameter error. |
| 8300001 | Invalid parameter value. |
| 8300002 | Operation failed. Cannot connect to service. |
| 8300003 | System internal error. |
| 8300999 | Unknown error code. |
**Example**
```js
let audioDevice={
deviceType: 1
}
call.setAudioDevice(audioDevice).then(() => {
console.log(`setAudioDevice success.`);
}).catch((err) => {
console.error(`setAudioDevice fail, promise: err->${JSON.stringify(err)}`);
});
```
## call.setAudioDevice<sup>9+</sup> ## call.setAudioDevice<sup>9+</sup>
setAudioDevice\(device: AudioDevice, options: AudioDeviceOptions, callback: AsyncCallback\<void\>\): void setAudioDevice\(device: AudioDevice, options: AudioDeviceOptions, callback: AsyncCallback\<void\>\): void
Sets the audio device for a call. This API uses an asynchronous callback to return the result. Sets the audio device for a call based on the specified options. This API uses an asynchronous callback to return the result.
**System API**: This is a system API. **System API**: This is a system API.
...@@ -3631,7 +3678,7 @@ Sets the audio device for a call. This API uses an asynchronous callback to retu ...@@ -3631,7 +3678,7 @@ Sets the audio device for a call. This API uses an asynchronous callback to retu
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------------ | ---- | -------------- | | -------- | ------------------------------------------ | ---- | -------------- |
| device | [AudioDevice](#audiodevice8) | Yes | Audio device. | | device | [AudioDevice](#audiodevice10) | Yes | Audio device. |
| options | [AudioDeviceOptions](#audiodeviceoptions9) | Yes | Audio device parameters.| | options | [AudioDeviceOptions](#audiodeviceoptions9) | Yes | Audio device parameters.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
...@@ -3651,10 +3698,13 @@ For details about the following error codes, see [Telephony Error Codes](../../r ...@@ -3651,10 +3698,13 @@ For details about the following error codes, see [Telephony Error Codes](../../r
**Example** **Example**
```js ```js
let audioDevice={
deviceType: 1
}
let audioDeviceOptions={ let audioDeviceOptions={
bluetoothAddress: "IEEE 802-2014" bluetoothAddress: "IEEE 802-2014"
} }
call.setAudioDevice(1, audioDeviceOptions, (err) => { call.setAudioDevice(audioDevice, audioDeviceOptions, (err) => {
console.log(`callback: err->${JSON.stringify(err)}`); console.log(`callback: err->${JSON.stringify(err)}`);
}); });
``` ```
...@@ -3674,7 +3724,7 @@ Sets the audio device for a call based on the specified options. This API uses a ...@@ -3674,7 +3724,7 @@ Sets the audio device for a call based on the specified options. This API uses a
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------------------------------------------ | ---- | ------------------ | | ------- | ------------------------------------------ | ---- | ------------------ |
| device | [AudioDevice](#audiodevice8) | Yes | Audio device. | | device | [AudioDevice](#audiodevice10) | Yes | Audio device. |
| options | [AudioDeviceOptions](#audiodeviceoptions9) | No | Audio device parameters.| | options | [AudioDeviceOptions](#audiodeviceoptions9) | No | Audio device parameters.|
**Return value** **Return value**
...@@ -3699,10 +3749,13 @@ For details about the following error codes, see [Telephony Error Codes](../../r ...@@ -3699,10 +3749,13 @@ For details about the following error codes, see [Telephony Error Codes](../../r
**Example** **Example**
```js ```js
let audioDevice={
deviceType: 1
}
let audioDeviceOptions={ let audioDeviceOptions={
bluetoothAddress: "IEEE 802-2014" bluetoothAddress: "IEEE 802-2014"
} }
call.setAudioDevice(1, audioDeviceOptions).then(() => { call.setAudioDevice(audioDevice, audioDeviceOptions).then(() => {
console.log(`setAudioDevice success.`); console.log(`setAudioDevice success.`);
}).catch((err) => { }).catch((err) => {
console.error(`setAudioDevice fail, promise: err->${JSON.stringify(err)}`); console.error(`setAudioDevice fail, promise: err->${JSON.stringify(err)}`);
...@@ -4242,7 +4295,7 @@ call.closeUnfinishedUssd(slotId).then(() => { ...@@ -4242,7 +4295,7 @@ call.closeUnfinishedUssd(slotId).then(() => {
## call.setVoNRState<sup>10+</sup> ## call.setVoNRState<sup>10+</sup>
setVoNRState\(slotId: number, state: VoNRState, callback: AsyncCallback\<boolean\>\): void setVoNRState\(slotId: number, state: VoNRState, callback: AsyncCallback\<void\>\): void
Sets the status of the VoNR switch. This API uses an asynchronous callback to return the result. Sets the status of the VoNR switch. This API uses an asynchronous callback to return the result.
...@@ -4258,7 +4311,7 @@ Sets the status of the VoNR switch. This API uses an asynchronous callback to re ...@@ -4258,7 +4311,7 @@ Sets the status of the VoNR switch. This API uses an asynchronous callback to re
| ----------- | ----------------------------- | ---- | ---------------------------------------------------- | | ----------- | ----------------------------- | ---- | ---------------------------------------------------- |
| slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 | | slotId | number | Yes | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2 |
| state | [VoNRState](#vonrstate10) | Yes | Status of the VoNR switch. | | state | [VoNRState](#vonrstate10) | Yes | Status of the VoNR switch. |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the result. Callback used to return the result. The value **true** indicates that the operation is successful, and value **false** indicates the opposite.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Error codes** **Error codes**
...@@ -4287,7 +4340,7 @@ call.setVoNRState(slotId, state, (err, data) => { ...@@ -4287,7 +4340,7 @@ call.setVoNRState(slotId, state, (err, data) => {
## call.setVoNRState<sup>10+</sup> ## call.setVoNRState<sup>10+</sup>
setVoNRState\(slotId: number, state: VoNRState\): Promise\<boolean\> setVoNRState\(slotId: number, state: VoNRState\): Promise\<void\>
Sets the status of the VoNR switch. This API uses a promise to return the result. Sets the status of the VoNR switch. This API uses a promise to return the result.
...@@ -4308,7 +4361,7 @@ Sets the status of the VoNR switch. This API uses a promise to return the result ...@@ -4308,7 +4361,7 @@ Sets the status of the VoNR switch. This API uses a promise to return the result
| Type | Description | | Type | Description |
| ---------------------- | --------------------------------------------- | | ---------------------- | --------------------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result. | | Promise&lt;void&gt; | Promise used to return the result. |
**Error codes** **Error codes**
...@@ -4329,7 +4382,7 @@ For details about the following error codes, see [Telephony Error Codes](../../r ...@@ -4329,7 +4382,7 @@ For details about the following error codes, see [Telephony Error Codes](../../r
```js ```js
let slotId = 0; let slotId = 0;
let state = 1; let state = 1;
call.setVoNRState(slotId, state).then(() => { call.setVoNRState(slotId, state).then((data) => {
console.log(`setVoNRState success, promise: data->${JSON.stringify(data)}`); console.log(`setVoNRState success, promise: data->${JSON.stringify(data)}`);
}).catch((err) => { }).catch((err) => {
console.error(`setVoNRState fail, promise: err->${JSON.stringify(err)}`); console.error(`setVoNRState fail, promise: err->${JSON.stringify(err)}`);
...@@ -4516,7 +4569,7 @@ For details about the following error codes, see [Telephony Error Codes](../../r ...@@ -4516,7 +4569,7 @@ For details about the following error codes, see [Telephony Error Codes](../../r
```js ```js
let slotId = 0; let slotId = 0;
call.canSetCallTransferTime(slotId).then(() => { call.canSetCallTransferTime(slotId).then((data) => {
console.log(`canSetCallTransferTime success, promise: data->${JSON.stringify(data)}`); console.log(`canSetCallTransferTime success, promise: data->${JSON.stringify(data)}`);
}).catch((err) => { }).catch((err) => {
console.error(`canSetCallTransferTime fail, promise: err->${JSON.stringify(err)}`); console.error(`canSetCallTransferTime fail, promise: err->${JSON.stringify(err)}`);
...@@ -4629,7 +4682,7 @@ Provides an option for determining whether a call is a video call. ...@@ -4629,7 +4682,7 @@ Provides an option for determining whether a call is a video call.
## DialCallOptions<sup>9+</sup> ## DialCallOptions<sup>9+</sup>
Defines options for initiating a call. Provides an option for determining whether a call is a video call.
**System API**: This is a system API. **System API**: This is a system API.
...@@ -4704,7 +4757,7 @@ Enumerates VoNR switch states. ...@@ -4704,7 +4757,7 @@ Enumerates VoNR switch states.
| VONR_STATE_OFF | 0 | Disabled. | | VONR_STATE_OFF | 0 | Disabled. |
| VONR_STATE_ON | 1 | Enabled. | | VONR_STATE_ON | 1 | Enabled. |
## AudioDevice<sup>8+</sup> ## AudioDevice<sup>10+</sup>
Enumerates audio devices. Enumerates audio devices.
...@@ -4712,13 +4765,10 @@ Enumerates audio devices. ...@@ -4712,13 +4765,10 @@ Enumerates audio devices.
**System capability**: SystemCapability.Telephony.CallManager **System capability**: SystemCapability.Telephony.CallManager
| Name | Value | Description | | Name | Type | Mandatory | Description |
| -------------------- | ---- | ------------ | | --------------------------------- | ------------------------------------- | ---- | ---------------- |
| DEVICE_EARPIECE | 0 | Headset device. | | deviceType <sup>10+</sup> | [AudioDeviceType](#audiodevicetype10) | Yes | Audio device type. |
| DEVICE_SPEAKER | 1 | Speaker device.| | address <sup>10+</sup> | string | No | Audio device address. |
| DEVICE_WIRED_HEADSET | 2 | Wired headset device.|
| DEVICE_BLUETOOTH_SCO | 3 | Bluetooth SCO device. |
| DEVICE_MIC | 4 | Microphone device|
## AudioDeviceType<sup>10+</sup> ## AudioDeviceType<sup>10+</sup>
...@@ -4745,8 +4795,8 @@ Defines the audio device information. ...@@ -4745,8 +4795,8 @@ Defines the audio device information.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------------------------------- | ------------------------------------- | ---- | ---------------- | | --------------------------------- | ------------------------------------- | ---- | ---------------- |
| audioDeviceList <sup>10+</sup> | [Array\<AudioDevice\>](#audiodevice8) | Yes | Audio device list. | | audioDeviceList <sup>10+</sup> | [Array\<AudioDevice\>](#audiodevice10) | Yes | Audio device list. |
| currentAudioDevice <sup>10+</sup> | [AudioDevice](#audiodevice8) | Yes | Audio device type. | | currentAudioDevice <sup>10+</sup> | [AudioDevice](#audiodevice10) | Yes | Audio device type. |
| isMuted <sup>10+</sup> | boolean | Yes | Whether the audio device is muted. | | isMuted <sup>10+</sup> | boolean | Yes | Whether the audio device is muted. |
......
# @ohos.hilog (HiLog) # @ohos.hilog (HiLog)
The **hilog** module allows your applications or services to output logs based on the specified type, level, and format string. Such logs help you learn the running status of applications and better debug programs. The HiLog subsystem allows your applications or services to output logs based on the specified type, level, and format string. Such logs help you learn the running status of applications and better debug programs.
> **NOTE**<br> > **NOTE**
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -23,7 +24,7 @@ Checks whether logs are printable based on the specified service domain, log tag ...@@ -23,7 +24,7 @@ Checks whether logs are printable based on the specified service domain, log tag
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | --------------------- | ---- | ------------------------------------------------------------ | | ------ | --------------------- | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value within your application as required.| | domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**.<br>You can define the value as required.|
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.| | tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| level | [LogLevel](#loglevel) | Yes | Log level. | | level | [LogLevel](#loglevel) | Yes | Log level. |
...@@ -41,11 +42,11 @@ hilog.isLoggable(0x0001, "testTag", hilog.LogLevel.INFO); ...@@ -41,11 +42,11 @@ hilog.isLoggable(0x0001, "testTag", hilog.LogLevel.INFO);
## LogLevel ## LogLevel
Enumerates the log levels. Log level.
**System capability**: SystemCapability.HiviewDFX.HiLog **System capability**: SystemCapability.HiviewDFX.HiLog
| Name | Value| Description | | Name | Value | Description |
| ----- | ------ | ------------------------------------------------------------ | | ----- | ------ | ------------------------------------------------------------ |
| DEBUG | 3 | Log level used to record more detailed process information than INFO logs to help developers analyze service processes and locate faults.| | DEBUG | 3 | Log level used to record more detailed process information than INFO logs to help developers analyze service processes and locate faults.|
| INFO | 4 | Log level used to record key service process nodes and exceptions that occur during service running,<br>for example, no network signal or login failure.<br>These logs should be recorded by the dominant module in the service to avoid repeated logging conducted by multiple invoked modules or low-level functions.| | INFO | 4 | Log level used to record key service process nodes and exceptions that occur during service running,<br>for example, no network signal or login failure.<br>These logs should be recorded by the dominant module in the service to avoid repeated logging conducted by multiple invoked modules or low-level functions.|
...@@ -67,9 +68,9 @@ DEBUG logs are not recorded in official versions by default. They are available ...@@ -67,9 +68,9 @@ DEBUG logs are not recorded in official versions by default. They are available
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value within your application as required.| | domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**.<br>You can define the value as required.|
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.| | tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.| | format | string | Yes | Format string used to output logs in a specified format. It can contain several elements, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **\<private>**.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.| | args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
**Example** **Example**
...@@ -98,9 +99,9 @@ Prints INFO logs. ...@@ -98,9 +99,9 @@ Prints INFO logs.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value within your application as required.| | domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**.<br>You can define the value as required. |
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.| | tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.| | format | string | Yes | Format string used to output logs in a specified format. It can contain several elements, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **\<private>**.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.| | args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
**Example** **Example**
...@@ -129,9 +130,9 @@ Prints WARN logs. ...@@ -129,9 +130,9 @@ Prints WARN logs.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value within your application as required.| | domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**.<br>You can define the value as required. |
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.| | tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.| | format | string | Yes | Format string used to output logs in a specified format. It can contain several elements, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **\<private>**.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.| | args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
**Example** **Example**
...@@ -160,9 +161,9 @@ Prints ERROR logs. ...@@ -160,9 +161,9 @@ Prints ERROR logs.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value within your application as required.| | domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**.<br>You can define the value as required. |
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.| | tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.| | format | string | Yes | Format string used to output logs in a specified format. It can contain several elements, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **\<private>**.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.| | args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
**Example** **Example**
...@@ -191,9 +192,9 @@ Prints FATAL logs. ...@@ -191,9 +192,9 @@ Prints FATAL logs.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value within your application as required.| | domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**.<br>You can define the value as required. |
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.| | tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.| | format | string | Yes | Format string used to output logs in a specified format. It can contain several elements, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **\<private>**.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.| | args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
**Example** **Example**
...@@ -209,3 +210,43 @@ If `"hello"` is filled in `%{public}s` and `3` in `%{private}d`, the output log ...@@ -209,3 +210,43 @@ If `"hello"` is filled in `%{public}s` and `3` in `%{private}d`, the output log
``` ```
08-05 12:21:47.579 2695-2703/com.example.myapplication F 00001/testTag: hello World <private> 08-05 12:21:47.579 2695-2703/com.example.myapplication F 00001/testTag: hello World <private>
``` ```
## Parameter Format
Parameters in the log are printed in the following format:
%[private flag]specifier
| Privacy Flag| Description|
| ------------ | ---- |
| Unspecified | The default value is **private**, indicating that parameters in plaintext are not printed.|
| private | Prints private parameters.|
| public | Prints parameters in plaintext.|
| Specifier| Description| Example|
| ------------ | ---- | ---- |
| d/i | Prints logs of the **number** and **bigint** types.| 123 |
| s | Prints logs of the **string undefined bool** and **null** types.| "123" |
**Example**
```js
let obj2 = new Object({name:"Jack", age:22});
let isBol = true;
let bigNum = BigInt(1234567890123456789);
hilog.info(0x0001, "jsHilogTest", "print object: %{public}s", JSON.stringify(obj2));
hilog.info(0x0001, "jsHilogTest", "private flag: %{private}s %s, print null: %{public}s", "hello", "world", null);
hilog.info(0x0001, "jsHilogTest", "print undefined: %{public}s", undefined);
hilog.info(0x0001, "jsHilogTest", "print number: %{public}d %{public}i", 123, 456);
hilog.info(0x0001, "jsHilogTest", "print bigNum: %{public}d %{public}i", bigNum, bigNum);
hilog.info(0x0001, "jsHilogTest", "print boolean: %{public}s", isBol);
```
Log printing result:
```
08-09 13:26:29.094 2266 2266 I A00001/jsHilogTest: print object: {"name":"Jack","age":22}
08-09 13:26:29.094 2266 2266 I A00001/jsHilogTest: private flag: <private> <private>, print null: null
08-09 13:26:29.094 2266 2266 I A00001/jsHilogTest: print undefined: undefined
08-09 13:26:29.094 2266 2266 I A00001/jsHilogTest: print number: 123 456
08-09 13:26:29.095 2266 2266 I A00001/jsHilogTest: print bigNum: 1234567890123456768 1234567890123456768
08-09 13:26:29.095 2266 2266 I A00001/jsHilogTest: print boolean: true
```
# @ohos.multimodalInput.inputDevice (Input Device) # @ohos.multimodalInput.inputDevice (Input Device)
The **inputDevice** module implements listening for connection, disconnection, and update events of input devices and displays information about input devices. For example, it can be used to listen for mouse insertion and removal and obtain information such as the ID, name, and pointer speed of the mouse. The **inputDevice** module allows you to listen for hot swap events of input devices and query information about input devices.
> **NOTE**<br> > **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -10,6 +11,7 @@ The **inputDevice** module implements listening for connection, disconnection, a ...@@ -10,6 +11,7 @@ The **inputDevice** module implements listening for connection, disconnection, a
```js ```js
import inputDevice from '@ohos.multimodalInput.inputDevice'; import inputDevice from '@ohos.multimodalInput.inputDevice';
``` ```
## inputDevice.getDeviceList<sup>9+</sup> ## inputDevice.getDeviceList<sup>9+</sup>
getDeviceList(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void getDeviceList(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
...@@ -20,25 +22,23 @@ Obtains the IDs of all input devices. This API uses an asynchronous callback to ...@@ -20,25 +22,23 @@ Obtains the IDs of all input devices. This API uses an asynchronous callback to
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------------------- | ---- | ---------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes | Callback used to return the result.| | callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes | Callback used to return the result.|
**Example** **Example**
```js ```js
try { try {
inputDevice.getDeviceIds((error, ids) => { inputDevice.getDeviceList((error, ids) => {
if (error) { if (error) {
console.log(`Failed to get device list. console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
error code=${err.code} msg=${err.message}`);
return; return;
} }
this.data = ids; console.log(`Device id list: ${JSON.stringify(ids)}`);
console.log("The device ID list is: " + ids);
}); });
} catch (error) { } catch (error) {
console.info("getDeviceList " + error.code + " " + error.message); console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -52,19 +52,19 @@ Obtains the IDs of all input devices. This API uses a promise to return the resu ...@@ -52,19 +52,19 @@ Obtains the IDs of all input devices. This API uses a promise to return the resu
**Return value** **Return value**
| Name | Description | | Parameters | Description |
| ---------------------------------- | ------------------------------- | | ---------------------------------- | ------------------------------------------- |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the result.| | Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the result.|
**Example** **Example**
```js ```js
try { try {
inputDevice.getDeviceIds().then((ids) => { inputDevice.getDeviceList().then((ids) => {
console.log("The device ID list is: " + ids); console.log(`Device id list: ${JSON.stringify(ids)}`);
}); });
} catch (error) { } catch (error) {
console.info("getDeviceList " + error.code + " " + error.message); console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -88,16 +88,15 @@ Obtains information about an input device. This API uses an asynchronous callbac ...@@ -88,16 +88,15 @@ Obtains information about an input device. This API uses an asynchronous callbac
```js ```js
// Obtain the name of the device whose ID is 1. // Obtain the name of the device whose ID is 1.
try { try {
inputDevice.getDeviceInfo(1, (error, inputDevice) => { inputDevice.getDeviceInfo(1, (error, deviceData) => {
if (error) { if (error) {
console.log(`Failed to get device information. console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
error code=${err.code} msg=${err.message}`);
return; return;
} }
console.log("The device name is: " + inputDevice.name); console.log(`Device info: ${JSON.stringify(deviceData)}`);
}); });
} catch (error) { } catch (error) {
console.info("getDeviceInfo " + error.code + " " + error.message); console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -117,7 +116,7 @@ Obtains information about an input device. This API uses a promise to return the ...@@ -117,7 +116,7 @@ Obtains information about an input device. This API uses a promise to return the
**Return value** **Return value**
| Name | Description | | Parameters | Description |
| -------------------------------------------------- | ------------------------------- | | -------------------------------------------------- | ------------------------------- |
| Promise&lt;[InputDeviceData](#inputdevicedata)&gt; | Promise used to return the result.| | Promise&lt;[InputDeviceData](#inputdevicedata)&gt; | Promise used to return the result.|
...@@ -126,20 +125,19 @@ Obtains information about an input device. This API uses a promise to return the ...@@ -126,20 +125,19 @@ Obtains information about an input device. This API uses a promise to return the
```js ```js
// Obtain the name of the device whose ID is 1. // Obtain the name of the device whose ID is 1.
try { try {
inputDevice.getDeviceInfo(id).then((inputDevice) => { inputDevice.getDeviceInfo(1).then((deviceData) => {
console.log("The device name is: " + inputDevice.name); console.log(`Device info: ${JSON.stringify(deviceData)}`);
}); });
} catch (error) { } catch (error) {
console.info("getDeviceInfo " + error.code + " " + error.message); console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
## inputDevice.on<sup>9+</sup> ## inputDevice.on<sup>9+</sup>
on(type: "change", listener: Callback&lt;DeviceListener&gt;): void on(type: "change", listener: Callback&lt;DeviceListener&gt;): void
Enables listening for hot swap events of an input device. Enables listening for device hot swap events.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice **System capability**: SystemCapability.MultimodalInput.Input.InputDevice
...@@ -156,13 +154,13 @@ Enables listening for hot swap events of an input device. ...@@ -156,13 +154,13 @@ Enables listening for hot swap events of an input device.
let isPhysicalKeyboardExist = true; let isPhysicalKeyboardExist = true;
try { try {
inputDevice.on("change", (data) => { inputDevice.on("change", (data) => {
console.log("type: " + data.type + ", deviceId: " + data.deviceId); console.log(`Device event info: ${JSON.stringify(data)}`);
inputDevice.getKeyboardType(data.deviceId, (err, ret) => { inputDevice.getKeyboardType(data.deviceId, (err, type) => {
console.log("The keyboard type of the device is: " + ret); console.log("The keyboard type is: " + type);
if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'add') { if (type == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'add') {
// The physical keyboard is connected. // The physical keyboard is connected.
isPhysicalKeyboardExist = true; isPhysicalKeyboardExist = true;
} else if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'remove') { } else if (type == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'remove') {
// The physical keyboard is disconnected. // The physical keyboard is disconnected.
isPhysicalKeyboardExist = false; isPhysicalKeyboardExist = false;
} }
...@@ -170,7 +168,7 @@ try { ...@@ -170,7 +168,7 @@ try {
}); });
// Check whether the soft keyboard is open based on the value of isPhysicalKeyboardExist. // Check whether the soft keyboard is open based on the value of isPhysicalKeyboardExist.
} catch (error) { } catch (error) {
console.info("oninputdevcie " + error.code + " " + error.message); console.log(`Get device info failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -178,7 +176,7 @@ try { ...@@ -178,7 +176,7 @@ try {
off(type: "change", listener?: Callback&lt;DeviceListener&gt;): void off(type: "change", listener?: Callback&lt;DeviceListener&gt;): void
Disables listening for hot swap events of an input device. Disables listening for device hot swap events. This API is called before the application exits.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice **System capability**: SystemCapability.MultimodalInput.Input.InputDevice
...@@ -192,33 +190,29 @@ Disables listening for hot swap events of an input device. ...@@ -192,33 +190,29 @@ Disables listening for hot swap events of an input device.
**Example** **Example**
```js ```js
callback: function(data) { function callback(data) {
console.log("type: " + data.type + ", deviceId: " + data.deviceId); console.log(`Report device event info: ${JSON.stringify(data, [`type`, `deviceId`])}`);
} };
try { try {
inputDevice.on("change", this.callback); inputDevice.on("change", callback);
} catch (error) { } catch (error) {
console.info("oninputdevcie " + error.code + " " + error.message) console.log(`Listen device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
// Enable listening for hot swap events of an input device.
inputDevice.on("change", listener);
// Disable this listener. // Disable this listener.
try { try {
inputDevice.off("change", this.callback); inputDevice.off("change", callback);
} catch (error) { } catch (error) {
console.info("offinputdevcie " + error.code + " " + error.message) console.log(`Cancel listening device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
// Disable all listeners. // Disable all listeners.
try { try {
inputDevice.off("change"); inputDevice.off("change");
} catch (error) { } catch (error) {
console.info("offinputdevcie " + error.code + " " + error.message); console.log(`Cancel all listening device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
// By default, the soft keyboard is closed when listening is disabled.
``` ```
## inputDevice.getDeviceIds<sup>(deprecated)</sup> ## inputDevice.getDeviceIds<sup>(deprecated)</sup>
...@@ -233,9 +227,9 @@ This API is deprecated since API version 9. You are advised to use [inputDevice. ...@@ -233,9 +227,9 @@ This API is deprecated since API version 9. You are advised to use [inputDevice.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------------------- | ---- | ----- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes | Callback used to return the result.| | callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes | Callback used to return the result.|
**Example** **Example**
...@@ -248,7 +242,6 @@ inputDevice.getDeviceIds((error, ids) => { ...@@ -248,7 +242,6 @@ inputDevice.getDeviceIds((error, ids) => {
console.log(`Device id list: ${JSON.stringify(ids)}`); console.log(`Device id list: ${JSON.stringify(ids)}`);
}); });
``` ```
```
## inputDevice.getDeviceIds<sup>(deprecated)</sup> ## inputDevice.getDeviceIds<sup>(deprecated)</sup>
...@@ -262,8 +255,8 @@ This API is deprecated since API version 9. You are advised to use [inputDevice. ...@@ -262,8 +255,8 @@ This API is deprecated since API version 9. You are advised to use [inputDevice.
**Return value** **Return value**
| Parameter | Description | | Parameters | Description |
| ---------------------------------- | ------------------- | | ---------------------------------- | ------------------------------------------- |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the result.| | Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -286,10 +279,10 @@ This API is deprecated since API version 9. You are advised to use [inputDevice. ...@@ -286,10 +279,10 @@ This API is deprecated since API version 9. You are advised to use [inputDevice.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------------------- | ---- | --------------------------- | | -------- | -------------------------------------------------------- | ---- | -------------------------------- |
| deviceId | number | Yes | ID of the input device. | | deviceId | number | Yes | ID of the input device. |
| callback | AsyncCallback&lt;[InputDeviceData](#inputdevicedata)&gt; | Yes | Callback used to return the result, which is an **InputDeviceData** object.| | callback | AsyncCallback&lt;[InputDeviceData](#inputdevicedata)&gt; | Yes | Callback used to return the result, which is an **InputDeviceData** object.|
**Example** **Example**
...@@ -316,14 +309,14 @@ This API is deprecated since API version 9. You are advised to use [inputDevice. ...@@ -316,14 +309,14 @@ This API is deprecated since API version 9. You are advised to use [inputDevice.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------ | | -------- | ------ | ---- | ------------ |
| deviceId | number | Yes | ID of the input device.| | deviceId | number | Yes | ID of the input device.|
**Return value** **Return value**
| Parameter | Description | | Parameters | Description |
| ---------------------------------------- | ------------------- | | -------------------------------------------------- | ----------------------------------- |
| Promise&lt;[InputDeviceData](#inputdevicedata)&gt; | Promise used to return the result.| | Promise&lt;[InputDeviceData](#inputdevicedata)&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -345,22 +338,22 @@ Obtains the key codes supported by the input device. This API uses an asynchrono ...@@ -345,22 +338,22 @@ Obtains the key codes supported by the input device. This API uses an asynchrono
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------ | ---- | --------------------------------- | | -------- | ----------------------------------------- | ---- | ------------------------------------------------------ |
| deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.| | deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
| keys | Array&lt;KeyCode&gt; | Yes | Key codes to be queried. A maximum of five key codes can be specified. | | keys | Array&lt;KeyCode&gt; | Yes | Key codes to be queried. A maximum of five key codes can be specified. |
| callback | AsyncCallback&lt;Array&lt;boolean&gt;&gt; | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;Array&lt;boolean&gt;&gt; | Yes | Callback used to return the result. |
**Example** **Example**
```js ```js
// Check whether the input device whose ID is 1 supports key codes 17, 22, and 2055. // Check whether the input device whose ID is 1 supports key codes 17, 22, and 2055.
try { try {
inputDevice.supportKeys(1, [17, 22, 2055], (error, ret) => { inputDevice.supportKeys(1, [17, 22, 2055], (error, supportResult) => {
console.log("The query result is as follows: " + ret); console.log(`Query result: ${JSON.stringify(supportResult)}`);
}); });
} catch (error) { } catch (error) {
console.info("supportKeys " + error.code + " " + error.message); console.log(`Query failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -374,15 +367,15 @@ Obtains the key codes supported by the input device. This API uses a promise to ...@@ -374,15 +367,15 @@ Obtains the key codes supported by the input device. This API uses a promise to
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | --------------------------------- | | -------- | -------------------- | ---- | ------------------------------------------------------ |
| deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.| | deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
| keys | Array&lt;KeyCode&gt; | Yes | Key codes to be queried. A maximum of five key codes can be specified. | | keys | Array&lt;KeyCode&gt; | Yes | Key codes to be queried. A maximum of five key codes can be specified. |
**Return value** **Return value**
| Parameter | Description | | Parameters | Description |
| ----------------------------------- | ------------------- | | ----------------------------------- | ------------------------------- |
| Promise&lt;Array&lt;boolean&gt;&gt; | Promise used to return the result.| | Promise&lt;Array&lt;boolean&gt;&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -390,11 +383,11 @@ Obtains the key codes supported by the input device. This API uses a promise to ...@@ -390,11 +383,11 @@ Obtains the key codes supported by the input device. This API uses a promise to
```js ```js
// Check whether the input device whose ID is 1 supports key codes 17, 22, and 2055. // Check whether the input device whose ID is 1 supports key codes 17, 22, and 2055.
try { try {
inputDevice.supportKeys(1, [17, 22, 2055]).then((ret) => { inputDevice.supportKeys(1, [17, 22, 2055]).then((supportResult) => {
console.log("The query result is as follows: " + ret); console.log(`Query result: ${JSON.stringify(supportResult)}`);
}); });
} catch (error) { } catch (error) {
console.info("supportKeys " + error.code + " " + error.message); console.log(`Query failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -408,41 +401,46 @@ Obtains the keyboard type of an input device. This API uses an asynchronous call ...@@ -408,41 +401,46 @@ Obtains the keyboard type of an input device. This API uses an asynchronous call
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------------------- | ---- | --------------------------------- | | -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
| deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.| | deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
| callback | AsyncCallback&lt;[KeyboardType](#keyboardtype9)&gt; | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;[KeyboardType](#keyboardtype9)&gt; | Yes | Callback used to return the result. |
**Example** **Example**
```js ```js
// Query the keyboard type of the input device whose ID is 1. // Query the keyboard type of the input device whose ID is 1.
try { try {
inputDevice.getKeyboardType(1, (error, number) => { inputDevice.getKeyboardType(1, (error, type) => {
if (error) { if (error) {
console.log(`Failed to get keyboardtype. console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`);
error code=${err.code} msg=${err.message}`);
return; return;
} }
console.log("The keyboard type of the device is: " + number); console.log(`Keyboard type: ${JSON.stringify(type)}`);
}); });
} catch (error) { } catch (error) {
console.info("getKeyboardType " + error.code + " " + error.message); console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
## inputDevice.getKeyboardType<sup>9+</sup> ## inputDevice.getKeyboardType<sup>9+</sup>
getKeyboardType(deviceId: number,): Promise&lt;KeyboardType&gt; getKeyboardType(deviceId: number): Promise&lt;KeyboardType&gt;
Obtains the keyboard type of an input device. This API uses a promise to return the result. Obtains the keyboard type of an input device. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice **System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
**Return value** **Return value**
| Parameter | Description | | Parameters | Description |
| ---------------------------------------- | ------------------- | | --------------------------------------------- | ------------------------------- |
| Promise&lt;[KeyboardType](#keyboardtype9)&gt; | Promise used to return the result.| | Promise&lt;[KeyboardType](#keyboardtype9)&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -450,11 +448,11 @@ Obtains the keyboard type of an input device. This API uses a promise to return ...@@ -450,11 +448,11 @@ Obtains the keyboard type of an input device. This API uses a promise to return
```js ```js
// Query the keyboard type of the input device whose ID is 1. // Query the keyboard type of the input device whose ID is 1.
try { try {
inputDevice.getKeyboardType(1).then((number) => { inputDevice.getKeyboardType(1).then((type) => {
console.log("The keyboard type of the device is: " + number); console.log(`Keyboard type: ${JSON.stringify(type)}`);
}); });
} catch (error) { } catch (error) {
console.info("getKeyboardType " + error.code + " " + error.message); console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -496,10 +494,10 @@ Defines the axis type of an input device. ...@@ -496,10 +494,10 @@ Defines the axis type of an input device.
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| --------- | ------ | ---- | ---- | ------- | | --------- | ------ | ---- | ---- | ------- |
| touchmajor | string | Yes| No| touchmajor axis. | | touchMajor | string | Yes| No| touchMajor axis. |
| touchminor | string | Yes| No| touchminor axis. | | touchMinor | string | Yes| No| touchMinor axis. |
| toolminor | string | Yes| No| toolminor axis. | | toolMinor | string | Yes| No| toolMinor axis. |
| toolmajor | string | Yes| No| toolmajor axis. | | toolMajor | string | Yes| No| toolMajor axis. |
| orientation | string | Yes| No| Orientation axis.| | orientation | string | Yes| No| Orientation axis.|
| pressure | string | Yes| No| Pressure axis. | | pressure | string | Yes| No| Pressure axis. |
| x | string | Yes| No| X axis. | | x | string | Yes| No| X axis. |
...@@ -524,7 +522,7 @@ Defines the axis range of an input device. ...@@ -524,7 +522,7 @@ Defines the axis range of an input device.
## SourceType<sup>9+</sup> ## SourceType<sup>9+</sup>
Enumerates the input source types. For example, if a mouse reports an x-axis event, the source of the x-axis is the mouse. Input source type of the axis. For example, if a mouse reports an x-axis event, the input source of the x-axis is the mouse.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice **System capability**: SystemCapability.MultimodalInput.Input.InputDevice
......
...@@ -623,7 +623,7 @@ FA model: ...@@ -623,7 +623,7 @@ FA model:
// Obtain the context. // Obtain the context.
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context = featureAbility.getContext();
let serviceType = "_print._tcp";
let discoveryService = mdns.createDiscoveryService(context, serviceType); let discoveryService = mdns.createDiscoveryService(context, serviceType);
discoveryService.startSearchingMDNS(); discoveryService.startSearchingMDNS();
``` ```
...@@ -639,7 +639,7 @@ class EntryAbility extends UIAbility { ...@@ -639,7 +639,7 @@ class EntryAbility extends UIAbility {
} }
} }
let context = globalThis.context; let context = globalThis.context;
let serviceType = "_print._tcp";
let discoveryService = mdns.createDiscoveryService(context, serviceType); let discoveryService = mdns.createDiscoveryService(context, serviceType);
discoveryService.startSearchingMDNS(); discoveryService.startSearchingMDNS();
``` ```
...@@ -660,7 +660,7 @@ FA model: ...@@ -660,7 +660,7 @@ FA model:
// Obtain the context. // Obtain the context.
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context = featureAbility.getContext();
let serviceType = "_print._tcp";
let discoveryService = mdns.createDiscoveryService(context, serviceType); let discoveryService = mdns.createDiscoveryService(context, serviceType);
discoveryService.stopSearchingMDNS(); discoveryService.stopSearchingMDNS();
``` ```
...@@ -676,7 +676,7 @@ class EntryAbility extends UIAbility { ...@@ -676,7 +676,7 @@ class EntryAbility extends UIAbility {
} }
} }
let context = globalThis.context; let context = globalThis.context;
let serviceType = "_print._tcp";
let discoveryService = mdns.createDiscoveryService(context, serviceType); let discoveryService = mdns.createDiscoveryService(context, serviceType);
discoveryService.stopSearchingMDNS(); discoveryService.stopSearchingMDNS();
``` ```
...@@ -700,6 +700,8 @@ Enables listening for **discoveryStart** events. ...@@ -700,6 +700,8 @@ Enables listening for **discoveryStart** events.
```js ```js
// See mdns.createDiscoveryService. // See mdns.createDiscoveryService.
let context = globalThis.context;
let serviceType = "_print._tcp";
let discoveryService = mdns.createDiscoveryService(context, serviceType); let discoveryService = mdns.createDiscoveryService(context, serviceType);
discoveryService.startSearchingMDNS(); discoveryService.startSearchingMDNS();
...@@ -729,6 +731,8 @@ Enables listening for **discoveryStop** events. ...@@ -729,6 +731,8 @@ Enables listening for **discoveryStop** events.
```js ```js
// See mdns.createDiscoveryService. // See mdns.createDiscoveryService.
let context = globalThis.context;
let serviceType = "_print._tcp";
let discoveryService = mdns.createDiscoveryService(context, serviceType); let discoveryService = mdns.createDiscoveryService(context, serviceType);
discoveryService.startSearchingMDNS(); discoveryService.startSearchingMDNS();
...@@ -758,6 +762,8 @@ Enables listening for **serviceFound** events. ...@@ -758,6 +762,8 @@ Enables listening for **serviceFound** events.
```js ```js
// See mdns.createDiscoveryService. // See mdns.createDiscoveryService.
let context = globalThis.context;
let serviceType = "_print._tcp";
let discoveryService = mdns.createDiscoveryService(context, serviceType); let discoveryService = mdns.createDiscoveryService(context, serviceType);
discoveryService.startSearchingMDNS(); discoveryService.startSearchingMDNS();
...@@ -787,6 +793,8 @@ Enables listening for **serviceLost** events. ...@@ -787,6 +793,8 @@ Enables listening for **serviceLost** events.
```js ```js
// See mdns.createDiscoveryService. // See mdns.createDiscoveryService.
let context = globalThis.context;
let serviceType = "_print._tcp";
let discoveryService = mdns.createDiscoveryService(context, serviceType); let discoveryService = mdns.createDiscoveryService(context, serviceType);
discoveryService.startSearchingMDNS(); discoveryService.startSearchingMDNS();
...@@ -805,7 +813,7 @@ Defines the mDNS service information. ...@@ -805,7 +813,7 @@ Defines the mDNS service information.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------------------- | ---------------------------------- | --- | ------------------------ | | --------------------- | ---------------------------------- | --- | ------------------------ |
| serviceType | string | Yes| Type of the mDNS service. The value is in the format of **\_\<name>.\<tcp/udp>**, where **name** contains a maximum of 63 characters excluding periods (.). | | serviceType | string | Yes| Type of the mDNS service. The value is in the format of **\_\<name>.<_tcp/_udp>**, where **name** contains a maximum of 63 characters excluding periods (.). |
| serviceName | string | Yes| Name of the mDNS service. | | serviceName | string | Yes| Name of the mDNS service. |
| port | number | No| Port number of the mDNS server. | | port | number | No| Port number of the mDNS server. |
| host | [NetAddress](js-apis-net-connection.md#netaddress) | No| IP address of the device that provides the mDNS service. The IP address is not effective when an mDNS service is added or removed. | | host | [NetAddress](js-apis-net-connection.md#netaddress) | No| IP address of the device that provides the mDNS service. The IP address is not effective when an mDNS service is added or removed. |
......
...@@ -147,7 +147,7 @@ try { ...@@ -147,7 +147,7 @@ try {
## power.suspend<sup>9+</sup> ## power.suspend<sup>9+</sup>
suspend(): void suspend(isImmediate?: boolean): void
Hibernates a device. Hibernates a device.
...@@ -155,6 +155,13 @@ Hibernates a device. ...@@ -155,6 +155,13 @@ Hibernates a device.
**System capability:** SystemCapability.PowerManager.PowerManager.Core **System capability:** SystemCapability.PowerManager.PowerManager.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ---------- |
| isImmediate<sup>10+</sup> | boolean | No | Whether to hibernate a device immediately. If this parameter is not specified, the default value **false** is used. The system automatically determines when to enter the hibernation state.<br>**NOTE**: This parameter is supported since API version 10.|
**Error codes** **Error codes**
For details about the error codes, see [Power Manager Error Codes](../errorcodes/errorcode-power.md). For details about the error codes, see [Power Manager Error Codes](../errorcodes/errorcode-power.md).
......
...@@ -15,7 +15,7 @@ import shortKey from '@ohos.multimodalInput.shortKey'; ...@@ -15,7 +15,7 @@ import shortKey from '@ohos.multimodalInput.shortKey';
## shortKey.setKeyDownDuration ## shortKey.setKeyDownDuration
setKeyDownDuration(businessId: string, delay: number, callback: AsyncCallback&lt;void&gt;): void setKeyDownDuration(businessKey: string, delay: number, callback: AsyncCallback&lt;void&gt;): void
Sets the delay for starting an ability using the shortcut key. This API uses an asynchronous callback to return the result. Sets the delay for starting an ability using the shortcut key. This API uses an asynchronous callback to return the result.
...@@ -25,7 +25,7 @@ Sets the delay for starting an ability using the shortcut key. This API uses an ...@@ -25,7 +25,7 @@ Sets the delay for starting an ability using the shortcut key. This API uses an
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ---------- | ------------------- | ---- | ------------------------------------------------------------ | | ---------- | ------------------- | ---- | ------------------------------------------------------------ |
| businessId | string | Yes | Unique service ID registered on the multimodal side. It corresponds to **businessId** in the **ability_launch_config.json** file.| | businessKey| string | Yes | Unique service ID registered on the multimodal side. It corresponds to **businessId** in the **ability_launch_config.json** file.|
| delay | number | Yes | Delay for starting an ability using the shortcut key, in ms.| | delay | number | Yes | Delay for starting an ability using the shortcut key, in ms.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
...@@ -49,7 +49,7 @@ try { ...@@ -49,7 +49,7 @@ try {
## shortKey.setKeyDownDuration ## shortKey.setKeyDownDuration
setKeyDownDuration(businessId: string, delay: number): Promise&lt;void&gt; setKeyDownDuration(businessKey: string, delay: number): Promise&lt;void&gt;
Sets the delay for starting an ability using the shortcut key. This API uses a promise to return the result. Sets the delay for starting an ability using the shortcut key. This API uses a promise to return the result.
...@@ -59,7 +59,7 @@ Sets the delay for starting an ability using the shortcut key. This API uses a p ...@@ -59,7 +59,7 @@ Sets the delay for starting an ability using the shortcut key. This API uses a p
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | ------------------------------------------------------------ | | ---------- | ------ | ---- | ------------------------------------------------------------ |
| businessId | string | Yes | Unique service ID registered on the multimodal side. It corresponds to **businessId** in the **ability_launch_config.json** file.| | businessKey| string | Yes | Unique service ID registered on the multimodal side. It corresponds to **businessId** in the **ability_launch_config.json** file.|
| delay | number | Yes | Delay for starting an ability using the shortcut key, in ms.| | delay | number | Yes | Delay for starting an ability using the shortcut key, in ms.|
**Return value** **Return value**
......
...@@ -479,12 +479,12 @@ Enables listening for message receiving events of the UDPSocket connection. This ...@@ -479,12 +479,12 @@ Enables listening for message receiving events of the UDPSocket connection. This
```js ```js
let udp = socket.constructUDPSocketInstance(); let udp = socket.constructUDPSocketInstance();
let messageView = '';
udp.on('message', value => { udp.on('message', value => {
for (var i = 0; i < value.message.length; i++) { for (var i = 0; i < value.message.length; i++) {
let messages = value.message[i] let messages = value.message[i]
let message = String.fromCharCode(messages); let message = String.fromCharCode(messages);
let messageView = ''; messageView += message;
messageView += item;
} }
console.log('on message message: ' + JSON.stringify(messageView)); console.log('on message message: ' + JSON.stringify(messageView));
console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo)); console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo));
...@@ -513,12 +513,12 @@ Disables listening for message receiving events of the UDPSocket connection. Thi ...@@ -513,12 +513,12 @@ Disables listening for message receiving events of the UDPSocket connection. Thi
```js ```js
let udp = socket.constructUDPSocketInstance(); let udp = socket.constructUDPSocketInstance();
let messageView = '';
let callback = value => { let callback = value => {
for (var i = 0; i < value.message.length; i++) { for (var i = 0; i < value.message.length; i++) {
let messages = value.message[i] let messages = value.message[i]
let message = String.fromCharCode(messages); let message = String.fromCharCode(messages);
let messageView = ''; messageView += message;
messageView += item;
} }
console.log('on message message: ' + JSON.stringify(messageView)); console.log('on message message: ' + JSON.stringify(messageView));
console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo)); console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo));
...@@ -541,7 +541,7 @@ Enables listening for data packet message events or close events of the UDPSocke ...@@ -541,7 +541,7 @@ Enables listening for data packet message events or close events of the UDPSocke
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------- | ---- | ------------------------------------------------------------ | | -------- | ---------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Type of the event to subscribe to.<br /><br>- **listening**: data packet message event<br>- **close**: close event| | type | string | Yes | Type of the event to subscribe to.<br>- **listening**: data packet message event<br>- **close**: close event|
| callback | Callback\<void\> | Yes | Callback used to return the result. | | callback | Callback\<void\> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -1365,12 +1365,12 @@ Enables listening for message receiving events of the TCPSocket connection. This ...@@ -1365,12 +1365,12 @@ Enables listening for message receiving events of the TCPSocket connection. This
```js ```js
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let messageView = '';
tcp.on('message', value => { tcp.on('message', value => {
for (var i = 0; i < value.message.length; i++) { for (var i = 0; i < value.message.length; i++) {
let messages = value.message[i] let messages = value.message[i]
let message = String.fromCharCode(messages); let message = String.fromCharCode(messages);
let messageView = ''; messageView += message;
messageView += item;
} }
console.log('on message message: ' + JSON.stringify(messageView)); console.log('on message message: ' + JSON.stringify(messageView));
console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo)); console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo));
...@@ -1399,12 +1399,12 @@ Disables listening for message receiving events of the TCPSocket connection. Thi ...@@ -1399,12 +1399,12 @@ Disables listening for message receiving events of the TCPSocket connection. Thi
```js ```js
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
let messageView = '';
let callback = value => { let callback = value => {
for (var i = 0; i < value.message.length; i++) { for (var i = 0; i < value.message.length; i++) {
let messages = value.message[i] let messages = value.message[i]
let message = String.fromCharCode(messages); let message = String.fromCharCode(messages);
let messageView = ''; messageView += message;
messageView += item;
} }
console.log('on message message: ' + JSON.stringify(messageView)); console.log('on message message: ' + JSON.stringify(messageView));
console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo)); console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo));
...@@ -1427,7 +1427,7 @@ Enables listening for connection or close events of the TCPSocket connection. Th ...@@ -1427,7 +1427,7 @@ Enables listening for connection or close events of the TCPSocket connection. Th
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------- | ---- | ------------------------------------------------------------ | | -------- | ---------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Type of the event to subscribe to.<br /><br>- **connect**: connection event<br>- **close**: close event| | type | string | Yes | Type of the event to subscribe to.<br>- **connect**: connection event<br>- **close**: close event|
| callback | Callback\<void\> | Yes | Callback used to return the result. | | callback | Callback\<void\> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -1457,7 +1457,7 @@ Disables listening for connection or close events of the TCPSocket connection. T ...@@ -1457,7 +1457,7 @@ Disables listening for connection or close events of the TCPSocket connection. T
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------- | ---- | ------------------------------------------------------------ | | -------- | ---------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Type of the event to subscribe to.<br /><br>- **connect**: connection event<br>- **close**: close event| | type | string | Yes | Type of the event to subscribe to.<br>- **connect**: connection event<br>- **close**: close event|
| callback | Callback\<void\> | No | Callback used to return the result. | | callback | Callback\<void\> | No | Callback used to return the result. |
**Example** **Example**
...@@ -1766,7 +1766,7 @@ promise.then(() => { ...@@ -1766,7 +1766,7 @@ promise.then(() => {
setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\<void\>): void setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\<void\>): void
Sets other properties of the TCPSocket connection after successful binding of the local IP address and port number of the TLSSocket connection. This API uses an asynchronous callback to return the result. Sets other properties of the TCPSocket connection after successful binding of the local IP address and port number of the connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -1818,7 +1818,7 @@ tls.setExtraOptions({ ...@@ -1818,7 +1818,7 @@ tls.setExtraOptions({
setExtraOptions(options: TCPExtraOptions): Promise\<void\> setExtraOptions(options: TCPExtraOptions): Promise\<void\>
Sets other properties of the TCPSocket connection after successful binding of the local IP address and port number of the TLSSocket connection. This API uses a promise to return the result. Sets other properties of the TCPSocket connection after successful binding of the local IP address and port number of the connection. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -1881,19 +1881,19 @@ Subscribes to **message** events of the TLSSocket connection. This API uses an a ...@@ -1881,19 +1881,19 @@ Subscribes to **message** events of the TLSSocket connection. This API uses an a
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------- | | -------- | ------------------------------------------------------------ | ---- | ----------------------------------------- |
| type | string | Yes | Type of the event to subscribe to.<br /> **message**: message receiving event| | type | string | Yes | Type of the event to subscribe to. **message**: message receiving event|
| callback | Callback\<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo)}\> | Yes | Callback used to return the result.<br> **message**: received message.<br>**remoteInfo**: socket connection information.| | callback | Callback\<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo)}\> | Yes | Callback used to return the result.<br> **message**: received message.<br>**remoteInfo**: socket connection information.|
**Example** **Example**
```js ```js
let tls = socket.constructTLSSocketInstance(); let tls = socket.constructTLSSocketInstance();
let messageView = '';
tls.on('message', value => { tls.on('message', value => {
for (var i = 0; i < value.message.length; i++) { for (var i = 0; i < value.message.length; i++) {
let messages = value.message[i] let messages = value.message[i]
let message = String.fromCharCode(messages); let message = String.fromCharCode(messages);
let messageView = ''; messageView += message;
messageView += item;
} }
console.log('on message message: ' + JSON.stringify(messageView)); console.log('on message message: ' + JSON.stringify(messageView));
console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo)); console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo));
...@@ -1915,19 +1915,19 @@ Unsubscribes from **message** events of the TLSSocket connection. This API uses ...@@ -1915,19 +1915,19 @@ Unsubscribes from **message** events of the TLSSocket connection. This API uses
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------- | | -------- | ------------------------------------------------------------ | ---- | ----------------------------------------- |
| type | string | Yes | Type of the event to subscribe to.<br /> **message**: message receiving event| | type | string | Yes | Type of the event to subscribe to. **message**: message receiving event|
| callback | Callback<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo)}> | No | Callback used to return the result. **message**: received message.<br>**remoteInfo**: socket connection information.| | callback | Callback<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo)}> | No | Callback used to return the result. **message**: received message.<br>**remoteInfo**: socket connection information.|
**Example** **Example**
```js ```js
let tls = socket.constructTLSSocketInstance(); let tls = socket.constructTLSSocketInstance();
let messageView = '';
let callback = value => { let callback = value => {
for (var i = 0; i < value.message.length; i++) { for (var i = 0; i < value.message.length; i++) {
let messages = value.message[i] let messages = value.message[i]
let message = String.fromCharCode(messages); let message = String.fromCharCode(messages);
let messageView = ''; messageView += message;
messageView += item;
} }
console.log('on message message: ' + JSON.stringify(messageView)); console.log('on message message: ' + JSON.stringify(messageView));
console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo)); console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo));
...@@ -1948,7 +1948,7 @@ Enables listening for connection or close events of the TLSSocket connection. Th ...@@ -1948,7 +1948,7 @@ Enables listening for connection or close events of the TLSSocket connection. Th
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------- | ---- | ------------------------------------------------------------ | | -------- | ---------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Type of the event to subscribe to.<br /><br>- **connect**: connection event<br>- **close**: close event| | type | string | Yes | Type of the event to subscribe to.<br>- **connect**: connection event<br>- **close**: close event|
| callback | Callback\<void\> | Yes | Callback used to return the result. | | callback | Callback\<void\> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -1978,7 +1978,7 @@ Disables listening for connection or close events of the TLSSocket connection. T ...@@ -1978,7 +1978,7 @@ Disables listening for connection or close events of the TLSSocket connection. T
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------- | ---- | ------------------------------------------------------------ | | -------- | ---------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Type of the event to subscribe to.<br /><br>- **connect**: connection event<br>- **close**: close event| | type | string | Yes | Type of the event to subscribe to.<br>- **connect**: connection event<br>- **close**: close event|
| callback | Callback\<void\> | No | Callback used to return the result. | | callback | Callback\<void\> | No | Callback used to return the result. |
**Example** **Example**
......
...@@ -152,7 +152,7 @@ Checks whether the user, for example, the application or system, has the device ...@@ -152,7 +152,7 @@ Checks whether the user, for example, the application or system, has the device
**Example** **Example**
```js ```js
let devicesName="1-1"; let devicesName = "1-1";
let bool = usb.hasRight(devicesName); let bool = usb.hasRight(devicesName);
console.log(`${bool}`); console.log(`${bool}`);
``` ```
...@@ -180,7 +180,7 @@ Requests the temporary permission for the application to access a USB device. Th ...@@ -180,7 +180,7 @@ Requests the temporary permission for the application to access a USB device. Th
**Example** **Example**
```js ```js
let devicesName="1-1"; let devicesName = "1-1";
usb.requestRight(devicesName).then((ret) => { usb.requestRight(devicesName).then((ret) => {
console.log(`requestRight = ${ret}`); console.log(`requestRight = ${ret}`);
}); });
...@@ -209,7 +209,7 @@ Removes the permission for the application to access a USB device. ...@@ -209,7 +209,7 @@ Removes the permission for the application to access a USB device.
**Example** **Example**
```js ```js
let devicesName= "1-1"; let devicesName = "1-1";
if (usb.removeRight(devicesName)) { if (usb.removeRight(devicesName)) {
console.log(`Succeed in removing right`); console.log(`Succeed in removing right`);
} }
...@@ -277,6 +277,16 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi ...@@ -277,6 +277,16 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**Example** **Example**
```js ```js
let devicesList = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
return;
}
let device = devicesList[0];
usb.requestRight(device.name);
let devicepipe = usb.connectDevice(device);
let interfaces = device.configs[0].interfaces[0];
let ret = usb.claimInterface(devicepipe, interfaces); let ret = usb.claimInterface(devicepipe, interfaces);
console.log(`claimInterface = ${ret}`); console.log(`claimInterface = ${ret}`);
``` ```
...@@ -307,7 +317,18 @@ Before you do this, ensure that you have claimed the interface by calling [usb.c ...@@ -307,7 +317,18 @@ Before you do this, ensure that you have claimed the interface by calling [usb.c
**Example** **Example**
```js ```js
let ret = usb.releaseInterface(devicepipe, interfaces); let devicesList = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
return;
}
let device = devicesList[0];
usb.requestRight(device.name);
let devicepipe = usb.connectDevice(device);
let interfaces = device.configs[0].interfaces[0];
let ret = usb.claimInterface(devicepipe, interfaces);
ret = usb.releaseInterface(devicepipe, interfaces);
console.log(`releaseInterface = ${ret}`); console.log(`releaseInterface = ${ret}`);
``` ```
...@@ -337,6 +358,16 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi ...@@ -337,6 +358,16 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**Example** **Example**
```js ```js
let devicesList = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
return;
}
let device = devicesList[0];
usb.requestRight(device.name);
let devicepipe = usb.connectDevice(device);
let config = device.configs[0];
let ret = usb.setConfiguration(devicepipe, config); let ret = usb.setConfiguration(devicepipe, config);
console.log(`setConfiguration = ${ret}`); console.log(`setConfiguration = ${ret}`);
``` ```
...@@ -367,7 +398,18 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi ...@@ -367,7 +398,18 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**Example** **Example**
```js ```js
let ret = usb.setInterface(devicepipe, interfaces); let devicesList = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
return;
}
let device = devicesList[0];
usb.requestRight(device.name);
let devicepipe = usb.connectDevice(device);
let interfaces = device.configs[0].interfaces[0];
let ret = usb.claimInterface(devicepipe, interfaces);
ret = usb.setInterface(devicepipe, interfaces);
console.log(`setInterface = ${ret}`); console.log(`setInterface = ${ret}`);
``` ```
...@@ -396,6 +438,14 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi ...@@ -396,6 +438,14 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**Example** **Example**
```js ```js
let devicesList = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
return;
}
usb.requestRight(devicesList[0].name);
let devicepipe = usb.connectDevice(devicesList[0]);
let ret = usb.getRawDescriptor(devicepipe); let ret = usb.getRawDescriptor(devicepipe);
``` ```
...@@ -424,6 +474,14 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi ...@@ -424,6 +474,14 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**Example** **Example**
```js ```js
let devicesList = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
return;
}
usb.requestRight(devicesList[0].name);
let devicepipe = usb.connectDevice(devicesList[0]);
let ret = usb.getFileDescriptor(devicepipe); let ret = usb.getFileDescriptor(devicepipe);
``` ```
...@@ -462,6 +520,15 @@ let param = { ...@@ -462,6 +520,15 @@ let param = {
index: 0, index: 0,
data: null data: null
}; };
let devicesList = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
return;
}
usb.requestRight(devicesList[0].name);
let devicepipe = usb.connectDevice(devicesList[0]);
usb.controlTransfer(devicepipe, param).then((ret) => { usb.controlTransfer(devicepipe, param).then((ret) => {
console.log(`controlTransfer = ${ret}`); console.log(`controlTransfer = ${ret}`);
}) })
...@@ -498,8 +565,22 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi ...@@ -498,8 +565,22 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
// Call usb.getDevices to obtain a data set. Then, obtain a USB device and its access permission. // Call usb.getDevices to obtain a data set. Then, obtain a USB device and its access permission.
// Pass the obtained USB device as a parameter to usb.connectDevice. Then, call usb.connectDevice to connect the USB device. // Pass the obtained USB device as a parameter to usb.connectDevice. Then, call usb.connectDevice to connect the USB device.
// Call usb.claimInterface to claim the USB interface. After that, call usb.bulkTransfer to start bulk transfer. // Call usb.claimInterface to claim the USB interface. After that, call usb.bulkTransfer to start bulk transfer.
let devicesList = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
return;
}
let device = devicesList[0];
usb.requestRight(device.name);
let devicepipe = usb.connectDevice(device);
let interfaces = device.configs[0].interfaces[0];
let endpoint = device.configs[0].interfaces[0].endpoints[0];
let ret = usb.claimInterface(devicepipe, interfaces);
let buffer = new Uint8Array(128);
usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret) => { usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret) => {
console.log(`bulkTransfer = ${ret}`); console.log(`bulkTransfer = ${ret}`);
}); });
``` ```
...@@ -528,6 +609,14 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi ...@@ -528,6 +609,14 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**Example** **Example**
```js ```js
let devicesList = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
return;
}
usb.requestRight(devicesList[0].name);
let devicepipe = usb.connectDevice(devicesList[0]);
let ret = usb.closePipe(devicepipe); let ret = usb.closePipe(devicepipe);
console.log(`closePipe = ${ret}`); console.log(`closePipe = ${ret}`);
``` ```
......
...@@ -182,11 +182,11 @@ This error code is reported if an error occurs while writing received data to th ...@@ -182,11 +182,11 @@ This error code is reported if an error occurs while writing received data to th
**Cause** **Cause**
The application does not have the data write permission. The application does not have the permission to write files or the file to be downloaded exceeds 5 MB.
**Solution** **Solution**
Check the permissions granted to the application. Check the application permission and the size of the file to be downloaded.
## 2300025 Failed to Upload Data ## 2300025 Failed to Upload Data
......
...@@ -7,125 +7,146 @@ Provides APIs related to MindSpore Lite model inference. ...@@ -7,125 +7,146 @@ Provides APIs related to MindSpore Lite model inference.
\@Syscap SystemCapability.Ai.MindSpore \@Syscap SystemCapability.Ai.MindSpore
**Since:** **Since**
9 9
## Summary ## Summary
### Files ### File
| Name | Description | | Name | Description |
| -------- | -------- | | ------------------------------- | ------------------------------------------------------------ |
| [context.h](context_8h.md) | Provides **Context** APIs for configuring runtime information. <br>File to Include: <mindspore/context.h> | | [context.h](context_8h.md) | Provides **Context** APIs for configuring runtime information.<br>File to include: \<mindspore/context.h>|
| [data_type.h](data__type_8h.md) | Declares tensor data types. <br>File to Include: <mindspore/data_type.h> | | [data_type.h](data__type_8h.md) | Declares tensor data types.<br>File to include: \<mindspore/data_type.h>|
| [format.h](format_8h.md) | Declares tensor data formats. <br>File to Include: <mindspore/format.h> | | [format.h](format_8h.md) | Declares tensor data formats.<br>File to include: \<mindspore/format.h> |
| [model.h](model_8h.md) | Provides model-related APIs for model creation and inference. <br>File to Include: <mindspore/model.h> | | [model.h](model_8h.md) | Provides model-related APIs for model creation and inference.<br>File to include: \<mindspore/model.h>|
| [status.h](status_8h.md) | Provides the status codes of MindSpore Lite. <br>File to Include: <mindspore/status.h> | | [status.h](status_8h.md) | Provides the status codes of MindSpore Lite.<br>File to include: \<mindspore/status.h>|
| [tensor.h](tensor_8h.md) | Provides APIs for creating and modifying tensor information. <br>File to Include: <mindspore/tensor.h> | | [tensor.h](tensor_8h.md) | Provides APIs for creating and modifying tensor information.<br>File to include: \<mindspore/tensor.h>|
| [types.h](types_8h.md) | Provides the model file types and device types supported by MindSpore Lite. <br>File to Include: <mindspore/types.h> | | [types.h](types_8h.md) | Provides the model file types and device types supported by MindSpore Lite.<br>File to include: \<mindspore/types.h>|
### Structs ### Structs
| Name | Description | | Name | Description |
| -------- | -------- | | ------------------------------------------------------------ | ---------------------------------------------------- |
| [OH_AI_TensorHandleArray](_o_h___a_i___tensor_handle_array.md) | Defines the tensor array structure, which is used to store the tensor array pointer and tensor array length. | | [OH_AI_TensorHandleArray](_o_h___a_i___tensor_handle_array.md) | Defines the tensor array structure, which is used to store the tensor array pointer and tensor array length.|
| [OH_AI_ShapeInfo](_o_h___a_i___shape_info.md) | Defines dimension information. The maximum dimension is set by **MS_MAX_SHAPE_NUM**. | | [OH_AI_ShapeInfo](_o_h___a_i___shape_info.md) | Defines dimension information. The maximum dimension is set by **MS_MAX_SHAPE_NUM**. |
| [OH_AI_CallBackParam](_o_h___a_i___call_back_param.md) | Defines the operator information passed in a callback. | | [OH_AI_CallBackParam](_o_h___a_i___call_back_param.md) | Defines the operator information passed in a callback. |
### Macros ### Macro Definition
| Name | Description |
| -------- | -------- |
| [OH_AI_MAX_SHAPE_NUM](#oh_ai_max_shape_num) 32 | Defines dimension information. The maximum dimension is set by **MS_MAX_SHAPE_NUM**. |
| Name | Description |
| ------------------------------------------------ | -------------------------------------------- |
| [OH_AI_MAX_SHAPE_NUM](#oh_ai_max_shape_num) 32 | Defines dimension information. The maximum dimension is set by **MS_MAX_SHAPE_NUM**.|
### Types ### Types
| Name | Description | | Name | Description |
| -------- | -------- | | ------------------------------------------------------------ | -------------------------------------------------- |
| [OH_AI_ContextHandle](#oh_ai_contexthandle) | Defines the pointer to the MindSpore context. | | [OH_AI_ContextHandle](#oh_ai_contexthandle) | Defines the pointer to the MindSpore context. |
| [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) | Defines the pointer to the MindSpore device information. | | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) | Defines the pointer to the MindSpore device information. |
| [OH_AI_DataType](#oh_ai_datatype) | Declares data types supported by MSTensor. | | [OH_AI_DataType](#oh_ai_datatype) | Declares data types supported by MSTensor. |
| [OH_AI_Format](#oh_ai_format) | Declares data formats supported by MSTensor. | | [OH_AI_Format](#oh_ai_format) | Declares data formats supported by MSTensor. |
| [OH_AI_ModelHandle](#oh_ai_modelhandle) | Defines the pointer to a model object. | | [OH_AI_ModelHandle](#oh_ai_modelhandle) | Defines the pointer to a model object. |
| [OH_AI_TensorHandleArray](#oh_ai_tensorhandlearray) | Defines the tensor array structure, which is used to store the tensor array pointer and tensor array length. | | [OH_AI_TensorHandleArray](#oh_ai_tensorhandlearray) | Defines the tensor array structure, which is used to store the tensor array pointer and tensor array length.|
| **OH_AI_ShapeInfo** | Defines dimension information. The maximum dimension is set by **MS_MAX_SHAPE_NUM**. | | [OH_AI_ShapeInfo](_o_h___a_i___shape_info.md) | Defines dimension information. The maximum dimension is set by **MS_MAX_SHAPE_NUM**. |
| [OH_AI_CallBackParam](#oh_ai_callbackparam) | Defines the operator information passed in a callback. | | [OH_AI_CallBackParam](#oh_ai_callbackparam) | Defines the operator information passed in a callback. |
| [OH_AI_KernelCallBack](#oh_ai_kernelcallback)) (const [OH_AI_TensorHandleArray](_o_h___a_i___tensor_handle_array.md) inputs, const [OH_AI_TensorHandleArray](_o_h___a_i___tensor_handle_array.md) outputs, const [OH_AI_CallBackParam](_o_h___a_i___call_back_param.md) kernel_Info) | Defines the pointer to a callback. | | [OH_AI_KernelCallBack](#oh_ai_kernelcallback) | Defines the pointer to a callback. |
| [OH_AI_Status](#oh_ai_status) | Defines MindSpore status codes. | | [OH_AI_Status](#oh_ai_status) | Defines MindSpore status codes. |
| [OH_AI_TensorHandle](#oh_ai_tensorhandle) | Defines the handle of a tensor object. | | [OH_AI_TensorHandle](#oh_ai_tensorhandle) | Defines the handle of a tensor object. |
| [OH_AI_ModelType](#oh_ai_modeltype) | Defines model file types. | | [OH_AI_ModelType](#oh_ai_modeltype) | Defines model file types. |
| [OH_AI_DeviceType](#oh_ai_devicetype) | Defines the supported device types. | | [OH_AI_DeviceType](#oh_ai_devicetype) | Defines the supported device types. |
| [OH_AI_NNRTDeviceType](#oh_ai_nnrtdevicetype) | Defines NNRt device types. |
| [OH_AI_PerformanceMode](#oh_ai_performancemode) | Defines performance modes of the NNRt device. |
| [OH_AI_Priority](#oh_ai_priority) | Defines NNRt inference task priorities. |
| [NNRTDeviceDesc](#nnrtdevicedesc) | Defines the NNRt device information, including the device ID and device name. |
### Enums ### Enums
| Name | Description | | Name | Description |
| -------- | -------- | | ------------------------------------------------------------ | ---------------------------------------- |
| [OH_AI_DataType](#oh_ai_datatype) {<br/>OH_AI_DATATYPE_UNKNOWN = 0, OH_AI_DATATYPE_OBJECTTYPE_STRING = 12, OH_AI_DATATYPE_OBJECTTYPE_LIST = 13, OH_AI_DATATYPE_OBJECTTYPE_TUPLE = 14,<br/>OH_AI_DATATYPE_OBJECTTYPE_TENSOR = 17, OH_AI_DATATYPE_NUMBERTYPE_BEGIN = 29, OH_AI_DATATYPE_NUMBERTYPE_BOOL = 30, OH_AI_DATATYPE_NUMBERTYPE_INT8 = 32,<br/>OH_AI_DATATYPE_NUMBERTYPE_INT16 = 33, OH_AI_DATATYPE_NUMBERTYPE_INT32 = 34, OH_AI_DATATYPE_NUMBERTYPE_INT64 = 35, OH_AI_DATATYPE_NUMBERTYPE_UINT8 = 37,<br/>OH_AI_DATATYPE_NUMBERTYPE_UINT16 = 38, OH_AI_DATATYPE_NUMBERTYPE_UINT32 = 39, OH_AI_DATATYPE_NUMBERTYPE_UINT64 = 40, OH_AI_DATATYPE_NUMBERTYPE_FLOAT16 = 42,<br/>OH_AI_DATATYPE_NUMBERTYPE_FLOAT32 = 43, OH_AI_DATATYPE_NUMBERTYPE_FLOAT64 = 44, OH_AI_DATATYPE_NUMBERTYPE_END = 46, OH_AI_DataTypeInvalid = INT32_MAX<br/>} | Declares data types supported by MSTensor. | | [OH_AI_DataType](#oh_ai_datatype-1) {<br>OH_AI_DATATYPE_UNKNOWN = 0, <br>OH_AI_DATATYPE_OBJECTTYPE_STRING = 12, <br>OH_AI_DATATYPE_OBJECTTYPE_LIST = 13, <br>OH_AI_DATATYPE_OBJECTTYPE_TUPLE = 14,<br>OH_AI_DATATYPE_OBJECTTYPE_TENSOR = 17, <br>OH_AI_DATATYPE_NUMBERTYPE_BEGIN = 29,<br> OH_AI_DATATYPE_NUMBERTYPE_BOOL = 30,<br> OH_AI_DATATYPE_NUMBERTYPE_INT8 = 32,<br>OH_AI_DATATYPE_NUMBERTYPE_INT16 = 33, <br>OH_AI_DATATYPE_NUMBERTYPE_INT32 = 34, <br>OH_AI_DATATYPE_NUMBERTYPE_INT64 = 35, <br>OH_AI_DATATYPE_NUMBERTYPE_UINT8 = 37,<br>OH_AI_DATATYPE_NUMBERTYPE_UINT16 = 38, <br>OH_AI_DATATYPE_NUMBERTYPE_UINT32 = 39,<br> OH_AI_DATATYPE_NUMBERTYPE_UINT64 = 40, <br>OH_AI_DATATYPE_NUMBERTYPE_FLOAT16 = 42,<br>OH_AI_DATATYPE_NUMBERTYPE_FLOAT32 = 43, <br>OH_AI_DATATYPE_NUMBERTYPE_FLOAT64 = 44, <br>OH_AI_DATATYPE_NUMBERTYPE_END = 46,<br> OH_AI_DataTypeInvalid = INT32_MAX<br>} | Declares data types supported by MSTensor. |
| [OH_AI_Format](#oh_ai_format) {<br/>OH_AI_FORMAT_NCHW = 0, OH_AI_FORMAT_NHWC = 1, OH_AI_FORMAT_NHWC4 = 2, OH_AI_FORMAT_HWKC = 3,<br/>OH_AI_FORMAT_HWCK = 4, OH_AI_FORMAT_KCHW = 5, OH_AI_FORMAT_CKHW = 6, OH_AI_FORMAT_KHWC = 7,<br/>OH_AI_FORMAT_CHWK = 8, OH_AI_FORMAT_HW = 9, OH_AI_FORMAT_HW4 = 10, OH_AI_FORMAT_NC = 11,<br/>OH_AI_FORMAT_NC4 = 12, OH_AI_FORMAT_NC4HW4 = 13, OH_AI_FORMAT_NCDHW = 15, OH_AI_FORMAT_NWC = 16,<br/>OH_AI_FORMAT_NCW = 17<br/>} | Declares data formats supported by MSTensor. | | [OH_AI_Format](#oh_ai_format-1) {<br>OH_AI_FORMAT_NCHW = 0,<br> OH_AI_FORMAT_NHWC = 1, <br>OH_AI_FORMAT_NHWC4 = 2, <br>OH_AI_FORMAT_HWKC = 3,<br>OH_AI_FORMAT_HWCK = 4, <br>OH_AI_FORMAT_KCHW = 5, <br>OH_AI_FORMAT_CKHW = 6,<br> OH_AI_FORMAT_KHWC = 7,<br>OH_AI_FORMAT_CHWK = 8,<br> OH_AI_FORMAT_HW = 9, <br>OH_AI_FORMAT_HW4 = 10,<br> OH_AI_FORMAT_NC = 11,<br>OH_AI_FORMAT_NC4 = 12, <br>OH_AI_FORMAT_NC4HW4 = 13, <br>OH_AI_FORMAT_NCDHW = 15,<br> OH_AI_FORMAT_NWC = 16,<br>OH_AI_FORMAT_NCW = 17<br>} | Declares data formats supported by MSTensor. |
| [OH_AI_CompCode](#oh_ai_compcode) { OH_AI_COMPCODE_CORE = 0x00000000u, OH_AI_COMPCODE_LITE = 0xF0000000u } | Defines MinSpore component codes. | | [OH_AI_CompCode](#oh_ai_compcode) { <br>OH_AI_COMPCODE_CORE = 0x00000000u, <br>OH_AI_COMPCODE_LITE = 0xF0000000u<br> } | Defines MindSpore component codes. |
| [OH_AI_Status](#oh_ai_status) {<br/>OH_AI_STATUS_SUCCESS = 0, OH_AI_STATUS_CORE_FAILED = OH_AI_COMPCODE_CORE \| 0x1, OH_AI_STATUS_LITE_ERROR = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -1), OH_AI_STATUS_LITE_NULLPTR = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -2),<br/>OH_AI_STATUS_LITE_PARAM_INVALID = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -3), OH_AI_STATUS_LITE_NO_CHANGE = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -4), OH_AI_STATUS_LITE_SUCCESS_EXIT = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -5), OH_AI_STATUS_LITE_MEMORY_FAILED = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -6),<br/>OH_AI_STATUS_LITE_NOT_SUPPORT = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -7), OH_AI_STATUS_LITE_THREADPOOL_ERROR = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -8), OH_AI_STATUS_LITE_UNINITIALIZED_OBJ = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -9), OH_AI_STATUS_LITE_OUT_OF_TENSOR_RANGE = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -100),<br/>OH_AI_STATUS_LITE_INPUT_TENSOR_ERROR, OH_AI_STATUS_LITE_REENTRANT_ERROR = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -102), OH_AI_STATUS_LITE_GRAPH_FILE_ERROR = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -200), OH_AI_STATUS_LITE_NOT_FIND_OP = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -300),<br/>OH_AI_STATUS_LITE_INVALID_OP_NAME = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -301), OH_AI_STATUS_LITE_INVALID_OP_ATTR = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -302), OH_AI_STATUS_LITE_OP_EXECUTE_FAILURE, OH_AI_STATUS_LITE_FORMAT_ERROR = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -400),<br/>OH_AI_STATUS_LITE_INFER_ERROR = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -500), OH_AI_STATUS_LITE_INFER_INVALID, OH_AI_STATUS_LITE_INPUT_PARAM_INVALID<br/>} | Defines MindSpore status codes. | | [OH_AI_Status](#oh_ai_status-1) {<br>OH_AI_STATUS_SUCCESS = 0, OH_AI_STATUS_CORE_FAILED = OH_AI_COMPCODE_CORE \| 0x1, OH_AI_STATUS_LITE_ERROR = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -1), OH_AI_STATUS_LITE_NULLPTR = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -2),<br>OH_AI_STATUS_LITE_PARAM_INVALID = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -3), OH_AI_STATUS_LITE_NO_CHANGE = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -4), OH_AI_STATUS_LITE_SUCCESS_EXIT = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -5), OH_AI_STATUS_LITE_MEMORY_FAILED = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -6),<br>OH_AI_STATUS_LITE_NOT_SUPPORT = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -7), OH_AI_STATUS_LITE_THREADPOOL_ERROR = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -8), OH_AI_STATUS_LITE_UNINITIALIZED_OBJ = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -9), OH_AI_STATUS_LITE_OUT_OF_TENSOR_RANGE = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -100),<br>OH_AI_STATUS_LITE_INPUT_TENSOR_ERROR, OH_AI_STATUS_LITE_REENTRANT_ERROR = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -102), OH_AI_STATUS_LITE_GRAPH_FILE_ERROR = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -200), OH_AI_STATUS_LITE_NOT_FIND_OP = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -300),<br>OH_AI_STATUS_LITE_INVALID_OP_NAME = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -301), OH_AI_STATUS_LITE_INVALID_OP_ATTR = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -302), OH_AI_STATUS_LITE_OP_EXECUTE_FAILURE, OH_AI_STATUS_LITE_FORMAT_ERROR = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -400),<br>OH_AI_STATUS_LITE_INFER_ERROR = OH_AI_COMPCODE_LITE \| (0x0FFFFFFF &amp; -500), OH_AI_STATUS_LITE_INFER_INVALID, OH_AI_STATUS_LITE_INPUT_PARAM_INVALID<br>} | Defines MindSpore status codes. |
| [OH_AI_ModelType](#oh_ai_modeltype) { OH_AI_MODELTYPE_MINDIR = 0, OH_AI_MODELTYPE_INVALID = 0xFFFFFFFF } | Defines model file types. | | [OH_AI_ModelType](#oh_ai_modeltype-1) { <br>OH_AI_MODELTYPE_MINDIR = 0, <br>OH_AI_MODELTYPE_INVALID = 0xFFFFFFFF <br>} | Defines model file types. |
| [OH_AI_DeviceType](#oh_ai_devicetype) {<br/>OH_AI_DEVICETYPE_CPU = 0, OH_AI_DEVICETYPE_GPU, OH_AI_DEVICETYPE_KIRIN_NPU, OH_AI_DEVICETYPE_NNRT = 60,<br/>OH_AI_DEVICETYPE_INVALID = 100<br/>} | Defines the supported device types. | | [OH_AI_DeviceType](#oh_ai_devicetype-1) {<br>OH_AI_DEVICETYPE_CPU = 0, <br>OH_AI_DEVICETYPE_GPU, <br>OH_AI_DEVICETYPE_KIRIN_NPU, <br>OH_AI_DEVICETYPE_NNRT = 60,<br>OH_AI_DEVICETYPE_INVALID = 100<br>} | Defines the supported device types.|
| [OH_AI_NNRTDeviceType](#oh_ai_nnrtdevicetype-1) { <br>OH_AI_NNRTDEVICE_OTHERS = 0, <br>OH_AI_NNRTDEVICE_CPU = 1, <br>OH_AI_NNRTDEVICE_GPU = 2, <br>OH_AI_NNRTDEVICE_ACCELERATOR = 3<br> } | Defines NNRt device types. |
| [OH_AI_PerformanceMode](#oh_ai_performancemode-1) {<br>OH_AI_PERFORMANCE_NONE = 0, <br>OH_AI_PERFORMANCE_LOW = 1, <br>OH_AI_PERFORMANCE_MEDIUM = 2,<br> OH_AI_PERFORMANCE_HIGH = 3,<br>OH_AI_PERFORMANCE_EXTREME = 4<br>} | Defines performance modes of the NNRt device. |
| [OH_AI_Priority](#oh_ai_priority-1) { <br>OH_AI_PRIORITY_NONE = 0, <br>OH_AI_PRIORITY_LOW = 1, <br>OH_AI_PRIORITY_MEDIUM = 2, <br>OH_AI_PRIORITY_HIGH = 3 <br>} | Defines NNRt inference task priorities. |
### Functions ### Functions
| Name | Description | | Name | Description |
| -------- | -------- | | ------------------------------------------------------------ | ------------------------------------------------------------ |
| [OH_AI_ContextCreate](#oh_ai_contextcreate) () | Creates a context object. | | [OH_AI_ContextCreate](#oh_ai_contextcreate) () | Creates a context object. |
| [OH_AI_ContextDestroy](#oh_ai_contextdestroy) ([OH_AI_ContextHandle](#oh_ai_contexthandle) \*context) | Destroys a context object. | | [OH_AI_ContextDestroy](#oh_ai_contextdestroy) ([OH_AI_ContextHandle](#oh_ai_contexthandle) \*context) | Destroys a context object. |
| [OH_AI_ContextSetThreadNum](#oh_ai_contextsetthreadnum) ([OH_AI_ContextHandle](#oh_ai_contexthandle) context, int32_t thread_num) | Sets the number of runtime threads. | | [OH_AI_ContextSetThreadNum](#oh_ai_contextsetthreadnum) ([OH_AI_ContextHandle](#oh_ai_contexthandle) context, int32_t thread_num) | Sets the number of runtime threads. |
| [OH_AI_ContextGetThreadNum](#oh_ai_contextgetthreadnum) (const [OH_AI_ContextHandle](#oh_ai_contexthandle) context) | Obtains the number of threads. | | [OH_AI_ContextGetThreadNum](#oh_ai_contextgetthreadnum) (const [OH_AI_ContextHandle](#oh_ai_contexthandle) context) | Obtains the number of threads. |
| [OH_AI_ContextSetThreadAffinityMode](#oh_ai_contextsetthreadaffinitymode) ([OH_AI_ContextHandle](#oh_ai_contexthandle) context, int mode) | Sets the affinity mode for binding runtime threads to CPU cores, which are categorized into little cores and big cores depending on the CPU frequency. | | [OH_AI_ContextSetThreadAffinityMode](#oh_ai_contextsetthreadaffinitymode) ([OH_AI_ContextHandle](#oh_ai_contexthandle) context, int mode) | Sets the affinity mode for binding runtime threads to CPU cores, which are classified into large, medium, and small cores based on the CPU frequency. You only need to bind the large or medium cores, but not small cores.|
| [OH_AI_ContextGetThreadAffinityMode](#oh_ai_contextgetthreadaffinitymode) (const [OH_AI_ContextHandle](#oh_ai_contexthandle) context) | Obtains the affinity mode for binding runtime threads to CPU cores. | | [OH_AI_ContextGetThreadAffinityMode](#oh_ai_contextgetthreadaffinitymode) (const [OH_AI_ContextHandle](#oh_ai_contexthandle) context) | Obtains the affinity mode for binding runtime threads to CPU cores. |
| [OH_AI_ContextSetThreadAffinityCoreList](#oh_ai_contextsetthreadaffinitycorelist) ([OH_AI_ContextHandle](#oh_ai_contexthandle) context, const int32_t \*core_list, size_t core_num) | Sets the list of CPU cores bound to a runtime thread. | | [OH_AI_ContextSetThreadAffinityCoreList](#oh_ai_contextsetthreadaffinitycorelist) ([OH_AI_ContextHandle](#oh_ai_contexthandle) context, const int32_t \*core_list, size_t core_num) | Sets the list of CPU cores bound to a runtime thread. |
| [OH_AI_ContextGetThreadAffinityCoreList](#oh_ai_contextgetthreadaffinitycorelist) (const [OH_AI_ContextHandle](#oh_ai_contexthandle) context, size_t \*core_num) | Obtains the list of bound CPU cores. | | [OH_AI_ContextGetThreadAffinityCoreList](#oh_ai_contextgetthreadaffinitycorelist) (const [OH_AI_ContextHandle](#oh_ai_contexthandle) context, size_t \*core_num) | Obtains the list of bound CPU cores. |
| [OH_AI_ContextSetEnableParallel](#oh_ai_contextsetenableparallel) ([OH_AI_ContextHandle](#oh_ai_contexthandle) context, bool is_parallel) | Sets whether to enable parallelism between operators. | | [OH_AI_ContextSetEnableParallel](#oh_ai_contextsetenableparallel) ([OH_AI_ContextHandle](#oh_ai_contexthandle) context, bool is_parallel) | Sets whether to enable parallelism between operators. The setting is ineffective because the feature of this API is not yet available. |
| [OH_AI_ContextGetEnableParallel](#oh_ai_contextgetenableparallel) (const [OH_AI_ContextHandle](#oh_ai_contexthandle) context) | Checks whether parallelism between operators is supported. | | [OH_AI_ContextGetEnableParallel](#oh_ai_contextgetenableparallel) (const [OH_AI_ContextHandle](#oh_ai_contexthandle) context) | Checks whether parallelism between operators is supported. |
| [OH_AI_ContextAddDeviceInfo](#oh_ai_contextadddeviceinfo) ([OH_AI_ContextHandle](#oh_ai_contexthandle) context, [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Adds information about a running device. | | [OH_AI_ContextAddDeviceInfo](#oh_ai_contextadddeviceinfo) ([OH_AI_ContextHandle](#oh_ai_contexthandle) context, [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Attaches the custom device information to the inference context. |
| [OH_AI_DeviceInfoCreate](#oh_ai_deviceinfocreate) ([OH_AI_DeviceType](#oh_ai_devicetype) device_type) | Creates a device information object. | | [OH_AI_DeviceInfoCreate](#oh_ai_deviceinfocreate) ([OH_AI_DeviceType](#oh_ai_devicetype) device_type) | Creates a device information object. |
| [OH_AI_DeviceInfoDestroy](#oh_ai_deviceinfodestroy) ([OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) \*device_info) | Destroys a device information instance. | | [OH_AI_DeviceInfoDestroy](#oh_ai_deviceinfodestroy) ([OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) \*device_info) | Destroys a device information object. Note: After the device information instance is added to the context, the caller does not need to destroy it manually. |
| [OH_AI_DeviceInfoSetProvider](#oh_ai_deviceinfosetprovider) ([OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info, const char \*provider) | Sets the name of a provider. | | [OH_AI_DeviceInfoSetProvider](#oh_ai_deviceinfosetprovider) ([OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info, const char \*provider) | Sets the provider name. |
| [OH_AI_DeviceInfoGetProvider](#oh_ai_deviceinfogetprovider) (const [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Obtains the provider name. | | [OH_AI_DeviceInfoGetProvider](#oh_ai_deviceinfogetprovider) (const [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Obtains the provider name. |
| [OH_AI_DeviceInfoSetProviderDevice](#oh_ai_deviceinfosetproviderdevice) ([OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info, const char \*device) | Sets the name of a provider device. | | [OH_AI_DeviceInfoSetProviderDevice](#oh_ai_deviceinfosetproviderdevice) ([OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info, const char \*device) | Sets the name of a provider device. |
| [OH_AI_DeviceInfoGetProviderDevice](#oh_ai_deviceinfogetproviderdevice) (const [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Obtains the name of a provider device. | | [OH_AI_DeviceInfoGetProviderDevice](#oh_ai_deviceinfogetproviderdevice) (const [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Obtains the name of a provider device. |
| [OH_AI_DeviceInfoGetDeviceType](#oh_ai_deviceinfogetdevicetype) (const [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Obtains the type of a provider device. | | [OH_AI_DeviceInfoGetDeviceType](#oh_ai_deviceinfogetdevicetype) (const [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Obtains the device type. |
| [OH_AI_DeviceInfoSetEnableFP16](#oh_ai_deviceinfosetenablefp16) ([OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info, bool is_fp16) | Sets whether to enable float16 inference. This function is available only for CPU/GPU devices. | | [OH_AI_DeviceInfoSetEnableFP16](#oh_ai_deviceinfosetenablefp16) ([OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info, bool is_fp16) | Sets whether to enable float16 inference. This function is available only for CPU and GPU devices. |
| [OH_AI_DeviceInfoGetEnableFP16](#oh_ai_deviceinfogetenablefp16) (const [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Checks whether float16 inference is enabled. This function is available only for CPU/GPU devices. | | [OH_AI_DeviceInfoGetEnableFP16](#oh_ai_deviceinfogetenablefp16) (const [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Checks whether float16 inference is enabled. This function is available only for CPU and GPU devices. |
| [OH_AI_DeviceInfoSetFrequency](#oh_ai_deviceinfosetfrequency) ([OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info, int frequency) | Sets the NPU frequency type. This function is available only for NPU devices. | | [OH_AI_DeviceInfoSetFrequency](#oh_ai_deviceinfosetfrequency) ([OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info, int frequency) | Sets the NPU frequency type. This function is available only for NPU devices. |
| [OH_AI_DeviceInfoGetFrequency](#oh_ai_deviceinfogetfrequency) (const [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Obtains the NPU frequency type. This function is available only for NPU devices. | | [OH_AI_DeviceInfoGetFrequency](#oh_ai_deviceinfogetfrequency) (const [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Obtains the NPU frequency type. This function is available only for NPU devices. |
| [OH_AI_ModelCreate](#oh_ai_modelcreate) () | Creates a model object. | | [OH_AI_GetAllNNRTDeviceDescs](#oh_ai_getallnnrtdevicedescs) (size_t \*num) | Obtains the descriptions of all NNRt devices in the system. |
| [OH_AI_ModelDestroy](#oh_ai_modeldestroy) ([OH_AI_ModelHandle](#oh_ai_modelhandle) \*model) | Destroys a model object. | | [OH_AI_DestroyAllNNRTDeviceDescs](#oh_ai_destroyallnnrtdevicedescs) ([NNRTDeviceDesc](#nnrtdevicedesc) \*\*desc) | Destroys the array of NNRT descriptions obtained by [OH_AI_GetAllNNRTDeviceDescs](#oh_ai_getallnnrtdevicedescs).|
| [OH_AI_ModelBuild](#oh_ai_modelbuild) ([OH_AI_ModelHandle](#oh_ai_modelhandle) model, const void \*model_data, size_t data_size, [OH_AI_ModelType](#oh_ai_modeltype) model_type, const [OH_AI_ContextHandle](#oh_ai_contexthandle) model_context) | Loads and builds a MindSpore model from the memory buffer. | | [OH_AI_GetDeviceIdFromNNRTDeviceDesc](#oh_ai_getdeviceidfromnnrtdevicedesc) (const [NNRTDeviceDesc](#nnrtdevicedesc) \*desc) | Obtains the NNRt device ID from the specified NNRt device description. Note that this ID is valid only for NNRt devices.|
| [OH_AI_ModelBuildFromFile](#oh_ai_modelbuildfromfile) ([OH_AI_ModelHandle](#oh_ai_modelhandle) model, const char \*model_path, [OH_AI_ModelType](#oh_ai_modeltype) model_type, const [OH_AI_ContextHandle](#oh_ai_contexthandle) model_context) | Loads and builds a MindSpore model from a model file. | | [OH_AI_GetNameFromNNRTDeviceDesc](#oh_ai_getnamefromnnrtdevicedesc) (const [NNRTDeviceDesc](#nnrtdevicedesc) \*desc) | Obtains the NNRt device name from the specified NNRt device description. |
| [OH_AI_ModelResize](#oh_ai_modelresize) ([OH_AI_ModelHandle](#oh_ai_modelhandle) model, const [OH_AI_TensorHandleArray](_o_h___a_i___tensor_handle_array.md) inputs, [OH_AI_ShapeInfo](_o_h___a_i___shape_info.md) \*shape_infos, size_t shape_info_num) | Adjusts the input tensor shapes of a built model. | | [OH_AI_GetTypeFromNNRTDeviceDesc](#oh_ai_gettypefromnnrtdevicedesc) (const [NNRTDeviceDesc](#nnrtdevicedesc) \*desc) | Obtains the NNRt device type from the specified NNRt device description. |
| [OH_AI_ModelPredict](#oh_ai_modelpredict) ([OH_AI_ModelHandle](#oh_ai_modelhandle) model, const [OH_AI_TensorHandleArray](_o_h___a_i___tensor_handle_array.md) inputs, [OH_AI_TensorHandleArray](_o_h___a_i___tensor_handle_array.md) \*outputs, const [OH_AI_KernelCallBack](#oh_ai_kernelcallback) before, const [OH_AI_KernelCallBack](#oh_ai_kernelcallback) after) | Performs model inference. | | [OH_AI_CreateNNRTDeviceInfoByName](#oh_ai_creatennrtdeviceinfobyname) (const char \*name) | Searches for the NNRt device with the specified name and creates the NNRt device information based on the information about the first found NNRt device.|
| [OH_AI_ModelGetInputs](#oh_ai_modelgetinputs) (const [OH_AI_ModelHandle](#oh_ai_modelhandle) model) | Obtains the input tensor array structure of a model. | | [OH_AI_CreateNNRTDeviceInfoByType](#oh_ai_creatennrtdeviceinfobytype) ([OH_AI_NNRTDeviceType](#oh_ai_nnrtdevicetype) type) | Searches for the NNRt device with the specified type and creates the NNRt device information based on the information about the first found NNRt device.|
| [OH_AI_ModelGetOutputs](#oh_ai_modelgetoutputs) (const [OH_AI_ModelHandle](#oh_ai_modelhandle) model) | Obtains the output tensor array structure of a model. | | [OH_AI_DeviceInfoSetDeviceId](#oh_ai_deviceinfosetdeviceid) ([OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info, size_t device_id) | Sets the ID of an NNRt device. This API is available only for NNRt devices. |
| [OH_AI_ModelGetInputByTensorName](#oh_ai_modelgetinputbytensorname) (const [OH_AI_ModelHandle](#oh_ai_modelhandle) model, const char \*tensor_name) | Obtains the input tensor of a model by tensor name. | | [OH_AI_DeviceInfoGetDeviceId](#oh_ai_deviceinfogetdeviceid) (const [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Obtains the ID of an NNRt device. This API is available only for NNRt devices. |
| [OH_AI_ModelGetOutputByTensorName](#oh_ai_modelgetoutputbytensorname) (const [OH_AI_ModelHandle](#oh_ai_modelhandle) model, const char \*tensor_name) | Obtains the output tensor of a model by tensor name. | | [OH_AI_DeviceInfoSetPerformanceMode](#oh_ai_deviceinfosetperformancemode) ([OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info, [OH_AI_PerformanceMode](#oh_ai_performancemode) mode) | Sets the performance mode of an NNRt device. This API is available only for NNRt devices. |
| [OH_AI_TensorCreate](#oh_ai_tensorcreate) (const char \*name, [OH_AI_DataType](#oh_ai_datatype) type, const int64_t \*shape, size_t shape_num, const void \*data, size_t data_len) | Creates a tensor object. | | [OH_AI_DeviceInfoGetPerformanceMode](#oh_ai_deviceinfogetperformancemode) (const [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Obtains the performance mode of an NNRt device. This API is available only for NNRt devices. |
| [OH_AI_TensorDestroy](#oh_ai_tensordestroy) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) \*tensor) | Destroys a tensor object. | | [OH_AI_DeviceInfoSetPriority](#oh_ai_deviceinfosetpriority) ([OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info, [OH_AI_Priority](#oh_ai_priority) priority) | Sets the priority of an NNRT task. This API is available only for NNRt devices. |
| [OH_AI_TensorClone](#oh_ai_tensorclone) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Clones a tensor. | | [OH_AI_DeviceInfoGetPriority](#oh_ai_deviceinfogetpriority) (const [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) device_info) | Obtains the priority of an NNRT task. This API is available only for NNRt devices. |
| [OH_AI_TensorSetName](#oh_ai_tensorsetname) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor, const char \*name) | Sets the name of a tensor. | | [OH_AI_ModelCreate](#oh_ai_modelcreate) () | Creates a model object. |
| [OH_AI_TensorGetName](#oh_ai_tensorgetname) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the name of a tensor. | | [OH_AI_ModelDestroy](#oh_ai_modeldestroy) ([OH_AI_ModelHandle](#oh_ai_modelhandle) \*model) | Destroys a model object. |
| [OH_AI_TensorSetDataType](#oh_ai_tensorsetdatatype) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor, [OH_AI_DataType](#oh_ai_datatype) type) | Sets the data type of a tensor. | | [OH_AI_ModelBuild](#oh_ai_modelbuild) ([OH_AI_ModelHandle](#oh_ai_modelhandle) model, const void \*model_data, size_t data_size, [OH_AI_ModelType](#oh_ai_modeltype) model_type, const [OH_AI_ContextHandle](#oh_ai_contexthandle) model_context) | Loads and builds a MindSpore model from the memory buffer. |
| [OH_AI_TensorGetDataType](#oh_ai_tensorgetdatatype) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the data type of a tensor. | | [OH_AI_ModelBuildFromFile](#oh_ai_modelbuildfromfile) ([OH_AI_ModelHandle](#oh_ai_modelhandle) model, const char \*model_path, [OH_AI_ModelType](#oh_ai_modeltype) model_type, const [OH_AI_ContextHandle](#oh_ai_contexthandle) model_context) | Loads and builds a MindSpore model from a model file. |
| [OH_AI_TensorSetShape](#oh_ai_tensorsetshape) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor, const int64_t \*shape, size_t shape_num) | Sets the shape of a tensor. | | [OH_AI_ModelResize](#oh_ai_modelresize) ([OH_AI_ModelHandle](#oh_ai_modelhandle) model, const [OH_AI_TensorHandleArray](_o_h___a_i___tensor_handle_array.md) inputs, [OH_AI_ShapeInfo](_o_h___a_i___shape_info.md) \*shape_infos, size_t shape_info_num) | Adjusts the input tensor shapes of a built model. |
| [OH_AI_TensorGetShape](#oh_ai_tensorgetshape) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor, size_t \*shape_num) | Obtains the shape of a tensor. | | [OH_AI_ModelPredict](#oh_ai_modelpredict) ([OH_AI_ModelHandle](#oh_ai_modelhandle) model, const [OH_AI_TensorHandleArray](_o_h___a_i___tensor_handle_array.md) inputs, [OH_AI_TensorHandleArray](_o_h___a_i___tensor_handle_array.md) \*outputs, const [OH_AI_KernelCallBack](#oh_ai_kernelcallback) before, const [OH_AI_KernelCallBack](#oh_ai_kernelcallback) after) | Performs model inference. |
| [OH_AI_TensorSetFormat](#oh_ai_tensorsetformat) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor, [OH_AI_Format](#oh_ai_format) format) | Sets the tensor data format. | | [OH_AI_ModelGetInputs](#oh_ai_modelgetinputs) (const [OH_AI_ModelHandle](#oh_ai_modelhandle) model) | Obtains the input tensor array structure of a model. |
| [OH_AI_TensorGetFormat](#oh_ai_tensorgetformat) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the tensor data format. | | [OH_AI_ModelGetOutputs](#oh_ai_modelgetoutputs) (const [OH_AI_ModelHandle](#oh_ai_modelhandle) model) | Obtains the output tensor array structure of a model. |
| [OH_AI_TensorSetData](#oh_ai_tensorsetdata) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor, void \*data) | Sets the tensor data. | | [OH_AI_ModelGetInputByTensorName](#oh_ai_modelgetinputbytensorname) (const [OH_AI_ModelHandle](#oh_ai_modelhandle) model, const char \*tensor_name) | Obtains the input tensor of a model by tensor name. |
| [OH_AI_TensorGetData](#oh_ai_tensorgetdata) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the pointer to tensor data. | | [OH_AI_ModelGetOutputByTensorName](#oh_ai_modelgetoutputbytensorname) (const [OH_AI_ModelHandle](#oh_ai_modelhandle) model, const char \*tensor_name) | Obtains the output tensor of a model by tensor name. |
| [OH_AI_TensorGetMutableData](#oh_ai_tensorgetmutabledata) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the pointer to variable tensor data. If the data is empty, memory will be allocated. | | [OH_AI_TensorCreate](#oh_ai_tensorcreate) (const char \*name, [OH_AI_DataType](#oh_ai_datatype) type, const int64_t \*shape, size_t shape_num, const void \*data, size_t data_len) | Creates a tensor object. |
| [OH_AI_TensorGetElementNum](#oh_ai_tensorgetelementnum) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the number of tensor elements. | | [OH_AI_TensorDestroy](#oh_ai_tensordestroy) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) \*tensor) | Destroys a tensor object. |
| [OH_AI_TensorGetDataSize](#oh_ai_tensorgetdatasize) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the number of bytes of the tensor data. | | [OH_AI_TensorClone](#oh_ai_tensorclone) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Clones a tensor. |
| [OH_AI_TensorSetName](#oh_ai_tensorsetname) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor, const char \*name) | Sets the tensor name. |
| [OH_AI_TensorGetName](#oh_ai_tensorgetname) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the tensor name. |
| [OH_AI_TensorSetDataType](#oh_ai_tensorsetdatatype) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor, [OH_AI_DataType](#oh_ai_datatype) type) | Sets the data type of a tensor. |
| [OH_AI_TensorGetDataType](#oh_ai_tensorgetdatatype) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the tensor type. |
| [OH_AI_TensorSetShape](#oh_ai_tensorsetshape) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor, const int64_t \*shape, size_t shape_num) | Sets the tensor shape. |
| [OH_AI_TensorGetShape](#oh_ai_tensorgetshape) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor, size_t \*shape_num) | Obtains the tensor shape. |
| [OH_AI_TensorSetFormat](#oh_ai_tensorsetformat) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor, [OH_AI_Format](#oh_ai_format) format) | Sets the tensor data format. |
| [OH_AI_TensorGetFormat](#oh_ai_tensorgetformat) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the tensor data format. |
| [OH_AI_TensorSetData](#oh_ai_tensorsetdata) ([OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor, void \*data) | Sets the tensor data. |
| [OH_AI_TensorGetData](#oh_ai_tensorgetdata) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the pointer to tensor data. |
| [OH_AI_TensorGetMutableData](#oh_ai_tensorgetmutabledata) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the pointer to variable tensor data. If the data is empty, memory will be allocated. |
| [OH_AI_TensorGetElementNum](#oh_ai_tensorgetelementnum) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the number of tensor elements. |
| [OH_AI_TensorGetDataSize](#oh_ai_tensorgetdatasize) (const [OH_AI_TensorHandle](#oh_ai_tensorhandle) tensor) | Obtains the number of bytes of the tensor data. |
## Macro Description ## Macro Description
...@@ -133,84 +154,116 @@ Provides APIs related to MindSpore Lite model inference. ...@@ -133,84 +154,116 @@ Provides APIs related to MindSpore Lite model inference.
### OH_AI_MAX_SHAPE_NUM ### OH_AI_MAX_SHAPE_NUM
``` ```
#define OH_AI_MAX_SHAPE_NUM 32 #define OH_AI_MAX_SHAPE_NUM 32
``` ```
**Description**<br>
**Description**
Defines dimension information. The maximum dimension is set by **MS_MAX_SHAPE_NUM**. Defines dimension information. The maximum dimension is set by **MS_MAX_SHAPE_NUM**.
## Type Description ## Type Description
### NNRTDeviceDesc
```
typedef struct NNRTDeviceDesc NNRTDeviceDesc
```
**Description**
Defines the NNRt device information, including the device ID and device name.
**Since**
10
### OH_AI_CallBackParam ### OH_AI_CallBackParam
``` ```
typedef struct OH_AI_CallBackParamOH_AI_CallBackParam typedef struct OH_AI_CallBackParam OH_AI_CallBackParam
``` ```
**Description**<br>
**Description**
Defines the operator information passed in a callback. Defines the operator information passed in a callback.
### OH_AI_ContextHandle ### OH_AI_ContextHandle
``` ```
typedef void* OH_AI_ContextHandle typedef void* OH_AI_ContextHandle
``` ```
**Description**<br>
Defines the pointer to the MindSpore context. **Description**
Defines the pointer to the MindSpore context.
### OH_AI_DataType ### OH_AI_DataType
``` ```
typedef enum OH_AI_DataTypeOH_AI_DataType typedef enum OH_AI_DataType OH_AI_DataType
``` ```
**Description**<br>
**Description**
Declares data types supported by MSTensor. Declares data types supported by MSTensor.
### OH_AI_DeviceInfoHandle ### OH_AI_DeviceInfoHandle
``` ```
typedef void* OH_AI_DeviceInfoHandle typedef void* OH_AI_DeviceInfoHandle
``` ```
**Description**<br>
**Description**
Defines the pointer to the MindSpore device information. Defines the pointer to the MindSpore device information.
### OH_AI_DeviceType ### OH_AI_DeviceType
``` ```
typedef enum OH_AI_DeviceTypeOH_AI_DeviceType typedef enum OH_AI_DeviceType OH_AI_DeviceType
``` ```
**Description**<br>
**Description**
Defines the supported device types. Defines the supported device types.
### OH_AI_Format ### OH_AI_Format
``` ```
typedef enum OH_AI_FormatOH_AI_Format typedef enum OH_AI_Format OH_AI_Format
``` ```
**Description**<br>
**Description**
Declares data formats supported by MSTensor. Declares data formats supported by MSTensor.
### OH_AI_KernelCallBack ### OH_AI_KernelCallBack
``` ```
typedef bool(* OH_AI_KernelCallBack) (const OH_AI_TensorHandleArray inputs, const OH_AI_TensorHandleArray outputs, const OH_AI_CallBackParam kernel_Info) typedef bool(* OH_AI_KernelCallBack) (const OH_AI_TensorHandleArray inputs, const OH_AI_TensorHandleArray outputs, const OH_AI_CallBackParam kernel_Info)
``` ```
**Description**<br>
**Description**
Defines the pointer to a callback. Defines the pointer to a callback.
This pointer is used to set the two callback functions in [OH_AI_ModelPredict](#oh_ai_modelpredict). Each callback function must contain three parameters, where **inputs** and **outputs** indicate the input and output tensors of the operator, and **kernel_Info** indicates information about the current operator. You can use the callback functions to monitor the operator execution status, for example, operator execution time and the operator correctness. This pointer is used to set the two callback functions in [OH_AI_ModelPredict](#oh_ai_modelpredict). Each callback function must contain three parameters, where **inputs** and **outputs** indicate the input and output tensors of the operator, and **kernel_Info** indicates information about the current operator. You can use the callback functions to monitor the operator execution status, for example, operator execution time and the operator correctness.
...@@ -218,51 +271,109 @@ This pointer is used to set the two callback functions in [OH_AI_ModelPredict](# ...@@ -218,51 +271,109 @@ This pointer is used to set the two callback functions in [OH_AI_ModelPredict](#
### OH_AI_ModelHandle ### OH_AI_ModelHandle
``` ```
typedef void* OH_AI_ModelHandle typedef void* OH_AI_ModelHandle
``` ```
**Description**<br>
**Description**
Defines the pointer to a model object. Defines the pointer to a model object.
### OH_AI_ModelType ### OH_AI_ModelType
``` ```
typedef enum OH_AI_ModelTypeOH_AI_ModelType typedef enum OH_AI_ModelType OH_AI_ModelType
``` ```
**Description**<br>
**Description**
Defines model file types. Defines model file types.
### OH_AI_NNRTDeviceType
```
typedef enum OH_AI_NNRTDeviceType OH_AI_NNRTDeviceType
```
**Description**
Defines NNRt device types.
**Since**
10
### OH_AI_PerformanceMode
```
typedef enum OH_AI_PerformanceMode OH_AI_PerformanceMode
```
**Description**
Defines performance modes of the NNRt device.
**Since**
10
### OH_AI_Priority
```
typedef enum OH_AI_Priority OH_AI_Priority
```
**Description**
Defines NNRt inference task priorities.
**Since**
10
### OH_AI_Status ### OH_AI_Status
``` ```
typedef enum OH_AI_StatusOH_AI_Status typedef enum OH_AI_Status OH_AI_Status
``` ```
**Description**<br>
**Description**
Defines MindSpore status codes. Defines MindSpore status codes.
### OH_AI_TensorHandle ### OH_AI_TensorHandle
``` ```
typedef void* OH_AI_TensorHandle typedef void* OH_AI_TensorHandle
``` ```
**Description**<br>
**Description**
Defines the handle of a tensor object. Defines the handle of a tensor object.
### OH_AI_TensorHandleArray ### OH_AI_TensorHandleArray
``` ```
typedef struct OH_AI_TensorHandleArrayOH_AI_TensorHandleArray typedef struct OH_AI_TensorHandleArray OH_AI_TensorHandleArray
``` ```
**Description**<br>
**Description**
Defines the tensor array structure, which is used to store the tensor array pointer and tensor array length. Defines the tensor array structure, which is used to store the tensor array pointer and tensor array length.
...@@ -271,215 +382,304 @@ Defines the tensor array structure, which is used to store the tensor array poin ...@@ -271,215 +382,304 @@ Defines the tensor array structure, which is used to store the tensor array poin
### OH_AI_CompCode ### OH_AI_CompCode
``` ```
enum OH_AI_CompCode enum OH_AI_CompCode
``` ```
**Description**<br>
Defines MinSpore component codes.
| Name | Description | **Description**
| -------- | -------- |
| OH_AI_COMPCODE_CORE | MindSpore Core code | Defines MindSpore component codes.
| OH_AI_COMPCODE_LITE | MindSpore Lite code |
| Value | Description |
| ------------------- | --------------------- |
| OH_AI_COMPCODE_CORE | MindSpore Core code|
| OH_AI_COMPCODE_LITE | MindSpore Lite code|
### OH_AI_DataType ### OH_AI_DataType
``` ```
enum OH_AI_DataType enum OH_AI_DataType
``` ```
**Description**<br>
**Description**
Declares data types supported by MSTensor. Declares data types supported by MSTensor.
| Name | Description | | Value | Description |
| -------- | -------- | | --------------------------------- | ---------------------- |
| OH_AI_DATATYPE_UNKNOWN | Unknown data type | | OH_AI_DATATYPE_UNKNOWN | Unknown data type. |
| OH_AI_DATATYPE_OBJECTTYPE_STRING | String data type | | OH_AI_DATATYPE_OBJECTTYPE_STRING | String data. |
| OH_AI_DATATYPE_OBJECTTYPE_LIST | List data type | | OH_AI_DATATYPE_OBJECTTYPE_LIST | List data. |
| OH_AI_DATATYPE_OBJECTTYPE_TUPLE | Tuple data type | | OH_AI_DATATYPE_OBJECTTYPE_TUPLE | Tuple data. |
| OH_AI_DATATYPE_OBJECTTYPE_TENSOR | TensorList data type | | OH_AI_DATATYPE_OBJECTTYPE_TENSOR | TensorList data. |
| OH_AI_DATATYPE_NUMBERTYPE_BEGIN | Beginning of the number type | | OH_AI_DATATYPE_NUMBERTYPE_BEGIN | Beginning of the number type. |
| OH_AI_DATATYPE_NUMBERTYPE_BOOL | Bool data type | | OH_AI_DATATYPE_NUMBERTYPE_BOOL | Bool data. |
| OH_AI_DATATYPE_NUMBERTYPE_INT8 | Int8 data type | | OH_AI_DATATYPE_NUMBERTYPE_INT8 | Int8 data. |
| OH_AI_DATATYPE_NUMBERTYPE_INT16 | Int16 data type | | OH_AI_DATATYPE_NUMBERTYPE_INT16 | Int16 data. |
| OH_AI_DATATYPE_NUMBERTYPE_INT32 | Int32 data type | | OH_AI_DATATYPE_NUMBERTYPE_INT32 | Int32 data. |
| OH_AI_DATATYPE_NUMBERTYPE_INT64 | Int64 data type | | OH_AI_DATATYPE_NUMBERTYPE_INT64 | Int64 data. |
| OH_AI_DATATYPE_NUMBERTYPE_UINT8 | UInt8 data type | | OH_AI_DATATYPE_NUMBERTYPE_UINT8 | UInt8 data. |
| OH_AI_DATATYPE_NUMBERTYPE_UINT16 | UInt16 data type | | OH_AI_DATATYPE_NUMBERTYPE_UINT16 | UInt16 data . |
| OH_AI_DATATYPE_NUMBERTYPE_UINT32 | UInt32 data type | | OH_AI_DATATYPE_NUMBERTYPE_UINT32 | UInt32 data. |
| OH_AI_DATATYPE_NUMBERTYPE_UINT64 | UInt64 data type | | OH_AI_DATATYPE_NUMBERTYPE_UINT64 | UInt64 data. |
| OH_AI_DATATYPE_NUMBERTYPE_FLOAT16 | Float16 data type | | OH_AI_DATATYPE_NUMBERTYPE_FLOAT16 | Float16 data. |
| OH_AI_DATATYPE_NUMBERTYPE_FLOAT32 | Float32 data type | | OH_AI_DATATYPE_NUMBERTYPE_FLOAT32 | Float32 data. |
| OH_AI_DATATYPE_NUMBERTYPE_FLOAT64 | Float64 data type | | OH_AI_DATATYPE_NUMBERTYPE_FLOAT64 | Float64 data. |
| OH_AI_DATATYPE_NUMBERTYPE_END | End of the number type | | OH_AI_DATATYPE_NUMBERTYPE_END | End of the number type.|
| OH_AI_DataTypeInvalid | Invalid data type | | OH_AI_DataTypeInvalid | Invalid data type. |
### OH_AI_DeviceType ### OH_AI_DeviceType
``` ```
enum OH_AI_DeviceType enum OH_AI_DeviceType
``` ```
**Description**<br>
**Description**
Defines the supported device types. Defines the supported device types.
| Name | Description | | Value | Description |
| -------- | -------- | | -------------------------- | --------------------------------------- |
| OH_AI_DEVICETYPE_CPU | Device type: CPU<br/>since 9 | | OH_AI_DEVICETYPE_CPU | Device type: CPU |
| OH_AI_DEVICETYPE_GPU | Device type: GPU<br/>Reserved, not support yet.<br/>since 9 | | OH_AI_DEVICETYPE_GPU | Device type: GPU Reserved |
| OH_AI_DEVICETYPE_KIRIN_NPU | Device type: Kirin NPU<br/>Reserved, not support yet.<br/>since 9 | | OH_AI_DEVICETYPE_KIRIN_NPU | Device type: Kirin NPU Reserved|
| OH_AI_DEVICETYPE_NNRT | Device type: NNRt<br/>OHOS-only device range[60,80).<br/>since 9 | | OH_AI_DEVICETYPE_NNRT | Device type: NNRt OHOS device range: [60, 80)|
| OH_AI_DEVICETYPE_INVALID | Invalid device type<br/>since 9 | | OH_AI_DEVICETYPE_INVALID | Invalid device type |
### OH_AI_Format ### OH_AI_Format
``` ```
enum OH_AI_Format enum OH_AI_Format
``` ```
**Description**<br>
**Description**
Declares data formats supported by MSTensor. Declares data formats supported by MSTensor.
| Name | Description | | Value | Description |
| -------- | -------- | | ------------------- | ---------------- |
| OH_AI_FORMAT_NCHW | NCHW format | | OH_AI_FORMAT_NCHW | Tensor data is stored in the sequence of batch number N, channel C, height H, and width W. |
| OH_AI_FORMAT_NHWC | NHWC format | | OH_AI_FORMAT_NHWC | Tensor data is stored in the sequence of batch number N, height H, width W, and channel C. |
| OH_AI_FORMAT_NHWC4 | NHWC4 format | | OH_AI_FORMAT_NHWC4 | Tensor data is stored in the sequence of batch number N, height H, width W, and channel C. The C axis is 4-byte aligned. |
| OH_AI_FORMAT_HWKC | HWKC format | | OH_AI_FORMAT_HWKC | Tensor data is stored in the sequence of height H, width W, core count K, and channel C. |
| OH_AI_FORMAT_HWCK | HWCK format | | OH_AI_FORMAT_HWCK | Tensor data is stored in the sequence of height H, width W, channel C, and core count K. |
| OH_AI_FORMAT_KCHW | KCHW format | | OH_AI_FORMAT_KCHW | Tensor data is stored in the sequence of core count K, channel C, height H, and width W. |
| OH_AI_FORMAT_CKHW | CKHW format | | OH_AI_FORMAT_CKHW | Tensor data is stored in the sequence of channel C, core count K, height H, and width W. |
| OH_AI_FORMAT_KHWC | KHWC format | | OH_AI_FORMAT_KHWC | Tensor data is stored in the sequence of core count K, height H, width W, and channel C. |
| OH_AI_FORMAT_CHWK | CHWK format | | OH_AI_FORMAT_CHWK | Tensor data is stored in the sequence of channel C, height H, width W, and core count K. |
| OH_AI_FORMAT_HW | HW format | | OH_AI_FORMAT_HW | Tensor data is stored in the sequence of height H and width W. |
| OH_AI_FORMAT_HW4 | HW4 format | | OH_AI_FORMAT_HW4 | Tensor data is stored in the sequence of height H and width W. The W axis is 4-byte aligned. |
| OH_AI_FORMAT_NC | NC format | | OH_AI_FORMAT_NC | Tensor data is stored in the sequence of batch number N and channel C. |
| OH_AI_FORMAT_NC4 | NC4 format | | OH_AI_FORMAT_NC4 | Tensor data is stored in the sequence of batch number N and channel C. The C axis is 4-byte aligned. |
| OH_AI_FORMAT_NC4HW4 | NC4HW4 format | | OH_AI_FORMAT_NC4HW4 | Tensor data is stored in the sequence of batch number N, channel C, height H, and width W. The C axis and W axis are 4-byte aligned.|
| OH_AI_FORMAT_NCDHW | NCDHW format | | OH_AI_FORMAT_NCDHW | Tensor data is stored in the sequence of batch number N, channel C, depth D, height H, and width W. |
| OH_AI_FORMAT_NWC | NWC format | | OH_AI_FORMAT_NWC | Tensor data is stored in the sequence of batch number N, width W, and channel C. |
| OH_AI_FORMAT_NCW | NCW format | | OH_AI_FORMAT_NCW | Tensor data is stored in the sequence of batch number N, channel C, and width W. |
### OH_AI_ModelType ### OH_AI_ModelType
``` ```
enum OH_AI_ModelType enum OH_AI_ModelType
``` ```
**Description**<br>
**Description**
Defines model file types. Defines model file types.
| Name | Description | | Value | Description |
| -------- | -------- | | ----------------------- | ------------------ |
| OH_AI_MODELTYPE_MINDIR | Model type: MindIR<br/>since 9 | | OH_AI_MODELTYPE_MINDIR | Model type of MindIR. The extension of the model file name is **.ms**.|
| OH_AI_MODELTYPE_INVALID | Invalid model type<br/>since 9 | | OH_AI_MODELTYPE_INVALID | Invalid model type. |
### OH_AI_NNRTDeviceType
```
enum OH_AI_NNRTDeviceType
```
**Description**
Defines NNRt device types.
**Since**
10
| Value | Description |
| ---------------------------- | ----------------------------------- |
| OH_AI_NNRTDEVICE_OTHERS | Others (any device type except the following three types).|
| OH_AI_NNRTDEVICE_CPU | CPU. |
| OH_AI_NNRTDEVICE_GPU | GPU. |
| OH_AI_NNRTDEVICE_ACCELERATOR | Specific acceleration device. |
### OH_AI_PerformanceMode
```
enum OH_AI_PerformanceMode
```
**Description**
Defines performance modes of the NNRt device.
**Since**
10
| Value | Description |
| ------------------------- | ------------------- |
| OH_AI_PERFORMANCE_NONE | No special settings. |
| OH_AI_PERFORMANCE_LOW | Low power consumption. |
| OH_AI_PERFORMANCE_MEDIUM | Power consumption and performance balancing.|
| OH_AI_PERFORMANCE_HIGH | High performance. |
| OH_AI_PERFORMANCE_EXTREME | Ultimate performance. |
### OH_AI_Priority
```
enum OH_AI_Priority
```
**Description**
Defines NNRt inference task priorities.
**Since**
10
| Value | Description |
| --------------------- | -------------- |
| OH_AI_PRIORITY_NONE | No priority preference.|
| OH_AI_PRIORITY_LOW | Low priority.|
| OH_AI_PRIORITY_MEDIUM | Medium priority|
| OH_AI_PRIORITY_HIGH | High priority. |
### OH_AI_Status ### OH_AI_Status
``` ```
enum OH_AI_Status enum OH_AI_Status
``` ```
**Description**<br>
Defines MindSpore status codes.
| Name | Description | **Description**
| -------- | -------- |
| OH_AI_STATUS_SUCCESS | Success | Defines MindSpore status codes.
| OH_AI_STATUS_CORE_FAILED | MindSpore Core failure |
| OH_AI_STATUS_LITE_ERROR | MindSpore Lite error |
| OH_AI_STATUS_LITE_NULLPTR | MindSpore Lite null pointer |
| OH_AI_STATUS_LITE_PARAM_INVALID | MindSpore Lite invalid parameters |
| OH_AI_STATUS_LITE_NO_CHANGE | MindSpore Lite no change |
| OH_AI_STATUS_LITE_SUCCESS_EXIT | MindSpore Lite exit without errors |
| OH_AI_STATUS_LITE_MEMORY_FAILED | MindSpore Lite memory allocation failure |
| OH_AI_STATUS_LITE_NOT_SUPPORT | MindSpore Lite not supported |
| OH_AI_STATUS_LITE_THREADPOOL_ERROR | MindSpore Lite thread pool error |
| OH_AI_STATUS_LITE_UNINITIALIZED_OBJ | MindSpore Lite uninitialized |
| OH_AI_STATUS_LITE_OUT_OF_TENSOR_RANGE | MindSpore Lite tensor overflow |
| OH_AI_STATUS_LITE_INPUT_TENSOR_ERROR | MindSpore Lite input tensor error |
| OH_AI_STATUS_LITE_REENTRANT_ERROR | MindSpore Lite reentry error |
| OH_AI_STATUS_LITE_GRAPH_FILE_ERROR | MindSpore Lite file error |
| OH_AI_STATUS_LITE_NOT_FIND_OP | MindSpore Lite operator not found |
| OH_AI_STATUS_LITE_INVALID_OP_NAME | MindSpore Lite invalid operators |
| OH_AI_STATUS_LITE_INVALID_OP_ATTR | MindSpore Lite invalid operator hyperparameters |
| OH_AI_STATUS_LITE_OP_EXECUTE_FAILURE | MindSpore Lite operator execution failure |
| OH_AI_STATUS_LITE_FORMAT_ERROR | MindSpore Lite tensor format error |
| OH_AI_STATUS_LITE_INFER_ERROR | MindSpore Lite shape inference error |
| OH_AI_STATUS_LITE_INFER_INVALID | MindSpore Lite invalid shape inference |
| OH_AI_STATUS_LITE_INPUT_PARAM_INVALID | MindSpore Lite invalid input parameters |
| Value | Description |
| ------------------------------------- | ----------------------------------------- |
| OH_AI_STATUS_SUCCESS | Success. |
| OH_AI_STATUS_CORE_FAILED | MindSpore Core failure. |
| OH_AI_STATUS_LITE_ERROR | MindSpore Lite error. |
| OH_AI_STATUS_LITE_NULLPTR | MindSpore Lite null pointer. |
| OH_AI_STATUS_LITE_PARAM_INVALID | MindSpore Lite invalid parameters. |
| OH_AI_STATUS_LITE_NO_CHANGE | MindSpore Lite no change. |
| OH_AI_STATUS_LITE_SUCCESS_EXIT | MindSpore Lite exit without errors.|
| OH_AI_STATUS_LITE_MEMORY_FAILED | MindSpore Lite memory allocation failure. |
| OH_AI_STATUS_LITE_NOT_SUPPORT | MindSpore Lite not supported. |
| OH_AI_STATUS_LITE_THREADPOOL_ERROR | MindSpore Lite thread pool error. |
| OH_AI_STATUS_LITE_UNINITIALIZED_OBJ | MindSpore Lite uninitialized. |
| OH_AI_STATUS_LITE_OUT_OF_TENSOR_RANGE | MindSpore Lite tensor overflow. |
| OH_AI_STATUS_LITE_INPUT_TENSOR_ERROR | MindSpore Lite input tensor error. |
| OH_AI_STATUS_LITE_REENTRANT_ERROR | MindSpore Lite reentry error. |
| OH_AI_STATUS_LITE_GRAPH_FILE_ERROR | MindSpore Lite file error. |
| OH_AI_STATUS_LITE_NOT_FIND_OP | MindSpore Lite operator not found. |
| OH_AI_STATUS_LITE_INVALID_OP_NAME | MindSpore Lite invalid operators. |
| OH_AI_STATUS_LITE_INVALID_OP_ATTR | MindSpore Lite invalid operator hyperparameters. |
| OH_AI_STATUS_LITE_OP_EXECUTE_FAILURE | MindSpore Lite operator execution failure. |
| OH_AI_STATUS_LITE_FORMAT_ERROR | MindSpore Lite tensor format error. |
| OH_AI_STATUS_LITE_INFER_ERROR | MindSpore Lite shape inference error. |
| OH_AI_STATUS_LITE_INFER_INVALID | MindSpore Lite invalid shape inference. |
| OH_AI_STATUS_LITE_INPUT_PARAM_INVALID | MindSpore Lite invalid input parameters.|
## Function Description ## Function Description
### OH_AI_ContextAddDeviceInfo() ### OH_AI_ContextAddDeviceInfo()
``` ```
OH_AI_API void OH_AI_ContextAddDeviceInfo (OH_AI_ContextHandle context, OH_AI_DeviceInfoHandle device_info ) OH_AI_API void OH_AI_ContextAddDeviceInfo (OH_AI_ContextHandle context, OH_AI_DeviceInfoHandle device_info )
``` ```
**Description**<br>
Adds information about a running device.
**Parameters** **Description**
| Name | Description | Attaches the custom device information to the inference context.
| -------- | -------- |
| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance. | **Parameters**
| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance. |
| Name | Description |
| ----------- | ------------------------------------------------------------ |
| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.|
| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
### OH_AI_ContextCreate() ### OH_AI_ContextCreate()
``` ```
OH_AI_API OH_AI_ContextHandle OH_AI_ContextCreate () OH_AI_API OH_AI_ContextHandle OH_AI_ContextCreate ()
``` ```
**Description**<br>
**Description**
Creates a context object. Creates a context object.
**Returns** **Returns**
[OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context. [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.
### OH_AI_ContextDestroy() ### OH_AI_ContextDestroy()
``` ```
OH_AI_API void OH_AI_ContextDestroy (OH_AI_ContextHandle * context) OH_AI_API void OH_AI_ContextDestroy (OH_AI_ContextHandle * context)
``` ```
**Description**<br>
**Description**
Destroys a context object. Destroys a context object.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ------- | ------------------------------------------------------------ |
| context | Level-2 pointer to [OH_AI_ContextHandle](#oh_ai_contexthandle). After the context is destroyed, the pointer is set to null. | | context | Level-2 pointer to [OH_AI_ContextHandle](#oh_ai_contexthandle). After the context is destroyed, the pointer is set to null. |
### OH_AI_ContextGetEnableParallel() ### OH_AI_ContextGetEnableParallel()
``` ```
OH_AI_API bool OH_AI_ContextGetEnableParallel (const OH_AI_ContextHandle context) OH_AI_API bool OH_AI_ContextGetEnableParallel (const OH_AI_ContextHandle context)
``` ```
**Description**<br>
**Description**
Checks whether parallelism between operators is supported. Checks whether parallelism between operators is supported.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ------- | ------------------------------------------------------------ |
| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance. | | context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.|
**Returns** **Returns**
...@@ -488,59 +688,65 @@ Whether parallelism between operators is supported. The value **true** means tha ...@@ -488,59 +688,65 @@ Whether parallelism between operators is supported. The value **true** means tha
### OH_AI_ContextGetThreadAffinityCoreList() ### OH_AI_ContextGetThreadAffinityCoreList()
``` ```
OH_AI_API const int32_t* OH_AI_ContextGetThreadAffinityCoreList (const OH_AI_ContextHandle context, size_t * core_num ) OH_AI_API const int32_t* OH_AI_ContextGetThreadAffinityCoreList (const OH_AI_ContextHandle context, size_t * core_num )
``` ```
**Description**<br>
**Description**
Obtains the list of bound CPU cores. Obtains the list of bound CPU cores.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | -------- | ------------------------------------------------------------ |
| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance. | | context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.|
| core_num | Number of CPU cores. | | core_num | Number of CPU cores. |
**Returns** **Returns**
List of bound CPU cores. Specifies the CPU core binding list. This list is managed by [OH_AI_ContextHandle](#oh_ai_contexthandle). The caller does not need to destroy it manually.
### OH_AI_ContextGetThreadAffinityMode() ### OH_AI_ContextGetThreadAffinityMode()
``` ```
OH_AI_API int OH_AI_ContextGetThreadAffinityMode (const OH_AI_ContextHandle context) OH_AI_API int OH_AI_ContextGetThreadAffinityMode (const OH_AI_ContextHandle context)
``` ```
**Description**<br>
**Description**
Obtains the affinity mode for binding runtime threads to CPU cores. Obtains the affinity mode for binding runtime threads to CPU cores.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ------- | ------------------------------------------------------------ |
| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance. | | context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.|
**Returns** **Returns**
Affinity mode. **0**: no affinities; **1**: big cores first; **2**: little cores first Affinity mode. **0**: no affinities; **1**: big cores first; **2**: medium cores first
### OH_AI_ContextGetThreadNum() ### OH_AI_ContextGetThreadNum()
``` ```
OH_AI_API int32_t OH_AI_ContextGetThreadNum (const OH_AI_ContextHandle context) OH_AI_API int32_t OH_AI_ContextGetThreadNum (const OH_AI_ContextHandle context)
``` ```
**Description**<br>
**Description**
Obtains the number of threads. Obtains the number of threads.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ------- | ------------------------------------------------------------ |
| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance. | | context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.|
**Returns** **Returns**
...@@ -549,125 +755,239 @@ Number of threads. ...@@ -549,125 +755,239 @@ Number of threads.
### OH_AI_ContextSetEnableParallel() ### OH_AI_ContextSetEnableParallel()
``` ```
OH_AI_API void OH_AI_ContextSetEnableParallel (OH_AI_ContextHandle context, bool is_parallel ) OH_AI_API void OH_AI_ContextSetEnableParallel (OH_AI_ContextHandle context, bool is_parallel )
``` ```
**Description**<br>
Sets whether to enable parallelism between operators.
**Parameters** **Description**
Sets whether to enable parallelism between operators. The setting is ineffective because the feature of this API is not yet available.
| Name | Description | **Parameters**
| -------- | -------- |
| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance. | | Name | Description |
| is_parallel | Whether to enable parallelism between operators. The value **true** means to enable parallelism between operators, and the value **false** means the opposite. | | ----------- | ------------------------------------------------------------ |
| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.|
| is_parallel | Whether parallelism between operators is supported. The value **true** means that parallelism between operators is supported, and the value **false** means the opposite. |
### OH_AI_ContextSetThreadAffinityCoreList() ### OH_AI_ContextSetThreadAffinityCoreList()
``` ```
OH_AI_API void OH_AI_ContextSetThreadAffinityCoreList (OH_AI_ContextHandle context, const int32_t * core_list, size_t core_num ) OH_AI_API void OH_AI_ContextSetThreadAffinityCoreList (OH_AI_ContextHandle context, const int32_t * core_list, size_t core_num )
``` ```
**Description**<br>
**Description**
Sets the list of CPU cores bound to a runtime thread. Sets the list of CPU cores bound to a runtime thread.
For example, if **core_list** is set to **[2,6,8]**, threads run on the 2nd, 6th, and 8th CPU cores. If [OH_AI_ContextSetThreadAffinityMode](#oh_ai_contextsetthreadaffinitymode) and [OH_AI_ContextSetThreadAffinityCoreList](#oh_ai_contextsetthreadaffinitycorelist) are called for the same context object, the **core_list** parameter of [OH_AI_ContextSetThreadAffinityCoreList](#oh_ai_contextsetthreadaffinitycorelist) takes effect, but the **mode** parameter of [OH_AI_ContextSetThreadAffinityMode](#oh_ai_contextsetthreadaffinitymode) does not. For example, if **core_list** is set to **[2,6,8]**, threads run on the 2nd, 6th, and 8th CPU cores. If [OH_AI_ContextSetThreadAffinityMode](#oh_ai_contextsetthreadaffinitymode) and [OH_AI_ContextSetThreadAffinityCoreList](#oh_ai_contextsetthreadaffinitycorelist) are called for the same context object, the **core_list** parameter of [OH_AI_ContextSetThreadAffinityCoreList](#oh_ai_contextsetthreadaffinitycorelist) takes effect, but the **mode** parameter of [OH_AI_ContextSetThreadAffinityMode](#oh_ai_contextsetthreadaffinitymode) does not.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | --------- | ------------------------------------------------------------ |
| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance. | | context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.|
| core_list | List of bound CPU cores. | | core_list | List of bound CPU cores. |
| core_num | Number of cores, which indicates the length of **core_list**. | | core_num | Number of cores, which indicates the length of **core_list**. |
### OH_AI_ContextSetThreadAffinityMode() ### OH_AI_ContextSetThreadAffinityMode()
``` ```
OH_AI_API void OH_AI_ContextSetThreadAffinityMode (OH_AI_ContextHandle context, int mode ) OH_AI_API void OH_AI_ContextSetThreadAffinityMode (OH_AI_ContextHandle context, int mode )
``` ```
**Description**<br>
Sets the affinity mode for binding runtime threads to CPU cores, which are categorized into little cores and big cores depending on the CPU frequency.
**Parameters** **Description**
Sets the affinity mode for binding runtime threads to CPU cores, which are classified into large, medium, and small cores based on the CPU frequency. You only need to bind the large or medium cores, but not small cores.
**Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ------- | ------------------------------------------------------------ |
| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance. | | context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.|
| mode | Affinity mode. **0**: no affinities; **1**: big cores first; **2**: little cores first | | mode | Affinity mode. **0**: no affinities; **1**: big cores first; **2**: medium cores first|
### OH_AI_ContextSetThreadNum() ### OH_AI_ContextSetThreadNum()
``` ```
OH_AI_API void OH_AI_ContextSetThreadNum (OH_AI_ContextHandle context, int32_t thread_num ) OH_AI_API void OH_AI_ContextSetThreadNum (OH_AI_ContextHandle context, int32_t thread_num )
``` ```
**Description**<br>
**Description**
Sets the number of runtime threads. Sets the number of runtime threads.
**Parameters** **Parameters**
| Name | Description |
| ---------- | ------------------------------------------------------------ |
| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance.|
| thread_num | Number of runtime threads. |
### OH_AI_CreateNNRTDeviceInfoByName()
```
OH_AI_API OH_AI_DeviceInfoHandle OH_AI_CreateNNRTDeviceInfoByName (const char * name)
```
**Description**
Searches for the NNRt device with the specified name and creates the NNRt device information based on the information about the first found NNRt device.
**Parameters**
| Name| Description |
| ---- | ---------------- |
| name | Name of the NNRt device.|
**Returns**
[OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.
**Since**
10
### OH_AI_CreateNNRTDeviceInfoByType()
```
OH_AI_API OH_AI_DeviceInfoHandle OH_AI_CreateNNRTDeviceInfoByType (OH_AI_NNRTDeviceType type)
```
**Description**
Searches for the NNRt device with the specified type and creates the NNRt device information based on the information about the first found NNRt device.
**Parameters**
| Name| Description |
| ---- | ------------------------------------------------------------ |
| type | NNRt device type, which is specified by [OH_AI_NNRTDeviceType](#oh_ai_nnrtdevicetype).|
**Returns**
[OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.
**Since**
10
### OH_AI_DestroyAllNNRTDeviceDescs()
```
OH_AI_API void OH_AI_DestroyAllNNRTDeviceDescs (NNRTDeviceDesc ** desc)
```
**Description**
Destroys the array of NNRT descriptions obtained by [OH_AI_GetAllNNRTDeviceDescs](#oh_ai_getallnnrtdevicedescs).
**Parameters**
| Name | Description | | Name| Description |
| -------- | -------- | | ---- | ------------------------------------------------------------ |
| context | [OH_AI_ContextHandle](#oh_ai_contexthandle) that points to the context instance. | | desc | Double pointer to the array of the NNRt device descriptions. After the operation is complete, the content pointed to by **desc** is set to **NULL**.|
| thread_num | Number of runtime threads. |
**Since**
10
### OH_AI_DeviceInfoCreate() ### OH_AI_DeviceInfoCreate()
``` ```
OH_AI_API OH_AI_DeviceInfoHandle OH_AI_DeviceInfoCreate (OH_AI_DeviceType device_type) OH_AI_API OH_AI_DeviceInfoHandle OH_AI_DeviceInfoCreate (OH_AI_DeviceType device_type)
``` ```
**Description**<br>
**Description**
Creates a device information object. Creates a device information object.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ----------- | ------------------------------------------------------- |
| device_type | Device type. For details, see [OH_AI_DeviceType](#oh_ai_devicetype). | | device_type | Device type, which is specified by [OH_AI_DeviceType](#oh_ai_devicetype).|
**Returns** **Returns**
[OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to the device information instance. [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.
### OH_AI_DeviceInfoDestroy() ### OH_AI_DeviceInfoDestroy()
``` ```
OH_AI_API void OH_AI_DeviceInfoDestroy (OH_AI_DeviceInfoHandle * device_info) OH_AI_API void OH_AI_DeviceInfoDestroy (OH_AI_DeviceInfoHandle * device_info)
``` ```
**Description**<br>
Destroys a device information instance.
**Parameters** **Description**
Destroys a device information object. Note: After the device information instance is added to the context, the caller does not need to destroy it manually.
**Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ----------- | ------------------------------------------------------------ |
| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance. | | device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
### OH_AI_DeviceInfoGetDeviceId()
```
OH_AI_API size_t OH_AI_DeviceInfoGetDeviceId (const OH_AI_DeviceInfoHandle device_info)
```
**Description**
Obtains the ID of an NNRt device. This API is available only for NNRt devices.
**Parameters**
| Name | Description |
| ----------- | ------------------------------------------------------------ |
| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
**Returns**
NNRt device ID.
**Since**
10
### OH_AI_DeviceInfoGetDeviceType() ### OH_AI_DeviceInfoGetDeviceType()
``` ```
OH_AI_API OH_AI_DeviceType OH_AI_DeviceInfoGetDeviceType (const OH_AI_DeviceInfoHandle device_info) OH_AI_API OH_AI_DeviceType OH_AI_DeviceInfoGetDeviceType (const OH_AI_DeviceInfoHandle device_info)
``` ```
**Description**<br>
Obtains the type of a provider device.
**Parameters** **Description**
Obtains the device type.
| Name | Description | **Parameters**
| -------- | -------- |
| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance. | | Name | Description |
| ----------- | ------------------------------------------------------------ |
| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
**Returns** **Returns**
...@@ -676,18 +996,20 @@ Type of the provider device. ...@@ -676,18 +996,20 @@ Type of the provider device.
### OH_AI_DeviceInfoGetEnableFP16() ### OH_AI_DeviceInfoGetEnableFP16()
``` ```
OH_AI_API bool OH_AI_DeviceInfoGetEnableFP16 (const OH_AI_DeviceInfoHandle device_info) OH_AI_API bool OH_AI_DeviceInfoGetEnableFP16 (const OH_AI_DeviceInfoHandle device_info)
``` ```
**Description**<br>
Checks whether float16 inference is enabled. This function is available only for CPU/GPU devices.
**Parameters** **Description**
Checks whether float16 inference is enabled. This function is available only for CPU and GPU devices.
**Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ----------- | ------------------------------------------------------------ |
| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance. | | device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
**Returns** **Returns**
...@@ -696,38 +1018,94 @@ Whether float16 inference is enabled. ...@@ -696,38 +1018,94 @@ Whether float16 inference is enabled.
### OH_AI_DeviceInfoGetFrequency() ### OH_AI_DeviceInfoGetFrequency()
``` ```
OH_AI_API int OH_AI_DeviceInfoGetFrequency (const OH_AI_DeviceInfoHandle device_info) OH_AI_API int OH_AI_DeviceInfoGetFrequency (const OH_AI_DeviceInfoHandle device_info)
``` ```
**Description**<br>
Obtains the NPU frequency type. This function is available only for NPU devices.
**Parameters** **Description**
Obtains the NPU frequency type. This API is available only for NPU devices.
**Parameters**
| Name | Description |
| ----------- | ------------------------------------------------------------ |
| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
**Returns**
NPU frequency type. The value ranges from **0** to **4**. **1**: low power consumption; **2**: balanced; **3**: high performance; **4**: ultra-high performance
### OH_AI_DeviceInfoGetPerformanceMode()
```
OH_AI_API OH_AI_PerformanceMode OH_AI_DeviceInfoGetPerformanceMode (const OH_AI_DeviceInfoHandle device_info)
```
**Description**
Obtains the performance mode of an NNRt device. This API is available only for NNRt devices.
**Parameters**
| Name | Description |
| ----------- | ------------------------------------------------------------ |
| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
**Returns**
NNRt performance mode, which is specified by [OH_AI_PerformanceMode](#oh_ai_performancemode).
**Since**
10
### OH_AI_DeviceInfoGetPriority()
```
OH_AI_API OH_AI_Priority OH_AI_DeviceInfoGetPriority (const OH_AI_DeviceInfoHandle device_info)
```
**Description**
| Name | Description | Obtains the priority of an NNRT task. This API is available only for NNRt devices.
| -------- | -------- |
| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance. | **Parameters**
| Name | Description |
| ----------- | ------------------------------------------------------------ |
| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
**Returns** **Returns**
Frequency type of the NPU. The value ranges from **0** to **4**. **1**: low power consumption; **2**: balanced; **3**: high performance; **4**: ultra-high performance NNRt task priority, which is specified by [OH_AI_Priority](#oh_ai_priority).
**Since**
10
### OH_AI_DeviceInfoGetProvider() ### OH_AI_DeviceInfoGetProvider()
``` ```
OH_AI_API const char* OH_AI_DeviceInfoGetProvider (const OH_AI_DeviceInfoHandle device_info) OH_AI_API const char* OH_AI_DeviceInfoGetProvider (const OH_AI_DeviceInfoHandle device_info)
``` ```
**Description**<br>
**Description**
Obtains the provider name. Obtains the provider name.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ----------- | ------------------------------------------------------------ |
| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance. | | device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
**Returns** **Returns**
...@@ -736,150 +1114,339 @@ Provider name. ...@@ -736,150 +1114,339 @@ Provider name.
### OH_AI_DeviceInfoGetProviderDevice() ### OH_AI_DeviceInfoGetProviderDevice()
``` ```
OH_AI_API const char* OH_AI_DeviceInfoGetProviderDevice (const OH_AI_DeviceInfoHandle device_info) OH_AI_API const char* OH_AI_DeviceInfoGetProviderDevice (const OH_AI_DeviceInfoHandle device_info)
``` ```
**Description**<br>
**Description**
Obtains the name of a provider device. Obtains the name of a provider device.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ----------- | ------------------------------------------------------------ |
| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance. | | device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
**Returns** **Returns**
Name of the provider device. Name of the provider device.
### OH_AI_DeviceInfoSetDeviceId()
```
OH_AI_API void OH_AI_DeviceInfoSetDeviceId (OH_AI_DeviceInfoHandle device_info, size_t device_id )
```
**Description**
Sets the ID of an NNRt device. This API is available only for NNRt devices.
**Parameters**
| Name | Description |
| ----------- | ------------------------------------------------------------ |
| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
| device_id | NNRt device ID. |
**Since**
10
### OH_AI_DeviceInfoSetEnableFP16() ### OH_AI_DeviceInfoSetEnableFP16()
``` ```
OH_AI_API void OH_AI_DeviceInfoSetEnableFP16 (OH_AI_DeviceInfoHandle device_info, bool is_fp16 ) OH_AI_API void OH_AI_DeviceInfoSetEnableFP16 (OH_AI_DeviceInfoHandle device_info, bool is_fp16 )
``` ```
**Description**<br>
Sets whether to enable float16 inference. This function is available only for CPU/GPU devices.
**Parameters** **Description**
Sets whether to enable float16 inference. This function is available only for CPU and GPU devices.
**Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ----------- | ------------------------------------------------------------ |
| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance. | | device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
| is_fp16 | Whether to enable float16 inference. | | is_fp16 | Whether to enable the float16 inference mode. |
### OH_AI_DeviceInfoSetFrequency() ### OH_AI_DeviceInfoSetFrequency()
``` ```
OH_AI_API void OH_AI_DeviceInfoSetFrequency (OH_AI_DeviceInfoHandle device_info, int frequency ) OH_AI_API void OH_AI_DeviceInfoSetFrequency (OH_AI_DeviceInfoHandle device_info, int frequency )
``` ```
**Description**<br>
**Description**
Sets the NPU frequency type. This function is available only for NPU devices. Sets the NPU frequency type. This function is available only for NPU devices.
**Parameters** **Parameters**
| Name | Description |
| ----------- | ------------------------------------------------------------ |
| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
| frequency | NPU frequency type. The value ranges from **0** to **4**. The default value is **3**. **1**: low power consumption; **2**: balanced; **3**: high performance; **4**: ultra-high performance|
### OH_AI_DeviceInfoSetPerformanceMode()
```
OH_AI_API void OH_AI_DeviceInfoSetPerformanceMode (OH_AI_DeviceInfoHandle device_info, OH_AI_PerformanceMode mode )
```
**Description**
Sets the performance mode of an NNRt device. This API is available only for NNRt devices.
**Parameters**
| Name | Description |
| ----------- | ------------------------------------------------------------ |
| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
| mode | NNRt performance mode, which is specified by [OH_AI_PerformanceMode](#oh_ai_performancemode).|
**Since**
| Name | Description | 10
| -------- | -------- |
| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance. |
| frequency | NPU frequency type. The value ranges from **0** to **4**. The default value is **3**. **1**: low power consumption; **2**: balanced; **3**: high performance; **4**: ultra-high performance | ### OH_AI_DeviceInfoSetPriority()
```
OH_AI_API void OH_AI_DeviceInfoSetPriority (OH_AI_DeviceInfoHandle device_info, OH_AI_Priority priority )
```
**Description**
Sets the priority of an NNRt task. This API is available only for NNRt devices.
**Parameters**
| Name | Description |
| ----------- | ------------------------------------------------------------ |
| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
| priority | NNRt task priority, which is specified by [OH_AI_Priority](#oh_ai_priority). |
**Since**
10
### OH_AI_DeviceInfoSetProvider() ### OH_AI_DeviceInfoSetProvider()
``` ```
OH_AI_API void OH_AI_DeviceInfoSetProvider (OH_AI_DeviceInfoHandle device_info, const char * provider ) OH_AI_API void OH_AI_DeviceInfoSetProvider (OH_AI_DeviceInfoHandle device_info, const char * provider )
``` ```
**Description**<br>
Sets the name of a provider.
**Parameters** **Description**
Sets the provider name.
| Name | Description | **Parameters**
| -------- | -------- |
| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance. | | Name | Description |
| provider | Provider name. | | ----------- | ------------------------------------------------------------ |
| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
| provider | Provider name. |
### OH_AI_DeviceInfoSetProviderDevice() ### OH_AI_DeviceInfoSetProviderDevice()
``` ```
OH_AI_API void OH_AI_DeviceInfoSetProviderDevice (OH_AI_DeviceInfoHandle device_info, const char * device ) OH_AI_API void OH_AI_DeviceInfoSetProviderDevice (OH_AI_DeviceInfoHandle device_info, const char * device )
``` ```
**Description**<br>
**Description**
Sets the name of a provider device. Sets the name of a provider device.
**Parameters** **Parameters**
| Name | Description |
| ----------- | ------------------------------------------------------------ |
| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance.|
| device | Name of the provider device, for example, CPU. |
### OH_AI_GetAllNNRTDeviceDescs()
```
OH_AI_API NNRTDeviceDesc* OH_AI_GetAllNNRTDeviceDescs (size_t * num)
```
**Description**
Obtains the descriptions of all NNRt devices in the system.
**Parameters**
| Name| Description |
| ---- | ------------------------ |
| num | Number of NNRt devices.|
**Returns**
Pointer to the array of the NNRt device descriptions. If the operation fails, **NULL** is returned.
**Since**
10
### OH_AI_GetDeviceIdFromNNRTDeviceDesc()
```
OH_AI_API size_t OH_AI_GetDeviceIdFromNNRTDeviceDesc (const NNRTDeviceDesc * desc)
```
**Description**
Obtains the NNRt device ID from the specified NNRt device description. Note that this ID is valid only for NNRt devices.
**Parameters**
| Name | Description | | Name| Description |
| -------- | -------- | | ---- | -------------------------------- |
| device_info | [OH_AI_DeviceInfoHandle](#oh_ai_deviceinfohandle) that points to a device information instance. | | desc | Pointer to the NNRt device description.|
| device | Name of the provider device, for example, CPU. |
**Returns**
NNRt device ID.
**Since**
10
### OH_AI_GetNameFromNNRTDeviceDesc()
```
OH_AI_API const char* OH_AI_GetNameFromNNRTDeviceDesc (const NNRTDeviceDesc * desc)
```
**Description**
Obtains the NNRt device name from the specified NNRt device description.
**Parameters**
| Name| Description |
| ---- | -------------------------------- |
| desc | Pointer to the NNRt device description.|
**Returns**
NNRt device name. The value is a pointer that points to a constant string, which is held by **desc**. The caller does not need to destroy it separately.
**Since**
10
### OH_AI_GetTypeFromNNRTDeviceDesc()
```
OH_AI_API OH_AI_NNRTDeviceType OH_AI_GetTypeFromNNRTDeviceDesc (const NNRTDeviceDesc * desc)
```
**Description**
Obtains the NNRt device type from the specified NNRt device description.
**Parameters**
| Name| Description |
| ---- | -------------------------------- |
| desc | Pointer to the NNRt device description.|
**Returns**
NNRt device type, which is specified by [OH_AI_NNRTDeviceType](#oh_ai_nnrtdevicetype).
**Since**
10
### OH_AI_ModelBuild() ### OH_AI_ModelBuild()
``` ```
OH_AI_API OH_AI_Status OH_AI_ModelBuild (OH_AI_ModelHandle model, const void * model_data, size_t data_size, OH_AI_ModelType model_type, const OH_AI_ContextHandle model_context ) OH_AI_API OH_AI_Status OH_AI_ModelBuild (OH_AI_ModelHandle model, const void * model_data, size_t data_size, OH_AI_ModelType model_type, const OH_AI_ContextHandle model_context )
``` ```
**Description**<br>
**Description**
Loads and builds a MindSpore model from the memory buffer. Loads and builds a MindSpore model from the memory buffer.
Note that the same {\@Link OH_AI_ContextHandle} object can only be passed to {\@Link OH_AI_ModelBuild} or {\@Link OH_AI_ModelBuildFromFile} once. If you call this function multiple times, make sure that you create multiple {\@Link OH_AI_ContextHandle} objects accordingly. Note that the same {\@Link OH_AI_ContextHandle} object can only be passed to {\@Link OH_AI_ModelBuild} or {\@Link OH_AI_ModelBuildFromFile} once. If you call this function multiple times, make sure that you create multiple {\@Link OH_AI_ContextHandle} objects accordingly.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ------------- | ------------------------------------------------------------ |
| model | Pointer to the model object. | | model | Pointer to the model object. |
| model_data | Address of the loaded model data in the memory. | | model_data | Address of the loaded model data in the memory. |
| data_size | Length of the model data. | | data_size | Length of the model data. |
| model_type | Type of the model file. For details, see [OH_AI_ModelType](#oh_ai_modeltype). | | model_type | Model file type, which is specified by [OH_AI_ModelType](#oh_ai_modeltype). |
| model_context | Context for model running. For details, see [OH_AI_ContextHandle](#oh_ai_contexthandle). | | model_context | Model runtime context, which is specified by [OH_AI_ContextHandle](#oh_ai_contexthandle).|
**Returns** **Returns**
Status code enumerated by [OH_AI_Status](#oh_ai_status). The value **MSStatus::kMSStatusSuccess** indicates that the operation is successful. Status code enumerated by [OH_AI_Status](#oh_ai_status-1). The value **MSStatus::kMSStatusSuccess** indicates that the operation is successful.
### OH_AI_ModelBuildFromFile() ### OH_AI_ModelBuildFromFile()
``` ```
OH_AI_API OH_AI_Status OH_AI_ModelBuildFromFile (OH_AI_ModelHandle model, const char * model_path, OH_AI_ModelType model_type, const OH_AI_ContextHandle model_context ) OH_AI_API OH_AI_Status OH_AI_ModelBuildFromFile (OH_AI_ModelHandle model, const char * model_path, OH_AI_ModelType model_type, const OH_AI_ContextHandle model_context )
``` ```
**Description**<br>
**Description**
Loads and builds a MindSpore model from a model file. Loads and builds a MindSpore model from a model file.
Note that the same {\@Link OH_AI_ContextHandle} object can only be passed to {\@Link OH_AI_ModelBuild} or {\@Link OH_AI_ModelBuildFromFile} once. If you call this function multiple times, make sure that you create multiple {\@Link OH_AI_ContextHandle} objects accordingly. Note that the same {\@Link OH_AI_ContextHandle} object can only be passed to {\@Link OH_AI_ModelBuild} or {\@Link OH_AI_ModelBuildFromFile} once. If you call this function multiple times, make sure that you create multiple {\@Link OH_AI_ContextHandle} objects accordingly.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ------------- | ------------------------------------------------------------ |
| model | Pointer to the model object. | | model | Pointer to the model object. |
| model_path | Path of the model file. | | model_path | Path of the model file. |
| model_type | Type of the model file. For details, see [OH_AI_ModelType](#oh_ai_modeltype). | | model_type | Model file type, which is specified by [OH_AI_ModelType](#oh_ai_modeltype). |
| model_context | Context for model running. For details, see [OH_AI_ContextHandle](#oh_ai_contexthandle). | | model_context | Model runtime context, which is specified by [OH_AI_ContextHandle](#oh_ai_contexthandle).|
**Returns** **Returns**
Status code enumerated by [OH_AI_Status](#oh_ai_status). The value **MSStatus::kMSStatusSuccess** indicates that the operation is successful. Status code enumerated by [OH_AI_Status](#oh_ai_status-1). The value **MSStatus::kMSStatusSuccess** indicates that the operation is successful.
### OH_AI_ModelCreate() ### OH_AI_ModelCreate()
``` ```
OH_AI_API OH_AI_ModelHandle OH_AI_ModelCreate () OH_AI_API OH_AI_ModelHandle OH_AI_ModelCreate ()
``` ```
**Description**<br>
**Description**
Creates a model object. Creates a model object.
**Returns** **Returns**
...@@ -889,35 +1456,39 @@ Pointer to the model object. ...@@ -889,35 +1456,39 @@ Pointer to the model object.
### OH_AI_ModelDestroy() ### OH_AI_ModelDestroy()
``` ```
OH_AI_API void OH_AI_ModelDestroy (OH_AI_ModelHandle * model) OH_AI_API void OH_AI_ModelDestroy (OH_AI_ModelHandle * model)
``` ```
**Description**<br>
**Description**
Destroys a model object. Destroys a model object.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ----- | -------------- |
| model | Pointer to the model object. | | model | Pointer to the model object.|
### OH_AI_ModelGetInputByTensorName() ### OH_AI_ModelGetInputByTensorName()
``` ```
OH_AI_API OH_AI_TensorHandle OH_AI_ModelGetInputByTensorName (const OH_AI_ModelHandle model, const char * tensor_name ) OH_AI_API OH_AI_TensorHandle OH_AI_ModelGetInputByTensorName (const OH_AI_ModelHandle model, const char * tensor_name )
``` ```
**Description**<br>
**Description**
Obtains the input tensor of a model by tensor name. Obtains the input tensor of a model by tensor name.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ----------- | -------------- |
| model | Pointer to the model object. | | model | Pointer to the model object.|
| tensor_name | Tensor name. | | tensor_name | Tensor name. |
**Returns** **Returns**
...@@ -926,18 +1497,20 @@ Pointer to the input tensor indicated by **tensor_name**. If the tensor does not ...@@ -926,18 +1497,20 @@ Pointer to the input tensor indicated by **tensor_name**. If the tensor does not
### OH_AI_ModelGetInputs() ### OH_AI_ModelGetInputs()
``` ```
OH_AI_API OH_AI_TensorHandleArray OH_AI_ModelGetInputs (const OH_AI_ModelHandle model) OH_AI_API OH_AI_TensorHandleArray OH_AI_ModelGetInputs (const OH_AI_ModelHandle model)
``` ```
**Description**<br>
**Description**
Obtains the input tensor array structure of a model. Obtains the input tensor array structure of a model.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ----- | -------------- |
| model | Pointer to the model object. | | model | Pointer to the model object.|
**Returns** **Returns**
...@@ -946,39 +1519,43 @@ Tensor array structure corresponding to the model input. ...@@ -946,39 +1519,43 @@ Tensor array structure corresponding to the model input.
### OH_AI_ModelGetOutputByTensorName() ### OH_AI_ModelGetOutputByTensorName()
``` ```
OH_AI_API OH_AI_TensorHandle OH_AI_ModelGetOutputByTensorName (const OH_AI_ModelHandle model, const char * tensor_name ) OH_AI_API OH_AI_TensorHandle OH_AI_ModelGetOutputByTensorName (const OH_AI_ModelHandle model, const char * tensor_name )
``` ```
**Description**<br>
**Description**
Obtains the output tensor of a model by tensor name. Obtains the output tensor of a model by tensor name.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ----------- | -------------- |
| model | Pointer to the model object. | | model | Pointer to the model object.|
| tensor_name | Tensor name. | | tensor_name | Tensor name. |
**Returns** **Returns**
Pointer to the output tensor indicated by **tensor_name**. If the tensor does not exist in the input, **null** will be returned. Pointer to the input tensor indicated by **tensor_name**. If the tensor does not exist, **null** will be returned.
### OH_AI_ModelGetOutputs() ### OH_AI_ModelGetOutputs()
``` ```
OH_AI_API OH_AI_TensorHandleArray OH_AI_ModelGetOutputs (const OH_AI_ModelHandle model) OH_AI_API OH_AI_TensorHandleArray OH_AI_ModelGetOutputs (const OH_AI_ModelHandle model)
``` ```
**Description**<br>
**Description**
Obtains the output tensor array structure of a model. Obtains the output tensor array structure of a model.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ----- | -------------- |
| model | Pointer to the model object. | | model | Pointer to the model object.|
**Returns** **Returns**
...@@ -987,126 +1564,138 @@ Tensor array structure corresponding to the model output. ...@@ -987,126 +1564,138 @@ Tensor array structure corresponding to the model output.
### OH_AI_ModelPredict() ### OH_AI_ModelPredict()
``` ```
OH_AI_API OH_AI_Status OH_AI_ModelPredict (OH_AI_ModelHandle model, const OH_AI_TensorHandleArray inputs, OH_AI_TensorHandleArray * outputs, const OH_AI_KernelCallBack before, const OH_AI_KernelCallBack after ) OH_AI_API OH_AI_Status OH_AI_ModelPredict (OH_AI_ModelHandle model, const OH_AI_TensorHandleArray inputs, OH_AI_TensorHandleArray * outputs, const OH_AI_KernelCallBack before, const OH_AI_KernelCallBack after )
``` ```
**Description**<br>
**Description**
Performs model inference. Performs model inference.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ------- | ------------------------------------ |
| model | Pointer to the model object. | | model | Pointer to the model object. |
| inputs | Tensor array structure corresponding to the model input. | | inputs | Tensor array structure corresponding to the model input. |
| outputs | Pointer to the tensor array structure corresponding to the model output. | | outputs | Pointer to the tensor array structure corresponding to the model output.|
| before | Callback function executed before model inference. | | before | Callback function executed before model inference. |
| after | Callback function executed after model inference. | | after | Callback function executed after model inference. |
**Returns** **Returns**
Status code enumerated by [OH_AI_Status](#oh_ai_status). The value **MSStatus::kMSStatusSuccess** indicates that the operation is successful. Status code enumerated by [OH_AI_Status](#oh_ai_status-1). The value **MSStatus::kMSStatusSuccess** indicates that the operation is successful.
### OH_AI_ModelResize() ### OH_AI_ModelResize()
``` ```
OH_AI_API OH_AI_Status OH_AI_ModelResize (OH_AI_ModelHandle model, const OH_AI_TensorHandleArray inputs, OH_AI_ShapeInfo * shape_infos, size_t shape_info_num ) OH_AI_API OH_AI_Status OH_AI_ModelResize (OH_AI_ModelHandle model, const OH_AI_TensorHandleArray inputs, OH_AI_ShapeInfo * shape_infos, size_t shape_info_num )
``` ```
**Description**<br>
**Description**
Adjusts the input tensor shapes of a built model. Adjusts the input tensor shapes of a built model.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | -------------- | ------------------------------------------------------------ |
| model | Pointer to the model object. | | model | Pointer to the model object. |
| inputs | Tensor array structure corresponding to the model input. | | inputs | Tensor array structure corresponding to the model input. |
| shape_infos | Input shape array, which consists of tensor shapes arranged in the model input sequence. The model adjusts the tensor shapes in sequence. | | shape_infos | Input shape information array, which consists of tensor shapes arranged in the model input sequence. The model adjusts the tensor shapes in sequence.|
| shape_info_num | Length of the input shape array. | | shape_info_num | Length of the shape information array. |
**Returns** **Returns**
Status code enumerated by [OH_AI_Status](#oh_ai_status). The value **MSStatus::kMSStatusSuccess** indicates that the operation is successful. Status code enumerated by [OH_AI_Status](#oh_ai_status-1). The value **MSStatus::kMSStatusSuccess** indicates that the operation is successful.
### OH_AI_TensorClone() ### OH_AI_TensorClone()
``` ```
OH_AI_API OH_AI_TensorHandle OH_AI_TensorClone (OH_AI_TensorHandle tensor) OH_AI_API OH_AI_TensorHandle OH_AI_TensorClone (OH_AI_TensorHandle tensor)
``` ```
**Description**<br>
**Description**
Clones a tensor. Clones a tensor.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ------ | ------------------ |
| tensor | Pointer to the tensor to clone. | | tensor | Pointer to the tensor to clone.|
**Returns** **Returns**
Handle of the new tensor object. Defines the handle of a tensor object.
### OH_AI_TensorCreate() ### OH_AI_TensorCreate()
``` ```
OH_AI_API OH_AI_TensorHandle OH_AI_TensorCreate (const char * name, OH_AI_DataType type, const int64_t * shape, size_t shape_num, const void * data, size_t data_len ) OH_AI_API OH_AI_TensorHandle OH_AI_TensorCreate (const char * name, OH_AI_DataType type, const int64_t * shape, size_t shape_num, const void * data, size_t data_len )
``` ```
**Description**<br>
**Description**
Creates a tensor object. Creates a tensor object.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | --------- | ------------------ |
| name | Tensor name. | | name | Tensor name. |
| type | Tensor data type. | | type | Tensor data type. |
| shape | Tensor dimension array. | | shape | Tensor dimension array. |
| shape_num | Length of the tensor dimension array. | | shape_num | Length of the tensor dimension array.|
| data | Data pointer. | | data | Data pointer. |
| data_len | Data length. | | data_len | Data length. |
**Returns** **Returns**
Handle of the tensor object. Defines the handle of a tensor object.
### OH_AI_TensorDestroy() ### OH_AI_TensorDestroy()
``` ```
OH_AI_API void OH_AI_TensorDestroy (OH_AI_TensorHandle * tensor) OH_AI_API void OH_AI_TensorDestroy (OH_AI_TensorHandle * tensor)
``` ```
**Description**<br>
**Description**
Destroys a tensor object. Destroys a tensor object.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ------ | ------------------------ |
| tensor | Level-2 pointer to the tensor handle. | | tensor | Level-2 pointer to the tensor handle.|
### OH_AI_TensorGetData() ### OH_AI_TensorGetData()
``` ```
OH_AI_API const void* OH_AI_TensorGetData (const OH_AI_TensorHandle tensor) OH_AI_API const void* OH_AI_TensorGetData (const OH_AI_TensorHandle tensor)
``` ```
**Description**<br>
**Description**
Obtains the pointer to tensor data. Obtains the pointer to tensor data.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ------ | -------------- |
| tensor | Handle of the tensor object. | | tensor | Handle of the tensor object.|
**Returns** **Returns**
...@@ -1115,18 +1704,20 @@ Pointer to tensor data. ...@@ -1115,18 +1704,20 @@ Pointer to tensor data.
### OH_AI_TensorGetDataSize() ### OH_AI_TensorGetDataSize()
``` ```
OH_AI_API size_t OH_AI_TensorGetDataSize (const OH_AI_TensorHandle tensor) OH_AI_API size_t OH_AI_TensorGetDataSize (const OH_AI_TensorHandle tensor)
``` ```
**Description**<br>
**Description**
Obtains the number of bytes of the tensor data. Obtains the number of bytes of the tensor data.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ------ | -------------- |
| tensor | Handle of the tensor object. | | tensor | Handle of the tensor object.|
**Returns** **Returns**
...@@ -1135,38 +1726,42 @@ Number of bytes of the tensor data. ...@@ -1135,38 +1726,42 @@ Number of bytes of the tensor data.
### OH_AI_TensorGetDataType() ### OH_AI_TensorGetDataType()
``` ```
OH_AI_API OH_AI_DataType OH_AI_TensorGetDataType (const OH_AI_TensorHandle tensor) OH_AI_API OH_AI_DataType OH_AI_TensorGetDataType (const OH_AI_TensorHandle tensor)
``` ```
**Description**<br>
Obtains the data type of a tensor.
**Parameters** **Description**
Obtains the tensor type.
| Name | Description | **Parameters**
| -------- | -------- |
| tensor | Handle of the tensor object. | | Name | Description |
| ------ | -------------- |
| tensor | Handle of the tensor object.|
**Returns** **Returns**
Data type of the tensor. Tensor data type.
### OH_AI_TensorGetElementNum() ### OH_AI_TensorGetElementNum()
``` ```
OH_AI_API int64_t OH_AI_TensorGetElementNum (const OH_AI_TensorHandle tensor) OH_AI_API int64_t OH_AI_TensorGetElementNum (const OH_AI_TensorHandle tensor)
``` ```
**Description**<br>
**Description**
Obtains the number of tensor elements. Obtains the number of tensor elements.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ------ | -------------- |
| tensor | Handle of the tensor object. | | tensor | Handle of the tensor object.|
**Returns** **Returns**
...@@ -1175,18 +1770,20 @@ Number of tensor elements. ...@@ -1175,18 +1770,20 @@ Number of tensor elements.
### OH_AI_TensorGetFormat() ### OH_AI_TensorGetFormat()
``` ```
OH_AI_API OH_AI_Format OH_AI_TensorGetFormat (const OH_AI_TensorHandle tensor) OH_AI_API OH_AI_Format OH_AI_TensorGetFormat (const OH_AI_TensorHandle tensor)
``` ```
**Description**<br>
**Description**
Obtains the tensor data format. Obtains the tensor data format.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ------ | -------------- |
| tensor | Handle of the tensor object. | | tensor | Handle of the tensor object.|
**Returns** **Returns**
...@@ -1195,38 +1792,42 @@ Tensor data format. ...@@ -1195,38 +1792,42 @@ Tensor data format.
### OH_AI_TensorGetMutableData() ### OH_AI_TensorGetMutableData()
``` ```
OH_AI_API void* OH_AI_TensorGetMutableData (const OH_AI_TensorHandle tensor) OH_AI_API void* OH_AI_TensorGetMutableData (const OH_AI_TensorHandle tensor)
``` ```
**Description**<br>
**Description**
Obtains the pointer to variable tensor data. If the data is empty, memory will be allocated. Obtains the pointer to variable tensor data. If the data is empty, memory will be allocated.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ------ | -------------- |
| tensor | Handle of the tensor object. | | tensor | Handle of the tensor object.|
**Returns** **Returns**
Pointer to variable tensor data. Pointer to tensor data.
### OH_AI_TensorGetName() ### OH_AI_TensorGetName()
``` ```
OH_AI_API const char* OH_AI_TensorGetName (const OH_AI_TensorHandle tensor) OH_AI_API const char* OH_AI_TensorGetName (const OH_AI_TensorHandle tensor)
``` ```
**Description**<br>
**Description**
Obtains the name of a tensor. Obtains the name of a tensor.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ------ | -------------- |
| tensor | Handle of the tensor object. | | tensor | Handle of the tensor object.|
**Returns** **Returns**
...@@ -1235,106 +1836,118 @@ Tensor name. ...@@ -1235,106 +1836,118 @@ Tensor name.
### OH_AI_TensorGetShape() ### OH_AI_TensorGetShape()
``` ```
OH_AI_API const int64_t* OH_AI_TensorGetShape (const OH_AI_TensorHandle tensor, size_t * shape_num ) OH_AI_API const int64_t* OH_AI_TensorGetShape (const OH_AI_TensorHandle tensor, size_t * shape_num )
``` ```
**Description**<br>
Obtains the shape of a tensor.
**Parameters** **Description**
| Name | Description | Obtains the tensor shape.
| -------- | -------- |
| tensor | Handle of the tensor object. | **Parameters**
| shape_num | Length of the tensor shape array. |
| Name | Description |
| --------- | ---------------------------------------------- |
| tensor | Handle of the tensor object. |
| shape_num | Length of the tensor shape array.|
**Returns** **Returns**
Tensor shape array. Shape array.
### OH_AI_TensorSetData() ### OH_AI_TensorSetData()
``` ```
OH_AI_API void OH_AI_TensorSetData (OH_AI_TensorHandle tensor, void * data ) OH_AI_API void OH_AI_TensorSetData (OH_AI_TensorHandle tensor, void * data )
``` ```
**Description**<br>
**Description**
Sets the tensor data. Sets the tensor data.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ------ | ---------------- |
| tensor | Handle of the tensor object. | | tensor | Handle of the tensor object. |
| data | Data pointer. | | data | Data pointer.|
### OH_AI_TensorSetDataType() ### OH_AI_TensorSetDataType()
``` ```
OH_AI_API void OH_AI_TensorSetDataType (OH_AI_TensorHandle tensor, OH_AI_DataType type ) OH_AI_API void OH_AI_TensorSetDataType (OH_AI_TensorHandle tensor, OH_AI_DataType type )
``` ```
**Description**<br>
Sets the data type of a tensor.
**Parameters** **Description**
Sets the tensor data type.
| Name | Description | **Parameters**
| -------- | -------- |
| tensor | Handle of the tensor object. | | Name | Description |
| type | Data type. For details, see [OH_AI_DataType](#oh_ai_datatype). | | ------ | --------------------------------------------------- |
| tensor | Handle of the tensor object. |
| type | Data type, which is specified by [OH_AI_DataType](#oh_ai_datatype).|
### OH_AI_TensorSetFormat() ### OH_AI_TensorSetFormat()
``` ```
OH_AI_API void OH_AI_TensorSetFormat (OH_AI_TensorHandle tensor, OH_AI_Format format ) OH_AI_API void OH_AI_TensorSetFormat (OH_AI_TensorHandle tensor, OH_AI_Format format )
``` ```
**Description**<br>
**Description**
Sets the tensor data format. Sets the tensor data format.
**Parameters** **Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ------ | ------------------ |
| tensor | Handle of the tensor object. | | tensor | Handle of the tensor object. |
| format | Tensor data format. | | format | Tensor data format.|
### OH_AI_TensorSetName() ### OH_AI_TensorSetName()
``` ```
OH_AI_API void OH_AI_TensorSetName (OH_AI_TensorHandle tensor, const char * name ) OH_AI_API void OH_AI_TensorSetName (OH_AI_TensorHandle tensor, const char *name )
``` ```
**Description**<br>
Sets the name of a tensor.
**Parameters** **Description**
Sets the tensor name.
**Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | ------ | -------------- |
| tensor | Handle of the tensor object. | | tensor | Handle of the tensor object.|
| name | Tensor name. | | name | Tensor name. |
### OH_AI_TensorSetShape() ### OH_AI_TensorSetShape()
``` ```
OH_AI_API void OH_AI_TensorSetShape (OH_AI_TensorHandle tensor, const int64_t * shape, size_t shape_num ) OH_AI_API void OH_AI_TensorSetShape (OH_AI_TensorHandle tensor, const int64_t * shape, size_t shape_num )
``` ```
**Description**<br>
Sets the shape of a tensor.
**Parameters** **Description**
Sets the tensor shape.
**Parameters**
| Name | Description | | Name | Description |
| -------- | -------- | | --------- | ------------------ |
| tensor | Handle of the tensor object. | | tensor | Handle of the tensor object. |
| shape | Tensor shape array. | | shape | Shape array. |
| shape_num | Length of the tensor shape array. | | shape_num | Length of the tensor shape array.|
...@@ -5,10 +5,11 @@ ...@@ -5,10 +5,11 @@
Provides **Context** APIs for configuring runtime information. Provides **Context** APIs for configuring runtime information.
**Since:** **Since**
9 9
**Related Modules:** **Related Modules**
[MindSpore](_mind_spore.md) [MindSpore](_mind_spore.md)
...@@ -18,35 +19,48 @@ Provides **Context** APIs for configuring runtime information. ...@@ -18,35 +19,48 @@ Provides **Context** APIs for configuring runtime information.
### Types ### Types
| Name | Description | | Name| Description|
| -------- | -------- | | -------- | -------- |
| [OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) | Defines the pointer to the MindSpore context. | | [OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) | Defines the pointer to the MindSpore context. |
| [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) | Defines the pointer to the MindSpore device information. | | [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) | Defines the pointer to the MindSpore device information.|
### Functions ### Functions
| Name | Description | | Name| Description|
| -------- | -------- | | -------- | -------- |
| [OH_AI_ContextCreate](_mind_spore.md#oh_ai_contextcreate) () | Creates a context object. | | [OH_AI_ContextCreate](_mind_spore.md#oh_ai_contextcreate) () | Creates a context object.|
| [OH_AI_ContextDestroy](_mind_spore.md#oh_ai_contextdestroy) ([OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) \*context) | Destroys a context object. | | [OH_AI_ContextDestroy](_mind_spore.md#oh_ai_contextdestroy) ([OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) \*context) | Destroys a context object.|
| [OH_AI_ContextSetThreadNum](_mind_spore.md#oh_ai_contextsetthreadnum) ([OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context, int32_t thread_num) | Sets the number of runtime threads. | | [OH_AI_ContextSetThreadNum](_mind_spore.md#oh_ai_contextsetthreadnum) ([OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context, int32_t thread_num) | Sets the number of runtime threads.|
| [OH_AI_ContextGetThreadNum](_mind_spore.md#oh_ai_contextgetthreadnum) (const [OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context) | Obtains the number of threads. | | [OH_AI_ContextGetThreadNum](_mind_spore.md#oh_ai_contextgetthreadnum) (const [OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context) | Obtains the number of threads.|
| [OH_AI_ContextSetThreadAffinityMode](_mind_spore.md#oh_ai_contextsetthreadaffinitymode) ([OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context, int mode) | Sets the affinity mode for binding runtime threads to CPU cores, which are categorized into little cores and big cores depending on the CPU frequency. | | [OH_AI_ContextSetThreadAffinityMode](_mind_spore.md#oh_ai_contextsetthreadaffinitymode) ([OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context, int mode) | Sets the affinity mode for binding runtime threads to CPU cores, which are classified into large, medium, and small cores based on the CPU frequency. You only need to bind the large or medium cores, but not small cores.|
| [OH_AI_ContextGetThreadAffinityMode](_mind_spore.md#oh_ai_contextgetthreadaffinitymode) (const [OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context) | Obtains the affinity mode for binding runtime threads to CPU cores. | | [OH_AI_ContextGetThreadAffinityMode](_mind_spore.md#oh_ai_contextgetthreadaffinitymode) (const [OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context) | Obtains the affinity mode for binding runtime threads to CPU cores.|
| [OH_AI_ContextSetThreadAffinityCoreList](_mind_spore.md#oh_ai_contextsetthreadaffinitycorelist) ([OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context, const int32_t \*core_list, size_t core_num) | Sets the list of CPU cores bound to a runtime thread. | | [OH_AI_ContextSetThreadAffinityCoreList](_mind_spore.md#oh_ai_contextsetthreadaffinitycorelist) ([OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context, const int32_t \*core_list, size_t core_num) | Sets the list of CPU cores bound to a runtime thread.|
| [OH_AI_ContextGetThreadAffinityCoreList](_mind_spore.md#oh_ai_contextgetthreadaffinitycorelist) (const [OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context, size_t \*core_num) | Obtains the list of bound CPU cores. | | [OH_AI_ContextGetThreadAffinityCoreList](_mind_spore.md#oh_ai_contextgetthreadaffinitycorelist) (const [OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context, size_t \*core_num) | Obtains the list of bound CPU cores.|
| [OH_AI_ContextSetEnableParallel](_mind_spore.md#oh_ai_contextsetenableparallel) ([OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context, bool is_parallel) | Sets whether to enable parallelism between operators. | | [OH_AI_ContextSetEnableParallel](_mind_spore.md#oh_ai_contextsetenableparallel) ([OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context, bool is_parallel) | Sets whether to enable parallelism between operators. The setting is ineffective because the feature of this API is not yet available.|
| [OH_AI_ContextGetEnableParallel](_mind_spore.md#oh_ai_contextgetenableparallel) (const [OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context) | Checks whether parallelism between operators is supported. | | [OH_AI_ContextGetEnableParallel](_mind_spore.md#oh_ai_contextgetenableparallel) (const [OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context) | Checks whether parallelism between operators is supported.|
| [OH_AI_ContextAddDeviceInfo](_mind_spore.md#oh_ai_contextadddeviceinfo) ([OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context, [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info) | Adds information about a running device. | | [OH_AI_ContextAddDeviceInfo](_mind_spore.md#oh_ai_contextadddeviceinfo) ([OH_AI_ContextHandle](_mind_spore.md#oh_ai_contexthandle) context, [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info) | Attaches the custom device information to the inference context.|
| [OH_AI_DeviceInfoCreate](_mind_spore.md#oh_ai_deviceinfocreate) ([OH_AI_DeviceType](_mind_spore.md#oh_ai_devicetype) device_type) | Creates a device information object. | | [OH_AI_DeviceInfoCreate](_mind_spore.md#oh_ai_deviceinfocreate) ([OH_AI_DeviceType](_mind_spore.md#oh_ai_devicetype) device_type) | Creates a device information object.|
| [OH_AI_DeviceInfoDestroy](_mind_spore.md#oh_ai_deviceinfodestroy) ([OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) \*device_info) | Destroys a device information instance. | | [OH_AI_DeviceInfoDestroy](_mind_spore.md#oh_ai_deviceinfodestroy) ([OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) \*device_info) | Destroys a device information object. Note: After the device information instance is added to the context, the caller does not need to destroy it manually.|
| [OH_AI_DeviceInfoSetProvider](_mind_spore.md#oh_ai_deviceinfosetprovider) ([OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info, const char \*provider) | Sets the name of a provider. | | [OH_AI_DeviceInfoSetProvider](_mind_spore.md#oh_ai_deviceinfosetprovider) ([OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info, const char \*provider) | Sets the provider name.|
| [OH_AI_DeviceInfoGetProvider](_mind_spore.md#oh_ai_deviceinfogetprovider) (const [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info) | Obtains the provider name. | | [OH_AI_DeviceInfoGetProvider](_mind_spore.md#oh_ai_deviceinfogetprovider) (const [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info) | Obtains the provider name.|
| [OH_AI_DeviceInfoSetProviderDevice](_mind_spore.md#oh_ai_deviceinfosetproviderdevice) ([OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info, const char \*device) | Sets the name of a provider device. | | [OH_AI_DeviceInfoSetProviderDevice](_mind_spore.md#oh_ai_deviceinfosetproviderdevice) ([OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info, const char \*device) | Sets the name of a provider device.|
| [OH_AI_DeviceInfoGetProviderDevice](_mind_spore.md#oh_ai_deviceinfogetproviderdevice) (const [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info) | Obtains the name of a provider device. | | [OH_AI_DeviceInfoGetProviderDevice](_mind_spore.md#oh_ai_deviceinfogetproviderdevice) (const [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info) | Obtains the name of a provider device.|
| [OH_AI_DeviceInfoGetDeviceType](_mind_spore.md#oh_ai_deviceinfogetdevicetype) (const [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info) | Obtains the type of a provider device. | | [OH_AI_DeviceInfoGetDeviceType](_mind_spore.md#oh_ai_deviceinfogetdevicetype) (const [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info) | Obtains the device type.|
| [OH_AI_DeviceInfoSetEnableFP16](_mind_spore.md#oh_ai_deviceinfosetenablefp16) ([OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info, bool is_fp16) | Sets whether to enable float16 inference. This function is available only for CPU/GPU devices. | | [OH_AI_DeviceInfoSetEnableFP16](_mind_spore.md#oh_ai_deviceinfosetenablefp16) ([OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info, bool is_fp16) | Sets whether to enable float16 inference. This function is available only for CPU and GPU devices.|
| [OH_AI_DeviceInfoGetEnableFP16](_mind_spore.md#oh_ai_deviceinfogetenablefp16) (const [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info) | Checks whether float16 inference is enabled. This function is available only for CPU/GPU devices. | | [OH_AI_DeviceInfoGetEnableFP16](_mind_spore.md#oh_ai_deviceinfogetenablefp16) (const [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info) | Checks whether float16 inference is enabled. This function is available only for CPU and GPU devices.|
| [OH_AI_DeviceInfoSetFrequency](_mind_spore.md#oh_ai_deviceinfosetfrequency) ([OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info, int frequency) | Sets the NPU frequency type. This function is available only for NPU devices. | | [OH_AI_DeviceInfoSetFrequency](_mind_spore.md#oh_ai_deviceinfosetfrequency) ([OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info, int frequency) | Sets the NPU frequency type. This function is available only for NPU devices.|
| [OH_AI_DeviceInfoGetFrequency](_mind_spore.md#oh_ai_deviceinfogetfrequency) (const [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info) | Obtains the NPU frequency type. This function is available only for NPU devices. | | [OH_AI_DeviceInfoGetFrequency](_mind_spore.md#oh_ai_deviceinfogetfrequency) (const [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info) | Obtains the NPU frequency type. This function is available only for NPU devices.|
| [OH_AI_GetAllNNRTDeviceDescs](_mind_spore.md#oh_ai_getallnnrtdevicedescs) (size_t \*num) | Obtains the descriptions of all NNRt devices in the system.|
| [OH_AI_DestroyAllNNRTDeviceDescs](_mind_spore.md#oh_ai_destroyallnnrtdevicedescs) ([NNRTDeviceDesc](_mind_spore.md#nnrtdevicedesc) \*\*desc) | Destroys the array of NNRT descriptions obtained by [OH_AI_GetAllNNRTDeviceDescs](_mind_spore.md#oh_ai_getallnnrtdevicedescs).|
| [OH_AI_GetDeviceIdFromNNRTDeviceDesc](_mind_spore.md#oh_ai_getdeviceidfromnnrtdevicedesc) (const [NNRTDeviceDesc](_mind_spore.md#nnrtdevicedesc) \*desc) | Obtains the NNRt device ID from the specified NNRt device description. Note that this ID is valid only for NNRt devices.|
| [OH_AI_GetNameFromNNRTDeviceDesc](_mind_spore.md#oh_ai_getnamefromnnrtdevicedesc) (const [NNRTDeviceDesc](_mind_spore.md#nnrtdevicedesc) \*desc) | Obtains the NNRt device name from the specified NNRt device description.|
| [OH_AI_GetTypeFromNNRTDeviceDesc](_mind_spore.md#oh_ai_gettypefromnnrtdevicedesc) (const [NNRTDeviceDesc](_mind_spore.md#nnrtdevicedesc) \*desc) | Obtains the NNRt device type from the specified NNRt device description.|
| [OH_AI_CreateNNRTDeviceInfoByName](_mind_spore.md#oh_ai_creatennrtdeviceinfobyname) (const char \*name) | Searches for the NNRt device with the specified name and creates the NNRt device information based on the information about the first found NNRt device.|
| [OH_AI_CreateNNRTDeviceInfoByType](_mind_spore.md#oh_ai_creatennrtdeviceinfobytype) ([OH_AI_NNRTDeviceType](_mind_spore.md#oh_ai_nnrtdevicetype) type) | Searches for the NNRt device with the specified type and creates the NNRt device information based on the information about the first found NNRt device.|
| [OH_AI_DeviceInfoSetDeviceId](_mind_spore.md#oh_ai_deviceinfosetdeviceid) ([OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info, size_t device_id) | Sets the ID of an NNRt device. This API is available only for NNRt devices.|
| [OH_AI_DeviceInfoGetDeviceId](_mind_spore.md#oh_ai_deviceinfogetdeviceid) (const [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info) | Obtains the ID of an NNRt device. This API is available only for NNRt devices.|
| [OH_AI_DeviceInfoSetPerformanceMode](_mind_spore.md#oh_ai_deviceinfosetperformancemode) ([OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info, [OH_AI_PerformanceMode](_mind_spore.md#oh_ai_performancemode) mode) | Sets the performance mode of an NNRt device. This API is available only for NNRt devices.|
| [OH_AI_DeviceInfoGetPerformanceMode](_mind_spore.md#oh_ai_deviceinfogetperformancemode) (const [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info) | Obtains the performance mode of an NNRt device. This API is available only for NNRt devices.|
| [OH_AI_DeviceInfoSetPriority](_mind_spore.md#oh_ai_deviceinfosetpriority) ([OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info, [OH_AI_Priority](_mind_spore.md#oh_ai_priority) priority) | Sets the priority of an NNRT task. This API is available only for NNRt devices.|
| [OH_AI_DeviceInfoGetPriority](_mind_spore.md#oh_ai_deviceinfogetpriority) (const [OH_AI_DeviceInfoHandle](_mind_spore.md#oh_ai_deviceinfohandle) device_info) | Obtains the priority of an NNRT task. This API is available only for NNRt devices.|
...@@ -26,7 +26,7 @@ For details about the requirements on the Linux environment, see [Quick Start](. ...@@ -26,7 +26,7 @@ For details about the requirements on the Linux environment, see [Quick Start](.
The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568) as an example to illustrate thermal log customization. The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568) as an example to illustrate thermal log customization.
1. Create the `thermal` folder in the product directory [/vendor/hihope/rk3568](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568). 1. Create the thermal folder in the product directory [/vendor/hihope/rk3568](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568).
2. Create a target folder by referring to the [default thermal log configuration folder](https://gitee.com/openharmony/drivers_peripheral/tree/master/thermal/interfaces/hdi_service/profile), and install it in `//vendor/hihope/rk3568/thermal`. The content is as follows: 2. Create a target folder by referring to the [default thermal log configuration folder](https://gitee.com/openharmony/drivers_peripheral/tree/master/thermal/interfaces/hdi_service/profile), and install it in `//vendor/hihope/rk3568/thermal`. The content is as follows:
...@@ -50,8 +50,6 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma ...@@ -50,8 +50,6 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma
| Configuration Item| Description| Data Type| Value Range| | Configuration Item| Description| Data Type| Value Range|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| interval | Interval for recording temperature tracing logs, in ms.| int | >0 |
| width | Width of the temperature tracing log, in characters.| int | >0 |
| outpath | Path for storing temperature tracing logs.| string | N/A| | outpath | Path for storing temperature tracing logs.| string | N/A|
**Table 2** Description of the node configuration **Table 2** Description of the node configuration
...@@ -63,7 +61,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma ...@@ -63,7 +61,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma
| value | path | Path for obtaining the thermal zone temperature.| | value | path | Path for obtaining the thermal zone temperature.|
```shell ```shell
<tracing interval="5000" width="20" outpath="/data/log/thermal-log"> <tracing outpath="/data/log/thermal-log">
<node> <node>
<title path="sys/class/thermal/thermal_zone0/type"/> <title path="sys/class/thermal/thermal_zone0/type"/>
<value path="sys/class/thermal/thermal_zone0/temp"/> <value path="sys/class/thermal/thermal_zone0/temp"/>
...@@ -86,10 +84,10 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma ...@@ -86,10 +84,10 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma
thermal.para.dac: thermal.para.dac:
```text ```text
persist.thermal.log.="power_host:power_host:600" # Configure access permissions. persist.thermal.log.="power_host:power_host:500" # Configure access permissions.
``` ```
6. Write the `BUILD.gn` file by referring to the [BUILD.gn](https://gitee.com/openharmony/drivers_peripheral/blob/master/thermal/interfaces/hdi_service/profile/BUILD.gn) file in the default thermal log configuration folder to pack the `thermal_hdi_config.xml` file to the `//vendor/etc/thermal_config/hdf` directory. The configuration is as follows: 6. Write the `BUILD.gn` file by referring to the [BUILD.gn](https://gitee.com/openharmony/drivers_peripheral/blob/master/thermal/interfaces/hdi_service/profile/BUILD.gn) file in the default thermal log configuration folder to pack the thermal_hdi_config.xml file to the `//vendor/etc/thermal_config/hdf` directory. The configuration is as follows:
```shell ```shell
import("//build/ohos.gni") import("//build/ohos.gni")
...@@ -97,7 +95,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma ...@@ -97,7 +95,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma
ohos_prebuilt_etc("thermal_hdf_config") { ohos_prebuilt_etc("thermal_hdf_config") {
source = "thermal_hdi_config.xml" source = "thermal_hdi_config.xml"
relative_install_dir = "thermal_config/hdf" relative_install_dir = "thermal_config/hdf"
install_images = [ chipset_base_dir ] # Required configuration for installing the thermal_hdi_config.xml file in the vendor directory. install_images = [ chipset_base_dir ] # Required configuration for installing the thermal_service_config.xml file in the vendor directory.
part_name = "product_rk3568" # Set part_name to product_rk3568 for subsequent build. You can change it as required. part_name = "product_rk3568" # Set part_name to product_rk3568 for subsequent build. You can change it as required.
} }
``` ```
...@@ -151,7 +149,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma ...@@ -151,7 +149,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma
"subsystem": "product_hihope" "subsystem": "product_hihope"
} }
``` ```
In the preceding code, `//vendor/hihope/rk3568/thermal/` is the folder path, `profile` and `etc` are folder names, and `thermal_hdf_config` and `param_files` are the build targets. In the preceding code, //vendor/hihope/rk3568/thermal/ is the folder path, profile and etc are folder names, and thermal_hdf_config and param_files are the build targets.
9. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md). 9. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
......
...@@ -13,5 +13,7 @@ ...@@ -13,5 +13,7 @@
| ArkUI | UX changed | [The hover effect of the \<Button> component is changed from scale-up by 100% to 105% to overlay of 0% to 5% opacity.](changelogs-arkui.md)| | ArkUI | UX changed | [The hover effect of the \<Button> component is changed from scale-up by 100% to 105% to overlay of 0% to 5% opacity.](changelogs-arkui.md)|
| ArkUI | UX changed | [The alignment mode of multi-line text in toasts is changed from center-aligned to left-aligned.](changelogs-arkui.md)| | ArkUI | UX changed | [The alignment mode of multi-line text in toasts is changed from center-aligned to left-aligned.](changelogs-arkui.md)|
| Bundle management subsystem | Mechanism changed | [The HAP is no longer decompressed during HAP installation.](changelogs-bundlemanager.md)| | Bundle management subsystem | Mechanism changed | [The HAP is no longer decompressed during HAP installation.](changelogs-bundlemanager.md)|
| Globalization | API added | [The getStringSync and getStringByNameSync APIs are added.](changelogs-global.md)|
| Globalization | Behavior changed | [The meaning of the return value for the API used to obtain the rawfile descriptor is changed.](changelogs-global.md)|
| Web | Input parameter added | [The input parameter type Resource is added for the setResponseData API.](changelogs-web.md) | | Web | Input parameter added | [The input parameter type Resource is added for the setResponseData API.](changelogs-web.md) |
| Resource scheduler subsystem | Behavior changed | [The reminder agent allows you to customize buttons for system applications. Clicking a custom button will redirect you to the specified application page.](changelogs-resourceschedule.md)| | Resource scheduler subsystem | Behavior changed | [The reminder agent allows you to customize buttons for system applications. Clicking a custom button will redirect you to the specified application page.](changelogs-resourceschedule.md)|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册