Context Management
Function: create_context
C Prototype |
aclError aclrtCreateContext(aclrtContext *context, int32_t deviceId) |
---|---|
Python Function |
context, ret = acl.rt.create_context(device_id) |
Function Usage |
Explicitly creates a context, which contains two streams, one default stream, and one stream for internal synchronization. It is a synchronous interface. The following application scenarios are supported:
|
Input Description |
device_id: int, ID of the device for which the context is to be created. |
Return Value |
context: int, pointer to the created context in C. ret: int, error code.
|
Restrictions |
None |
Precautions |
None |
Function: destroy_context
C Prototype |
aclError aclrtDestroyContext(aclrtContext context) |
---|---|
Python Function |
ret = acl.rt.destroy_context(context) |
Function Usage |
Destroys a context and releases the resources of the context. It is a synchronous interface. Only the context created by calling acl.rt.create_context can be destroyed. |
Input Description |
Context: int, context object pointer to be destroyed. The context object can be obtained using create or get. |
Return Value |
ret: int, error code.
|
Restrictions |
Do not destroy the context repeatedly. Otherwise, a segment error occurs. Destruction API: The released or destroyed resources are no longer available after this API is called. You are advised to set the released or destroyed resources to invalid values (for example, 0 or None) after calling this API. |
Precautions |
None |
Function: set_context
C Prototype |
aclError aclrtSetCurrentContext(aclrtContext context) |
---|---|
Python Function |
ret = acl.rt.set_context(context) |
Function Usage |
Sets context of a thread. It is a synchronous interface. |
Input Description |
context: int, current context object pointer of the thread. |
Return Value |
ret: int, error code.
|
Restrictions |
|
Precautions |
The validity of the input parameters of this API must be ensured by users. |
Function: get_context
C Prototype |
aclError aclrtGetCurrentContext(aclrtContext *context) |
---|---|
Python Function |
Context, ret = acl.rt.get_context() |
Function Usage |
Obtains the context of a thread. It is a synchronous interface. |
Input Description |
None |
Return Value |
context: int, context object pointer. ret: int, error code.
|
Restrictions |
None |
Precautions |
None |