Sets the compute device in the calling process or thread, and creates a default context implicitly. This API is synchronous.
For the Ascend 310 AI Processor, the default context contains two streams: one default stream and one stream for internal synchronization.
For the Ascend 910 AI Processor, the default context contains one default stream.
For the Ascend 310P AI Processor, in standard form, the default context contains two streams: one default stream and one stream for internal synchronization.
If aclrtSetDevice is called repeatedly in a process while aclrtResetDevice is not called to reset the device, no functional error is reported because the device will be automatically reset when the process exits. However, it is advisable to use aclrtResetDevice in conjunction with aclrtSetDevice to reset the device when it is no longer needed.
The following use cases are supported:
aclError aclrtSetDevice(int32_t deviceId)
Parameter |
Input/Output |
Description |
|---|---|---|
deviceId |
Input |
Device ID. Must be in the range of [0, Device count – 1]. Call aclrtGetDeviceCount to obtain the device count. |
0 on success; else, failure.
For details about the API call sequence and example, see Runtime Resource Allocation and Deallocation.