From 94be510c18186d81551abca54820149b2a0a0b9b Mon Sep 17 00:00:00 2001 From: Maciej Dziuban Date: Thu, 26 Nov 2020 17:52:21 +0000 Subject: [PATCH] Add initial placement hints for USM in OpenCL Related-To: NEO-5059 Signed-off-by: Maciej Dziuban --- opencl/extensions/public/cl_ext_private.h | 2 ++ .../source/helpers/memory_properties_helpers_base.inl | 10 ++++++---- .../helpers/memory_properties_helpers_tests.cpp | 6 ++++++ .../memory_properties_flags_common.inl | 4 ++-- .../page_fault_manager/cpu_page_fault_manager.cpp | 2 +- .../cpu_page_fault_manager_tests.cpp | 10 +++++----- 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/opencl/extensions/public/cl_ext_private.h b/opencl/extensions/public/cl_ext_private.h index 65f4645640..ca442e67e9 100644 --- a/opencl/extensions/public/cl_ext_private.h +++ b/opencl/extensions/public/cl_ext_private.h @@ -103,6 +103,8 @@ using cl_unified_shared_memory_capabilities_intel = cl_bitfield; /* cl_mem_alloc_flags_intel - bitfield */ #define CL_MEM_ALLOC_DEFAULT_INTEL 0 #define CL_MEM_ALLOC_WRITE_COMBINED_INTEL (1 << 0) +#define CL_MEM_ALLOC_INITIAL_PLACEMENT_DEVICE_INTEL (1 << 1) +#define CL_MEM_ALLOC_INITIAL_PLACEMENT_HOST_INTEL (1 << 2) /* cl_mem_alloc_info_intel */ #define CL_MEM_ALLOC_TYPE_INTEL 0x419A diff --git a/opencl/source/helpers/memory_properties_helpers_base.inl b/opencl/source/helpers/memory_properties_helpers_base.inl index a31f8aa673..d24282a194 100644 --- a/opencl/source/helpers/memory_properties_helpers_base.inl +++ b/opencl/source/helpers/memory_properties_helpers_base.inl @@ -65,19 +65,21 @@ MemoryProperties MemoryPropertiesHelper::createMemoryProperties(cl_mem_flags fla if (isValueSet(flagsIntel, CL_MEM_LOCALLY_UNCACHED_RESOURCE)) { memoryProperties.flags.locallyUncachedResource = true; } - if (isValueSet(flagsIntel, CL_MEM_LOCALLY_UNCACHED_SURFACE_STATE_RESOURCE)) { memoryProperties.flags.locallyUncachedInSurfaceState = true; } - if (isValueSet(flags, CL_MEM_FORCE_HOST_MEMORY_INTEL)) { memoryProperties.flags.forceHostMemory = true; } - if (isValueSet(allocflags, CL_MEM_ALLOC_WRITE_COMBINED_INTEL)) { memoryProperties.allocFlags.allocWriteCombined = true; } - + if (isValueSet(allocflags, CL_MEM_ALLOC_INITIAL_PLACEMENT_DEVICE_INTEL)) { + memoryProperties.allocFlags.usmInitialPlacementGpu = true; + } + if (isValueSet(allocflags, CL_MEM_ALLOC_INITIAL_PLACEMENT_HOST_INTEL)) { + memoryProperties.allocFlags.usmInitialPlacementCpu = true; + } if (isValueSet(flagsIntel, CL_MEM_48BIT_RESOURCE_INTEL)) { memoryProperties.flags.resource48Bit = true; } diff --git a/opencl/test/unit_test/helpers/memory_properties_helpers_tests.cpp b/opencl/test/unit_test/helpers/memory_properties_helpers_tests.cpp index 244aed7369..086812a3f6 100644 --- a/opencl/test/unit_test/helpers/memory_properties_helpers_tests.cpp +++ b/opencl/test/unit_test/helpers/memory_properties_helpers_tests.cpp @@ -71,6 +71,12 @@ TEST(MemoryProperties, givenValidPropertiesWhenCreateMemoryPropertiesThenTrueIsR properties = MemoryPropertiesHelper::createMemoryProperties(0, 0, CL_MEM_ALLOC_WRITE_COMBINED_INTEL, pDevice); EXPECT_TRUE(properties.allocFlags.allocWriteCombined); + properties = MemoryPropertiesHelper::createMemoryProperties(0, 0, CL_MEM_ALLOC_INITIAL_PLACEMENT_DEVICE_INTEL, pDevice); + EXPECT_TRUE(properties.allocFlags.usmInitialPlacementGpu); + + properties = MemoryPropertiesHelper::createMemoryProperties(0, 0, CL_MEM_ALLOC_INITIAL_PLACEMENT_HOST_INTEL, pDevice); + EXPECT_TRUE(properties.allocFlags.usmInitialPlacementCpu); + properties = MemoryPropertiesHelper::createMemoryProperties(0, CL_MEM_48BIT_RESOURCE_INTEL, 0, pDevice); EXPECT_TRUE(properties.flags.resource48Bit); } diff --git a/shared/source/memory_properties/memory_properties_flags_common.inl b/shared/source/memory_properties/memory_properties_flags_common.inl index 28df95c3f8..5fa43f97c8 100644 --- a/shared/source/memory_properties/memory_properties_flags_common.inl +++ b/shared/source/memory_properties/memory_properties_flags_common.inl @@ -28,12 +28,12 @@ struct MemoryFlags { uint32_t forceHostMemory : 1; uint32_t shareable : 1; uint32_t resource48Bit : 1; - uint32_t usmInitialPlacementCpu : 1; - uint32_t usmInitialPlacementGpu : 1; }; struct MemoryAllocFlags { uint32_t allocWriteCombined : 1; + uint32_t usmInitialPlacementCpu : 1; + uint32_t usmInitialPlacementGpu : 1; }; } // namespace NEO diff --git a/shared/source/page_fault_manager/cpu_page_fault_manager.cpp b/shared/source/page_fault_manager/cpu_page_fault_manager.cpp index 10b52a3a8e..3b13732bd6 100644 --- a/shared/source/page_fault_manager/cpu_page_fault_manager.cpp +++ b/shared/source/page_fault_manager/cpu_page_fault_manager.cpp @@ -15,7 +15,7 @@ namespace NEO { void PageFaultManager::insertAllocation(void *ptr, size_t size, SVMAllocsManager *unifiedMemoryManager, void *cmdQ, const MemoryProperties &memoryProperties) { - const bool initialPlacementCpu = !memoryProperties.flags.usmInitialPlacementGpu; + const bool initialPlacementCpu = !memoryProperties.allocFlags.usmInitialPlacementGpu; const auto domain = initialPlacementCpu ? AllocationDomain::Cpu : AllocationDomain::None; std::unique_lock lock{mtx}; diff --git a/shared/test/unit_test/page_fault_manager/cpu_page_fault_manager_tests.cpp b/shared/test/unit_test/page_fault_manager/cpu_page_fault_manager_tests.cpp index 2c61f9d570..ba09a3c36e 100644 --- a/shared/test/unit_test/page_fault_manager/cpu_page_fault_manager_tests.cpp +++ b/shared/test/unit_test/page_fault_manager/cpu_page_fault_manager_tests.cpp @@ -232,7 +232,7 @@ TEST_F(PageFaultManagerTest, givenInitialPlacementCpuWhenVerifyingPagefaultThenF void *alloc = reinterpret_cast(0x1); MemoryProperties memoryProperties{}; - memoryProperties.flags.usmInitialPlacementCpu = 1; + memoryProperties.allocFlags.usmInitialPlacementCpu = 1; pageFaultManager->insertAllocation(alloc, 10, reinterpret_cast(unifiedMemoryManager), nullptr, memoryProperties); EXPECT_EQ(pageFaultManager->transferToCpuCalled, 0); EXPECT_EQ(pageFaultManager->memoryData.size(), 1u); @@ -252,7 +252,7 @@ TEST_F(PageFaultManagerTest, givenInitialPlacementGpuWhenVerifyingPagefaultThenF void *alloc = reinterpret_cast(0x1); MemoryProperties memoryProperties{}; - memoryProperties.flags.usmInitialPlacementGpu = 1; + memoryProperties.allocFlags.usmInitialPlacementGpu = 1; pageFaultManager->insertAllocation(alloc, 10, reinterpret_cast(unifiedMemoryManager), nullptr, memoryProperties); EXPECT_EQ(pageFaultManager->transferToCpuCalled, 0); EXPECT_EQ(pageFaultManager->memoryData.size(), 1u); @@ -277,7 +277,7 @@ TEST_F(PageFaultManagerTest, givenInitialPlacementCpuWhenMovingToGpuDomainThenFi void *alloc = reinterpret_cast(0x1); MemoryProperties memoryProperties{}; - memoryProperties.flags.usmInitialPlacementCpu = 1; + memoryProperties.allocFlags.usmInitialPlacementCpu = 1; pageFaultManager->insertAllocation(alloc, 10, reinterpret_cast(unifiedMemoryManager), cmdQ, memoryProperties); EXPECT_EQ(pageFaultManager->transferToCpuCalled, 0); EXPECT_EQ(pageFaultManager->memoryData.size(), 1u); @@ -301,7 +301,7 @@ TEST_F(PageFaultManagerTest, givenInitialPlacementGpuWhenMovingToGpuDomainThenFi void *alloc = reinterpret_cast(0x1); MemoryProperties memoryProperties{}; - memoryProperties.flags.usmInitialPlacementGpu = 1; + memoryProperties.allocFlags.usmInitialPlacementGpu = 1; pageFaultManager->insertAllocation(alloc, 10, reinterpret_cast(unifiedMemoryManager), cmdQ, memoryProperties); EXPECT_EQ(pageFaultManager->transferToCpuCalled, 0); EXPECT_EQ(pageFaultManager->memoryData.size(), 1u); @@ -324,7 +324,7 @@ TEST_F(PageFaultManagerTest, givenAllocationMovedToGpuDomainWhenVerifyingPagefau void *alloc = reinterpret_cast(0x1); MemoryProperties memoryProperties{}; - memoryProperties.flags.usmInitialPlacementGpu = 1; + memoryProperties.allocFlags.usmInitialPlacementGpu = 1; pageFaultManager->insertAllocation(alloc, 10, reinterpret_cast(unifiedMemoryManager), cmdQ, memoryProperties); EXPECT_EQ(pageFaultManager->transferToCpuCalled, 0); EXPECT_EQ(pageFaultManager->memoryData.size(), 1u);