Persistent Stream
Tasks in a non-persistent stream are dequeued from the stream after being executed. To execute a task for multiple times, you need to deliver the task to a non-persistent stream for multiple times.
The Runtime module provides persistent streams to support task persistence. Tasks delivered to a persistent stream are not executed immediately, and are not destroyed immediately after being executed. Tasks in a persistent stream are destroyed only when the persistent stream is destroyed.
Call aclrtCreateStreamWithConfig to create a persistent stream. The persistent stream needs to be bound to the model running instance to support repeated execution of the model. The following is the sample code, which is for reference only and cannot be directly copied for compilation and running:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | // Create a persistent stream. aclrtStream stream; aclrtCreateStreamWithConfig(&stream, 0, ACL_STREAM_PERSISTENT); // Build a model running instance. aclmdlRI modelRI; aclmdlRIBuildBegin(&modelRI, 0); // Bind the persistent stream to a model running instance. aclmdlRIBindStream(modelRI, stream, ACL_MODEL_STREAM_FLAG_HEAD); // Deliver tasks to the persistent stream. ...... // Mark the end of task delivery. aclmdlRIEndTask(modelRI, stream); // End the model running instance building. aclmdlRIBuildEnd(modelRI, nullptr); // Execute the model running instance multiple times in the default stream. aclmdlRIExecute(modelRI, -1); aclmdlRIExecute(modelRI, -1); // Unbind the persistent stream from the model running instance. aclmdlRIUnbindStream(modelRI, stream); // Destroy resources. aclrtDestroyStream(stream); aclmdlRIDestroy(modelRI); ...... |