openharmony 鸿蒙 capi-context-h

2026-08-25 浏览 (1)

context.h

Overview

Provides context-related APIs for configuring runtime information. These APIs are non-thread-safe.

File to include: <mindspore/context.h>

Library: libmindspore_lite_ndk.so

System capability: SystemCapability.Ai.MindSpore

Since: 9

Related module: MindSpore

Summary

Structs

Nametypedef KeywordDescription
OH_AI_ContextHandlevoid*Defines the pointer to the MindSpore Lite context.
OH_AI_DeviceInfoHandlevoid*Defines the pointer to the MindSpore Lite device information.

Functions

NameDescription
OH_AI_API OH_AI_ContextHandle OH_AI_ContextCreate()Creates a context object. This API must be used together with OH_AI_ContextDestroy.
OH_AI_API void OH_AI_ContextDestroy(OH_AI_ContextHandle *context)Destroys a context object.
OH_AI_API void OH_AI_ContextSetThreadNum(OH_AI_ContextHandle context, int32_t thread_num)Sets the number of runtime threads.
OH_AI_API int32_t OH_AI_ContextGetThreadNum(const OH_AI_ContextHandle context)Obtains the number of threads.
OH_AI_API void OH_AI_ContextSetThreadAffinityMode(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_API int OH_AI_ContextGetThreadAffinityMode(const OH_AI_ContextHandle context)Obtains the affinity mode for binding runtime threads to CPU cores.
OH_AI_API void OH_AI_ContextSetThreadAffinityCoreList(OH_AI_ContextHandle context, const int32_t *core_list,size_t core_num)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 and OH_AI_ContextSetThreadAffinityCoreList are called for the same context object,
the core_list parameter of OH_AI_ContextSetThreadAffinityCoreList takes effect, but the mode parameter of OH_AI_ContextSetThreadAffinityMode does not.
OH_AI_API const int32_t *OH_AI_ContextGetThreadAffinityCoreList(const OH_AI_ContextHandle context, size_t *core_num)Obtains the list of bound CPU cores.
OH_AI_API void OH_AI_ContextSetEnableParallel(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_API bool OH_AI_ContextGetEnableParallel(const OH_AI_ContextHandle context)Checks whether parallelism between operators is supported.
OH_AI_API void OH_AI_ContextAddDeviceInfo(OH_AI_ContextHandle context, OH_AI_DeviceInfoHandle device_info)Attaches the custom device information to the inference context.
OH_AI_API OH_AI_DeviceInfoHandle OH_AI_DeviceInfoCreate(OH_AI_DeviceType device_type)Creates a device information object.
OH_AI_API void OH_AI_DeviceInfoDestroy(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_API void OH_AI_DeviceInfoSetProvider(OH_AI_DeviceInfoHandle device_info, const char *provider)Sets the name of the provider.
OH_AI_API const char *OH_AI_DeviceInfoGetProvider(const OH_AI_DeviceInfoHandle device_info)Obtains the provider name.
OH_AI_API void OH_AI_DeviceInfoSetProviderDevice(OH_AI_DeviceInfoHandle device_info, const char *device)Sets the name of a provider device.
OH_AI_API const char *OH_AI_DeviceInfoGetProviderDevice(const OH_AI_DeviceInfoHandle device_info)Obtains the name of a provider device.
OH_AI_API OH_AI_DeviceType OH_AI_DeviceInfoGetDeviceType(const OH_AI_DeviceInfoHandle device_info)Obtains the device type.
OH_AI_API void OH_AI_DeviceInfoSetEnableFP16(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_API bool OH_AI_DeviceInfoGetEnableFP16(const OH_AI_DeviceInfoHandle device_info)Checks whether float16 inference is enabled. This function is available only for CPU and GPU devices.
OH_AI_API void OH_AI_DeviceInfoSetFrequency(OH_AI_DeviceInfoHandle device_info, int frequency)Sets the NPU frequency type. This function is available only for NPU devices.
OH_AI_API int OH_AI_DeviceInfoGetFrequency(const OH_AI_DeviceInfoHandle device_info)Obtains the NPU frequency type. This function is available only for NPU devices.
OH_AI_API NNRTDeviceDesc *OH_AI_GetAllNNRTDeviceDescs(size_t *num)Obtains the descriptions of all NNRt devices in the system.
OH_AI_API NNRTDeviceDesc *OH_AI_GetElementOfNNRTDeviceDescs(NNRTDeviceDesc *descs, size_t index)Obtains the pointer to an element in the NNRt device description array.
OH_AI_API void OH_AI_DestroyAllNNRTDeviceDescs(NNRTDeviceDesc **desc)Destroys the NNRt device description array obtained by OH_AI_GetAllNNRTDeviceDescs.
OH_AI_API size_t OH_AI_GetDeviceIdFromNNRTDeviceDesc(const 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_API const char *OH_AI_GetNameFromNNRTDeviceDesc(const NNRTDeviceDesc *desc)Obtains the NNRt device name from the specified NNRt device description.
OH_AI_API OH_AI_NNRTDeviceType OH_AI_GetTypeFromNNRTDeviceDesc(const NNRTDeviceDesc *desc)Obtains the NNRt device type from the specified NNRt device description.
OH_AI_API OH_AI_DeviceInfoHandle 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_API OH_AI_DeviceInfoHandle OH_AI_CreateNNRTDeviceInfoByType(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_API void OH_AI_DeviceInfoSetDeviceId(OH_AI_DeviceInfoHandle device_info, size_t device_id)Sets the NNRt device ID. This function is available only for NNRt devices.
OH_AI_API size_t OH_AI_DeviceInfoGetDeviceId(const OH_AI_DeviceInfoHandle device_info)Obtains the NNRt device ID. This function is available only for NNRt devices.
OH_AI_API void OH_AI_DeviceInfoSetPerformanceMode(OH_AI_DeviceInfoHandle device_info, OH_AI_PerformanceMode mode)Sets the NNRt performance mode. This function is available only for NNRt devices.
OH_AI_API OH_AI_PerformanceMode OH_AI_DeviceInfoGetPerformanceMode(const OH_AI_DeviceInfoHandle device_info)Obtains the NNRt performance mode. This function is available only for NNRt devices.
OH_AI_API void OH_AI_DeviceInfoSetPriority(OH_AI_DeviceInfoHandle device_info, OH_AI_Priority priority)Sets the priority of an NNRt task. This function is available only for NNRt devices.
OH_AI_API OH_AI_Priority OH_AI_DeviceInfoGetPriority(const OH_AI_DeviceInfoHandle device_info)Obtains the priority of an NNRt task. This function is available only for NNRt devices.
OH_AI_API OH_AI_Status OH_AI_DeviceInfoAddExtension(OH_AI_DeviceInfoHandle device_info, const char *name,const char *value, size_t value_size)Adds extended configuration in the form of key/value pairs to the device information. This function is available only for NNRt devices.
Currently, only the following 11 keys are supported: {"CachePath": "YourCachePath"}, {"CacheVersion": "YourCacheVersion"}, {"QuantBuffer": "YourQuantBuffer"}, {"ModelName": "YourModelName"}, {"isProfiling": "YourProfilingSwitch"}, {"opLayout": "YourOpLayout"}, {"InputDims": "YourInputDims"}, {"DynamicDims": "YourDynamicDims"}, {"QuantConfigData": "YourQuantConfigData"}, {"BandMode": "YourBandMode"}, and {"NPU_FM_SHARED": "YourNPU_FM_SHARED"}. You can configure the value of each key based on the actual requirement.

Function Description

OH_AI_ContextCreate()

OH_AI_API OH_AI_ContextHandle OH_AI_ContextCreate()

Description

Creates a context object. This API must be used together with OH_AI_ContextDestroy.

Since: 9

Returns

TypeDescription
OH_AI_API OH_AI_ContextHandleOH_AI_ContextHandle that points to the context.

OH_AI_ContextDestroy()

OH_AI_API void OH_AI_ContextDestroy(OH_AI_ContextHandle *context)

Description

Destroys a context object.

Since: 9

Parameters

NameDescription
OH_AI_ContextHandle *contextLevel-2 pointer to OH_AI_ContextHandle. After the context is destroyed, the context is set to a null pointer.

OH_AI_ContextSetThreadNum()

OH_AI_API void OH_AI_ContextSetThreadNum(OH_AI_ContextHandle context, int32_t thread_num)

Description

Sets the number of runtime threads.

Since: 9

Parameters

NameDescription
OH_AI_ContextHandle contextOH_AI_ContextHandle that points to the context instance.
int32_t thread_numNumber of runtime threads. The length is subject to system restrictions.

OH_AI_ContextGetThreadNum()

OH_AI_API int32_t OH_AI_ContextGetThreadNum(const OH_AI_ContextHandle context)

Description

Obtains the number of threads.

Since: 9

Parameters

NameDescription
const OH_AI_ContextHandle contextOH_AI_ContextHandle that points to the context instance.

Returns

TypeDescription
OH_AI_API int32_tNumber of threads.

OH_AI_ContextSetThreadAffinityMode()

OH_AI_API void OH_AI_ContextSetThreadAffinityMode(OH_AI_ContextHandle context, int mode)

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.

Since: 9

Parameters

NameDescription
OH_AI_ContextHandle contextOH_AI_ContextHandle that points to the context instance.
int modeAffinity mode. 0: no affinities; 1: big cores first; 2: medium cores first

OH_AI_ContextGetThreadAffinityMode()

OH_AI_API int OH_AI_ContextGetThreadAffinityMode(const OH_AI_ContextHandle context)

Description

Obtains the affinity mode for binding runtime threads to CPU cores.

Since: 9

Parameters

NameDescription
const OH_AI_ContextHandle contextOH_AI_ContextHandle that points to the context instance.

Returns

TypeDescription
OH_AI_API intAffinity mode. 0: no affinities; 1: big cores first; 2: medium cores first

OH_AI_ContextSetThreadAffinityCoreList()

OH_AI_API void OH_AI_ContextSetThreadAffinityCoreList(OH_AI_ContextHandle context, const int32_t *core_list,size_t core_num)

Description

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 and OH_AI_ContextSetThreadAffinityCoreList are called for the same context object,
the core_list parameter of OH_AI_ContextSetThreadAffinityCoreList takes effect, but the mode parameter of OH_AI_ContextSetThreadAffinityMode does not.

Since: 9

Parameters

NameDescription
OH_AI_ContextHandle contextOH_AI_ContextHandle that points to the context instance.
const int32_t *core_listList of bound CPU cores.
size_t core_numNumber of cores, which indicates the length of core_list.

OH_AI_ContextGetThreadAffinityCoreList()

OH_AI_API const int32_t *OH_AI_ContextGetThreadAffinityCoreList(const OH_AI_ContextHandle context, size_t *core_num)

Description

Obtains the list of bound CPU cores.

Since: 9

Parameters

NameDescription
const OH_AI_ContextHandle contextOH_AI_ContextHandle that points to the context instance.
size_t *core_numNumber of CPU cores.

Returns

TypeDescription
OH_AI_API const int32_t *List of bound CPU cores. This list is managed by OH_AI_ContextHandle. The caller does not need to destroy it manually.

OH_AI_ContextSetEnableParallel()

OH_AI_API void OH_AI_ContextSetEnableParallel(OH_AI_ContextHandle context, bool is_parallel)

Description

Sets whether to enable parallelism between operators. The setting is ineffective because the feature of this API is not yet available.

Since: 9

Parameters

NameDescription
OH_AI_ContextHandle contextOH_AI_ContextHandle that points to the context instance.
bool is_parallelWhether parallelism between operators is supported. The value true indicates that parallelism between operators is supported, and the value false indicates the opposite.

OH_AI_ContextGetEnableParallel()

OH_AI_API bool OH_AI_ContextGetEnableParallel(const OH_AI_ContextHandle context)

Description

Checks whether parallelism between operators is supported.

Since: 9

Parameters

NameDescription
const OH_AI_ContextHandle contextOH_AI_ContextHandle that points to the context instance.

Returns

TypeDescription
OH_AI_API boolWhether parallelism between operators is supported. The value true indicates that parallelism between operators is supported, and the value false indicates the opposite.

OH_AI_ContextAddDeviceInfo()

OH_AI_API void OH_AI_ContextAddDeviceInfo(OH_AI_ContextHandle context, OH_AI_DeviceInfoHandle device_info)

Description

Attaches the custom device information to the inference context.

Since: 9

Parameters

NameDescription
OH_AI_ContextHandle contextOH_AI_ContextHandle that points to the context instance.
OH_AI_DeviceInfoHandle device_infoOH_AI_DeviceInfoHandle that points to the device information instance.

OH_AI_DeviceInfoCreate()

OH_AI_API OH_AI_DeviceInfoHandle OH_AI_DeviceInfoCreate(OH_AI_DeviceType device_type)

Description

Creates a device information object.

Since: 9

Parameters

NameDescription
OH_AI_DeviceType device_typeDevice type, which is specified by OH_AI_DeviceType.

Returns

TypeDescription
OH_AI_API OH_AI_DeviceInfoHandleOH_AI_DeviceInfoHandle that points to the device information instance.

OH_AI_DeviceInfoDestroy()

OH_AI_API void OH_AI_DeviceInfoDestroy(OH_AI_DeviceInfoHandle *device_info)

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.

Since: 9

Parameters

NameDescription
OH_AI_DeviceInfoHandle *device_infoOH_AI_DeviceInfoHandle that points to the device information instance.

OH_AI_DeviceInfoSetProvider()

OH_AI_API void OH_AI_DeviceInfoSetProvider(OH_AI_DeviceInfoHandle device_info, const char *provider)

Description

Sets the name of the provider.

Since: 9

Parameters

NameDescription
OH_AI_DeviceInfoHandle device_infoOH_AI_DeviceInfoHandle that points to the device information instance.
const char *providerProvider name. The string length is subject to system restrictions.

OH_AI_DeviceInfoGetProvider()

OH_AI_API const char *OH_AI_DeviceInfoGetProvider(const OH_AI_DeviceInfoHandle device_info)

Description

Obtains the provider name.

Since: 9

Parameters

NameDescription
const OH_AI_DeviceInfoHandle device_infoOH_AI_DeviceInfoHandle that points to the device information instance.

Returns

TypeDescription
OH_AI_API const char *Provider name.

OH_AI_DeviceInfoSetProviderDevice()

OH_AI_API void OH_AI_DeviceInfoSetProviderDevice(OH_AI_DeviceInfoHandle device_info, const char *device)

Description

Sets the name of a provider device.

Since: 9

Parameters

NameDescription
OH_AI_DeviceInfoHandle device_infoOH_AI_DeviceInfoHandle that points to the device information instance.
const char *deviceName of the provider device, for example, CPU. The string length is subject to system restrictions.

OH_AI_DeviceInfoGetProviderDevice()

OH_AI_API const char *OH_AI_DeviceInfoGetProviderDevice(const OH_AI_DeviceInfoHandle device_info)

Description

Obtains the name of a provider device.

Since: 9

Parameters

NameDescription
const OH_AI_DeviceInfoHandle device_infoOH_AI_DeviceInfoHandle that points to the device information instance.

Returns

TypeDescription
OH_AI_API const char *Name of the provider device.

OH_AI_DeviceInfoGetDeviceType()

OH_AI_API OH_AI_DeviceType OH_AI_DeviceInfoGetDeviceType(const OH_AI_DeviceInfoHandle device_info)

Description

Obtains the device type.

Since: 9

Parameters

NameDescription
const OH_AI_DeviceInfoHandle device_infoOH_AI_DeviceInfoHandle that points to the device information instance.

Returns

TypeDescription
OH_AI_API OH_AI_DeviceTypeType of the provider device.

OH_AI_DeviceInfoSetEnableFP16()

OH_AI_API void OH_AI_DeviceInfoSetEnableFP16(OH_AI_DeviceInfoHandle device_info, bool is_fp16)

Description

Sets whether to enable float16 inference. This function is available only for CPU and GPU devices.

Since: 9

Parameters

NameDescription
OH_AI_DeviceInfoHandle device_infoOH_AI_DeviceInfoHandle that points to the device information instance.
bool is_fp16Whether to enable the float16 inference mode. The value true means to enable the float16 inference mode, and the value false means the opposite.

OH_AI_DeviceInfoGetEnableFP16()

OH_AI_API bool OH_AI_DeviceInfoGetEnableFP16(const OH_AI_DeviceInfoHandle device_info)

Description

Checks whether float16 inference is enabled. This function is available only for CPU and GPU devices.

Since: 9

Parameters

NameDescription
const OH_AI_DeviceInfoHandle device_infoOH_AI_DeviceInfoHandle that points to the device information instance.

Returns

TypeDescription
OH_AI_API boolWhether to enable the float16 inference mode. The value true means to enable the float16 inference mode, and the value false means the opposite.

OH_AI_DeviceInfoSetFrequency()

OH_AI_API void OH_AI_DeviceInfoSetFrequency(OH_AI_DeviceInfoHandle device_info, int frequency)

Description

Sets the NPU frequency type. This function is available only for NPU devices.

Since: 9

Parameters

NameDescription
OH_AI_DeviceInfoHandle device_infoOH_AI_DeviceInfoHandle that points to the device information instance.
int frequencyNPU frequency type. The value ranges from 0 to 4. The default value is 3. Meanings of each value: 0: auto system adjustment; 1: low power consumption; 2: balanced; 3: high performance; 4: ultra-high performance.

OH_AI_DeviceInfoGetFrequency()

OH_AI_API int OH_AI_DeviceInfoGetFrequency(const OH_AI_DeviceInfoHandle device_info)

Description

Obtains the NPU frequency type. This function is available only for NPU devices.

Since: 9

Parameters

NameDescription
const OH_AI_DeviceInfoHandle device_infoOH_AI_DeviceInfoHandle that points to the device information instance.

Returns

TypeDescription
OH_AI_API intNPU frequency type. Meanings of each value: 0: auto system adjustment; 1: low power consumption; 2: balanced; 3: high performance; 4: ultra-high performance.

OH_AI_GetAllNNRTDeviceDescs()

OH_AI_API NNRTDeviceDesc *OH_AI_GetAllNNRTDeviceDescs(size_t *num)

Description

Obtains the descriptions of all NNRt devices in the system.

Since: 10

Parameters

NameDescription
size_t *numNumber of NNRt devices.

Returns

TypeDescription
OH_AI_API NNRTDeviceDesc *Pointer to the NNRt device description array. If the operation fails, NULL is returned.

OH_AI_GetElementOfNNRTDeviceDescs()

OH_AI_API NNRTDeviceDesc *OH_AI_GetElementOfNNRTDeviceDescs(NNRTDeviceDesc *descs, size_t index)

Description

Obtains the pointer to an element in the NNRt device description array.

Since: 10

Parameters

NameDescription
NNRTDeviceDesc *descsNNRt device description array.
size_t indexIndex of an array element.

Returns

TypeDescription
OH_AI_API NNRTDeviceDesc *Pointer to the NNRt device description.

OH_AI_DestroyAllNNRTDeviceDescs()

OH_AI_API void OH_AI_DestroyAllNNRTDeviceDescs(NNRTDeviceDesc **desc)

Description

Destroys the NNRt device description array obtained by OH_AI_GetAllNNRTDeviceDescs.

Since: 10

Parameters

NameDescription
NNRTDeviceDesc **descDouble pointer to the NNRt device description array. After the operation is complete, the content pointed to by desc is set to NULL.

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.

Since: 10

Parameters

NameDescription
const NNRTDeviceDesc *descPointer to the NNRt device description.

Returns

TypeDescription
OH_AI_API size_tNNRt device ID.

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.

Since: 10

Parameters

NameDescription
const NNRTDeviceDesc *descPointer to the NNRt device description.

Returns

TypeDescription
OH_AI_API const char *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.

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.

Since: 10

Parameters

NameDescription
const NNRTDeviceDesc *descPointer to the NNRt device description.

Returns

TypeDescription
OH_AI_API OH_AI_NNRTDeviceTypeNNRt device type, which is specified by OH_AI_NNRTDeviceType.

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.

Since: 10

Parameters

NameDescription
const char *nameName of the target NNRt device. The string length is subject to system restrictions.

Returns

TypeDescription
OH_AI_API OH_AI_DeviceInfoHandleOH_AI_DeviceInfoHandle that points to the device information instance.

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.

Since: 10

Parameters

NameDescription
OH_AI_NNRTDeviceType typeNNRt device type, which is specified by OH_AI_NNRTDeviceType.

Returns

TypeDescription
OH_AI_API OH_AI_DeviceInfoHandleOH_AI_DeviceInfoHandle that points to the device information instance.

OH_AI_DeviceInfoSetDeviceId()

OH_AI_API void OH_AI_DeviceInfoSetDeviceId(OH_AI_DeviceInfoHandle device_info, size_t device_id)

Description

Sets the NNRt device ID. This function is available only for NNRt devices.

Since: 10

Parameters

NameDescription
OH_AI_DeviceInfoHandle device_infoOH_AI_DeviceInfoHandle that points to the device information instance.
size_t device_idNNRt device ID.

OH_AI_DeviceInfoGetDeviceId()

OH_AI_API size_t OH_AI_DeviceInfoGetDeviceId(const OH_AI_DeviceInfoHandle device_info)

Description

Obtains the NNRt device ID. This function is available only for NNRt devices.

Since: 10

Parameters

NameDescription
const OH_AI_DeviceInfoHandle device_infoOH_AI_DeviceInfoHandle that points to the device information instance.

Returns

TypeDescription
OH_AI_API size_tNNRt device ID.

OH_AI_DeviceInfoSetPerformanceMode()

OH_AI_API void OH_AI_DeviceInfoSetPerformanceMode(OH_AI_DeviceInfoHandle device_info, OH_AI_PerformanceMode mode)

Description

Sets the NNRt performance mode. This function is available only for NNRt devices.

Since: 10

Parameters

NameDescription
OH_AI_DeviceInfoHandle device_infoOH_AI_DeviceInfoHandle that points to the device information instance.
OH_AI_PerformanceMode modeNNRt performance mode, which is specified by OH_AI_PerformanceMode.

OH_AI_DeviceInfoGetPerformanceMode()

OH_AI_API OH_AI_PerformanceMode OH_AI_DeviceInfoGetPerformanceMode(const OH_AI_DeviceInfoHandle device_info)

Description

Obtains the NNRt performance mode. This function is available only for NNRt devices.

Since: 10

Parameters

NameDescription
const OH_AI_DeviceInfoHandle device_infoOH_AI_DeviceInfoHandle that points to the device information instance.

Returns

TypeDescription
OH_AI_API OH_AI_PerformanceModeNNRt performance mode, which is specified by OH_AI_PerformanceMode.

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 function is available only for NNRt devices.

Since: 10

Parameters

NameDescription
OH_AI_DeviceInfoHandle device_infoOH_AI_DeviceInfoHandle that points to the device information instance.
OH_AI_Priority priorityNNRt task priority, which is specified by OH_AI_Priority.

OH_AI_DeviceInfoGetPriority()

OH_AI_API OH_AI_Priority OH_AI_DeviceInfoGetPriority(const OH_AI_DeviceInfoHandle device_info)

Description

Obtains the priority of an NNRt task. This function is available only for NNRt devices.

Since: 23

Parameters

NameDescription
const OH_AI_DeviceInfoHandle device_infoOH_AI_DeviceInfoHandle that points to the device information instance.

Returns

TypeDescription
OH_AI_API OH_AI_PriorityNNRt task priority, which is specified by OH_AI_Priority.

OH_AI_DeviceInfoAddExtension()

OH_AI_API OH_AI_Status OH_AI_DeviceInfoAddExtension(OH_AI_DeviceInfoHandle device_info, const char *name,const char *value, size_t value_size)

Description

Adds extended configuration in the form of key/value pairs to the device information. This function is available only for NNRt devices.
Currently, only the following 11 keys are supported: {"CachePath": "YourCachePath"}, {"CacheVersion": "YourCacheVersion"}, {"QuantBuffer": "YourQuantBuffer"}, {"ModelName": "YourModelName"}, {"isProfiling": "YourProfilingSwitch"}, {"opLayout": "YourOpLayout"}, {"InputDims": "YourInputDims"}, {"DynamicDims": "YourDynamicDims"}, {"QuantConfigData": "YourQuantConfigData"}, {"BandMode": "YourBandMode"}, and {"NPU_FM_SHARED": "YourNPU_FM_SHARED"}. You can configure the value of each key based on the actual requirement.

Since: 10

Parameters

NameDescription
OH_AI_DeviceInfoHandle device_infoOH_AI_DeviceInfoHandle that points to the device information instance.
const char *nameKey in an extended key/value pair. The value is a C string. The value contains up to 128 characters.
const char *valueStart address of the value in an extended key/value pair. The string length is subject to system restrictions.
size_t value_sizeLength of the value in an extended key/value pair.

Returns

TypeDescription
OH_AI_API OH_AI_StatusStatus code enumerated by OH_AI_Status. The value OH_AI_STATUS_SUCCESS indicates that the operation is successful. If the operation fails, an error code is returned.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-format-h

openharmony 鸿蒙 capi-tensor-h

openharmony 鸿蒙 capi-mindspore-oh-ai-callbackparam

openharmony 鸿蒙 capi-mindspore-oh-ai-shapeinfo

openharmony 鸿蒙 capi-mindspore-oh-ai-contexthandle

openharmony 鸿蒙 capi-mindspore-oh-ai-traincfghandle

openharmony 鸿蒙 capi-mindspore-oh-ai-allocatorhandle

openharmony 鸿蒙 js-apis-mindSporeLite

openharmony 鸿蒙 capi-mindspore-oh-ai-tensorHandle

openharmony 鸿蒙 Readme-EN

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/IUqrzd8m