diff --git a/runtime/helpers/mem_properties_parser_helper.cpp b/runtime/helpers/mem_properties_parser_helper.cpp index 395d36e3cd..5e08f3ad99 100644 --- a/runtime/helpers/mem_properties_parser_helper.cpp +++ b/runtime/helpers/mem_properties_parser_helper.cpp @@ -29,10 +29,10 @@ bool NEO::MemoryPropertiesParser::parseMemoryProperties(const cl_mem_properties_ return true; } -void MemoryPropertiesParser::fillPoliciesInProperties(AllocationProperties &allocationProperties, const MemoryProperties &memoryProperties) { +void MemoryPropertiesParser::fillPoliciesInProperties(AllocationProperties &allocationProperties, const MemoryPropertiesFlags &memoryProperties) { fillCachePolicyInProperties(allocationProperties, - isValueSet(memoryProperties.flags_intel, CL_MEM_LOCALLY_UNCACHED_RESOURCE), - isValueSet(memoryProperties.flags, CL_MEM_READ_ONLY), + memoryProperties.locallyUncachedResource, + memoryProperties.readOnly, false); } diff --git a/runtime/helpers/mem_properties_parser_helper.h b/runtime/helpers/mem_properties_parser_helper.h index 319bea5912..be1f21a44f 100644 --- a/runtime/helpers/mem_properties_parser_helper.h +++ b/runtime/helpers/mem_properties_parser_helper.h @@ -10,6 +10,7 @@ #include "runtime/memory_manager/allocation_properties.h" #include "mem_obj_types.h" +#include "memory_properties_flags.h" namespace NEO { @@ -17,14 +18,14 @@ class MemoryPropertiesParser { public: static bool parseMemoryProperties(const cl_mem_properties_intel *properties, MemoryProperties &propertiesStruct); - static AllocationProperties getAllocationProperties(MemoryProperties memoryProperties, bool allocateMemory, + static AllocationProperties getAllocationProperties(MemoryPropertiesFlags memoryProperties, bool allocateMemory, size_t size, GraphicsAllocation::AllocationType type, bool multiStorageResource) { AllocationProperties allocationProperties(allocateMemory, size, type, multiStorageResource); fillPoliciesInProperties(allocationProperties, memoryProperties); return allocationProperties; } - static void fillPoliciesInProperties(AllocationProperties &allocationProperties, const MemoryProperties &memoryProperties); + static void fillPoliciesInProperties(AllocationProperties &allocationProperties, const MemoryPropertiesFlags &memoryProperties); static void fillCachePolicyInProperties(AllocationProperties &allocationProperties, bool uncached, bool readOnly, bool deviceOnlyVisibilty) { diff --git a/runtime/mem_obj/buffer.cpp b/runtime/mem_obj/buffer.cpp index d462889330..e9cecda1b2 100644 --- a/runtime/mem_obj/buffer.cpp +++ b/runtime/mem_obj/buffer.cpp @@ -220,7 +220,8 @@ Buffer *Buffer::create(Context *context, } if (!memory) { - AllocationProperties allocProperties = MemoryPropertiesParser::getAllocationProperties(properties, allocateMemory, size, allocationType, context->areMultiStorageAllocationsPreferred()); + MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties); + AllocationProperties allocProperties = MemoryPropertiesParser::getAllocationProperties(memoryProperties, allocateMemory, size, allocationType, context->areMultiStorageAllocationsPreferred()); memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties, hostPtr); } @@ -233,7 +234,8 @@ Buffer *Buffer::create(Context *context, allocationType = GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY; zeroCopyAllowed = false; copyMemoryFromHostPtr = true; - AllocationProperties allocProperties = MemoryPropertiesParser::getAllocationProperties(properties, true, size, allocationType, context->areMultiStorageAllocationsPreferred()); + MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties); + AllocationProperties allocProperties = MemoryPropertiesParser::getAllocationProperties(memoryProperties, true, size, allocationType, context->areMultiStorageAllocationsPreferred()); memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties); } diff --git a/runtime/mem_obj/image.cpp b/runtime/mem_obj/image.cpp index 0d4ffa391d..4c77b42e64 100644 --- a/runtime/mem_obj/image.cpp +++ b/runtime/mem_obj/image.cpp @@ -253,7 +253,8 @@ Image *Image::create(Context *context, if (isValueSet(properties.flags, CL_MEM_USE_HOST_PTR)) { if (!context->isSharedContext) { - AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(imgInfo, false, properties); + MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties); + AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(imgInfo, false, memoryProperties); memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties, hostPtr); @@ -277,7 +278,8 @@ Image *Image::create(Context *context, mapAllocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, hostPtr); } } else { - AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(imgInfo, true, properties); + MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties); + AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(imgInfo, true, memoryProperties); memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties); if (memory && MemoryPool::isSystemMemoryPool(memory->getMemoryPool())) { diff --git a/runtime/mem_obj/mem_obj_helper.h b/runtime/mem_obj/mem_obj_helper.h index 2f79c89b5c..e0255bdba6 100644 --- a/runtime/mem_obj/mem_obj_helper.h +++ b/runtime/mem_obj/mem_obj_helper.h @@ -88,7 +88,7 @@ class MemObjHelper { return validateExtraMemoryProperties(properties); } - static AllocationProperties getAllocationPropertiesWithImageInfo(ImageInfo &imgInfo, bool allocateMemory, const MemoryProperties &memoryProperties) { + static AllocationProperties getAllocationPropertiesWithImageInfo(ImageInfo &imgInfo, bool allocateMemory, const MemoryPropertiesFlags &memoryProperties) { AllocationProperties allocationProperties{allocateMemory, imgInfo, GraphicsAllocation::AllocationType::IMAGE}; MemoryPropertiesParser::fillPoliciesInProperties(allocationProperties, memoryProperties); return allocationProperties; diff --git a/runtime/mem_obj/pipe.cpp b/runtime/mem_obj/pipe.cpp index f102c5af79..1ffaee520e 100644 --- a/runtime/mem_obj/pipe.cpp +++ b/runtime/mem_obj/pipe.cpp @@ -9,6 +9,7 @@ #include "runtime/context/context.h" #include "runtime/helpers/get_info.h" +#include "runtime/helpers/memory_properties_flags_helpers.h" #include "runtime/mem_obj/mem_obj_helper.h" #include "runtime/memory_manager/memory_manager.h" @@ -49,10 +50,11 @@ Pipe *Pipe::create(Context *context, DEBUG_BREAK_IF(!memoryManager); MemoryProperties memoryProperties{flags}; + MemoryPropertiesFlags memoryPropertiesFlags = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(memoryProperties); while (true) { auto size = static_cast(packetSize * (maxPackets + 1) + intelPipeHeaderReservedSpace); AllocationProperties allocProperties = - MemoryPropertiesParser::getAllocationProperties(memoryProperties, true, size, GraphicsAllocation::AllocationType::PIPE, false); + MemoryPropertiesParser::getAllocationProperties(memoryPropertiesFlags, true, size, GraphicsAllocation::AllocationType::PIPE, false); GraphicsAllocation *memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties); if (!memory) { errcodeRet = CL_OUT_OF_HOST_MEMORY; diff --git a/runtime/sharings/d3d/d3d_surface.cpp b/runtime/sharings/d3d/d3d_surface.cpp index 7c3cdeafdd..61f5698d8b 100644 --- a/runtime/sharings/d3d/d3d_surface.cpp +++ b/runtime/sharings/d3d/d3d_surface.cpp @@ -12,6 +12,7 @@ #include "runtime/gmm_helper/gmm.h" #include "runtime/gmm_helper/gmm_helper.h" #include "runtime/helpers/get_info.h" +#include "runtime/helpers/memory_properties_flags_helpers.h" #include "runtime/mem_obj/image.h" #include "runtime/mem_obj/mem_obj_helper.h" #include "runtime/memory_manager/memory_manager.h" @@ -92,8 +93,9 @@ Image *D3DSurface::create(Context *context, cl_dx9_surface_info_khr *surfaceInfo imgDesc.image_width /= 2; imgDesc.image_height /= 2; } - - AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(imgInfo, true, flags); + MemoryProperties properties{flags}; + MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties); + AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(imgInfo, true, memoryProperties); allocProperties.allocationType = GraphicsAllocation::AllocationType::SHARED_RESOURCE_COPY; alloc = context->getMemoryManager()->allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr); diff --git a/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp b/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp index 75e46406b8..97292e81a8 100644 --- a/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp +++ b/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp @@ -469,7 +469,7 @@ HWTEST_F(AubCommandStreamReceiverNoHostPtrTests, givenAubCommandStreamReceiverWh auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr); - AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(imgInfo, true, 0); + AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(imgInfo, true, {}); auto imageAllocation = memoryManager->allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr); ASSERT_NE(nullptr, imageAllocation); diff --git a/unit_tests/mem_obj/image_tests.cpp b/unit_tests/mem_obj/image_tests.cpp index 517d863186..fc88e48d98 100644 --- a/unit_tests/mem_obj/image_tests.cpp +++ b/unit_tests/mem_obj/image_tests.cpp @@ -1466,7 +1466,7 @@ HWTEST_F(HwImageTest, givenImageHwWhenSettingCCSParamsThenSetClearColorParamsIsC format.image_channel_order = CL_RGBA; auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr); - AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(imgInfo, true, 0); + AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(imgInfo, true, {}); auto graphicsAllocation = memoryManager.allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr); @@ -1497,7 +1497,7 @@ HWTEST_F(HwImageTest, givenImageHwWithUnifiedSurfaceAndMcsWhenSettingParamsForMu cl_image_format format = {}; auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr); - AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(imgInfo, true, 0); + AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(imgInfo, true, {}); auto graphicsAllocation = memoryManager.allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr); diff --git a/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.inl b/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.inl index 5eff99ea58..b3943bf26d 100644 --- a/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.inl +++ b/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.inl @@ -6,6 +6,7 @@ */ #include "runtime/execution_environment/execution_environment.h" +#include "runtime/helpers/memory_properties_flags_helpers.h" #include "runtime/mem_obj/mem_obj_helper.h" #include "runtime/memory_manager/os_agnostic_memory_manager.h" #include "test.h" @@ -55,23 +56,29 @@ TEST(AllocationFlagsTest, givenAllocateMemoryFlagWhenGetAllocationFlagsIsCalledT } TEST(UncacheableFlagsTest, givenUncachedResourceFlagWhenGetAllocationFlagsIsCalledThenUncacheableFlagIsCorrectlySet) { - MemoryProperties memoryProperties; - memoryProperties.flags_intel = CL_MEM_LOCALLY_UNCACHED_RESOURCE; + MemoryProperties properties; + properties.flags_intel = CL_MEM_LOCALLY_UNCACHED_RESOURCE; + MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties); auto allocationFlags = MemoryPropertiesParser::getAllocationProperties(memoryProperties, false, 0, GraphicsAllocation::AllocationType::BUFFER, false); EXPECT_TRUE(allocationFlags.flags.uncacheable); - memoryProperties.flags_intel = 0; + properties.flags_intel = 0; + memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties); allocationFlags = MemoryPropertiesParser::getAllocationProperties(memoryProperties, false, 0, GraphicsAllocation::AllocationType::BUFFER, false); EXPECT_FALSE(allocationFlags.flags.uncacheable); } TEST(AllocationFlagsTest, givenReadOnlyResourceFlagWhenGetAllocationFlagsIsCalledThenFlushL3FlagsAreCorrectlySet) { + MemoryProperties properties; + properties.flags = CL_MEM_READ_ONLY; + MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties); + auto allocationFlags = - MemoryPropertiesParser::getAllocationProperties(CL_MEM_READ_ONLY, true, 0, GraphicsAllocation::AllocationType::BUFFER, false); + MemoryPropertiesParser::getAllocationProperties(memoryProperties, true, 0, GraphicsAllocation::AllocationType::BUFFER, false); EXPECT_FALSE(allocationFlags.flags.flushL3RequiredForRead); EXPECT_FALSE(allocationFlags.flags.flushL3RequiredForWrite); - allocationFlags = MemoryPropertiesParser::getAllocationProperties(0, true, 0, GraphicsAllocation::AllocationType::BUFFER, false); + allocationFlags = MemoryPropertiesParser::getAllocationProperties({}, true, 0, GraphicsAllocation::AllocationType::BUFFER, false); EXPECT_TRUE(allocationFlags.flags.flushL3RequiredForRead); EXPECT_TRUE(allocationFlags.flags.flushL3RequiredForWrite); } diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp index b298e08704..05114973e3 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -1249,7 +1249,7 @@ TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleter EXPECT_EQ(0u, wddm->createAllocationResult.called); deleter->expectDrainBlockingValue(true); - AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(imgInfo, true, 0); + AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(imgInfo, true, {}); memoryManager->allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr); EXPECT_EQ(1, deleter->drainCalled); @@ -1268,7 +1268,7 @@ TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleter EXPECT_EQ(0u, wddm->createAllocationResult.called); EXPECT_EQ(0u, wddm->mapGpuVirtualAddressResult.called); - AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(imgInfo, true, 0); + AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(imgInfo, true, {}); auto allocation = memoryManager->allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr); EXPECT_EQ(0, deleter->drainCalled); @@ -1286,7 +1286,7 @@ TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithoutAsyncDele wddm->createAllocationStatus = STATUS_GRAPHICS_NO_VIDEO_MEMORY; EXPECT_EQ(0u, wddm->createAllocationResult.called); - AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(imgInfo, true, 0); + AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(imgInfo, true, {}); memoryManager->allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr); EXPECT_EQ(1u, wddm->createAllocationResult.called);