For the Ascend 310 AI Processor, this function is not supported in the current version.
Note the following restrictions:
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.
int main(int argc, const char *argv[])
{
//Initialize AscendCL.
auto ret = aclInit(NULL);
int32_t canAccessPeer = 0;
//Query whether memory copy is supported between device 0 and device 1.
ret = aclrtDeviceCanAccessPeer(&canAccessPeer, 0, 1);
//1 indicates that memory copy is supported.
if (canAccessPeer == 1) {
// ************************************************************
//Operate device 0.
ret = aclrtSetDevice(0);
//Enable memory copy from the current device (device 0) to the specified device (device 1).
ret = aclrtDeviceEnablePeerAccess(1, 0);
void *dev0;
ret = aclrtMalloc(&dev0, 10, ACL_MEM_MALLOC_HUGE_FIRST_P2P);
ret = aclrtMemset(dev0, 10, 1, 10);
ret = aclrtResetDevice(0);
// ************************************************************
//Operate device 1.
ret = aclrtSetDevice(1);
//Enable memory copy from the current device (device 1) to the specified device (device 0).
ret = aclrtDeviceEnablePeerAccess(0, 0);
void *dev1;
ret = aclrtMalloc(&dev1, 10, ACL_MEM_MALLOC_HUGE_FIRST_P2P);
ret = aclrtMemset(dev1, 10, 0, 10);
//Perform memory copy to transfer data from device 0 to device 1.
ret = aclrtMemcpy(dev1, 10, dev0, 10, ACL_MEMCPY_DEVICE_TO_DEVICE);
ret = aclrtResetDevice(1);
// ************************************************************
printf("P2P copy success\n");
} else {
printf("current device doesn't support p2p feature\n");
}
//Deinitialize AscendCL.
aclFinalize();
return 0;
}