From f19a872233fbfe2eb933f25fa3d9a780ced774e5 Mon Sep 17 00:00:00 2001 From: vboggara-xilinx <50370340+vboggara-xilinx@users.noreply.github.com> Date: Wed, 11 Nov 2020 10:58:23 +0530 Subject: [PATCH] CR-1082655:Added support for device buffer to device buffer copy in xclCopyBO in sw and hw emu 2020.2 (#4432) --- .../cpu_em/generic_pcie_hal2/shim.cxx | 23 ++++++++++++++----- .../hw_em/generic_pcie_hal2/shim.cxx | 21 +++++++++++++---- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/runtime_src/core/pcie/emulation/cpu_em/generic_pcie_hal2/shim.cxx b/src/runtime_src/core/pcie/emulation/cpu_em/generic_pcie_hal2/shim.cxx index 77dd7e95892..85fcd6a7a03 100644 --- a/src/runtime_src/core/pcie/emulation/cpu_em/generic_pcie_hal2/shim.cxx +++ b/src/runtime_src/core/pcie/emulation/cpu_em/generic_pcie_hal2/shim.cxx @@ -1359,22 +1359,33 @@ int CpuemShim::xclCopyBO(unsigned int dst_boHandle, unsigned int src_boHandle, s return -1; } } - else { - if (dBO->fd < 0) - { - std::cout << "bo is not exported for copying" << std::endl; + else if (!xclemulation::xocl_bo_host_only(sBO) && !xclemulation::xocl_bo_host_only(dBO) && (dBO->fd < 0) && (sBO->fd < 0)) { + unsigned char temp_buffer[size]; + // copy data from source buffer to temp buffer + if (xclCopyBufferDevice2Host((void*)temp_buffer, sBO->base, size, src_offset) != size) { + std::cerr << "ERROR: copy buffer from device to host failed " << std::endl; return -1; } + // copy data from temp buffer to destination buffer + if (xclCopyBufferHost2Device(dBO->base, (void*)temp_buffer, size, dst_offset) != size) { + std::cerr << "ERROR: copy buffer from host to device failed " << std::endl; + return -1; + } + } + else if (dBO->fd >= 0) { int ack = false; auto fItr = mFdToFileNameMap.find(dBO->fd); - if (fItr != mFdToFileNameMap.end()) - { + if (fItr != mFdToFileNameMap.end()) { const std::string& sFileName = std::get<0>((*fItr).second); xclCopyBO_RPC_CALL(xclCopyBO, sBO->base, sFileName, size, src_offset, dst_offset); } if (!ack) return -1; } + else { + std::cerr << "ERROR: Copy buffer from source to destination faliled" << std::endl; + return -1; + } PRINTENDFUNC; return 0; diff --git a/src/runtime_src/core/pcie/emulation/hw_em/generic_pcie_hal2/shim.cxx b/src/runtime_src/core/pcie/emulation/hw_em/generic_pcie_hal2/shim.cxx index 4b5d349df25..4a515e5eaf9 100755 --- a/src/runtime_src/core/pcie/emulation/hw_em/generic_pcie_hal2/shim.cxx +++ b/src/runtime_src/core/pcie/emulation/hw_em/generic_pcie_hal2/shim.cxx @@ -2622,12 +2622,21 @@ int HwEmShim::xclCopyBO(unsigned int dst_boHandle, unsigned int src_boHandle, si if (xclCopyBufferDevice2Host((void*)host_only_buffer, sBO->base, size, src_offset, sBO->topology) != size) { return -1; } - } - else { - if (dBO->fd < 0) { - std::cout << "bo is not exported for copying" << std::endl; + }// source and destination buffers are device_only + else if (!xclemulation::xocl_bo_host_only(sBO) && !xclemulation::xocl_bo_host_only(dBO) && (dBO->fd < 0) && (sBO->fd < 0)) { + unsigned char temp_buffer[size]; + // copy data from source buffer to temp buffer + if (xclCopyBufferDevice2Host((void*)temp_buffer, sBO->base, size, src_offset, sBO->topology) != size) { + std::cerr << "ERROR: copy buffer from device to host failed " << std::endl; + return -1; + } + // copy data from temp buffer to destination buffer + if (xclCopyBufferHost2Device(dBO->base, (void*)temp_buffer, size, dst_offset, dBO->topology) != size) { + std::cerr << "ERROR: copy buffer from host to device failed " << std::endl; return -1; } + } + else if(dBO->fd >= 0){ //destination p2p buffer int ack = false; auto fItr = mFdToFileNameMap.find(dBO->fd); if (fItr != mFdToFileNameMap.end()) { @@ -2637,6 +2646,10 @@ int HwEmShim::xclCopyBO(unsigned int dst_boHandle, unsigned int src_boHandle, si if (!ack) return -1; } + else{ + std::cerr << "ERROR: Copy buffer from source to destination faliled" << std::endl; + return -1; + } PRINTENDFUNC; return 0;