Intra-Host Data Transfer
acl.rt.memcpy can be called to execute the memory copy task synchronously in the host, but acl.rt.memcpy_async cannot be called to execute memory copy asynchronously in the host.
If ACL_MEMCPY_HOST_TO_HOST type is selected when acl.rt.memcpy_async is called, a failure message is returned when acl.rt.synchronize_stream is called to wait for the task execution although the API is successfully called and a memory copy task is delivered, because acl.rt.memcpy_async is an asynchronous API.
After APIs are called, add an exception handling branch, and record error logs and warning logs. The following is a code snippet of key steps only, which is not ready to use.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import acl # ...... # 1. Allocate memory. size = 1 * 1024 * 1024 host_ptr_a, ret = acl.rt.malloc_host(size) host_ptr_b, ret = acl.rt.malloc_host(size) # 2. After the memory is allocated, read data into the memory and implement the customized function read_file. read_file(fileName, host_ptr_a, size) # 3. Perform synchronous memory copy. # In synchronous memory copy, host_ptr_a indicates the address of the pointer to the source memory address on the host, host_ptr_b indicates the address of the pointer to the destination memory address on the host, and size indicates the memory size. # ACL_MEMCPY_HOST_TO_HOST = 0 ret = acl.rt.memcpy(host_ptr_b, size, host_ptr_a, size, ACL_MEMCPY_HOST_TO_HOST) # 4. Destroy allocations in a timely manner. ret = acl.rt.free_host(host_ptr_a) ret = acl.rt.free_host(host_ptr_b) # ...... |
Parent topic: Data Copy