Reuse graphics allocation from mapped buffers in OpenCL

Related-To: NEO-6352
Signed-off-by: Maciej Dziuban <maciej.dziuban@intel.com>
This commit is contained in:
Maciej Dziuban
2021-10-18 15:07:01 +00:00
committed by Compute-Runtime-Automation
parent f164acad0b
commit f1b6b733f0
21 changed files with 376 additions and 54 deletions

View File

@@ -82,6 +82,38 @@ cl_int Context::setDestructorCallback(void(CL_CALLBACK *funcNotify)(cl_context,
return CL_SUCCESS;
}
cl_int Context::tryGetExistingHostPtrAllocation(const void *ptr,
size_t size,
uint32_t rootDeviceIndex,
GraphicsAllocation *&allocation,
InternalMemoryType &memoryType,
bool &isCpuCopyAllowed) {
if (getSVMAllocsManager()) {
SvmAllocationData *svmEntry = getSVMAllocsManager()->getSVMAlloc(ptr);
if (svmEntry) {
memoryType = svmEntry->memoryType;
if ((svmEntry->gpuAllocations.getGraphicsAllocation(rootDeviceIndex)->getGpuAddress() + svmEntry->size) < (castToUint64(ptr) + size)) {
return CL_INVALID_OPERATION;
}
allocation = svmEntry->cpuAllocation ? svmEntry->cpuAllocation : svmEntry->gpuAllocations.getGraphicsAllocation(rootDeviceIndex);
if (isCpuCopyAllowed) {
if (svmEntry->memoryType == DEVICE_UNIFIED_MEMORY) {
isCpuCopyAllowed = false;
}
}
return CL_SUCCESS;
}
}
if (MapInfo mapInfo = {}; mapOperationsStorage.getInfoForHostPtr(ptr, size, mapInfo)) {
if (mapInfo.graphicsAllocation) {
allocation = mapInfo.graphicsAllocation;
}
}
return CL_SUCCESS;
}
const std::set<uint32_t> &Context::getRootDeviceIndices() const {
return rootDeviceIndices;
}

View File

@@ -9,6 +9,7 @@
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/helpers/common_types.h"
#include "shared/source/helpers/vec.h"
#include "shared/source/unified_memory/unified_memory.h"
#include "opencl/source/cl_device/cl_device_vector.h"
#include "opencl/source/context/context_type.h"
@@ -96,6 +97,13 @@ class Context : public BaseObject<_cl_context> {
auto &getMapOperationsStorage() { return mapOperationsStorage; }
cl_int tryGetExistingHostPtrAllocation(const void *ptr,
size_t size,
uint32_t rootDeviceIndex,
GraphicsAllocation *&allocation,
InternalMemoryType &memoryType,
bool &isCpuCopyAllowed);
const std::set<uint32_t> &getRootDeviceIndices() const;
uint32_t getMaxRootDeviceIndex() const;