aclrtCreateContext

Description

Creates a context explicitly in the current process or thread. This API is synchronous.

For the Ascend 310 AI Processor, the context contains two streams: one default stream and one stream for internal synchronization.

For the Ascend 910 AI Processor, the context contains one default stream.

For the Ascend 310P AI Processor, in standard form, the context contains two streams: one default stream and one stream for internal synchronization.

Restrictions

The following use cases are supported:

For the Ascend 310 AI Processor, if the aclrtSetDevice API is not called by the app, when the aclrtCreateContext API is called for the first time, the system binds a default stream to the device based on the device ID passed by the API (each device is bound to one default stream). Therefore, only when the aclrtCreateContext API is called for the first time, three streams are occupied: the default stream bound to the device, the default stream in the context, and the stream used for internal synchronization in the context.

For the Ascend 310P AI Processor, For the Ascend 910 AI Processor, if the aclrtSetDevice API is not called by the app, when the aclrtCreateContext API is called for the first time, the system binds a default stream to the device based on the device ID passed by the API (each device is bound to one default stream). Therefore, only when the aclrtCreateContext API is called for the first time, two streams are occupied: the default stream bound to the device and the default stream in the context.

Prototype

aclError aclrtCreateContext(aclrtContext *context, int32_t deviceId)

Parameters

Parameter

Input/Output

Description

deviceId

Input

ID of the device where the context is to be created.

context

Output

Context pointer.

Returns

0 on success; else, failure.

See Also

For details about the API call sequence and example, see Runtime Resource Allocation and Deallocation.