Default Stream
When the aclrtSetDevice or aclrtCreateContext API is called, Runtime automatically creates a default stream. Each context has a default stream. If different host threads use the same context, they share the same default stream.
For APIs (such as aclrtMemcpyAsync) that require the stream parameter, if the default stream is used as the input parameter, pass nullptr directly. For APIs (such as aclrtMemcpy) that do not require the stream parameter, the default stream is not used.
The default stream cannot be destroyed by explicitly calling aclrtDestroyStream. When aclrtResetDevice or aclrtResetDeviceForce is called to release resources, the stream is automatically destroyed by default.
The following is a code sample for delivering compute tasks to the default stream, which is for reference only and cannot be directly copied for compilation or running.
1 2 3 4 5 6 7 8 9 10 11 12 13 | // Specify a device. (The default stream is automatically created in the API.) aclrtSetDevice(0); // Deliver the host-to-device copy task, MyKernel task, and device-to-host copy task to the default stream. aclrtMemcpyAsync(devPtrIn, size, hostPtr, hostSize, ACL_MEMCPY_HOST_TO_DEVICE, nullptr); myKernel<<<8, nullptr, nullptr>>>(devPtrIn, devPtrOut, size); aclrtMemcpyAsync(hostPtr, hostSize, devPtrOut, size, ACL_MEMCPY_DEVICE_TO_HOST, nullptr); // Synchronize the default stream. aclrtStreamSynchronize(nullptr); // Reset the device. (The default stream is automatically destroyed in the API.) aclrtResetDevice(0); |