Stream Creation and Destruction
Call aclrtCreateStream to create a stream. The obtained aclrtStream object is used as the stream input parameter for subsequent asynchronous memory copy, stream synchronization, and kernel execution. An explicitly created stream needs to be explicitly destroyed by calling aclrtDestroyStream. When a stream is destroyed, if there are unfinished tasks in the stream, the stream is destroyed after the tasks are complete.
The following is a code sample for creating a stream and delivering compute tasks to the stream, which is for reference only and cannot be directly copied for compilation or running. For the complete sample code, click here.
1 2 3 4 5 6 7 8 9 10 11 | // Explicitly create a stream. aclrtStream stream; aclrtCreateStream(&stream); // Deliver the host-to-device copy task, MyKernel task, and device-to-host copy task to the stream. aclrtMemcpyAsync(devPtr, devSize, hostPtr, hostSize, ACL_MEMCPY_HOST_TO_DEVICE, stream); myKernel<<<8, nullptr, stream>>>(); aclrtMemcpyAsync(hostPtr, hostSize, devPtr, devSize, ACL_MEMCPY_DEVICE_TO_HOST, stream); // Destroy the stream (after the device-to-host copy task is complete). aclrtDestroyStream(stream); |
Parent topic: Stream Management