Following the API calls, add exception handling branches and specify log printing of error and information levels. The following is a code snippet of key steps only, which is not ready to be built or run.
#include "acl/acl.h"
// ......
void runThread(aclrtStream stream) {
int32_t deviceId =0 ;
aclrtContext context;
//If only one context is created, the thread uses this context by default.
//If there are multiple contexts, aclrtSetCurrentContext should be called to set the context for the current thread.
aclrtCreateContext(&context, deviceId);
aclrtCreateStream(&stream);
//Call the task execution API.
// ....
//Destroy allocations.
aclrtDestroyStream(stream);
aclrtDestroyContext(context);
}
aclrtStream stream1;
aclrtStream stream2;
//Create two threads. Each thread corresponds to a stream.
std::thread t1(runThread, stream1);
std::thread t2(runThread, stream2);
//Explicitly call the join functions to ensure that the threads are ended.
t1.join();
t2.join();