From ddcd3fbbed040a3c09be11c8ac6cbb09f7121595 Mon Sep 17 00:00:00 2001 From: Filip Hazubski Date: Fri, 26 Apr 2019 09:48:23 +0200 Subject: [PATCH] Simplify getAllocationProperties Change-Id: I006337ec700e50259c46be1fd73fde34562c8b83 Related-To: NEO-2535 Signed-off-by: Filip Hazubski --- runtime/mem_obj/mem_obj_helper.cpp | 8 +++---- runtime/mem_obj/mem_obj_helper.h | 20 ++++++++++------ runtime/memory_manager/svm_memory_manager.cpp | 6 ++--- unit_tests/mem_obj/mem_obj_helper_tests.cpp | 24 +++++++++++++++++++ 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/runtime/mem_obj/mem_obj_helper.cpp b/runtime/mem_obj/mem_obj_helper.cpp index 3e5d14c3aa98f..ff14d8031547e 100644 --- a/runtime/mem_obj/mem_obj_helper.cpp +++ b/runtime/mem_obj/mem_obj_helper.cpp @@ -31,13 +31,11 @@ bool MemObjHelper::parseMemoryProperties(const cl_mem_properties_intel *properti return true; } -AllocationProperties MemObjHelper::getAllocationProperties(MemoryProperties memoryProperties, bool allocateMemory, - size_t size, GraphicsAllocation::AllocationType type) { - AllocationProperties allocationProperties(allocateMemory, size, type); +void MemObjHelper::fillPoliciesInProperties(AllocationProperties &allocationProperties, MemoryProperties &memoryProperties) { fillCachePolicyInProperties(allocationProperties, isValueSet(memoryProperties.flags_intel, CL_MEM_LOCALLY_UNCACHED_RESOURCE), - isValueSet(memoryProperties.flags, CL_MEM_READ_ONLY)); - return allocationProperties; + isValueSet(memoryProperties.flags, CL_MEM_READ_ONLY), + false); } bool MemObjHelper::isSuitableForRenderCompression(bool renderCompressed, const MemoryProperties &properties, ContextType contextType, bool preferCompression) { diff --git a/runtime/mem_obj/mem_obj_helper.h b/runtime/mem_obj/mem_obj_helper.h index 631832a85dfc1..4c2adc6951599 100644 --- a/runtime/mem_obj/mem_obj_helper.h +++ b/runtime/mem_obj/mem_obj_helper.h @@ -88,19 +88,25 @@ class MemObjHelper { return validateExtraMemoryProperties(properties); } - static AllocationProperties getAllocationProperties(MemoryProperties properties, bool allocateMemory, - size_t size, GraphicsAllocation::AllocationType type); + static AllocationProperties getAllocationProperties(MemoryProperties memoryProperties, bool allocateMemory, + size_t size, GraphicsAllocation::AllocationType type) { + AllocationProperties allocationProperties(allocateMemory, size, type); + fillPoliciesInProperties(allocationProperties, memoryProperties); + return allocationProperties; + } + static AllocationProperties getAllocationProperties(ImageInfo &imgInfo, bool allocateMemory, MemoryProperties memoryProperties) { AllocationProperties allocationProperties{allocateMemory, imgInfo, GraphicsAllocation::AllocationType::IMAGE}; - fillCachePolicyInProperties(allocationProperties, - isValueSet(memoryProperties.flags_intel, CL_MEM_LOCALLY_UNCACHED_RESOURCE), - isValueSet(memoryProperties.flags, CL_MEM_READ_ONLY)); + fillPoliciesInProperties(allocationProperties, memoryProperties); return allocationProperties; } - static void fillCachePolicyInProperties(AllocationProperties &allocationProperties, bool uncached, bool readOnly) { + static void fillPoliciesInProperties(AllocationProperties &allocationProperties, MemoryProperties &memoryProperties); + + static void fillCachePolicyInProperties(AllocationProperties &allocationProperties, bool uncached, bool readOnly, + bool deviceOnlyVisibilty) { allocationProperties.flags.uncacheable = uncached; - auto cacheFlushRequired = !uncached && !readOnly; + auto cacheFlushRequired = !uncached && !readOnly && !deviceOnlyVisibilty; allocationProperties.flags.flushL3RequiredForRead = cacheFlushRequired; allocationProperties.flags.flushL3RequiredForWrite = cacheFlushRequired; } diff --git a/runtime/memory_manager/svm_memory_manager.cpp b/runtime/memory_manager/svm_memory_manager.cpp index 391e3cd25c88a..c8edb33494232 100644 --- a/runtime/memory_manager/svm_memory_manager.cpp +++ b/runtime/memory_manager/svm_memory_manager.cpp @@ -102,7 +102,7 @@ void SVMAllocsManager::freeSVMAlloc(void *ptr) { void *SVMAllocsManager::createZeroCopySvmAllocation(size_t size, const SvmAllocationProperties &svmProperties) { AllocationProperties properties{true, size, GraphicsAllocation::AllocationType::SVM_ZERO_COPY}; - MemObjHelper::fillCachePolicyInProperties(properties, false, svmProperties.readOnly); + MemObjHelper::fillCachePolicyInProperties(properties, false, svmProperties.readOnly, false); GraphicsAllocation *allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties); if (!allocation) { return nullptr; @@ -122,7 +122,7 @@ void *SVMAllocsManager::createSvmAllocationWithDeviceStorage(size_t size, const size_t alignedSize = alignUp(size, 2 * MemoryConstants::megaByte); AllocationProperties cpuProperties{true, alignedSize, GraphicsAllocation::AllocationType::SVM_CPU}; cpuProperties.alignment = 2 * MemoryConstants::megaByte; - MemObjHelper::fillCachePolicyInProperties(cpuProperties, false, svmProperties.readOnly); + MemObjHelper::fillCachePolicyInProperties(cpuProperties, false, svmProperties.readOnly, false); GraphicsAllocation *allocationCpu = memoryManager->allocateGraphicsMemoryWithProperties(cpuProperties); if (!allocationCpu) { return nullptr; @@ -133,7 +133,7 @@ void *SVMAllocsManager::createSvmAllocationWithDeviceStorage(size_t size, const AllocationProperties gpuProperties{false, alignedSize, GraphicsAllocation::AllocationType::SVM_GPU}; gpuProperties.alignment = 2 * MemoryConstants::megaByte; - MemObjHelper::fillCachePolicyInProperties(gpuProperties, false, svmProperties.readOnly); + MemObjHelper::fillCachePolicyInProperties(gpuProperties, false, svmProperties.readOnly, false); GraphicsAllocation *allocationGpu = memoryManager->allocateGraphicsMemoryWithProperties(gpuProperties, svmPtr); if (!allocationGpu) { memoryManager->freeGraphicsMemory(allocationCpu); diff --git a/unit_tests/mem_obj/mem_obj_helper_tests.cpp b/unit_tests/mem_obj/mem_obj_helper_tests.cpp index f2a778cd2b253..d8e0f0e7439a1 100644 --- a/unit_tests/mem_obj/mem_obj_helper_tests.cpp +++ b/unit_tests/mem_obj/mem_obj_helper_tests.cpp @@ -135,3 +135,27 @@ TEST(MemObjHelper, givenParentMemObjAndHostPtrFlagsWhenValidatingMemoryPropertie EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForImage(properties, imageWithAccessFlagsUnrestricted.get())); } } + +TEST(MemObjHelper, givenDifferentParametersWhenCallingFillCachePolicyInPropertiesThenFlushL3FlagsAreCorrectlySet) { + AllocationProperties allocationProperties{0, GraphicsAllocation::AllocationType::BUFFER}; + + for (auto uncached : ::testing::Bool()) { + for (auto readOnly : ::testing::Bool()) { + for (auto deviceOnlyVisibilty : ::testing::Bool()) { + if (uncached || readOnly || deviceOnlyVisibilty) { + allocationProperties.flags.flushL3RequiredForRead = true; + allocationProperties.flags.flushL3RequiredForWrite = true; + MemObjHelper::fillCachePolicyInProperties(allocationProperties, uncached, readOnly, deviceOnlyVisibilty); + EXPECT_FALSE(allocationProperties.flags.flushL3RequiredForRead); + EXPECT_FALSE(allocationProperties.flags.flushL3RequiredForWrite); + } else { + allocationProperties.flags.flushL3RequiredForRead = false; + allocationProperties.flags.flushL3RequiredForWrite = false; + MemObjHelper::fillCachePolicyInProperties(allocationProperties, uncached, readOnly, deviceOnlyVisibilty); + EXPECT_TRUE(allocationProperties.flags.flushL3RequiredForRead); + EXPECT_TRUE(allocationProperties.flags.flushL3RequiredForWrite); + } + } + } + } +}