Intra-host data transfer is implemented by using the memory copy API.
You can use the aclrtMemcpy API to execute an intra-host memory copy task synchronously, but you cannot use the aclrtMemcpyAsync API to execute the task asynchronously. If aclrtMemcpyAsync is called and the ACL_MEMCPY_HOST_TO_HOST type is selected to deliver a memory copy task, a failure message will still be returned when the aclrtSynchronizeStream API is called to wait for the task to be executed.
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.
//1. Allocate memory. uint64_t size = 1 * 1024 * 1024; void* hostPtrA = NULL; void* hostPtrB = NULL; aclrtMallocHost(&hostPtrA, size); aclrtMallocHost(&hostPtrB, size); //2. After the memory is allocated, load data into the memory and implement the user-defined function ReadFile. ReadFile(fileName, hostPtrA, size); //3. Perform synchronous or asynchronous memory copy. //Copy memory synchronously. hostPtrA indicates the pointer to the source memory address on the host. hostPtrB indicates the pointer to the destination memory address on the host. size indicates the memory size. aclrtMemcpy(hostPtrB, size, hostPtrA, size, ACL_MEMCPY_HOST_TO_HOST); //4. Destroy allocations in a timely manner. aclrtFreeHost(hostPtrA); aclrtFreeHost(hostPtrB); // ......