From e10f39017d83bf484362e9fa95efabd65f133659 Mon Sep 17 00:00:00 2001 From: "Baj, Tomasz" Date: Wed, 6 Sep 2023 11:01:48 +0000 Subject: [PATCH] fix: Add ImageInfo to createGraphicsAllocation on Linux Related-To: NEO-6757 Signed-off-by: Baj, Tomasz --- level_zero/core/source/image/image_hw.inl | 4 ++-- opencl/source/mem_obj/mem_obj_helper.cpp | 2 +- opencl/source/sharings/gl/linux/gl_texture_linux.cpp | 2 +- .../source/sharings/unified/linux/unified_image_linux.cpp | 4 +++- opencl/source/sharings/unified/unified_image.cpp | 5 ++--- opencl/source/sharings/unified/unified_image.h | 1 - opencl/source/sharings/unified/unified_sharing.cpp | 8 ++++++-- opencl/source/sharings/unified/unified_sharing.h | 2 ++ opencl/source/sharings/va/va_surface.cpp | 2 +- opencl/test/unit_test/mem_obj/image_tiled_tests.cpp | 3 +++ .../os_interface/linux/cl_drm_memory_manager_tests.cpp | 6 +++--- .../sharings/unified/unified_sharing_image_tests.cpp | 4 ++++ shared/source/memory_manager/allocation_properties.h | 4 ++-- shared/source/os_interface/linux/drm_memory_manager.cpp | 4 +--- shared/test/common/mocks/mock_gmm.h | 2 +- .../aub_command_stream_receiver_2_tests.cpp | 2 +- 16 files changed, 33 insertions(+), 22 deletions(-) diff --git a/level_zero/core/source/image/image_hw.inl b/level_zero/core/source/image/image_hw.inl index 309703f0ff..ed6040c7d1 100644 --- a/level_zero/core/source/image/image_hw.inl +++ b/level_zero/core/source/image/image_hw.inl @@ -81,7 +81,7 @@ ze_result_t ImageCoreFamily::initialize(Device *device, const ze_ return ZE_RESULT_ERROR_UNSUPPORTED_ENUMERATION; } if (lookupTable.sharedHandleType.isDMABUFHandle) { - NEO::AllocationProperties properties(device->getRootDeviceIndex(), true, imgInfo, NEO::AllocationType::SHARED_IMAGE, device->getNEODevice()->getDeviceBitfield()); + NEO::AllocationProperties properties(device->getRootDeviceIndex(), true, &imgInfo, NEO::AllocationType::SHARED_IMAGE, device->getNEODevice()->getDeviceBitfield()); allocation = device->getNEODevice()->getMemoryManager()->createGraphicsAllocationFromSharedHandle(lookupTable.sharedHandleType.fd, properties, false, false, true, nullptr); device->getNEODevice()->getMemoryManager()->closeSharedHandle(allocation); } else if (lookupTable.sharedHandleType.isNTHandle) { @@ -93,7 +93,7 @@ ze_result_t ImageCoreFamily::initialize(Device *device, const ze_ allocation->getDefaultGmm()->queryImageParams(imgInfo); } } else { - NEO::AllocationProperties properties(device->getRootDeviceIndex(), true, imgInfo, NEO::AllocationType::IMAGE, device->getNEODevice()->getDeviceBitfield()); + NEO::AllocationProperties properties(device->getRootDeviceIndex(), true, &imgInfo, NEO::AllocationType::IMAGE, device->getNEODevice()->getDeviceBitfield()); properties.flags.preferCompressed = isSuitableForCompression(lookupTable, imgInfo); diff --git a/opencl/source/mem_obj/mem_obj_helper.cpp b/opencl/source/mem_obj/mem_obj_helper.cpp index 6f8d252314..17c93c4ebb 100644 --- a/opencl/source/mem_obj/mem_obj_helper.cpp +++ b/opencl/source/mem_obj/mem_obj_helper.cpp @@ -84,7 +84,7 @@ AllocationProperties MemObjHelper::getAllocationPropertiesWithImageInfo( const HardwareInfo &hwInfo, DeviceBitfield subDevicesBitfieldParam, bool deviceOnlyVisibilty) { auto deviceBitfield = MemoryPropertiesHelper::adjustDeviceBitfield(rootDeviceIndex, memoryProperties, subDevicesBitfieldParam); - AllocationProperties allocationProperties{rootDeviceIndex, allocateMemory, imgInfo, AllocationType::IMAGE, deviceBitfield}; + AllocationProperties allocationProperties{rootDeviceIndex, allocateMemory, &imgInfo, AllocationType::IMAGE, deviceBitfield}; MemoryPropertiesHelper::fillPoliciesInProperties(allocationProperties, memoryProperties, hwInfo, deviceOnlyVisibilty); return allocationProperties; } diff --git a/opencl/source/sharings/gl/linux/gl_texture_linux.cpp b/opencl/source/sharings/gl/linux/gl_texture_linux.cpp index 3c7e3f0c76..4b0495ac32 100644 --- a/opencl/source/sharings/gl/linux/gl_texture_linux.cpp +++ b/opencl/source/sharings/gl/linux/gl_texture_linux.cpp @@ -102,7 +102,7 @@ Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl imgInfo.surfaceFormat = &surfaceFormatInfo.surfaceFormat; AllocationProperties allocProperties(context->getDevice(0)->getRootDeviceIndex(), false, // allocateMemory - imgInfo, + &imgInfo, AllocationType::SHARED_IMAGE, context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())); auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(texInfo.globalShareHandle, allocProperties, false, false, false, nullptr); diff --git a/opencl/source/sharings/unified/linux/unified_image_linux.cpp b/opencl/source/sharings/unified/linux/unified_image_linux.cpp index 10d8a58642..fc1910d32b 100644 --- a/opencl/source/sharings/unified/linux/unified_image_linux.cpp +++ b/opencl/source/sharings/unified/linux/unified_image_linux.cpp @@ -7,6 +7,7 @@ #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/gmm_helper/gmm.h" +#include "shared/source/gmm_helper/resource_info.h" #include "shared/source/helpers/surface_format_info.h" #include "opencl/source/cl_device/cl_device.h" @@ -16,7 +17,8 @@ namespace NEO { void *UnifiedImage::swapGmm(GraphicsAllocation *graphicsAllocation, Context *context, ImageInfo *imgInfo) { - if (!graphicsAllocation->getDefaultGmm()) { + if (graphicsAllocation->getDefaultGmm()->gmmResourceInfo->getResourceType() == RESOURCE_BUFFER) { + imgInfo->linearStorage = true; auto gmmHelper = context->getDevice(0)->getRootDeviceEnvironment().getGmmHelper(); auto gmm = std::make_unique(gmmHelper, *imgInfo, StorageInfo{}, false); gmm->updateImgInfoAndDesc(*imgInfo, 0, NEO::ImagePlane::NO_PLANE); diff --git a/opencl/source/sharings/unified/unified_image.cpp b/opencl/source/sharings/unified/unified_image.cpp index cec5b0238b..be13016858 100644 --- a/opencl/source/sharings/unified/unified_image.cpp +++ b/opencl/source/sharings/unified/unified_image.cpp @@ -10,6 +10,7 @@ #include "shared/source/gmm_helper/gmm.h" #include "shared/source/helpers/get_info.h" #include "shared/source/helpers/hw_info.h" +#include "shared/source/helpers/surface_format_info.h" #include "shared/source/memory_manager/graphics_allocation.h" #include "shared/source/memory_manager/memory_manager.h" #include "shared/source/os_interface/product_helper.h" @@ -30,7 +31,7 @@ Image *UnifiedImage::createSharedUnifiedImage(Context *context, cl_mem_flags fla imgInfo.imgDesc = Image::convertDescriptor(*imageDesc); imgInfo.surfaceFormat = &clSurfaceFormat->surfaceFormat; - GraphicsAllocation *graphicsAllocation = createGraphicsAllocation(context, description, AllocationType::SHARED_IMAGE); + GraphicsAllocation *graphicsAllocation = createGraphicsAllocation(context, description, &imgInfo, AllocationType::SHARED_IMAGE); if (!graphicsAllocation) { errorCode.set(CL_INVALID_MEM_OBJECT); return nullptr; @@ -38,8 +39,6 @@ Image *UnifiedImage::createSharedUnifiedImage(Context *context, cl_mem_flags fla swapGmm(graphicsAllocation, context, &imgInfo); - graphicsAllocation->getDefaultGmm()->updateOffsetsInImgInfo(imgInfo, 0u); - auto &memoryManager = *context->getMemoryManager(); if (graphicsAllocation->getDefaultGmm()->unifiedAuxTranslationCapable()) { const auto &hwInfo = context->getDevice(0)->getHardwareInfo(); diff --git a/opencl/source/sharings/unified/unified_image.h b/opencl/source/sharings/unified/unified_image.h index 533f714842..4ccec1252c 100644 --- a/opencl/source/sharings/unified/unified_image.h +++ b/opencl/source/sharings/unified/unified_image.h @@ -14,7 +14,6 @@ namespace NEO { class Image; class Context; -struct ImageInfo; class UnifiedImage : public UnifiedSharing { using UnifiedSharing::UnifiedSharing; diff --git a/opencl/source/sharings/unified/unified_sharing.cpp b/opencl/source/sharings/unified/unified_sharing.cpp index 62844484e3..029b48183f 100644 --- a/opencl/source/sharings/unified/unified_sharing.cpp +++ b/opencl/source/sharings/unified/unified_sharing.cpp @@ -8,6 +8,7 @@ #include "opencl/source/sharings/unified/unified_sharing.h" #include "shared/source/helpers/string.h" +#include "shared/source/helpers/surface_format_info.h" #include "shared/source/helpers/timestamp_packet.h" #include "shared/source/memory_manager/allocation_properties.h" @@ -34,6 +35,10 @@ void UnifiedSharing::releaseResource(MemObj *memObject, uint32_t rootDeviceIndex } GraphicsAllocation *UnifiedSharing::createGraphicsAllocation(Context *context, UnifiedSharingMemoryDescription description, AllocationType allocationType) { + return createGraphicsAllocation(context, description, nullptr, allocationType); +} + +GraphicsAllocation *UnifiedSharing::createGraphicsAllocation(Context *context, UnifiedSharingMemoryDescription description, ImageInfo *imgInfo, AllocationType allocationType) { auto memoryManager = context->getMemoryManager(); switch (description.type) { case UnifiedSharingHandleType::Win32Nt: { @@ -43,9 +48,8 @@ GraphicsAllocation *UnifiedSharing::createGraphicsAllocation(Context *context, U case UnifiedSharingHandleType::Win32Shared: { const AllocationProperties properties{context->getDevice(0)->getRootDeviceIndex(), false, // allocateMemory - 0u, // size + imgInfo, allocationType, - false, // isMultiStorageAllocation context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())}; return memoryManager->createGraphicsAllocationFromSharedHandle(toOsHandle(description.handle), properties, false, false, true, nullptr); } diff --git a/opencl/source/sharings/unified/unified_sharing.h b/opencl/source/sharings/unified/unified_sharing.h index 9eff3245dd..dc3c085604 100644 --- a/opencl/source/sharings/unified/unified_sharing.h +++ b/opencl/source/sharings/unified/unified_sharing.h @@ -11,6 +11,7 @@ #include "opencl/source/sharings/unified/unified_sharing_types.h" namespace NEO { +struct ImageInfo; class UnifiedSharingFunctions : public SharingFunctions { public: @@ -32,6 +33,7 @@ class UnifiedSharing : public SharingHandler { void releaseResource(MemObj *memObject, uint32_t rootDeviceIndex) override; static GraphicsAllocation *createGraphicsAllocation(Context *context, UnifiedSharingMemoryDescription description, AllocationType allocationType); + static GraphicsAllocation *createGraphicsAllocation(Context *context, UnifiedSharingMemoryDescription description, ImageInfo *imgInfo, AllocationType allocationType); private: UnifiedSharingFunctions *sharingFunctions; diff --git a/opencl/source/sharings/va/va_surface.cpp b/opencl/source/sharings/va/va_surface.cpp index 65822e153f..7bcd9819c5 100644 --- a/opencl/source/sharings/va/va_surface.cpp +++ b/opencl/source/sharings/va/va_surface.cpp @@ -204,7 +204,7 @@ Image *VASurface::createSharedVaSurface(Context *context, VASharingFunctions *sh AllocationProperties properties(context->getDevice(0)->getRootDeviceIndex(), false, // allocateMemory - sharedSurfaceInfo.imgInfo, AllocationType::SHARED_IMAGE, + &sharedSurfaceInfo.imgInfo, AllocationType::SHARED_IMAGE, context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())); auto alloc = memoryManager->createGraphicsAllocationFromSharedHandle(sharedSurfaceInfo.sharedHandle, properties, false, false, true, nullptr); diff --git a/opencl/test/unit_test/mem_obj/image_tiled_tests.cpp b/opencl/test/unit_test/mem_obj/image_tiled_tests.cpp index b6649d1900..17c4db2323 100644 --- a/opencl/test/unit_test/mem_obj/image_tiled_tests.cpp +++ b/opencl/test/unit_test/mem_obj/image_tiled_tests.cpp @@ -5,6 +5,7 @@ * */ +#include "shared/source/gmm_helper/resource_info.h" #include "shared/source/helpers/gfx_core_helper.h" #include "shared/test/common/helpers/unit_test_helper.h" #include "shared/test/common/mocks/mock_gmm.h" @@ -138,6 +139,7 @@ TEST_P(CreateNonTiledImageTest, GivenSharedNonTiledImageWhenCheckingIsTiledThenF info.imgDesc = Image::convertDescriptor(imageDesc); info.plane = GMM_NO_PLANE; + info.linearStorage = true; auto gmm = MockGmm::queryImgParams(context.getDevice(0)->getGmmHelper(), info, false); @@ -158,6 +160,7 @@ TEST_P(CreateNonTiledImageTest, GivenSharedNonTiledImageWhenCheckingIsTiledThenF ASSERT_NE(nullptr, image); EXPECT_FALSE(image->isTiledAllocation()); + EXPECT_EQ(info.linearStorage, image->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex())->getDefaultGmm()->gmmResourceInfo->getResourceFlags()->Info.Linear); delete image; } diff --git a/opencl/test/unit_test/os_interface/linux/cl_drm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/linux/cl_drm_memory_manager_tests.cpp index 2940aa4c72..55ccccada9 100644 --- a/opencl/test/unit_test/os_interface/linux/cl_drm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/cl_drm_memory_manager_tests.cpp @@ -767,7 +767,7 @@ TEST_F(ClDrmMemoryManagerTest, givenOsHandleWithNonTiledObjectWhenCreateFromShar imgInfo.surfaceFormat = &gmmSurfaceFormat->surfaceFormat; imgInfo.plane = GMM_PLANE_Y; - AllocationProperties properties(rootDeviceIndex, false, imgInfo, AllocationType::SHARED_IMAGE, context.getDevice(0)->getDeviceBitfield()); + AllocationProperties properties(rootDeviceIndex, false, &imgInfo, AllocationType::SHARED_IMAGE, context.getDevice(0)->getDeviceBitfield()); auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, nullptr); ASSERT_NE(nullptr, graphicsAllocation); @@ -810,7 +810,7 @@ TEST_F(ClDrmMemoryManagerTest, givenOsHandleWithTileYObjectWhenCreateFromSharedH imgInfo.surfaceFormat = &gmmSurfaceFormat->surfaceFormat; imgInfo.plane = GMM_PLANE_Y; - AllocationProperties properties(rootDeviceIndex, false, imgInfo, AllocationType::SHARED_IMAGE, context.getDevice(0)->getDeviceBitfield()); + AllocationProperties properties(rootDeviceIndex, false, &imgInfo, AllocationType::SHARED_IMAGE, context.getDevice(0)->getDeviceBitfield()); auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, nullptr); ASSERT_NE(nullptr, graphicsAllocation); @@ -852,7 +852,7 @@ TEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhenCreateFromSharedHandleFa imgInfo.surfaceFormat = &gmmSurfaceFormat->surfaceFormat; imgInfo.plane = GMM_PLANE_Y; - AllocationProperties properties(rootDeviceIndex, false, imgInfo, AllocationType::SHARED_IMAGE, context.getDevice(0)->getDeviceBitfield()); + AllocationProperties properties(rootDeviceIndex, false, &imgInfo, AllocationType::SHARED_IMAGE, context.getDevice(0)->getDeviceBitfield()); auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false, true, nullptr); ASSERT_NE(nullptr, graphicsAllocation); diff --git a/opencl/test/unit_test/sharings/unified/unified_sharing_image_tests.cpp b/opencl/test/unit_test/sharings/unified/unified_sharing_image_tests.cpp index 704d24d342..d5897e6872 100644 --- a/opencl/test/unit_test/sharings/unified/unified_sharing_image_tests.cpp +++ b/opencl/test/unit_test/sharings/unified/unified_sharing_image_tests.cpp @@ -80,6 +80,10 @@ TEST_F(UnifiedSharingImageTestsWithMemoryManager, givenValidContextAndMemoryMana auto image = std::unique_ptr(UnifiedImage::createSharedUnifiedImage(context.get(), flags, getValidUnifiedSharingDesc(), &format, &imageDesc, &retVal)); ASSERT_EQ(CL_SUCCESS, retVal); + + auto renderSize = image->getGraphicsAllocation(device->getRootDeviceIndex())->getDefaultGmm()->gmmResourceInfo->getSizeAllocation(); + size_t expectedSize = imageDesc.image_row_pitch * imageDesc.image_height; + EXPECT_GE(renderSize, expectedSize); } TEST_F(UnifiedSharingImageTestsWithMemoryManager, givenPassedFormatWhenCreatingUnifiedImageThenFormatIsCorrectlySetInImageObject) { diff --git a/shared/source/memory_manager/allocation_properties.h b/shared/source/memory_manager/allocation_properties.h index 7755363ee3..9d511a04ba 100644 --- a/shared/source/memory_manager/allocation_properties.h +++ b/shared/source/memory_manager/allocation_properties.h @@ -56,11 +56,11 @@ struct AllocationProperties { : AllocationProperties(rootDeviceIndex, true, size, allocationType, false, subDevicesBitfieldParam) {} AllocationProperties(uint32_t rootDeviceIndex, bool allocateMemory, - ImageInfo &imgInfo, + ImageInfo *imgInfo, AllocationType allocationType, DeviceBitfield subDevicesBitfieldParam) : AllocationProperties(rootDeviceIndex, allocateMemory, 0u, allocationType, false, subDevicesBitfieldParam) { - this->imgInfo = &imgInfo; + this->imgInfo = imgInfo; } AllocationProperties(uint32_t rootDeviceIndex, diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index 080610f28e..af6d02d186 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -1023,12 +1023,9 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o if (properties.imgInfo) { GemGetTiling getTiling{}; getTiling.handle = boHandle; - auto ioctlHelper = drm.getIoctlHelper(); - ret = ioctlHelper->getGemTiling(&getTiling); if (ret) { - auto ioctlHelper = drm.getIoctlHelper(); if (getTiling.tilingMode == static_cast(ioctlHelper->getDrmParamValue(DrmParam::TilingNone))) { properties.imgInfo->linearStorage = true; } @@ -1037,6 +1034,7 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o Gmm *gmm = new Gmm(executionEnvironment.rootDeviceEnvironments[properties.rootDeviceIndex]->getGmmHelper(), *properties.imgInfo, createStorageInfoFromProperties(properties), properties.flags.preferCompressed); + gmm->updateImgInfoAndDesc(*properties.imgInfo, 0, NEO::ImagePlane::NO_PLANE); drmAllocation->setDefaultGmm(gmm); bo->setPatIndex(drm.getPatIndex(gmm, properties.allocationType, CacheRegion::Default, CachePolicy::WriteBack, false)); diff --git a/shared/test/common/mocks/mock_gmm.h b/shared/test/common/mocks/mock_gmm.h index e0a620118d..10acfd29b2 100644 --- a/shared/test/common/mocks/mock_gmm.h +++ b/shared/test/common/mocks/mock_gmm.h @@ -47,7 +47,7 @@ class MockGmm : public Gmm { imgDesc.imageWidth = 5; imgDesc.imageHeight = 5; auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr); - return memoryManager.allocateGraphicsMemoryWithProperties({mockRootDeviceIndex, true, imgInfo, AllocationType::IMAGE, mockDeviceBitfield}); + return memoryManager.allocateGraphicsMemoryWithProperties({mockRootDeviceIndex, true, &imgInfo, AllocationType::IMAGE, mockDeviceBitfield}); } }; } // namespace NEO diff --git a/shared/test/unit_test/command_stream/aub_command_stream_receiver_2_tests.cpp b/shared/test/unit_test/command_stream/aub_command_stream_receiver_2_tests.cpp index 149e0f24ef..0748fde2bf 100644 --- a/shared/test/unit_test/command_stream/aub_command_stream_receiver_2_tests.cpp +++ b/shared/test/unit_test/command_stream/aub_command_stream_receiver_2_tests.cpp @@ -607,7 +607,7 @@ HWTEST_F(AubCommandStreamReceiverNoHostPtrTests, givenAubCommandStreamReceiverWh auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr); AllocationProperties allocProperties{0u /* rootDeviceIndex */, true /* allocateMemory */, - imgInfo, AllocationType::IMAGE, deviceBitfield}; + &imgInfo, AllocationType::IMAGE, deviceBitfield}; auto imageAllocation = memoryManager->allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr); ASSERT_NE(nullptr, imageAllocation);