3. Runtime Configuration

This topic describes the runtime configuration APIs of CANN Runtime, which are used to set and query system parameters, device resource limits, and stream resource limits.

aclrtSetSysParamOpt

aclError aclrtSetSysParamOpt(aclSysParamOpt opt, int64_t value)

Applicable Products

  • Ascend 950PR&950DT products: Supported
  • Atlas A3 products: Supported
  • Atlas A2 products: Supported
  • Atlas 200I/500 A2 inference products: Supported
  • Atlas inference products: Supported
  • Atlas training products: Supported

Description

Sets the runtime parameter in the current process. After calling this API to set the runtime parameter, if you need to obtain the parameter value, call the aclrtGetSysParamOpt API.

The difference between this API and the aclrtCtxSetSysParamOpt API is that the scope of this API is the process, while the scope of the aclrtCtxSetSysParamOpt API is the context.

Parameters

Name Input/Output Description
opt Input Runtime parameter. For details, see aclSysParamOpt.
value Input Runtime parameter value.

Return Values

Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.




aclrtGetSysParamOpt

aclError aclrtGetSysParamOpt(aclSysParamOpt opt, int64_t *value)

Applicable Products

  • Ascend 950PR&950DT products: Supported
  • Atlas A3 products: Supported
  • Atlas A2 products: Supported
  • Atlas 200I/500 A2 inference products: Supported
  • Atlas inference products: Supported
  • Atlas training products: Supported

Description

Obtains the runtime parameter value in the current process.

If the aclrtSetSysParamOpt API is not called to set the runtime parameter, calling this API directly returns the default value 0 for each parameter, indicating that deterministic computation or memory access out-of-bounds detection is not enabled. After the runtime parameter is set by calling the aclrtSetSysParamOpt API, call the aclrtGetSysParamOpt API to obtain the parameter value.

Parameters

Name Input/Output Description
opt Input Runtime parameter. For details, see aclSysParamOpt.
value Output Runtime parameter value.

Return Values

Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.




aclrtGetDeviceResLimit

aclError aclrtGetDeviceResLimit(int32_t deviceId, aclrtDevResLimitType type, uint32_t* value)

Applicable Products

  • Ascend 950PR&950DT products: Supported
  • Atlas A3 products: Supported
  • Atlas A2 products: Supported
  • Atlas 200I/500 A2 inference products: Supported
  • Atlas inference products: Supported
  • Atlas training products: Supported

Description

Obtains the device resource limit of the current process.

If aclrtSetDeviceResLimit is not called to set the device resource limit of the current process, this API returns the default resource limit of the AI processor hardware.

Parameters

Name Input/Output Description
deviceId Input Device ID.
After the user calls aclrtGetDeviceCount to obtain the number of available devices, the value range of this device ID is [0, (Number of available devices - 1)].
type Input Resource type. For details, see aclrtDevResLimitType.
value Output Size of the resource limit.

Return Values

Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.




aclrtSetDeviceResLimit

aclError aclrtSetDeviceResLimit(int32_t deviceId, aclrtDevResLimitType type, uint32_t value)

Applicable Products

  • Ascend 950PR&950DT products: Supported
  • Atlas A3 products: Supported
  • Atlas A2 products: Supported
  • Atlas 200I/500 A2 inference products: Supported
  • Atlas inference products: Supported
  • Atlas training products: Supported

Description

Sets the device resource limit of the current process.

This API should be used after calling aclrtSetDevice and before executing operators. If the resource limit is set for the same device multiple times, the last setting takes effect.

In addition to the process-level device resource limit, the stream-level device resource limit is also supported. It can be implemented by using aclrtSetStreamResLimit and aclrtUseStreamResInCurrentThread together.

The priority of the device resource limits is as follows: stream-level device resource limit > process-level device resource limit > AI processor hardware resource limit

Parameters

Name Input/Output Description
deviceId Input Device ID.
After the user calls aclrtGetDeviceCount to obtain the number of available devices, the value range of this device ID is [0, (Number of available devices - 1)].
type Input Resource type. For details, see aclrtDevResLimitType.
value Input Size of the resource limit.

Return Values

Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.

Constraints

The setting by this API takes effect only on tasks dispatched subsequently. For example, in the scenario where APIs such as aclmdlRICaptureBegin and aclmdlRICaptureEnd are called to capture stream tasks into a model and then model inference is executed, call this API to set the device resource limit before the capture.




aclrtResetDeviceResLimit

aclError aclrtResetDeviceResLimit(int32_t deviceId)

Applicable Products

  • Ascend 950PR&950DT products: Supported
  • Atlas A3 products: Supported
  • Atlas A2 products: Supported
  • Atlas 200I/500 A2 inference products: Supported
  • Atlas inference products: Supported
  • Atlas training products: Supported

Description

Resets the device resource limit of the current process to restore the default configuration after the device resource limit is set by calling aclrtSetDeviceResLimit. At this time, you can query the default resource limit through aclrtGetDeviceResLimit.

Parameters

Name Input/Output Description
deviceId Input Device ID.
After the user calls aclrtGetDeviceCount to obtain the number of available devices, the value range of this device ID is [0, (Number of available devices - 1)].

