From bfbc0e07ba9492a5faf6a4a5181c7dee8f32a402 Mon Sep 17 00:00:00 2001 From: Filip Hazubski Date: Tue, 17 Nov 2020 00:23:13 +0000 Subject: [PATCH] Update MemoryProperties initialization Always specify the device. Related-To: NEO-4651 Signed-off-by: Filip Hazubski --- .../helpers/memory_properties_helpers.cpp | 9 ++++-- .../helpers/memory_properties_helpers.h | 10 +++++-- .../memory_properties_helpers_base.inl | 9 ++++-- .../source/mem_obj/mem_obj_helper_common.inl | 8 ++++-- .../enqueue_parent_kernel_tests_gen8.cpp | 3 +- .../enqueue_parent_kernel_tests_gen9.cpp | 3 +- .../aub_command_stream_receiver_2_tests.cpp | 5 +++- .../unit_test/helpers/base_object_tests.cpp | 4 ++- .../kernel/kernel_image_arg_tests.cpp | 6 ++-- .../test/unit_test/mem_obj/image3d_tests.cpp | 5 ++-- opencl/test/unit_test/mem_obj/image_tests.cpp | 3 +- ..._manager_allocate_in_device_pool_tests.inl | 10 +++++-- opencl/test/unit_test/mocks/mock_buffer.h | 28 ++++++++++++------- .../linux/drm_command_stream_tests.cpp | 8 ++++-- .../windows/wddm_memory_manager_tests.cpp | 13 +++++++-- 15 files changed, 86 insertions(+), 38 deletions(-) diff --git a/opencl/source/helpers/memory_properties_helpers.cpp b/opencl/source/helpers/memory_properties_helpers.cpp index e7a0a51e9c..4c03d86f68 100644 --- a/opencl/source/helpers/memory_properties_helpers.cpp +++ b/opencl/source/helpers/memory_properties_helpers.cpp @@ -5,6 +5,8 @@ * */ +#include "opencl/source/cl_device/cl_device.h" +#include "opencl/source/context/context.h" #include "opencl/source/helpers/memory_properties_helpers_base.inl" #include "opencl/source/mem_obj/mem_obj_helper.h" @@ -13,13 +15,16 @@ namespace NEO { void MemoryPropertiesHelper::addExtraMemoryProperties(MemoryProperties &properties, cl_mem_flags flags, cl_mem_flags_intel flagsIntel, const Device *pDevice) { } -DeviceBitfield MemoryPropertiesHelper::adjustDeviceBitfield(const MemoryProperties &memoryProperties, DeviceBitfield deviceBitfield) { + +DeviceBitfield MemoryPropertiesHelper::adjustDeviceBitfield(uint32_t rootDeviceIndex, const MemoryProperties &memoryProperties, + DeviceBitfield deviceBitfield) { return deviceBitfield; } bool MemoryPropertiesHelper::parseMemoryProperties(const cl_mem_properties_intel *properties, MemoryProperties &memoryProperties, cl_mem_flags &flags, cl_mem_flags_intel &flagsIntel, cl_mem_alloc_flags_intel &allocflags, ObjType objectType, Context &context) { + Device *pDevice = &context.getDevice(0)->getDevice(); if (properties != nullptr) { for (int i = 0; properties[i] != 0; i += 2) { @@ -39,7 +44,7 @@ bool MemoryPropertiesHelper::parseMemoryProperties(const cl_mem_properties_intel } } - memoryProperties = MemoryPropertiesHelper::createMemoryProperties(flags, flagsIntel, allocflags, nullptr); + memoryProperties = MemoryPropertiesHelper::createMemoryProperties(flags, flagsIntel, allocflags, pDevice); switch (objectType) { case MemoryPropertiesHelper::ObjType::BUFFER: diff --git a/opencl/source/helpers/memory_properties_helpers.h b/opencl/source/helpers/memory_properties_helpers.h index 0846b15f64..b168c12dac 100644 --- a/opencl/source/helpers/memory_properties_helpers.h +++ b/opencl/source/helpers/memory_properties_helpers.h @@ -35,9 +35,13 @@ class MemoryPropertiesHelper { cl_mem_flags &flags, cl_mem_flags_intel &flagsIntel, cl_mem_alloc_flags_intel &allocflags, ObjType objectType, Context &context); - static AllocationProperties getAllocationProperties(uint32_t rootDeviceIndex, MemoryProperties memoryProperties, bool allocateMemory, size_t size, - GraphicsAllocation::AllocationType type, bool multiStorageResource, const HardwareInfo &hwInfo, DeviceBitfield subDevicesBitfieldParam); - static DeviceBitfield adjustDeviceBitfield(const MemoryProperties &memoryProperties, DeviceBitfield subDevicesBitfieldParam); + static AllocationProperties getAllocationProperties( + uint32_t rootDeviceIndex, MemoryProperties memoryProperties, bool allocateMemory, size_t size, + GraphicsAllocation::AllocationType type, bool multiStorageResource, const HardwareInfo &hwInfo, + DeviceBitfield subDevicesBitfieldParam); + + static DeviceBitfield adjustDeviceBitfield(uint32_t rootDeviceIndex, const MemoryProperties &memoryProperties, + DeviceBitfield subDevicesBitfieldParam); static void fillPoliciesInProperties(AllocationProperties &allocationProperties, const MemoryProperties &memoryProperties, const HardwareInfo &hwInfo); diff --git a/opencl/source/helpers/memory_properties_helpers_base.inl b/opencl/source/helpers/memory_properties_helpers_base.inl index 4e3701a9fa..a31f8aa673 100644 --- a/opencl/source/helpers/memory_properties_helpers_base.inl +++ b/opencl/source/helpers/memory_properties_helpers_base.inl @@ -87,9 +87,12 @@ MemoryProperties MemoryPropertiesHelper::createMemoryProperties(cl_mem_flags fla return memoryProperties; } -AllocationProperties MemoryPropertiesHelper::getAllocationProperties(uint32_t rootDeviceIndex, MemoryProperties memoryProperties, bool allocateMemory, size_t size, - GraphicsAllocation::AllocationType type, bool multiStorageResource, const HardwareInfo &hwInfo, DeviceBitfield subDevicesBitfieldParam) { - auto deviceBitfield = adjustDeviceBitfield(memoryProperties, subDevicesBitfieldParam); +AllocationProperties MemoryPropertiesHelper::getAllocationProperties( + uint32_t rootDeviceIndex, MemoryProperties memoryProperties, bool allocateMemory, size_t size, + GraphicsAllocation::AllocationType type, bool multiStorageResource, const HardwareInfo &hwInfo, + DeviceBitfield subDevicesBitfieldParam) { + + auto deviceBitfield = adjustDeviceBitfield(rootDeviceIndex, memoryProperties, subDevicesBitfieldParam); AllocationProperties allocationProperties(rootDeviceIndex, allocateMemory, size, type, multiStorageResource, deviceBitfield); fillPoliciesInProperties(allocationProperties, memoryProperties, hwInfo); return allocationProperties; diff --git a/opencl/source/mem_obj/mem_obj_helper_common.inl b/opencl/source/mem_obj/mem_obj_helper_common.inl index 0e6a5bf5e2..8a4de8f105 100644 --- a/opencl/source/mem_obj/mem_obj_helper_common.inl +++ b/opencl/source/mem_obj/mem_obj_helper_common.inl @@ -69,9 +69,11 @@ bool MemObjHelper::validateMemoryPropertiesForImage(const MemoryProperties &memo return validateExtraMemoryProperties(memoryProperties, flags, flagsIntel, context); } -AllocationProperties MemObjHelper::getAllocationPropertiesWithImageInfo(uint32_t rootDeviceIndex, ImageInfo &imgInfo, bool allocateMemory, - const MemoryProperties &memoryProperties, const HardwareInfo &hwInfo, DeviceBitfield subDevicesBitfieldParam) { - auto deviceBitfield = MemoryPropertiesHelper::adjustDeviceBitfield(memoryProperties, subDevicesBitfieldParam); +AllocationProperties MemObjHelper::getAllocationPropertiesWithImageInfo( + uint32_t rootDeviceIndex, ImageInfo &imgInfo, bool allocateMemory, const MemoryProperties &memoryProperties, + const HardwareInfo &hwInfo, DeviceBitfield subDevicesBitfieldParam) { + + auto deviceBitfield = MemoryPropertiesHelper::adjustDeviceBitfield(rootDeviceIndex, memoryProperties, subDevicesBitfieldParam); AllocationProperties allocationProperties{rootDeviceIndex, allocateMemory, imgInfo, GraphicsAllocation::AllocationType::IMAGE, deviceBitfield}; MemoryPropertiesHelper::fillPoliciesInProperties(allocationProperties, memoryProperties, hwInfo); return allocationProperties; diff --git a/opencl/test/unit_test/aub_tests/gen8/execution_model/enqueue_parent_kernel_tests_gen8.cpp b/opencl/test/unit_test/aub_tests/gen8/execution_model/enqueue_parent_kernel_tests_gen8.cpp index f839bf16e5..f7977170b7 100644 --- a/opencl/test/unit_test/aub_tests/gen8/execution_model/enqueue_parent_kernel_tests_gen8.cpp +++ b/opencl/test/unit_test/aub_tests/gen8/execution_model/enqueue_parent_kernel_tests_gen8.cpp @@ -56,10 +56,11 @@ GEN8TEST_F(GEN8AUBParentKernelFixture, EnqueueParentKernel) { desc.image_row_pitch = 0; desc.image_slice_pitch = 0; + auto memoryProperties = MemoryPropertiesHelper::createMemoryProperties(0, 0, 0, &pClDevice->getDevice()); auto surfaceFormat = Image::getSurfaceFormatFromTable(0, &imageFormat, context->getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); std::unique_ptr image(Image::create( pContext, - {}, + memoryProperties, 0, 0, surfaceFormat, diff --git a/opencl/test/unit_test/aub_tests/gen9/execution_model/enqueue_parent_kernel_tests_gen9.cpp b/opencl/test/unit_test/aub_tests/gen9/execution_model/enqueue_parent_kernel_tests_gen9.cpp index 6d61ad9bf8..9a6c09f41c 100644 --- a/opencl/test/unit_test/aub_tests/gen9/execution_model/enqueue_parent_kernel_tests_gen9.cpp +++ b/opencl/test/unit_test/aub_tests/gen9/execution_model/enqueue_parent_kernel_tests_gen9.cpp @@ -54,10 +54,11 @@ GEN9TEST_F(AUBParentKernelFixture, EnqueueParentKernel) { desc.image_slice_pitch = 0; // clang-format on + auto memoryProperties = MemoryPropertiesHelper::createMemoryProperties(0, 0, 0, &context->getDevice(0)->getDevice()); auto surfaceFormat = Image::getSurfaceFormatFromTable(0, &imageFormat, context->getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); Image *image = Image::create( pContext, - {}, + memoryProperties, 0, 0, surfaceFormat, diff --git a/opencl/test/unit_test/command_stream/aub_command_stream_receiver_2_tests.cpp b/opencl/test/unit_test/command_stream/aub_command_stream_receiver_2_tests.cpp index 522180c9e4..a272224d72 100644 --- a/opencl/test/unit_test/command_stream/aub_command_stream_receiver_2_tests.cpp +++ b/opencl/test/unit_test/command_stream/aub_command_stream_receiver_2_tests.cpp @@ -11,6 +11,7 @@ #include "shared/source/helpers/hw_helper.h" #include "shared/source/os_interface/os_context.h" #include "shared/test/unit_test/helpers/debug_manager_state_restore.h" +#include "shared/test/unit_test/mocks/ult_device_factory.h" #include "opencl/source/helpers/hardware_context_controller.h" #include "opencl/source/mem_obj/mem_obj_helper.h" @@ -500,6 +501,7 @@ HWTEST_F(AubCommandStreamReceiverNoHostPtrTests, givenAubCommandStreamReceiverWh executionEnvironment->memoryManager.reset(memoryManager); auto hwInfo = executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo(); auto engineInstance = HwHelper::get(hwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*hwInfo)[0]; + UltDeviceFactory deviceFactory{1, 0}; DeviceBitfield deviceBitfield(1); MockOsContext osContext(0, deviceBitfield, engineInstance.first, PreemptionMode::Disabled, false, false, false); @@ -513,7 +515,8 @@ HWTEST_F(AubCommandStreamReceiverNoHostPtrTests, givenAubCommandStreamReceiverWh auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr); - AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(aubCsr->getRootDeviceIndex(), imgInfo, true, {}, *hwInfo, osContext.getDeviceBitfield()); + auto memoryProperties = MemoryPropertiesHelper::createMemoryProperties(0, 0, 0, deviceFactory.rootDevices[0]); + AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(aubCsr->getRootDeviceIndex(), imgInfo, true, memoryProperties, *hwInfo, osContext.getDeviceBitfield()); auto imageAllocation = memoryManager->allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr); ASSERT_NE(nullptr, imageAllocation); diff --git a/opencl/test/unit_test/helpers/base_object_tests.cpp b/opencl/test/unit_test/helpers/base_object_tests.cpp index bae9b117da..c37f7dbe55 100644 --- a/opencl/test/unit_test/helpers/base_object_tests.cpp +++ b/opencl/test/unit_test/helpers/base_object_tests.cpp @@ -287,9 +287,11 @@ TEST(CastToImage, WhenCastingFromMemObjThenBehavesAsExpected) { extern std::thread::id tempThreadID; class MockBuffer : public MockBufferStorage, public Buffer { + using MockBufferStorage::device; + public: MockBuffer() : MockBufferStorage(), - Buffer(nullptr, MemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, nullptr), + Buffer(nullptr, MemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, MockBufferStorage::device.get()), CL_MEM_USE_HOST_PTR, 0, sizeof(data), &data, &data, GraphicsAllocationHelper::toMultiGraphicsAllocation(&mockGfxAllocation), true, false, false) { } diff --git a/opencl/test/unit_test/kernel/kernel_image_arg_tests.cpp b/opencl/test/unit_test/kernel/kernel_image_arg_tests.cpp index 0cdf316f5f..3ed2b84f3c 100644 --- a/opencl/test/unit_test/kernel/kernel_image_arg_tests.cpp +++ b/opencl/test/unit_test/kernel/kernel_image_arg_tests.cpp @@ -98,8 +98,9 @@ TEST_F(KernelImageArgTest, givenImageWithNumSamplesWhenSetArgIsCalledThenPatchNu imgDesc.image_width = 5; imgDesc.image_height = 5; + auto memoryProperties = MemoryPropertiesHelper::createMemoryProperties(0, 0, 0, pDevice); auto surfaceFormat = Image::getSurfaceFormatFromTable(0, &imgFormat, context->getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); - auto sampleImg = Image::create(context.get(), {}, 0, 0, surfaceFormat, &imgDesc, nullptr, retVal); + auto sampleImg = Image::create(context.get(), memoryProperties, 0, 0, surfaceFormat, &imgDesc, nullptr, retVal); EXPECT_EQ(CL_SUCCESS, retVal); cl_mem memObj = sampleImg; @@ -224,8 +225,9 @@ HWTEST_F(KernelImageArgTest, givenImgWithMcsAllocWhenMakeResidentThenMakeMcsAllo imgDesc.image_width = 5; imgDesc.image_height = 5; + auto memoryProperties = MemoryPropertiesHelper::createMemoryProperties(0, 0, 0, pDevice); auto surfaceFormat = Image::getSurfaceFormatFromTable(0, &imgFormat, context->getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); - auto img = Image::create(context.get(), {}, 0, 0, surfaceFormat, &imgDesc, nullptr, retVal); + auto img = Image::create(context.get(), memoryProperties, 0, 0, surfaceFormat, &imgDesc, nullptr, retVal); EXPECT_EQ(CL_SUCCESS, retVal); auto mcsAlloc = context->getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{pDevice->getRootDeviceIndex(), MemoryConstants::pageSize}); img->setMcsAllocation(mcsAlloc); diff --git a/opencl/test/unit_test/mem_obj/image3d_tests.cpp b/opencl/test/unit_test/mem_obj/image3d_tests.cpp index 91393638bd..01a517e0c1 100644 --- a/opencl/test/unit_test/mem_obj/image3d_tests.cpp +++ b/opencl/test/unit_test/mem_obj/image3d_tests.cpp @@ -93,10 +93,11 @@ HWTEST_F(CreateImage3DTest, GivenTiledOrForcedLinearWhenCreatingImageThenPropert auto surfaceFormat = Image::getSurfaceFormatFromTable(0, &imageFormat, context->getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); auto imgInfo = MockGmm::initImgInfo(imageDesc, 0, surfaceFormat); MockGmm::queryImgParams(context->getDevice(0)->getGmmClientContext(), imgInfo); + auto memoryProperties = MemoryPropertiesHelper::createMemoryProperties(0, 0, 0, &context->getDevice(0)->getDevice()); auto image = Image::create( context, - {}, + memoryProperties, 0, 0, surfaceFormat, @@ -120,7 +121,7 @@ HWTEST_F(CreateImage3DTest, GivenTiledOrForcedLinearWhenCreatingImageThenPropert image = Image::create( context, - {}, + memoryProperties, 0, 0, surfaceFormat, diff --git a/opencl/test/unit_test/mem_obj/image_tests.cpp b/opencl/test/unit_test/mem_obj/image_tests.cpp index 1c09fe6efb..5a097598ec 100644 --- a/opencl/test/unit_test/mem_obj/image_tests.cpp +++ b/opencl/test/unit_test/mem_obj/image_tests.cpp @@ -1623,7 +1623,8 @@ HWTEST_F(HwImageTest, givenImageHwWithUnifiedSurfaceAndMcsWhenSettingParamsForMu cl_image_format format = {}; auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr); - AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(0, imgInfo, true, {}, context.getDevice(0)->getHardwareInfo(), context.getDeviceBitfieldForAllocation(0)); + auto memoryProperties = MemoryPropertiesHelper::createMemoryProperties(0, 0, 0, &context.getDevice(0)->getDevice()); + AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(0, imgInfo, true, memoryProperties, context.getDevice(0)->getHardwareInfo(), context.getDeviceBitfieldForAllocation(0)); auto graphicsAllocation = memoryManager.allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr); diff --git a/opencl/test/unit_test/memory_manager/memory_manager_allocate_in_device_pool_tests.inl b/opencl/test/unit_test/memory_manager/memory_manager_allocate_in_device_pool_tests.inl index eb4dc3be4b..24460ce036 100644 --- a/opencl/test/unit_test/memory_manager/memory_manager_allocate_in_device_pool_tests.inl +++ b/opencl/test/unit_test/memory_manager/memory_manager_allocate_in_device_pool_tests.inl @@ -52,10 +52,13 @@ TEST(MemoryManagerTest, givenAllowed32BitAndFroce32BitWhenGraphicsAllocationInDe TEST(AllocationFlagsTest, givenAllocateMemoryFlagWhenGetAllocationFlagsIsCalledThenAllocateFlagIsCorrectlySet) { HardwareInfo hwInfo(*defaultHwInfo); - auto allocationProperties = MemoryPropertiesHelper::getAllocationProperties(0, {}, true, 0, GraphicsAllocation::AllocationType::BUFFER, false, hwInfo, {}); + UltDeviceFactory deviceFactory{1, 0}; + auto pDevice = deviceFactory.rootDevices[0]; + MemoryProperties memoryProperties = MemoryPropertiesHelper::createMemoryProperties(0, 0, 0, pDevice); + auto allocationProperties = MemoryPropertiesHelper::getAllocationProperties(0, memoryProperties, true, 0, GraphicsAllocation::AllocationType::BUFFER, false, hwInfo, {}); EXPECT_TRUE(allocationProperties.flags.allocateMemory); - auto allocationProperties2 = MemoryPropertiesHelper::getAllocationProperties(0, {}, false, 0, GraphicsAllocation::AllocationType::BUFFER, false, hwInfo, {}); + auto allocationProperties2 = MemoryPropertiesHelper::getAllocationProperties(0, memoryProperties, false, 0, GraphicsAllocation::AllocationType::BUFFER, false, hwInfo, {}); EXPECT_FALSE(allocationProperties2.flags.allocateMemory); } @@ -87,8 +90,9 @@ TEST(AllocationFlagsTest, givenReadOnlyResourceFlagWhenGetAllocationFlagsIsCalle EXPECT_FALSE(allocationFlags.flags.flushL3RequiredForRead); EXPECT_FALSE(allocationFlags.flags.flushL3RequiredForWrite); + memoryProperties = MemoryPropertiesHelper::createMemoryProperties(0, 0, 0, pDevice); auto allocationFlags2 = MemoryPropertiesHelper::getAllocationProperties( - 0, {}, true, 0, GraphicsAllocation::AllocationType::BUFFER, false, pDevice->getHardwareInfo(), {}); + 0, memoryProperties, true, 0, GraphicsAllocation::AllocationType::BUFFER, false, pDevice->getHardwareInfo(), {}); EXPECT_TRUE(allocationFlags2.flags.flushL3RequiredForRead); EXPECT_TRUE(allocationFlags2.flags.flushL3RequiredForWrite); } diff --git a/opencl/test/unit_test/mocks/mock_buffer.h b/opencl/test/unit_test/mocks/mock_buffer.h index bfd64a0f6e..08831f15a4 100644 --- a/opencl/test/unit_test/mocks/mock_buffer.h +++ b/opencl/test/unit_test/mocks/mock_buffer.h @@ -39,13 +39,15 @@ class MockBuffer : public MockBufferStorage, public Buffer { using MockBufferStorage::device; MockBuffer(GraphicsAllocation &alloc) : MockBufferStorage(), Buffer( - nullptr, MemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, nullptr), CL_MEM_USE_HOST_PTR, 0, alloc.getUnderlyingBufferSize(), alloc.getUnderlyingBuffer(), alloc.getUnderlyingBuffer(), + nullptr, MemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, MockBufferStorage::device.get()), + CL_MEM_USE_HOST_PTR, 0, alloc.getUnderlyingBufferSize(), alloc.getUnderlyingBuffer(), alloc.getUnderlyingBuffer(), GraphicsAllocationHelper::toMultiGraphicsAllocation(&alloc), true, false, false), externalAlloc(&alloc) { } MockBuffer() : MockBufferStorage(), Buffer( - nullptr, MemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, nullptr), CL_MEM_USE_HOST_PTR, 0, sizeof(data), &data, &data, + nullptr, MemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, MockBufferStorage::device.get()), + CL_MEM_USE_HOST_PTR, 0, sizeof(data), &data, &data, GraphicsAllocationHelper::toMultiGraphicsAllocation(&mockGfxAllocation), true, false, false) { } ~MockBuffer() override { @@ -66,12 +68,15 @@ class AlignedBuffer : public MockBufferStorage, public Buffer { using MockBufferStorage::device; AlignedBuffer() : MockBufferStorage(false), Buffer( - nullptr, MemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, nullptr), CL_MEM_USE_HOST_PTR, 0, sizeof(data) / 2, alignUp(&data, 64), alignUp(&data, 64), + nullptr, MemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, MockBufferStorage::device.get()), + CL_MEM_USE_HOST_PTR, 0, sizeof(data) / 2, alignUp(&data, 64), alignUp(&data, 64), GraphicsAllocationHelper::toMultiGraphicsAllocation(&mockGfxAllocation), true, false, false) { } - AlignedBuffer(GraphicsAllocation *gfxAllocation) : MockBufferStorage(), Buffer( - nullptr, MemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, nullptr), CL_MEM_USE_HOST_PTR, 0, sizeof(data) / 2, alignUp(&data, 64), alignUp(&data, 64), - GraphicsAllocationHelper::toMultiGraphicsAllocation(gfxAllocation), true, false, false) { + AlignedBuffer(GraphicsAllocation *gfxAllocation) + : MockBufferStorage(), Buffer( + nullptr, MemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, MockBufferStorage::device.get()), + CL_MEM_USE_HOST_PTR, 0, sizeof(data) / 2, alignUp(&data, 64), alignUp(&data, 64), + GraphicsAllocationHelper::toMultiGraphicsAllocation(gfxAllocation), true, false, false) { } void setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation, bool isReadOnly, const Device &device) override { Buffer::setSurfaceState(this->device.get(), memory, getSize(), getCpuAddress(), 0, &mockGfxAllocation, 0, 0); @@ -83,12 +88,15 @@ class UnalignedBuffer : public MockBufferStorage, public Buffer { using MockBufferStorage::device; UnalignedBuffer() : MockBufferStorage(true), Buffer( - nullptr, MemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, nullptr), CL_MEM_USE_HOST_PTR, 0, sizeof(data) / 2, alignUp(&data, 4), alignUp(&data, 4), + nullptr, MemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, MockBufferStorage::device.get()), + CL_MEM_USE_HOST_PTR, 0, sizeof(data) / 2, alignUp(&data, 4), alignUp(&data, 4), GraphicsAllocationHelper::toMultiGraphicsAllocation(&mockGfxAllocation), false, false, false) { } - UnalignedBuffer(GraphicsAllocation *gfxAllocation) : MockBufferStorage(true), Buffer( - nullptr, MemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, nullptr), CL_MEM_USE_HOST_PTR, 0, sizeof(data) / 2, alignUp(&data, 4), alignUp(&data, 4), - GraphicsAllocationHelper::toMultiGraphicsAllocation(gfxAllocation), false, false, false) { + UnalignedBuffer(GraphicsAllocation *gfxAllocation) + : MockBufferStorage(true), Buffer( + nullptr, MemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, MockBufferStorage::device.get()), + CL_MEM_USE_HOST_PTR, 0, sizeof(data) / 2, alignUp(&data, 4), alignUp(&data, 4), + GraphicsAllocationHelper::toMultiGraphicsAllocation(gfxAllocation), false, false, false) { } void setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3, bool alignSizeForAuxTranslation, bool isReadOnly, const Device &device) override { Buffer::setSurfaceState(this->device.get(), memory, getSize(), getCpuAddress(), 0, &mockGfxAllocation, 0, 0); diff --git a/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp index 5f31fee962..77b0d0da2a 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp @@ -30,6 +30,7 @@ #include "opencl/test/unit_test/helpers/execution_environment_helper.h" #include "opencl/test/unit_test/mocks/linux/mock_drm_command_stream_receiver.h" #include "opencl/test/unit_test/mocks/mock_allocation_properties.h" +#include "opencl/test/unit_test/mocks/mock_buffer.h" #include "opencl/test/unit_test/mocks/mock_gmm.h" #include "opencl/test/unit_test/mocks/mock_gmm_page_table_mngr.h" #include "opencl/test/unit_test/mocks/mock_host_ptr_manager.h" @@ -1498,7 +1499,9 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, makeNonResidentOnMemObjectCalls mm->freeGraphicsMemory(allocation1); } -class DrmMockBuffer : public Buffer { +class DrmMockBuffer : public MockBufferStorage, public Buffer { + using MockBufferStorage::device; + public: static DrmMockBuffer *create() { char *data = static_cast(::alignedMalloc(128, 64)); @@ -1513,7 +1516,8 @@ class DrmMockBuffer : public Buffer { DrmMockBuffer(char *data, size_t size, DrmAllocation *alloc) : Buffer( - nullptr, MemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, nullptr), CL_MEM_USE_HOST_PTR, 0, size, data, data, + nullptr, MemoryPropertiesHelper::createMemoryProperties(CL_MEM_USE_HOST_PTR, 0, 0, MockBufferStorage::device.get()), + CL_MEM_USE_HOST_PTR, 0, size, data, data, GraphicsAllocationHelper::toMultiGraphicsAllocation(alloc), true, false, false), data(data), gfxAllocation(alloc) { diff --git a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp index b9fc18c714..f3312f9fc9 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp @@ -19,6 +19,7 @@ #include "shared/test/unit_test/helpers/debug_manager_state_restore.h" #include "shared/test/unit_test/helpers/ult_hw_config.h" #include "shared/test/unit_test/mocks/mock_device.h" +#include "shared/test/unit_test/mocks/ult_device_factory.h" #include "shared/test/unit_test/utilities/base_object_utils.h" #include "opencl/source/helpers/memory_properties_helpers.h" @@ -1432,6 +1433,7 @@ TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsDisable } TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleterWhenCannotAllocateMemoryForTiledImageThenDrainIsCalledAndCreateAllocationIsCalledTwice) { + UltDeviceFactory deviceFactory{1, 0}; cl_image_desc imgDesc = {}; imgDesc.image_type = CL_MEM_OBJECT_IMAGE3D; ImageInfo imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr); @@ -1440,7 +1442,8 @@ TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleter EXPECT_EQ(0, deleter->drainCalled); EXPECT_EQ(0u, wddm->createAllocationResult.called); deleter->expectDrainBlockingValue(true); - AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(0, imgInfo, true, {}, *hwInfo, mockDeviceBitfield); + auto memoryProperties = MemoryPropertiesHelper::createMemoryProperties(0, 0, 0, deviceFactory.rootDevices[0]); + AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(0, imgInfo, true, memoryProperties, *hwInfo, mockDeviceBitfield); memoryManager->allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr); EXPECT_EQ(1, deleter->drainCalled); @@ -1448,6 +1451,7 @@ TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleter } TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleterWhenCanAllocateMemoryForTiledImageThenDrainIsNotCalledAndCreateAllocationIsCalledOnce) { + UltDeviceFactory deviceFactory{1, 0}; cl_image_desc imgDesc; imgDesc.image_type = CL_MEM_OBJECT_IMAGE3D; ImageInfo imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr); @@ -1459,7 +1463,8 @@ TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleter EXPECT_EQ(0u, wddm->createAllocationResult.called); EXPECT_EQ(0u, wddm->mapGpuVirtualAddressResult.called); - AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(0, imgInfo, true, {}, *hwInfo, mockDeviceBitfield); + auto memoryProperties = MemoryPropertiesHelper::createMemoryProperties(0, 0, 0, deviceFactory.rootDevices[0]); + AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(0, imgInfo, true, memoryProperties, *hwInfo, mockDeviceBitfield); auto allocation = memoryManager->allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr); EXPECT_EQ(0, deleter->drainCalled); @@ -1469,6 +1474,7 @@ TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleter } TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithoutAsyncDeleterWhenCannotAllocateMemoryForTiledImageThenCreateAllocationIsCalledOnce) { + UltDeviceFactory deviceFactory{1, 0}; memoryManager->setDeferredDeleter(nullptr); cl_image_desc imgDesc; imgDesc.image_type = CL_MEM_OBJECT_IMAGE3D; @@ -1477,7 +1483,8 @@ TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithoutAsyncDele wddm->createAllocationStatus = STATUS_GRAPHICS_NO_VIDEO_MEMORY; EXPECT_EQ(0u, wddm->createAllocationResult.called); - AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(0, imgInfo, true, {}, *hwInfo, mockDeviceBitfield); + auto memoryProperties = MemoryPropertiesHelper::createMemoryProperties(0, 0, 0, deviceFactory.rootDevices[0]); + AllocationProperties allocProperties = MemObjHelper::getAllocationPropertiesWithImageInfo(0, imgInfo, true, memoryProperties, *hwInfo, mockDeviceBitfield); memoryManager->allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr); EXPECT_EQ(1u, wddm->createAllocationResult.called);