SWDEV-232894 Port hipMemcpy optimizations from HCC to VDI

Apply the optimization to change for OpenCL too.
Clean up some unnecessary checks.

Change-Id: I840261fe35baeeadeba7388e86779d482f509aad
This commit is contained in:
Alex Xie
2020-04-28 22:12:30 -04:00
committed by German Andryeyev
parent 1de8abd031
commit 6c5a42b33c
7 changed files with 21 additions and 41 deletions
+11 -25
View File
@@ -28,9 +28,6 @@
#include <algorithm>
namespace roc {
constexpr size_t max_h2d_std_memcpy_sz{8 * 1024}; // 8 KiB.
constexpr size_t max_d2h_std_memcpy_sz{64}; // 1 cacheline.
DmaBlitManager::DmaBlitManager(VirtualGPU& gpu, Setup setup)
: HostBlitManager(gpu, setup),
MinSizeForPinnedTransfer(dev().settings().pinnedMinXferSize_),
@@ -1627,17 +1624,13 @@ bool KernelBlitManager::readBuffer(device::Memory& srcMemory, void* dstHost,
amd::ScopedLock k(lockXferOps_);
bool result = false;
if (amd::IS_HIP && context_->isLargeBar() && size[0] <= max_d2h_std_memcpy_sz && size[1] == 0 && size[2] == 0) {
if (dev().info().largeBar_ && size[0] <= kMaxD2hMemcpySize) {
if ((srcMemory.owner()->getHostMem() == nullptr) && (srcMemory.owner()->getSvmPtr() != nullptr)) {
void* src = srcMemory.owner()->getSvmPtr();
hsa_agent_t agents[1];
agents[0] = dev().getCpuAgent();
if (HSA_STATUS_SUCCESS == hsa_amd_agents_allow_access(1, agents, NULL, src)) {
synchronize();
std::memcpy(dstHost, src, size[0]);
return true;
}
std::memcpy(dstHost, src, size[0]);
// Set HASPENDINGDISPATCH_ FLAG. That will force L2 invalidation on flush
gpu().hasPendingDispatch();
return true;
}
}
@@ -1734,21 +1727,14 @@ bool KernelBlitManager::writeBuffer(const void* srcHost, device::Memory& dstMemo
amd::ScopedLock k(lockXferOps_);
bool result = false;
if (amd::IS_HIP && context_->isLargeBar() && size[0] <= max_h2d_std_memcpy_sz && size[1] == 0 && size[2] == 0) {
if (dev().info().largeBar_ && size[0] <= kMaxH2dMemcpySize) {
if ((dstMemory.owner()->getHostMem() == nullptr) && (dstMemory.owner()->getSvmPtr() != nullptr)) {
void* dst = dstMemory.owner()->getSvmPtr();
hsa_agent_t agents[1];
agents[0] = dev().getCpuAgent();
if (HSA_STATUS_SUCCESS == hsa_amd_agents_allow_access(1, agents, NULL, dst)) {
synchronize();
std::memcpy(dst, srcHost, size[0]);
if (AMD_OPT_FLUSH) {
gpu().hasPendingDispatch(); // Set hasPendingDispatch_ flag. So synchronize() use a barrier to invalidate cache
synchronize();
}
return true;
}
std::memcpy(dst, srcHost, size[0]);
// Set HASPENDINGDISPATCH_ FLAG. Then synchronize() will use barrier to invalidate cache
gpu().hasPendingDispatch();
synchronize();
return true;
}
}