diff --git a/core/memory_properties/memory_properties_flags.h b/core/memory_properties/memory_properties_flags.h index d09549b952..c42c44b6a0 100644 --- a/core/memory_properties/memory_properties_flags.h +++ b/core/memory_properties/memory_properties_flags.h @@ -10,7 +10,11 @@ namespace NEO { -struct MemoryPropertiesFlags : MemoryPropertiesFlagsBase { +struct MemoryPropertiesFlags { + union { + MemoryFlags flags; + uint32_t allFlags = 0; + }; + static_assert(sizeof(MemoryPropertiesFlags::flags) == sizeof(MemoryPropertiesFlags::allFlags), ""); }; - } // namespace NEO diff --git a/core/memory_properties/memory_properties_flags_common.inl b/core/memory_properties/memory_properties_flags_common.inl index 1523382a02..0f2361f9d3 100644 --- a/core/memory_properties/memory_properties_flags_common.inl +++ b/core/memory_properties/memory_properties_flags_common.inl @@ -6,29 +6,22 @@ */ namespace NEO { - -struct MemoryPropertiesFlagsBase { - bool readWrite = false; - bool writeOnly = false; - bool readOnly = false; - bool useHostPtr = false; - bool allocHostPtr = false; - bool copyHostPtr = false; - - bool hostWriteOnly = false; - bool hostReadOnly = false; - bool hostNoAccess = false; - - bool kernelReadAndWrite = false; - - bool forceLinearStorage = false; - bool accessFlagsUnrestricted = false; - bool noAccess = false; - - bool locallyUncachedResource = false; - bool allowUnrestrictedSize = false; - - bool forceSharedPhysicalMemory = false; +struct MemoryFlags { + uint32_t readWrite : 1; + uint32_t writeOnly : 1; + uint32_t readOnly : 1; + uint32_t useHostPtr : 1; + uint32_t allocHostPtr : 1; + uint32_t copyHostPtr : 1; + uint32_t hostWriteOnly : 1; + uint32_t hostReadOnly : 1; + uint32_t hostNoAccess : 1; + uint32_t kernelReadAndWrite : 1; + uint32_t forceLinearStorage : 1; + uint32_t accessFlagsUnrestricted : 1; + uint32_t noAccess : 1; + uint32_t locallyUncachedResource : 1; + uint32_t allowUnrestrictedSize : 1; + uint32_t forceSharedPhysicalMemory : 1; }; - } // namespace NEO diff --git a/runtime/helpers/mem_properties_parser_helper.cpp b/runtime/helpers/mem_properties_parser_helper.cpp index 5e08f3ad99..86ead6fbf4 100644 --- a/runtime/helpers/mem_properties_parser_helper.cpp +++ b/runtime/helpers/mem_properties_parser_helper.cpp @@ -31,8 +31,8 @@ bool NEO::MemoryPropertiesParser::parseMemoryProperties(const cl_mem_properties_ void MemoryPropertiesParser::fillPoliciesInProperties(AllocationProperties &allocationProperties, const MemoryPropertiesFlags &memoryProperties) { fillCachePolicyInProperties(allocationProperties, - memoryProperties.locallyUncachedResource, - memoryProperties.readOnly, + memoryProperties.flags.locallyUncachedResource, + memoryProperties.flags.readOnly, false); } diff --git a/runtime/helpers/memory_properties_flags_helpers_base.inl b/runtime/helpers/memory_properties_flags_helpers_base.inl index 2f801919b1..bb1459005f 100644 --- a/runtime/helpers/memory_properties_flags_helpers_base.inl +++ b/runtime/helpers/memory_properties_flags_helpers_base.inl @@ -17,54 +17,54 @@ MemoryPropertiesFlags MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(M MemoryPropertiesFlags memoryPropertiesFlags; if (isValueSet(properties.flags, CL_MEM_READ_WRITE)) { - memoryPropertiesFlags.readWrite = true; + memoryPropertiesFlags.flags.readWrite = true; } if (isValueSet(properties.flags, CL_MEM_WRITE_ONLY)) { - memoryPropertiesFlags.writeOnly = true; + memoryPropertiesFlags.flags.writeOnly = true; } if (isValueSet(properties.flags, CL_MEM_READ_ONLY)) { - memoryPropertiesFlags.readOnly = true; + memoryPropertiesFlags.flags.readOnly = true; } if (isValueSet(properties.flags, CL_MEM_USE_HOST_PTR)) { - memoryPropertiesFlags.useHostPtr = true; + memoryPropertiesFlags.flags.useHostPtr = true; } if (isValueSet(properties.flags, CL_MEM_ALLOC_HOST_PTR)) { - memoryPropertiesFlags.allocHostPtr = true; + memoryPropertiesFlags.flags.allocHostPtr = true; } if (isValueSet(properties.flags, CL_MEM_COPY_HOST_PTR)) { - memoryPropertiesFlags.copyHostPtr = true; + memoryPropertiesFlags.flags.copyHostPtr = true; } if (isValueSet(properties.flags, CL_MEM_HOST_WRITE_ONLY)) { - memoryPropertiesFlags.hostWriteOnly = true; + memoryPropertiesFlags.flags.hostWriteOnly = true; } if (isValueSet(properties.flags, CL_MEM_HOST_READ_ONLY)) { - memoryPropertiesFlags.hostReadOnly = true; + memoryPropertiesFlags.flags.hostReadOnly = true; } if (isValueSet(properties.flags, CL_MEM_HOST_NO_ACCESS)) { - memoryPropertiesFlags.hostNoAccess = true; + memoryPropertiesFlags.flags.hostNoAccess = true; } if (isValueSet(properties.flags, CL_MEM_KERNEL_READ_AND_WRITE)) { - memoryPropertiesFlags.kernelReadAndWrite = true; + memoryPropertiesFlags.flags.kernelReadAndWrite = true; } if (isValueSet(properties.flags, CL_MEM_FORCE_LINEAR_STORAGE_INTEL) || isValueSet(properties.flags_intel, CL_MEM_FORCE_LINEAR_STORAGE_INTEL)) { - memoryPropertiesFlags.forceLinearStorage = true; + memoryPropertiesFlags.flags.forceLinearStorage = true; } if (isValueSet(properties.flags, CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)) { - memoryPropertiesFlags.accessFlagsUnrestricted = true; + memoryPropertiesFlags.flags.accessFlagsUnrestricted = true; } if (isValueSet(properties.flags, CL_MEM_NO_ACCESS_INTEL)) { - memoryPropertiesFlags.noAccess = true; + memoryPropertiesFlags.flags.noAccess = true; } if (isValueSet(properties.flags, CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL) || isValueSet(properties.flags_intel, CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL)) { - memoryPropertiesFlags.allowUnrestrictedSize = true; + memoryPropertiesFlags.flags.allowUnrestrictedSize = true; } if (isValueSet(properties.flags_intel, CL_MEM_LOCALLY_UNCACHED_RESOURCE)) { - memoryPropertiesFlags.locallyUncachedResource = true; + memoryPropertiesFlags.flags.locallyUncachedResource = true; } if (isValueSet(properties.flags, CL_MEM_FORCE_SHARED_PHYSICAL_MEMORY_INTEL)) { - memoryPropertiesFlags.forceSharedPhysicalMemory = true; + memoryPropertiesFlags.flags.forceSharedPhysicalMemory = true; } addExtraMemoryPropertiesFlags(memoryPropertiesFlags, properties); diff --git a/runtime/mem_obj/buffer.cpp b/runtime/mem_obj/buffer.cpp index 9b33cd13a7..49411abbf1 100644 --- a/runtime/mem_obj/buffer.cpp +++ b/runtime/mem_obj/buffer.cpp @@ -340,13 +340,13 @@ void Buffer::checkMemory(MemoryPropertiesFlags memoryProperties, } if (hostPtr) { - if (!(memoryProperties.useHostPtr || memoryProperties.copyHostPtr)) { + if (!(memoryProperties.flags.useHostPtr || memoryProperties.flags.copyHostPtr)) { errcodeRet = CL_INVALID_HOST_PTR; return; } } - if (memoryProperties.useHostPtr) { + if (memoryProperties.flags.useHostPtr) { if (hostPtr) { auto fragment = memoryManager->getHostPtrManager()->getFragment(hostPtr); if (fragment && fragment->driverAllocation) { @@ -364,7 +364,7 @@ void Buffer::checkMemory(MemoryPropertiesFlags memoryProperties, } } - if (memoryProperties.copyHostPtr) { + if (memoryProperties.flags.copyHostPtr) { if (hostPtr) { copyMemoryFromHostPtr = true; } else { @@ -377,11 +377,11 @@ void Buffer::checkMemory(MemoryPropertiesFlags memoryProperties, GraphicsAllocation::AllocationType Buffer::getGraphicsAllocationType(const MemoryPropertiesFlags &properties, bool sharedContext, ContextType contextType, bool renderCompressedBuffers, bool isLocalMemoryEnabled, bool preferCompression) { - if (is32bit || sharedContext || properties.forceSharedPhysicalMemory) { + if (is32bit || sharedContext || properties.flags.forceSharedPhysicalMemory) { return GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY; } - if (properties.useHostPtr && !isLocalMemoryEnabled) { + if (properties.flags.useHostPtr && !isLocalMemoryEnabled) { return GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY; } @@ -393,7 +393,7 @@ GraphicsAllocation::AllocationType Buffer::getGraphicsAllocationType(const Memor bool Buffer::isReadOnlyMemoryPermittedByFlags(const MemoryPropertiesFlags &properties) { // Host won't access or will only read and kernel will only read - return (properties.hostNoAccess || properties.hostReadOnly) && properties.readOnly; + return (properties.flags.hostNoAccess || properties.flags.hostReadOnly) && properties.flags.readOnly; } Buffer *Buffer::createSubBuffer(cl_mem_flags flags, diff --git a/runtime/mem_obj/image.cpp b/runtime/mem_obj/image.cpp index 2fe7914476..2fb4df8cc1 100644 --- a/runtime/mem_obj/image.cpp +++ b/runtime/mem_obj/image.cpp @@ -181,7 +181,7 @@ 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; MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties); - imgInfo.linearStorage = context->isSharedContext || !GmmHelper::allowTiling(*imageDesc) || memoryProperties.forceLinearStorage; + imgInfo.linearStorage = context->isSharedContext || !GmmHelper::allowTiling(*imageDesc) || memoryProperties.flags.forceLinearStorage; imgInfo.preferRenderCompression = MemObjHelper::isSuitableForRenderCompression(!imgInfo.linearStorage, memoryProperties, context->peekContextType(), true); @@ -461,7 +461,7 @@ cl_int Image::validate(Context *context, ((parentBuffer->getFlags() & CL_MEM_USE_HOST_PTR) && (reinterpret_cast(parentBuffer->getHostPtr()) % (*baseAddressAlignment))) || (minimumBufferSize > parentBuffer->getSize())) { return CL_INVALID_IMAGE_FORMAT_DESCRIPTOR; - } else if (memoryProperties.useHostPtr || memoryProperties.copyHostPtr) { + } else if (memoryProperties.flags.useHostPtr || memoryProperties.flags.copyHostPtr) { return CL_INVALID_VALUE; } } @@ -549,7 +549,7 @@ cl_int Image::validatePlanarYUV(Context *context, errorCode = CL_INVALID_IMAGE_DESCRIPTOR; break; } - if (!memoryProperties.hostNoAccess) { + if (!memoryProperties.flags.hostNoAccess) { errorCode = CL_INVALID_VALUE; break; } else { @@ -575,7 +575,7 @@ cl_int Image::validatePlanarYUV(Context *context, cl_int Image::validatePackedYUV(const MemoryPropertiesFlags &memoryProperties, const cl_image_desc *imageDesc) { cl_int errorCode = CL_SUCCESS; while (true) { - if (!memoryProperties.readOnly) { + if (!memoryProperties.flags.readOnly) { errorCode = CL_INVALID_VALUE; break; } else { diff --git a/unit_tests/helpers/memory_properties_flags_helpers_tests.cpp b/unit_tests/helpers/memory_properties_flags_helpers_tests.cpp index e91a3320a1..c5965e1b11 100644 --- a/unit_tests/helpers/memory_properties_flags_helpers_tests.cpp +++ b/unit_tests/helpers/memory_properties_flags_helpers_tests.cpp @@ -16,48 +16,48 @@ TEST(MemoryPropertiesFlags, givenValidPropertiesWhenCreateMemoryPropertiesFlagsT MemoryPropertiesFlags properties; properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(CL_MEM_READ_WRITE); - EXPECT_TRUE(properties.readWrite); + EXPECT_TRUE(properties.flags.readWrite); properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(CL_MEM_WRITE_ONLY); - EXPECT_TRUE(properties.writeOnly); + EXPECT_TRUE(properties.flags.writeOnly); properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(CL_MEM_READ_ONLY); - EXPECT_TRUE(properties.readOnly); + EXPECT_TRUE(properties.flags.readOnly); properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(CL_MEM_USE_HOST_PTR); - EXPECT_TRUE(properties.useHostPtr); + EXPECT_TRUE(properties.flags.useHostPtr); properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(CL_MEM_ALLOC_HOST_PTR); - EXPECT_TRUE(properties.allocHostPtr); + EXPECT_TRUE(properties.flags.allocHostPtr); properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(CL_MEM_COPY_HOST_PTR); - EXPECT_TRUE(properties.copyHostPtr); + EXPECT_TRUE(properties.flags.copyHostPtr); properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(CL_MEM_HOST_WRITE_ONLY); - EXPECT_TRUE(properties.hostWriteOnly); + EXPECT_TRUE(properties.flags.hostWriteOnly); properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(CL_MEM_HOST_READ_ONLY); - EXPECT_TRUE(properties.hostReadOnly); + EXPECT_TRUE(properties.flags.hostReadOnly); properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(CL_MEM_HOST_NO_ACCESS); - EXPECT_TRUE(properties.hostNoAccess); + EXPECT_TRUE(properties.flags.hostNoAccess); properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(CL_MEM_KERNEL_READ_AND_WRITE); - EXPECT_TRUE(properties.kernelReadAndWrite); + EXPECT_TRUE(properties.flags.kernelReadAndWrite); properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL); - EXPECT_TRUE(properties.accessFlagsUnrestricted); + EXPECT_TRUE(properties.flags.accessFlagsUnrestricted); properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(CL_MEM_NO_ACCESS_INTEL); - EXPECT_TRUE(properties.noAccess); + EXPECT_TRUE(properties.flags.noAccess); MemoryProperties memoryProperties; memoryProperties.flags_intel = CL_MEM_LOCALLY_UNCACHED_RESOURCE; properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(memoryProperties); - EXPECT_TRUE(properties.locallyUncachedResource); + EXPECT_TRUE(properties.flags.locallyUncachedResource); properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(CL_MEM_FORCE_SHARED_PHYSICAL_MEMORY_INTEL); - EXPECT_TRUE(properties.forceSharedPhysicalMemory); + EXPECT_TRUE(properties.flags.forceSharedPhysicalMemory); } TEST(MemoryPropertiesFlags, givenClMemForceLinearStorageFlagWhenCreateMemoryPropertiesFlagsThenReturnProperValue) { @@ -67,22 +67,22 @@ TEST(MemoryPropertiesFlags, givenClMemForceLinearStorageFlagWhenCreateMemoryProp memoryProperties.flags |= CL_MEM_FORCE_LINEAR_STORAGE_INTEL; memoryProperties.flags_intel = 0; properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(memoryProperties); - EXPECT_TRUE(properties.forceLinearStorage); + EXPECT_TRUE(properties.flags.forceLinearStorage); memoryProperties.flags = 0; memoryProperties.flags_intel |= CL_MEM_FORCE_LINEAR_STORAGE_INTEL; properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(memoryProperties); - EXPECT_TRUE(properties.forceLinearStorage); + EXPECT_TRUE(properties.flags.forceLinearStorage); memoryProperties.flags |= CL_MEM_FORCE_LINEAR_STORAGE_INTEL; memoryProperties.flags_intel |= CL_MEM_FORCE_LINEAR_STORAGE_INTEL; properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(memoryProperties); - EXPECT_TRUE(properties.forceLinearStorage); + EXPECT_TRUE(properties.flags.forceLinearStorage); memoryProperties.flags = 0; memoryProperties.flags_intel = 0; properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(memoryProperties); - EXPECT_FALSE(properties.forceLinearStorage); + EXPECT_FALSE(properties.flags.forceLinearStorage); } TEST(MemoryPropertiesFlags, givenClAllowUnrestrictedSizeFlagWhenCreateMemoryPropertiesFlagsThenReturnProperValue) { @@ -92,20 +92,20 @@ TEST(MemoryPropertiesFlags, givenClAllowUnrestrictedSizeFlagWhenCreateMemoryProp memoryProperties.flags |= CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL; memoryProperties.flags_intel = 0; properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(memoryProperties); - EXPECT_TRUE(properties.allowUnrestrictedSize); + EXPECT_TRUE(properties.flags.allowUnrestrictedSize); memoryProperties.flags = 0; memoryProperties.flags_intel |= CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL; properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(memoryProperties); - EXPECT_TRUE(properties.allowUnrestrictedSize); + EXPECT_TRUE(properties.flags.allowUnrestrictedSize); memoryProperties.flags |= CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL; memoryProperties.flags_intel |= CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL; properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(memoryProperties); - EXPECT_TRUE(properties.allowUnrestrictedSize); + EXPECT_TRUE(properties.flags.allowUnrestrictedSize); memoryProperties.flags = 0; memoryProperties.flags_intel = 0; properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(memoryProperties); - EXPECT_FALSE(properties.allowUnrestrictedSize); + EXPECT_FALSE(properties.flags.allowUnrestrictedSize); } \ No newline at end of file diff --git a/unit_tests/mem_obj/mem_obj_helper_tests.cpp b/unit_tests/mem_obj/mem_obj_helper_tests.cpp index 861a7b34e3..9767703947 100644 --- a/unit_tests/mem_obj/mem_obj_helper_tests.cpp +++ b/unit_tests/mem_obj/mem_obj_helper_tests.cpp @@ -34,22 +34,22 @@ TEST(MemObjHelper, givenClMemForceLinearStorageFlagWhenCheckForLinearStorageForc properties.flags |= CL_MEM_FORCE_LINEAR_STORAGE_INTEL; properties.flags_intel = 0; memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties); - EXPECT_TRUE(memoryProperties.forceLinearStorage); + EXPECT_TRUE(memoryProperties.flags.forceLinearStorage); properties.flags = 0; properties.flags_intel |= CL_MEM_FORCE_LINEAR_STORAGE_INTEL; memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties); - EXPECT_TRUE(memoryProperties.forceLinearStorage); + EXPECT_TRUE(memoryProperties.flags.forceLinearStorage); properties.flags |= CL_MEM_FORCE_LINEAR_STORAGE_INTEL; properties.flags_intel |= CL_MEM_FORCE_LINEAR_STORAGE_INTEL; memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties); - EXPECT_TRUE(memoryProperties.forceLinearStorage); + EXPECT_TRUE(memoryProperties.flags.forceLinearStorage); properties.flags = 0; properties.flags_intel = 0; memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties); - EXPECT_FALSE(memoryProperties.forceLinearStorage); + EXPECT_FALSE(memoryProperties.flags.forceLinearStorage); } TEST(MemObjHelper, givenValidPropertiesWhenValidatingMemoryPropertiesThenTrueIsReturned) {