npu.open

Description

Registers an NPU device, used in conjunction with as_default to set the NPU as the default device.

Prototype

npu.open(device_id=None).as_default()

Parameters

Parameter

Input/Output

Description

device_id

Input

ID of the NPU device to be initialized. Defaults to the value of the ASCEND_DEVICE_ID environment variable or 0 if the ASCEND_DEVICE_ID environment variable is not set.

ASCEND_DEVICE_ID specifies the logical ID of the Ascend AI Processor used by the current process. Value range: [0, N-1]. Example:

export ASCEND_DEVICE_ID=0

Returns

A npu_device instance.

Example

1
2
import npu_device as npu
npu.open().as_default()