Return Values

Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.




aclrtGetStreamResLimit

aclError aclrtGetStreamResLimit(aclrtStream stream, aclrtDevResLimitType type, uint32_t *value)

Applicable Products

  • Ascend 950PR&950DT products: Supported
  • Atlas A3 products: Supported
  • Atlas A2 products: Supported
  • Atlas 200I/500 A2 inference products: Supported
  • Atlas inference products: Supported
  • Atlas training products: Supported

Description

Obtains the device resource limit of a specified stream.

If the aclrtSetStreamResLimit API is not called to set the device resource limit, the priority of the device resource limit obtained by calling this API is as follows: the device resource limit of the current process (set by calling the aclrtSetDeviceResLimit API) > the default resource limit of the AI processor hardware.

Parameters

Name Input/Output Description
stream Input Stream. For details about the type definition, see aclrtStream.
If NULL is passed in, the default stream is used.
type Input Resource type. For details, see aclrtDevResLimitType.
value Output Size of the resource limit.

Return Values

Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.




aclrtSetStreamResLimit

aclError aclrtSetStreamResLimit(aclrtStream stream, aclrtDevResLimitType type, uint32_t value)

Applicable Products

  • Ascend 950PR&950DT products: Supported
  • Atlas A3 products: Supported
  • Atlas A2 products: Supported
  • Atlas 200I/500 A2 inference products: Supported
  • Atlas inference products: Supported
  • Atlas training products: Supported

Description

Sets the device resource limit of the specified stream.

This API should be used after calling aclrtSetDevice and before executing operators. If the resource limit is set for the same stream multiple times, the last setting takes effect.

After calling this API to set the device resource limit of the specified stream, call aclrtUseStreamResInCurrentThread to set the device resource limit of the specified stream to be used in the current thread.

Parameters

Name Input/Output Description
stream Input Stream. For details about the type definition, see aclrtStream.
If NULL is passed in, the default stream is used.
type Input Resource type. For details, see aclrtDevResLimitType.
value Input Size of the resource limit.

Return Values

Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.




aclrtResetStreamResLimit

aclError aclrtResetStreamResLimit(aclrtStream stream)

Applicable Products

  • Ascend 950PR&950DT products: Supported
  • Atlas A3 products: Supported
  • Atlas A2 products: Supported
  • Atlas 200I/500 A2 inference products: Supported
  • Atlas inference products: Supported
  • Atlas training products: Supported

Description

Resets the device resource limit of the specified stream to restore the default configuration after the aclrtSetStreamResLimit API is called to set the device resource limit of the specified stream. At this time, the default resource limit can be queried through the aclrtGetStreamResLimit API.

Parameters

Name Input/Output Description
stream Input Stream. For details about the type definition, see aclrtStream.
If NULL is passed in, the default stream is used.

Return Values

Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.




aclrtUseStreamResInCurrentThread

aclError aclrtUseStreamResInCurrentThread([aclrtStream](25-05_Typedefs.md#aclrtStream) stream)

Applicable Products

  • Ascend 950PR&950DT products: Supported
  • Atlas A3 products: Supported
  • Atlas A2 products: Supported
  • Atlas 200I/500 A2 inference products: Supported
  • Atlas inference products: Supported
  • Atlas training products: Supported

Description

Uses the device resource limit on the specified stream in the current thread. If this API is called multiple times to set the stream, the last setting takes effect.

Parameters

Name Input/Output Description
stream Input Stream. For details about the type definition, see aclrtStream.
You must first call aclrtSetStreamResLimit to set the device resource limit on the stream.

Return Values

Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.




aclrtUnuseStreamResInCurrentThread

aclError aclrtUnuseStreamResInCurrentThread(aclrtStream stream)

Applicable Products

  • Ascend 950PR&950DT products: Supported
  • Atlas A3 products: Supported
  • Atlas A2 products: Supported
  • Atlas 200I/500 A2 inference products: Supported
  • Atlas inference products: Supported
  • Atlas training products: Supported

Description

Cancels the use of the device resource limit on the specified stream in the current thread.

Parameters

Name Input/Output Description
stream Input Stream. For details about the type definition, see aclrtStream.

Return Values

Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.




aclrtGetResInCurrentThread

aclError aclrtGetResInCurrentThread(aclrtDevResLimitType type, uint32_t *value)

Applicable Products

  • Ascend 950PR&950DT products: Supported
  • Atlas A3 products: Supported
  • Atlas A2 products: Supported
  • Atlas 200I/500 A2 inference products: Supported
  • Atlas inference products: Supported
  • Atlas training products: Supported

Description

Obtains the device resources available in the current thread.

When the device resources are obtained, the value is returned according to the following priority: stream-level device resource limit (set by calling the aclrtSetStreamResLimit API) > the device resource limit of the current process (set by calling the aclrtSetDeviceResLimit API) > the default resource limit of the AI processor hardware.

Parameters

Name Input/Output Description
type Input Resource type. For details, see aclrtDevResLimitType.
value Output Resource quantity.

Return Values

Returns 0 if the operation is successful; returns other values if the operation fails. For details, see aclError.