diff --git a/core/memory_properties/memory_properties_flags_common.inl b/core/memory_properties/memory_properties_flags_common.inl index 0eb651d80d..1523382a02 100644 --- a/core/memory_properties/memory_properties_flags_common.inl +++ b/core/memory_properties/memory_properties_flags_common.inl @@ -27,6 +27,8 @@ struct MemoryPropertiesFlagsBase { bool locallyUncachedResource = false; bool allowUnrestrictedSize = false; + + bool forceSharedPhysicalMemory = false; }; } // namespace NEO diff --git a/runtime/helpers/memory_properties_flags_helpers_base.inl b/runtime/helpers/memory_properties_flags_helpers_base.inl index 28af10c86c..2f801919b1 100644 --- a/runtime/helpers/memory_properties_flags_helpers_base.inl +++ b/runtime/helpers/memory_properties_flags_helpers_base.inl @@ -63,6 +63,9 @@ MemoryPropertiesFlags MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(M if (isValueSet(properties.flags_intel, CL_MEM_LOCALLY_UNCACHED_RESOURCE)) { memoryPropertiesFlags.locallyUncachedResource = true; } + if (isValueSet(properties.flags, CL_MEM_FORCE_SHARED_PHYSICAL_MEMORY_INTEL)) { + memoryPropertiesFlags.forceSharedPhysicalMemory = true; + } addExtraMemoryPropertiesFlags(memoryPropertiesFlags, properties); diff --git a/runtime/mem_obj/buffer.cpp b/runtime/mem_obj/buffer.cpp index 76f97e24fc..bc8bfa000c 100644 --- a/runtime/mem_obj/buffer.cpp +++ b/runtime/mem_obj/buffer.cpp @@ -144,15 +144,15 @@ Buffer *Buffer::create(Context *context, MemoryManager *memoryManager = context->getMemoryManager(); UNRECOVERABLE_IF(!memoryManager); + MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties); GraphicsAllocation::AllocationType allocationType = getGraphicsAllocationType( - properties, + memoryProperties, context->isSharedContext, context->peekContextType(), HwHelper::renderCompressedBuffersSupported(context->getDevice(0)->getHardwareInfo()), memoryManager->isLocalMemorySupported(), HwHelper::get(context->getDevice(0)->getHardwareInfo().platform.eRenderCoreFamily).obtainRenderBufferCompressionPreference(size)); - MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties); checkMemory(memoryProperties, size, hostPtr, errcodeRet, alignementSatisfied, copyMemoryFromHostPtr, memoryManager); if (errcodeRet != CL_SUCCESS) { @@ -372,14 +372,14 @@ void Buffer::checkMemory(MemoryPropertiesFlags memoryProperties, return; } -GraphicsAllocation::AllocationType Buffer::getGraphicsAllocationType(const MemoryProperties &properties, bool sharedContext, +GraphicsAllocation::AllocationType Buffer::getGraphicsAllocationType(const MemoryPropertiesFlags &properties, bool sharedContext, ContextType contextType, bool renderCompressedBuffers, bool isLocalMemoryEnabled, bool preferCompression) { - if (is32bit || sharedContext || isValueSet(properties.flags, CL_MEM_FORCE_SHARED_PHYSICAL_MEMORY_INTEL)) { + if (is32bit || sharedContext || properties.forceSharedPhysicalMemory) { return GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY; } - if (isValueSet(properties.flags, CL_MEM_USE_HOST_PTR) && !isLocalMemoryEnabled) { + if (properties.useHostPtr && !isLocalMemoryEnabled) { return GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY; } diff --git a/runtime/mem_obj/buffer.h b/runtime/mem_obj/buffer.h index 69b4f3b27a..b84cb44118 100644 --- a/runtime/mem_obj/buffer.h +++ b/runtime/mem_obj/buffer.h @@ -147,7 +147,7 @@ class Buffer : public MemObj { bool &isZeroCopy, bool ©MemoryFromHostPtr, MemoryManager *memMngr); - static GraphicsAllocation::AllocationType getGraphicsAllocationType(const MemoryProperties &properties, bool sharedContext, + static GraphicsAllocation::AllocationType getGraphicsAllocationType(const MemoryPropertiesFlags &properties, bool sharedContext, ContextType contextType, bool renderCompressedBuffers, bool localMemoryEnabled, bool preferCompression); static bool isReadOnlyMemoryPermittedByFlags(cl_mem_flags flags); diff --git a/runtime/mem_obj/image.cpp b/runtime/mem_obj/image.cpp index 0bdc61e1d4..0d4ffa391d 100644 --- a/runtime/mem_obj/image.cpp +++ b/runtime/mem_obj/image.cpp @@ -21,6 +21,7 @@ #include "runtime/helpers/get_info.h" #include "runtime/helpers/hw_helper.h" #include "runtime/helpers/hw_info.h" +#include "runtime/helpers/memory_properties_flags_helpers.h" #include "runtime/helpers/mipmap.h" #include "runtime/helpers/surface_formats.h" #include "runtime/mem_obj/buffer.h" @@ -182,7 +183,8 @@ Image *Image::create(Context *context, auto hostPtrRowPitch = imageDesc->image_row_pitch ? imageDesc->image_row_pitch : imageWidth * surfaceFormat->ImageElementSizeInBytes; auto hostPtrSlicePitch = imageDesc->image_slice_pitch ? imageDesc->image_slice_pitch : hostPtrRowPitch * imageHeight; auto isTilingAllowed = context->isSharedContext ? false : GmmHelper::allowTiling(*imageDesc) && !MemObjHelper::isLinearStorageForced(properties); - imgInfo.preferRenderCompression = MemObjHelper::isSuitableForRenderCompression(isTilingAllowed, properties, + MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties); + imgInfo.preferRenderCompression = MemObjHelper::isSuitableForRenderCompression(isTilingAllowed, memoryProperties, context->peekContextType(), true); switch (imageDesc->image_type) { diff --git a/runtime/mem_obj/mem_obj_helper.cpp b/runtime/mem_obj/mem_obj_helper.cpp index 34a45f552f..d18bde9f96 100644 --- a/runtime/mem_obj/mem_obj_helper.cpp +++ b/runtime/mem_obj/mem_obj_helper.cpp @@ -9,9 +9,11 @@ #include "common/helpers/bit_helpers.h" +#include "memory_properties_flags.h" + namespace NEO { -bool MemObjHelper::isSuitableForRenderCompression(bool renderCompressed, const MemoryProperties &properties, ContextType contextType, bool preferCompression) { +bool MemObjHelper::isSuitableForRenderCompression(bool renderCompressed, const MemoryPropertiesFlags &properties, ContextType contextType, bool preferCompression) { return renderCompressed; } diff --git a/runtime/mem_obj/mem_obj_helper.h b/runtime/mem_obj/mem_obj_helper.h index fceab2ac77..2f79c89b5c 100644 --- a/runtime/mem_obj/mem_obj_helper.h +++ b/runtime/mem_obj/mem_obj_helper.h @@ -16,6 +16,7 @@ #include "CL/cl.h" #include "mem_obj_types.h" +#include "memory_properties_flags.h" namespace NEO { @@ -114,7 +115,7 @@ class MemObjHelper { isValueSet(memoryProperties.flags_intel, CL_MEM_FORCE_LINEAR_STORAGE_INTEL); } - static bool isSuitableForRenderCompression(bool renderCompressed, const MemoryProperties &properties, ContextType contextType, bool preferCompression); + static bool isSuitableForRenderCompression(bool renderCompressed, const MemoryPropertiesFlags &properties, ContextType contextType, bool preferCompression); protected: static bool checkUsedFlagsForBuffer(const MemoryProperties &properties) { diff --git a/unit_tests/context/driver_diagnostics_tests.cpp b/unit_tests/context/driver_diagnostics_tests.cpp index 73ace6e1d4..53ea6d26a7 100644 --- a/unit_tests/context/driver_diagnostics_tests.cpp +++ b/unit_tests/context/driver_diagnostics_tests.cpp @@ -8,6 +8,7 @@ #include "driver_diagnostics_tests.h" #include "core/unit_tests/helpers/debug_manager_state_restore.h" +#include "runtime/helpers/memory_properties_flags_helpers.h" #include "runtime/mem_obj/mem_obj_helper.h" #include "unit_tests/mocks/mock_gmm.h" @@ -487,6 +488,8 @@ TEST_F(PerformanceHintTest, givenUncompressedBufferWhenItsCreatedThenProperPerfo auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(&hwInfo)); cl_device_id deviceId = static_cast(device.get()); const MemoryProperties properties(CL_MEM_READ_WRITE); + MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties); + size_t size = 0u; cl_context_properties validProperties[3] = {CL_CONTEXT_SHOW_DIAGNOSTICS_INTEL, CL_CONTEXT_DIAGNOSTICS_LEVEL_ALL_INTEL, 0}; @@ -496,7 +499,7 @@ TEST_F(PerformanceHintTest, givenUncompressedBufferWhenItsCreatedThenProperPerfo if (context->getMemoryManager()) { isCompressed = MemObjHelper::isSuitableForRenderCompression( HwHelper::renderCompressedBuffersSupported(hwInfo), - properties, context->peekContextType(), + memoryProperties, context->peekContextType(), HwHelper::get(hwInfo.platform.eRenderCoreFamily).obtainRenderBufferCompressionPreference(size)) && !is32bit && !context->isSharedContext && (!isValueSet(properties.flags, CL_MEM_USE_HOST_PTR) || context->getMemoryManager()->isLocalMemorySupported()) && diff --git a/unit_tests/helpers/memory_properties_flags_helpers_tests.cpp b/unit_tests/helpers/memory_properties_flags_helpers_tests.cpp index 218178061a..e91a3320a1 100644 --- a/unit_tests/helpers/memory_properties_flags_helpers_tests.cpp +++ b/unit_tests/helpers/memory_properties_flags_helpers_tests.cpp @@ -55,6 +55,9 @@ TEST(MemoryPropertiesFlags, givenValidPropertiesWhenCreateMemoryPropertiesFlagsT memoryProperties.flags_intel = CL_MEM_LOCALLY_UNCACHED_RESOURCE; properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(memoryProperties); EXPECT_TRUE(properties.locallyUncachedResource); + + properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(CL_MEM_FORCE_SHARED_PHYSICAL_MEMORY_INTEL); + EXPECT_TRUE(properties.forceSharedPhysicalMemory); } TEST(MemoryPropertiesFlags, givenClMemForceLinearStorageFlagWhenCreateMemoryPropertiesFlagsThenReturnProperValue) { diff --git a/unit_tests/mem_obj/buffer_tests.cpp b/unit_tests/mem_obj/buffer_tests.cpp index 8bc9ada9fc..9d39ed263e 100644 --- a/unit_tests/mem_obj/buffer_tests.cpp +++ b/unit_tests/mem_obj/buffer_tests.cpp @@ -14,6 +14,7 @@ #include "runtime/gmm_helper/resource_info.h" #include "runtime/helpers/array_count.h" #include "runtime/helpers/hw_helper.h" +#include "runtime/helpers/memory_properties_flags_helpers.h" #include "runtime/helpers/options.h" #include "runtime/mem_obj/buffer.h" #include "runtime/memory_manager/allocations_list.h" @@ -321,8 +322,8 @@ TEST(Buffer, givenAllocHostPtrFlagPassedToBufferCreateWhenNoSharedContextOrRende } TEST(Buffer, givenRenderCompressedBuffersEnabledWhenAllocationTypeIsQueriedThenBufferCompressedTypeIsReturnedIn64Bit) { - MemoryProperties properties; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, false, true); + MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags({}); + auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, false, true); if (is32bit) { EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type); } else { @@ -331,8 +332,8 @@ TEST(Buffer, givenRenderCompressedBuffersEnabledWhenAllocationTypeIsQueriedThenB } TEST(Buffer, givenRenderCompressedBuffersDisabledLocalMemoryEnabledWhenAllocationTypeIsQueriedThenBufferTypeIsReturnedIn64Bit) { - MemoryProperties properties; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, true, true); + MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags({}); + auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, true, true); if (is32bit) { EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type); } else { @@ -341,28 +342,30 @@ TEST(Buffer, givenRenderCompressedBuffersDisabledLocalMemoryEnabledWhenAllocatio } TEST(Buffer, givenSharedContextWhenAllocationTypeIsQueriedThenBufferHostMemoryTypeIsReturned) { - MemoryProperties properties; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, true, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, false, true); + MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags({}); + auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, true, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, false, true); EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type); } TEST(Buffer, givenSharedContextAndRenderCompressedBuffersEnabledWhenAllocationTypeIsQueriedThenBufferHostMemoryTypeIsReturned) { - MemoryProperties properties; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, true, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, false, true); + MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags({}); + auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, true, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, false, true); EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type); } TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryDisabledWhenAllocationTypeIsQueriedThenBufferHostMemoryTypeIsReturned) { MemoryProperties properties; properties.flags = CL_MEM_USE_HOST_PTR; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, false, true); + MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties); + auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, false, true); EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type); } TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryEnabledWhenAllocationTypeIsQueriedThenBufferTypeIsReturned) { MemoryProperties properties; properties.flags = CL_MEM_USE_HOST_PTR; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, true, true); + MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties); + auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, true, true); if (is64bit) { EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER, type); } else { @@ -373,7 +376,8 @@ TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryEnabledWhenAllocationTypeIsQueried TEST(Buffer, givenAllocHostPtrFlagWhenAllocationTypeIsQueriedThenBufferTypeIsReturned) { MemoryProperties properties; properties.flags = CL_MEM_ALLOC_HOST_PTR; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, false, true); + MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties); + auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, false, true); if (is64bit) { EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER, type); } else { @@ -384,14 +388,16 @@ TEST(Buffer, givenAllocHostPtrFlagWhenAllocationTypeIsQueriedThenBufferTypeIsRet TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryDisabledAndRenderCompressedBuffersEnabledWhenAllocationTypeIsQueriedThenBufferMemoryTypeIsReturned) { MemoryProperties properties; properties.flags = CL_MEM_USE_HOST_PTR; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, false, true); + MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties); + auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, false, true); EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type); } TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryEnabledAndRenderCompressedBuffersEnabledWhenAllocationTypeIsQueriedThenBufferMemoryTypeIsReturned) { MemoryProperties properties; properties.flags = CL_MEM_USE_HOST_PTR; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, true, true); + MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties); + auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, true, true); if (is64bit) { EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, type); } else { @@ -402,14 +408,16 @@ TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryEnabledAndRenderCompressedBuffersE TEST(Buffer, givenUseHostPointerFlagAndForceSharedPhysicalStorageWhenLocalMemoryIsEnabledThenBufferHostMemoryTypeIsReturned) { MemoryProperties properties; properties.flags = CL_MEM_USE_HOST_PTR | CL_MEM_FORCE_SHARED_PHYSICAL_MEMORY_INTEL; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, true, true); + MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties); + auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, true, true); EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type); } TEST(Buffer, givenAllocHostPtrFlagAndRenderCompressedBuffersEnabledWhenAllocationTypeIsQueriedThenBufferCompressedTypeIsReturned) { MemoryProperties properties; properties.flags = CL_MEM_ALLOC_HOST_PTR; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, false, true); + MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties); + auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, false, true); if (is64bit) { EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, type); } else { @@ -418,8 +426,8 @@ TEST(Buffer, givenAllocHostPtrFlagAndRenderCompressedBuffersEnabledWhenAllocatio } TEST(Buffer, givenZeroFlagsNoSharedContextAndRenderCompressedBuffersDisabledWhenAllocationTypeIsQueriedThenBufferTypeIsReturned) { - MemoryProperties properties; - auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, false, true); + MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags({}); + auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, false, true); if (is32bit) { EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type); } else {