The app you develop must contain the code logic for runtime resource allocation. See API Call Sequence to learn about the overall API call sequence before viewing the resource allocation and deallocation workflows in this section.
Runtime resources include the device, context, and stream.
Allocate the device, context, and stream resources in sequence. The context and stream can be created implicitly or explicitly.
The key APIs are described as follows:
To pass the default stream to any API call, pass NULL directly.
Call aclrtCreateContext to explicitly create a context and call aclrtCreateStream to explicitly create a stream. When a context is explicitly created, the compute device is set by the call to aclrtSetDevice. The device ID is passed to the aclrtCreateContext call.
If the query result is ACL_HOST, host memory needs to be allocated for data transfer.
If the query result is ACL_DEVICE, only device memory needs to be allocated for data transfer.
For details, see Data Transfer.
Destroy the runtime allocations, including the stream, context, and device in sequence.
The key APIs are described as follows: