diff --git a/opencl/test/unit_test/mem_obj/buffer_tests.cpp b/opencl/test/unit_test/mem_obj/buffer_tests.cpp index 22633027c6..17395a906b 100644 --- a/opencl/test/unit_test/mem_obj/buffer_tests.cpp +++ b/opencl/test/unit_test/mem_obj/buffer_tests.cpp @@ -28,6 +28,7 @@ #include "opencl/test/unit_test/fixtures/multi_root_device_fixture.h" #include "opencl/test/unit_test/mocks/mock_buffer.h" #include "opencl/test/unit_test/mocks/mock_command_queue.h" +#include "opencl/test/unit_test/mocks/mock_platform.h" using namespace NEO; @@ -2073,3 +2074,20 @@ TEST_F(MultiRootDeviceBufferTest, givenNullptrGraphicsAllocationForRootDeviceInd address = buffer->getBufferAddress(0); EXPECT_EQ(reinterpret_cast(buffer->getHostPtr()), address); } + +TEST(ResidencyTests, whenBuffersIsCreatedWithMakeResidentFlagThenItSuccessfulyCreates) { + VariableBackup backup(&ultHwConfig); + ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false; + ultHwConfig.forceOsAgnosticMemoryManager = false; + DebugManagerStateRestore restorer; + DebugManager.flags.MakeAllBuffersResident.set(true); + + initPlatform(); + auto device = platform()->getClDevice(0u); + + MockContext context(device, false); + auto retValue = CL_SUCCESS; + auto clBuffer = clCreateBuffer(&context, 0u, 4096u, nullptr, &retValue); + ASSERT_EQ(retValue, CL_SUCCESS); + clReleaseMemObject(clBuffer); +} diff --git a/opencl/test/unit_test/os_interface/linux/CMakeLists.txt b/opencl/test/unit_test/os_interface/linux/CMakeLists.txt index efa3a6fb85..00086bb2a2 100644 --- a/opencl/test/unit_test/os_interface/linux/CMakeLists.txt +++ b/opencl/test/unit_test/os_interface/linux/CMakeLists.txt @@ -10,19 +10,13 @@ set(IGDRCL_SRCS_tests_os_interface_linux ${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream_tests_1.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream_tests_2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_gem_close_worker_tests.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/cl_drm_memory_manager_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/linux_create_command_queue_with_properties_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_performance_counters_linux.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_performance_counters_linux.h ${CMAKE_CURRENT_SOURCE_DIR}/performance_counters_linux_tests.cpp ) -if("${BRANCH_TYPE}" STREQUAL "") - list(APPEND IGDRCL_SRCS_tests_os_interface_linux - ${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager_localmem_upstream_tests.cpp - ) -endif() - if(NEO_ENABLE_i915_PRELIM_DETECTION) if(TESTS_XE_HPC_CORE) list(APPEND IGDRCL_SRCS_tests_os_interface_linux 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 new file mode 100644 index 0000000000..bfa97f6f6e --- /dev/null +++ b/opencl/test/unit_test/os_interface/linux/cl_drm_memory_manager_tests.cpp @@ -0,0 +1,872 @@ +/* + * Copyright (C) 2018-2022 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/built_ins/sip.h" +#include "shared/source/command_stream/device_command_stream.h" +#include "shared/source/command_stream/linear_stream.h" +#include "shared/source/command_stream/preemption.h" +#include "shared/source/gmm_helper/gmm_helper.h" +#include "shared/source/helpers/aligned_memory.h" +#include "shared/source/helpers/constants.h" +#include "shared/source/helpers/ptr_math.h" +#include "shared/source/helpers/timestamp_packet.h" +#include "shared/source/os_interface/linux/allocator_helper.h" +#include "shared/source/os_interface/linux/drm_allocation.h" +#include "shared/source/os_interface/linux/drm_buffer_object.h" +#include "shared/source/os_interface/linux/drm_command_stream.h" +#include "shared/source/os_interface/linux/drm_memory_manager.h" +#include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/helpers/unit_test_helper.h" +#include "shared/test/common/libult/linux/drm_mock.h" +#include "shared/test/common/mocks/linux/mock_drm_allocation.h" +#include "shared/test/common/mocks/mock_gmm.h" +#include "shared/test/common/os_interface/linux/drm_memory_manager_tests.h" +#include "shared/test/common/test_macros/test.h" +#include "shared/test/unit_test/helpers/gtest_helpers.h" + +#include "opencl/source/event/event.h" +#include "opencl/source/helpers/cl_memory_properties_helpers.h" +#include "opencl/source/mem_obj/buffer.h" +#include "opencl/source/mem_obj/image.h" +#include "opencl/test/unit_test/mocks/mock_cl_device.h" +#include "opencl/test/unit_test/mocks/mock_context.h" +#include "opencl/test/unit_test/mocks/mock_platform.h" + +#include "gtest/gtest.h" + +#include + +using namespace NEO; + +using DrmMemoryManagerTest = Test; + +struct ClDrmMemoryManagerTest : public DrmMemoryManagerTest { + void SetUp() override { + MemoryManagementFixture::SetUp(); + + executionEnvironment = MockClDevice::prepareExecutionEnvironment(defaultHwInfo.get(), numRootDevices - 1); + DrmMemoryManagerFixture::SetUp(new DrmMockCustom(*executionEnvironment->rootDeviceEnvironments[0]), false); + pClDevice = new MockClDevice{device}; // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks) + device->incRefInternal(); + } + void TearDown() override { + delete pClDevice; + DrmMemoryManagerTest::TearDown(); + } + + MockClDevice *pClDevice = nullptr; +}; + +TEST_F(ClDrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferAllocationThen32BitBufferIsReturned) { + DebugManagerStateRestore dbgRestorer; + mock->ioctl_expected.gemUserptr = 1; + mock->ioctl_expected.gemWait = 1; + mock->ioctl_expected.gemClose = 1; + + DebugManager.flags.Force32bitAddressing.set(true); + MockContext context(pClDevice); + memoryManager->setForce32BitAllocations(true); + + auto size = MemoryConstants::pageSize; + auto retVal = CL_SUCCESS; + + auto buffer = Buffer::create( + &context, + CL_MEM_ALLOC_HOST_PTR, + size, + nullptr, + retVal); + EXPECT_EQ(CL_SUCCESS, retVal); + + EXPECT_TRUE(buffer->isMemObjZeroCopy()); + auto bufferAddress = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuAddress(); + auto baseAddress = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuBaseAddress(); + + EXPECT_LT(ptrDiff(bufferAddress, baseAddress), MemoryConstants::max32BitAddress); + + delete buffer; +} + +TEST_F(ClDrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferCreatedFromHostPtrThen32BitBufferIsReturned) { + DebugManagerStateRestore dbgRestorer; + mock->ioctl_expected.gemUserptr = 1; + mock->ioctl_expected.gemWait = 1; + mock->ioctl_expected.gemClose = 1; + + DebugManager.flags.Force32bitAddressing.set(true); + MockContext context(pClDevice); + memoryManager->setForce32BitAllocations(true); + + auto size = MemoryConstants::pageSize; + void *ptr = reinterpret_cast(0x1000); + auto ptrOffset = MemoryConstants::cacheLineSize; + uintptr_t offsetedPtr = (uintptr_t)ptr + ptrOffset; + auto retVal = CL_SUCCESS; + + auto buffer = Buffer::create( + &context, + CL_MEM_USE_HOST_PTR, + size, + reinterpret_cast(offsetedPtr), + retVal); + EXPECT_EQ(CL_SUCCESS, retVal); + + EXPECT_TRUE(buffer->isMemObjZeroCopy()); + auto bufferAddress = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuAddress(); + auto drmAllocation = static_cast(buffer->getGraphicsAllocation(rootDeviceIndex)); + + auto baseAddress = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuBaseAddress(); + EXPECT_LT(ptrDiff(bufferAddress, baseAddress), MemoryConstants::max32BitAddress); + + EXPECT_TRUE(drmAllocation->is32BitAllocation()); + + auto allocationCpuPtr = drmAllocation->getUnderlyingBuffer(); + auto allocationPageOffset = ptrDiff(allocationCpuPtr, alignDown(allocationCpuPtr, MemoryConstants::pageSize)); + + auto allocationGpuPtr = drmAllocation->getGpuAddress(); + auto allocationGpuOffset = ptrDiff(allocationGpuPtr, alignDown(allocationGpuPtr, MemoryConstants::pageSize)); + + auto bufferObject = drmAllocation->getBO(); + + EXPECT_EQ(drmAllocation->getUnderlyingBuffer(), reinterpret_cast(offsetedPtr)); + + // Gpu address should be different + EXPECT_NE(offsetedPtr, drmAllocation->getGpuAddress()); + // Gpu address offset iqual to cpu offset + EXPECT_EQ(allocationGpuOffset, ptrOffset); + + EXPECT_EQ(allocationPageOffset, ptrOffset); + + auto boAddress = bufferObject->peekAddress(); + EXPECT_EQ(alignDown(boAddress, MemoryConstants::pageSize), boAddress); + + delete buffer; +} + +TEST_F(ClDrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferCreatedFrom64BitHostPtrThen32BitBufferIsReturned) { + DebugManagerStateRestore dbgRestorer; + { + if (is32bit) { + mock->ioctl_expected.total = -1; + } else { + mock->ioctl_expected.gemUserptr = 1; + mock->ioctl_expected.gemWait = 1; + mock->ioctl_expected.gemClose = 1; + + DebugManager.flags.Force32bitAddressing.set(true); + MockContext context(pClDevice); + memoryManager->setForce32BitAllocations(true); + + auto size = MemoryConstants::pageSize; + void *ptr = reinterpret_cast(0x100000000000); + auto ptrOffset = MemoryConstants::cacheLineSize; + uintptr_t offsetedPtr = (uintptr_t)ptr + ptrOffset; + auto retVal = CL_SUCCESS; + + auto buffer = Buffer::create( + &context, + CL_MEM_USE_HOST_PTR, + size, + reinterpret_cast(offsetedPtr), + retVal); + EXPECT_EQ(CL_SUCCESS, retVal); + + EXPECT_TRUE(buffer->isMemObjZeroCopy()); + auto bufferAddress = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuAddress(); + + auto baseAddress = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuBaseAddress(); + EXPECT_LT(ptrDiff(bufferAddress, baseAddress), MemoryConstants::max32BitAddress); + + auto drmAllocation = static_cast(buffer->getGraphicsAllocation(rootDeviceIndex)); + + EXPECT_TRUE(drmAllocation->is32BitAllocation()); + + auto allocationCpuPtr = drmAllocation->getUnderlyingBuffer(); + auto allocationPageOffset = ptrDiff(allocationCpuPtr, alignDown(allocationCpuPtr, MemoryConstants::pageSize)); + auto bufferObject = drmAllocation->getBO(); + + EXPECT_EQ(allocationPageOffset, ptrOffset); + + auto boAddress = bufferObject->peekAddress(); + EXPECT_EQ(alignDown(boAddress, MemoryConstants::pageSize), boAddress); + + delete buffer; + DebugManager.flags.Force32bitAddressing.set(false); + } + } +} + +TEST_F(ClDrmMemoryManagerTest, GivenSizeAbove2GBWhenUseHostPtrAndAllocHostPtrAreCreatedThenFirstSucceedsAndSecondFails) { + DebugManagerStateRestore dbgRestorer; + mock->ioctl_expected.total = -1; + DebugManager.flags.Force32bitAddressing.set(true); + MockContext context(pClDevice); + memoryManager->setForce32BitAllocations(true); + + size_t size = 2 * GB; + void *ptr = reinterpret_cast(0x100000000000); + auto retVal = CL_SUCCESS; + + auto buffer = Buffer::create( + &context, + CL_MEM_USE_HOST_PTR, + size, + ptr, + retVal); + + size_t size2 = 4 * GB - MemoryConstants::pageSize; // Keep size aligned + + auto buffer2 = Buffer::create( + &context, + CL_MEM_ALLOC_HOST_PTR, + size2, + nullptr, + retVal); + + EXPECT_NE(retVal, CL_SUCCESS); + EXPECT_EQ(nullptr, buffer2); + + if (buffer) { + auto bufferPtr = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuAddress(); + + EXPECT_TRUE(buffer->getGraphicsAllocation(rootDeviceIndex)->is32BitAllocation()); + auto baseAddress = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuBaseAddress(); + EXPECT_LT(ptrDiff(bufferPtr, baseAddress), MemoryConstants::max32BitAddress); + } + + delete buffer; +} + +TEST_F(ClDrmMemoryManagerTest, GivenSizeAbove2GBWhenAllocHostPtrAndUseHostPtrAreCreatedThenFirstSucceedsAndSecondFails) { + DebugManagerStateRestore dbgRestorer; + mock->ioctl_expected.total = -1; + DebugManager.flags.Force32bitAddressing.set(true); + MockContext context(pClDevice); + memoryManager->setForce32BitAllocations(true); + + size_t size = 2 * GB; + void *ptr = reinterpret_cast(0x100000000000); + auto retVal = CL_SUCCESS; + + auto buffer = Buffer::create( + &context, + CL_MEM_ALLOC_HOST_PTR, + size, + nullptr, + retVal); + + size_t size2 = 4 * GB - MemoryConstants::pageSize; // Keep size aligned + + auto buffer2 = Buffer::create( + &context, + CL_MEM_USE_HOST_PTR, + size2, + ptr, + retVal); + + EXPECT_NE(retVal, CL_SUCCESS); + EXPECT_EQ(nullptr, buffer2); + + if (buffer) { + auto bufferPtr = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuAddress(); + + EXPECT_TRUE(buffer->getGraphicsAllocation(rootDeviceIndex)->is32BitAllocation()); + auto baseAddress = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuBaseAddress(); + EXPECT_LT(ptrDiff(bufferPtr, baseAddress), MemoryConstants::max32BitAddress); + } + + delete buffer; +} + +TEST_F(ClDrmMemoryManagerTest, givenDrmBufferWhenItIsQueriedForInternalAllocationThenBoIsReturned) { + mock->ioctl_expected.total = -1; + mock->outputFd = 1337; + MockContext context(pClDevice); + + size_t size = 1u; + auto retVal = CL_SUCCESS; + + auto buffer = Buffer::create( + &context, + CL_MEM_ALLOC_HOST_PTR, + size, + nullptr, + retVal); + + uint64_t handle = 0llu; + + retVal = clGetMemObjectInfo(buffer, CL_MEM_ALLOCATION_HANDLE_INTEL, sizeof(handle), &handle, nullptr); + EXPECT_EQ(retVal, CL_SUCCESS); + + EXPECT_EQ(static_cast(1337), handle); + + clReleaseMemObject(buffer); +} + +HWTEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageWithMipCountZeroIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) { + if (!UnitTestHelper::tiledImagesSupported) { + GTEST_SKIP(); + } + mock->ioctl_expected.gemCreate = 1; + mock->ioctl_expected.gemSetTiling = 1; + mock->ioctl_expected.gemWait = 1; + mock->ioctl_expected.gemClose = 1; + + MockContext context(pClDevice); + + cl_image_format imageFormat; + imageFormat.image_channel_data_type = CL_UNORM_INT8; + imageFormat.image_channel_order = CL_R; + + cl_image_desc imageDesc = {}; + + imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D; + imageDesc.image_width = 64u; + imageDesc.image_height = 64u; + + auto retVal = CL_SUCCESS; + + cl_mem_flags flags = CL_MEM_WRITE_ONLY; + auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); + std::unique_ptr dstImage(Image::create( + &context, ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()), + flags, 0, surfaceFormat, &imageDesc, nullptr, retVal)); + EXPECT_EQ(CL_SUCCESS, retVal); + ASSERT_NE(nullptr, dstImage); + auto imageGraphicsAllocation = dstImage->getGraphicsAllocation(rootDeviceIndex); + ASSERT_NE(nullptr, imageGraphicsAllocation); + EXPECT_TRUE(imageGraphicsAllocation->getDefaultGmm()->resourceParams.Usage == + GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_IMAGE); + + DrmAllocation *drmAllocation = static_cast(imageGraphicsAllocation); + auto imageSize = drmAllocation->getUnderlyingBufferSize(); + auto rowPitch = dstImage->getImageDesc().image_row_pitch; + + EXPECT_EQ(1u, this->mock->createParamsHandle); + EXPECT_EQ(imageSize, this->mock->createParamsSize); + __u32 tilingMode = I915_TILING_Y; + EXPECT_EQ(tilingMode, this->mock->setTilingMode); + EXPECT_EQ(rowPitch, this->mock->setTilingStride); + EXPECT_EQ(1u, this->mock->setTilingHandle); +} + +HWTEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageWithMipCountNonZeroIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) { + if (!UnitTestHelper::tiledImagesSupported) { + GTEST_SKIP(); + } + mock->ioctl_expected.gemCreate = 1; + mock->ioctl_expected.gemSetTiling = 1; + mock->ioctl_expected.gemWait = 1; + mock->ioctl_expected.gemClose = 1; + + MockContext context(pClDevice); + + cl_image_format imageFormat; + imageFormat.image_channel_data_type = CL_UNORM_INT8; + imageFormat.image_channel_order = CL_R; + + cl_image_desc imageDesc = {}; + + imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D; + imageDesc.image_width = 64u; + imageDesc.image_height = 64u; + imageDesc.num_mip_levels = 1u; + + auto retVal = CL_SUCCESS; + + cl_mem_flags flags = CL_MEM_WRITE_ONLY; + auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); + std::unique_ptr dstImage(Image::create( + &context, ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()), + flags, 0, surfaceFormat, &imageDesc, nullptr, retVal)); + EXPECT_EQ(CL_SUCCESS, retVal); + ASSERT_NE(nullptr, dstImage); + EXPECT_EQ(static_cast(imageDesc.num_mip_levels), dstImage->peekMipCount()); + auto imageGraphicsAllocation = dstImage->getGraphicsAllocation(rootDeviceIndex); + ASSERT_NE(nullptr, imageGraphicsAllocation); + EXPECT_TRUE(imageGraphicsAllocation->getDefaultGmm()->resourceParams.Usage == + GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_IMAGE); + + DrmAllocation *drmAllocation = static_cast(imageGraphicsAllocation); + auto imageSize = drmAllocation->getUnderlyingBufferSize(); + auto rowPitch = dstImage->getImageDesc().image_row_pitch; + + EXPECT_EQ(1u, this->mock->createParamsHandle); + EXPECT_EQ(imageSize, this->mock->createParamsSize); + __u32 tilingMode = I915_TILING_Y; + EXPECT_EQ(tilingMode, this->mock->setTilingMode); + EXPECT_EQ(rowPitch, this->mock->setTilingStride); + EXPECT_EQ(1u, this->mock->setTilingHandle); +} + +TEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageIsBeingCreatedAndAllocationFailsThenReturnNullptr) { + MockContext context(pClDevice); + + cl_image_format imageFormat; + imageFormat.image_channel_data_type = CL_UNORM_INT8; + imageFormat.image_channel_order = CL_R; + + cl_image_desc imageDesc = {}; + + imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D; + imageDesc.image_width = 64u; + imageDesc.image_height = 64u; + + auto retVal = CL_SUCCESS; + + InjectedFunction method = [&](size_t failureIndex) { + cl_mem_flags flags = CL_MEM_WRITE_ONLY; + auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); + std::unique_ptr dstImage(Image::create( + &context, ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()), + flags, 0, surfaceFormat, &imageDesc, nullptr, retVal)); + if (MemoryManagement::nonfailingAllocation == failureIndex) { + EXPECT_NE(nullptr, dstImage.get()); + } else { + EXPECT_EQ(nullptr, dstImage.get()); + } + }; + + injectFailures(method); + mock->reset(); +} + +HWTEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageIsBeingCreatedFromHostPtrThenAllocateGraphicsMemoryForImageIsUsed) { + if (!UnitTestHelper::tiledImagesSupported) { + GTEST_SKIP(); + } + + device->setPreemptionMode(PreemptionMode::Disabled); + + auto csr = static_cast *>(device->getDefaultEngine().commandStreamReceiver); + csr->callHwFlush = false; + + mock->ioctl_expected.gemCreate = 1; + mock->ioctl_expected.gemSetTiling = 1; + mock->ioctl_expected.gemWait = 2; + mock->ioctl_expected.gemClose = 2; + mock->ioctl_expected.gemUserptr = 1; + mock->ioctl_expected.execbuffer2 = 0; + + // builtins kernels + mock->ioctl_expected.gemUserptr += 5; + + // command buffers + mock->ioctl_expected.gemUserptr += 2; + additionalDestroyDeviceIoctls.gemClose += 2; + additionalDestroyDeviceIoctls.gemWait += 2; + + // indirect heaps + mock->ioctl_expected.gemUserptr += 3; + additionalDestroyDeviceIoctls.gemClose += 3; + additionalDestroyDeviceIoctls.gemWait += 3; + + if (device->getDefaultEngine().commandStreamReceiver->peekTimestampPacketWriteEnabled()) { + mock->ioctl_expected.gemUserptr++; + additionalDestroyDeviceIoctls.gemClose++; + additionalDestroyDeviceIoctls.gemWait++; + } + + if (device->getDefaultEngine().commandStreamReceiver->getClearColorAllocation() != nullptr) { + mock->ioctl_expected.gemUserptr++; + additionalDestroyDeviceIoctls.gemClose++; + additionalDestroyDeviceIoctls.gemWait++; + } + + MockContext context(pClDevice); + + cl_image_format imageFormat; + imageFormat.image_channel_data_type = CL_UNORM_INT8; + imageFormat.image_channel_order = CL_R; + + cl_image_desc imageDesc = {}; + + imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D; + imageDesc.image_width = 64u; + imageDesc.image_height = 64u; + + auto data = alignedMalloc(64u * 64u * 4 * 8, MemoryConstants::pageSize); + + auto retVal = CL_SUCCESS; + + cl_mem_flags flags = CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR; + auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); + std::unique_ptr dstImage(Image::create( + &context, ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()), + flags, 0, surfaceFormat, &imageDesc, data, retVal)); + EXPECT_EQ(CL_SUCCESS, retVal); + ASSERT_NE(nullptr, dstImage); + auto imageGraphicsAllocation = dstImage->getGraphicsAllocation(rootDeviceIndex); + ASSERT_NE(nullptr, imageGraphicsAllocation); + EXPECT_TRUE(imageGraphicsAllocation->getDefaultGmm()->resourceParams.Usage == + GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_IMAGE); + + DrmAllocation *drmAllocation = static_cast(imageGraphicsAllocation); + auto imageSize = drmAllocation->getUnderlyingBufferSize(); + auto rowPitch = dstImage->getImageDesc().image_row_pitch; + + EXPECT_EQ(1u, this->mock->createParamsHandle); + EXPECT_EQ(imageSize, this->mock->createParamsSize); + __u32 tilingMode = I915_TILING_Y; + EXPECT_EQ(tilingMode, this->mock->setTilingMode); + EXPECT_EQ(rowPitch, this->mock->setTilingStride); + EXPECT_EQ(1u, this->mock->setTilingHandle); + + alignedFree(data); +} + +TEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhenMemoryAllocatedForImageThenUnmapSizeCorrectlySetWhenLimitedRangeAllocationUsedOrNotUsed) { + mock->ioctl_expected.gemUserptr = 2; + mock->ioctl_expected.gemWait = 2; + mock->ioctl_expected.gemClose = 2; + + MockContext context(pClDevice); + + cl_image_format imageFormat; + imageFormat.image_channel_data_type = CL_UNORM_INT8; + imageFormat.image_channel_order = CL_R; + + cl_image_desc imageDesc = {}; + + imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D; + imageDesc.image_width = 64u; + + auto data = alignedMalloc(64u * 4 * 8, MemoryConstants::pageSize); + + auto retVal = CL_SUCCESS; + + cl_mem_flags flags = CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR; + auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); + std::unique_ptr dstImage(Image::create( + &context, ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()), + flags, 0, surfaceFormat, &imageDesc, data, retVal)); + EXPECT_EQ(CL_SUCCESS, retVal); + ASSERT_NE(nullptr, dstImage); + auto imageGraphicsAllocation = dstImage->getGraphicsAllocation(rootDeviceIndex); + ASSERT_NE(nullptr, imageGraphicsAllocation); + + alignedFree(data); +} + +TEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhenNonTiledImgWithMipCountZeroisBeingCreatedThenAllocateGraphicsMemoryIsUsed) { + mock->ioctl_expected.gemUserptr = 2; + mock->ioctl_expected.gemWait = 2; + mock->ioctl_expected.gemClose = 2; + + MockContext context(pClDevice); + + cl_image_format imageFormat; + imageFormat.image_channel_data_type = CL_UNORM_INT8; + imageFormat.image_channel_order = CL_R; + + cl_image_desc imageDesc = {}; + + imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D; + imageDesc.image_width = 64u; + + auto data = alignedMalloc(64u * 4 * 8, MemoryConstants::pageSize); + + auto retVal = CL_SUCCESS; + this->mock->createParamsHandle = 0; + this->mock->createParamsSize = 0; + + cl_mem_flags flags = CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR; + auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); + std::unique_ptr dstImage(Image::create( + &context, ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()), + flags, 0, surfaceFormat, &imageDesc, data, retVal)); + EXPECT_EQ(CL_SUCCESS, retVal); + ASSERT_NE(nullptr, dstImage); + auto imageGraphicsAllocation = dstImage->getGraphicsAllocation(rootDeviceIndex); + ASSERT_NE(nullptr, imageGraphicsAllocation); + EXPECT_TRUE(imageGraphicsAllocation->getDefaultGmm()->resourceParams.Usage == + GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_IMAGE); + + EXPECT_EQ(0u, this->mock->createParamsHandle); + EXPECT_EQ(0u, this->mock->createParamsSize); + __u32 tilingMode = I915_TILING_NONE; + EXPECT_EQ(tilingMode, this->mock->setTilingMode); + EXPECT_EQ(0u, this->mock->setTilingStride); + EXPECT_EQ(0u, this->mock->setTilingHandle); + + EXPECT_EQ(Sharing::nonSharedResource, imageGraphicsAllocation->peekSharedHandle()); + + alignedFree(data); +} + +TEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhenNonTiledImgWithMipCountNonZeroisBeingCreatedThenAllocateGraphicsMemoryIsUsed) { + mock->ioctl_expected.gemUserptr = 1; + mock->ioctl_expected.gemWait = 1; + mock->ioctl_expected.gemClose = 1; + + MockContext context(pClDevice); + + cl_image_format imageFormat; + imageFormat.image_channel_data_type = CL_UNORM_INT8; + imageFormat.image_channel_order = CL_R; + + cl_image_desc imageDesc = {}; + + imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D; + imageDesc.image_width = 64u; + imageDesc.num_mip_levels = 1u; + + auto data = alignedMalloc(64u * 4 * 8, MemoryConstants::pageSize); + + auto retVal = CL_SUCCESS; + + this->mock->createParamsHandle = 0; + this->mock->createParamsSize = 0; + + cl_mem_flags flags = CL_MEM_WRITE_ONLY; + auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); + std::unique_ptr dstImage(Image::create( + &context, ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()), + flags, 0, surfaceFormat, &imageDesc, data, retVal)); + EXPECT_EQ(CL_SUCCESS, retVal); + ASSERT_NE(nullptr, dstImage); + EXPECT_EQ(static_cast(imageDesc.num_mip_levels), dstImage->peekMipCount()); + auto imageGraphicsAllocation = dstImage->getGraphicsAllocation(rootDeviceIndex); + ASSERT_NE(nullptr, imageGraphicsAllocation); + EXPECT_TRUE(imageGraphicsAllocation->getDefaultGmm()->resourceParams.Usage == + GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_IMAGE); + + EXPECT_EQ(0u, this->mock->createParamsHandle); + EXPECT_EQ(0u, this->mock->createParamsSize); + __u32 tilingMode = I915_TILING_NONE; + EXPECT_EQ(tilingMode, this->mock->setTilingMode); + EXPECT_EQ(0u, this->mock->setTilingStride); + EXPECT_EQ(0u, this->mock->setTilingHandle); + + EXPECT_EQ(Sharing::nonSharedResource, imageGraphicsAllocation->peekSharedHandle()); + + alignedFree(data); +} + +TEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhen1DarrayImageIsBeingCreatedFromHostPtrThenTilingIsNotCalled) { + mock->ioctl_expected.gemUserptr = 2; + mock->ioctl_expected.gemWait = 2; + mock->ioctl_expected.gemClose = 2; + + MockContext context(pClDevice); + + cl_image_format imageFormat; + imageFormat.image_channel_data_type = CL_UNORM_INT8; + imageFormat.image_channel_order = CL_R; + + cl_image_desc imageDesc = {}; + + imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D; + imageDesc.image_width = 64u; + + auto data = alignedMalloc(64u * 4 * 8, MemoryConstants::pageSize); + + auto retVal = CL_SUCCESS; + this->mock->createParamsHandle = 0; + this->mock->createParamsSize = 0; + + cl_mem_flags flags = CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR; + auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); + std::unique_ptr dstImage(Image::create( + &context, ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()), + flags, 0, surfaceFormat, &imageDesc, data, retVal)); + auto imageGraphicsAllocation = dstImage->getGraphicsAllocation(rootDeviceIndex); + ASSERT_NE(nullptr, imageGraphicsAllocation); + + EXPECT_EQ(0u, this->mock->createParamsHandle); + EXPECT_EQ(0u, this->mock->createParamsSize); + __u32 tilingMode = I915_TILING_NONE; + EXPECT_EQ(tilingMode, this->mock->setTilingMode); + EXPECT_EQ(0u, this->mock->setTilingStride); + EXPECT_EQ(0u, this->mock->setTilingHandle); + + EXPECT_EQ(Sharing::nonSharedResource, imageGraphicsAllocation->peekSharedHandle()); + + alignedFree(data); +} + +TEST_F(ClDrmMemoryManagerTest, givenHostPointerNotRequiringCopyWhenAllocateGraphicsMemoryForImageIsCalledThenGraphicsAllocationIsReturned) { + mock->ioctl_expected.gemUserptr = 1; + mock->ioctl_expected.gemWait = 1; + mock->ioctl_expected.gemClose = 1; + + ImageDescriptor imgDesc = {}; + imgDesc.imageType = ImageType::Image1D; + imgDesc.imageWidth = MemoryConstants::pageSize; + imgDesc.imageHeight = 1; + + cl_image_format imageFormat = {}; + imageFormat.image_channel_data_type = CL_UNSIGNED_INT8; + imageFormat.image_channel_order = CL_R; + + cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR; + MockContext context(pClDevice); + auto surfaceFormat = &Image::getSurfaceFormatFromTable(flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features)->surfaceFormat; + + auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, surfaceFormat); + imgInfo.rowPitch = imgDesc.imageWidth * surfaceFormat->ImageElementSizeInBytes; + imgInfo.slicePitch = imgInfo.rowPitch * imgDesc.imageHeight; + imgInfo.size = imgInfo.slicePitch; + imgInfo.linearStorage = true; + + auto hostPtr = alignedMalloc(imgDesc.imageWidth * imgDesc.imageHeight * 4, MemoryConstants::pageSize); + bool copyRequired = MockMemoryManager::isCopyRequired(imgInfo, hostPtr); + EXPECT_FALSE(copyRequired); + + AllocationData allocationData; + allocationData.imgInfo = &imgInfo; + allocationData.hostPtr = hostPtr; + allocationData.rootDeviceIndex = rootDeviceIndex; + + auto imageAllocation = memoryManager->allocateGraphicsMemoryForImage(allocationData); + ASSERT_NE(nullptr, imageAllocation); + EXPECT_EQ(hostPtr, imageAllocation->getUnderlyingBuffer()); + + memoryManager->freeGraphicsMemory(imageAllocation); + alignedFree(hostPtr); +} + +TEST_F(ClDrmMemoryManagerTest, givenOsHandleWithNonTiledObjectWhenCreateFromSharedHandleIsCalledThenNonTiledGmmIsCreatedAndSetInAllocation) { + mock->ioctl_expected.primeFdToHandle = 1; + mock->ioctl_expected.gemWait = 1; + mock->ioctl_expected.gemClose = 1; + mock->ioctl_expected.gemGetTiling = 1; + mock->getTilingModeOut = I915_TILING_NONE; + + osHandle handle = 1u; + uint32_t boHandle = 2u; + mock->outputHandle = boHandle; + + cl_mem_flags flags = CL_MEM_READ_ONLY; + cl_image_desc imgDesc = {}; + cl_image_format gmmImgFormat = {CL_NV12_INTEL, CL_UNORM_INT8}; + const ClSurfaceFormatInfo *gmmSurfaceFormat = nullptr; + ImageInfo imgInfo = {}; + + imgDesc.image_width = 4; + imgDesc.image_height = 4; + imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D; + + imgInfo.imgDesc = Image::convertDescriptor(imgDesc); + MockContext context(pClDevice); + gmmSurfaceFormat = Image::getSurfaceFormatFromTable(flags, &gmmImgFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); + imgInfo.surfaceFormat = &gmmSurfaceFormat->surfaceFormat; + imgInfo.plane = GMM_PLANE_Y; + + AllocationProperties properties(rootDeviceIndex, false, imgInfo, AllocationType::SHARED_IMAGE, context.getDevice(0)->getDeviceBitfield()); + + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false); + ASSERT_NE(nullptr, graphicsAllocation); + EXPECT_EQ(boHandle, mock->getTilingHandleIn); + EXPECT_EQ(AllocationType::SHARED_IMAGE, graphicsAllocation->getAllocationType()); + + auto gmm = graphicsAllocation->getDefaultGmm(); + ASSERT_NE(nullptr, gmm); + EXPECT_EQ(1u, gmm->resourceParams.Flags.Info.Linear); + EXPECT_EQ(0u, gmm->resourceParams.Flags.Info.TiledY); + + memoryManager->freeGraphicsMemory(graphicsAllocation); +} + +TEST_F(ClDrmMemoryManagerTest, givenOsHandleWithTileYObjectWhenCreateFromSharedHandleIsCalledThenTileYGmmIsCreatedAndSetInAllocation) { + mock->ioctl_expected.primeFdToHandle = 1; + mock->ioctl_expected.gemWait = 1; + mock->ioctl_expected.gemClose = 1; + mock->ioctl_expected.gemGetTiling = 1; + mock->getTilingModeOut = I915_TILING_Y; + + osHandle handle = 1u; + uint32_t boHandle = 2u; + mock->outputHandle = boHandle; + + cl_mem_flags flags = CL_MEM_READ_ONLY; + cl_image_desc imgDesc = {}; + cl_image_format gmmImgFormat = {CL_NV12_INTEL, CL_UNORM_INT8}; + const ClSurfaceFormatInfo *gmmSurfaceFormat = nullptr; + ImageInfo imgInfo = {}; + + imgDesc.image_width = 4; + imgDesc.image_height = 4; + imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D; + + imgInfo.imgDesc = Image::convertDescriptor(imgDesc); + MockContext context(pClDevice); + gmmSurfaceFormat = Image::getSurfaceFormatFromTable(flags, &gmmImgFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); + imgInfo.surfaceFormat = &gmmSurfaceFormat->surfaceFormat; + imgInfo.plane = GMM_PLANE_Y; + + AllocationProperties properties(rootDeviceIndex, false, imgInfo, AllocationType::SHARED_IMAGE, context.getDevice(0)->getDeviceBitfield()); + + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false); + ASSERT_NE(nullptr, graphicsAllocation); + EXPECT_EQ(boHandle, mock->getTilingHandleIn); + EXPECT_EQ(AllocationType::SHARED_IMAGE, graphicsAllocation->getAllocationType()); + + auto gmm = graphicsAllocation->getDefaultGmm(); + ASSERT_NE(nullptr, gmm); + EXPECT_EQ(0u, gmm->resourceParams.Flags.Info.Linear); + + memoryManager->freeGraphicsMemory(graphicsAllocation); +} + +TEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhenCreateFromSharedHandleFailsToCallGetTilingThenNonLinearStorageIsAssumed) { + mock->ioctl_expected.primeFdToHandle = 1; + mock->ioctl_expected.gemGetTiling = 1; + mock->ioctl_expected.gemWait = 1; + mock->ioctl_expected.gemClose = 1; + this->ioctlResExt = {mock->ioctl_cnt.total + 1, -1}; + mock->ioctl_res_ext = &ioctlResExt; + + osHandle handle = 1u; + uint32_t boHandle = 2u; + mock->outputHandle = boHandle; + + cl_mem_flags flags = CL_MEM_READ_ONLY; + cl_image_desc imgDesc = {}; + cl_image_format gmmImgFormat = {CL_NV12_INTEL, CL_UNORM_INT8}; + const ClSurfaceFormatInfo *gmmSurfaceFormat = nullptr; + ImageInfo imgInfo = {}; + + imgDesc.image_width = 4; + imgDesc.image_height = 4; + imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D; + + imgInfo.imgDesc = Image::convertDescriptor(imgDesc); + MockContext context(pClDevice); + gmmSurfaceFormat = Image::getSurfaceFormatFromTable(flags, &gmmImgFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); + imgInfo.surfaceFormat = &gmmSurfaceFormat->surfaceFormat; + imgInfo.plane = GMM_PLANE_Y; + + AllocationProperties properties(rootDeviceIndex, false, imgInfo, AllocationType::SHARED_IMAGE, context.getDevice(0)->getDeviceBitfield()); + + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false); + ASSERT_NE(nullptr, graphicsAllocation); + EXPECT_EQ(boHandle, mock->getTilingHandleIn); + EXPECT_EQ(AllocationType::SHARED_IMAGE, graphicsAllocation->getAllocationType()); + + auto gmm = graphicsAllocation->getDefaultGmm(); + ASSERT_NE(nullptr, gmm); + EXPECT_EQ(0u, gmm->resourceParams.Flags.Info.Linear); + + memoryManager->freeGraphicsMemory(graphicsAllocation); +} + +TEST(DrmMemoryMangerTest, givenMultipleRootDeviceWhenMemoryManagerGetsDrmThenDrmIsFromCorrectRootDevice) { + DebugManagerStateRestore restorer; + DebugManager.flags.CreateMultipleRootDevices.set(4); + VariableBackup backup{&ultHwConfig}; + ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false; + initPlatform(); + + TestedDrmMemoryManager drmMemoryManager(*platform()->peekExecutionEnvironment()); + for (auto i = 0u; i < platform()->peekExecutionEnvironment()->rootDeviceEnvironments.size(); i++) { + auto drmFromRootDevice = platform()->peekExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface->getDriverModel()->as(); + EXPECT_EQ(drmFromRootDevice, &drmMemoryManager.getDrm(i)); + EXPECT_EQ(i, drmMemoryManager.getRootDeviceIndex(drmFromRootDevice)); + } + EXPECT_EQ(CommonConstants::unspecifiedDeviceIndex, drmMemoryManager.getRootDeviceIndex(nullptr)); +} diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests_impl.h b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests_impl.h deleted file mode 100644 index b85732601c..0000000000 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests_impl.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2020-2022 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#pragma once -#include "shared/test/common/helpers/ult_hw_config.h" -#include "shared/test/common/helpers/variable_backup.h" -#include "shared/test/common/os_interface/linux/drm_memory_manager_tests.h" - -namespace NEO { - -class DrmMemoryManagerFixtureImpl : public DrmMemoryManagerFixture { - public: - DrmMockCustom *mockExp; - - void SetUp() override { - backup = std::make_unique>(&ultHwConfig); - ultHwConfig.csrBaseCallCreatePreemption = false; - - MemoryManagementFixture::SetUp(); - executionEnvironment = MockDevice::prepareExecutionEnvironment(defaultHwInfo.get(), numRootDevices - 1); - mockExp = new DrmMockCustom(*executionEnvironment->rootDeviceEnvironments[0]); - DrmMemoryManagerFixture::SetUp(mockExp, true); - } - - void TearDown() override { - mockExp->testIoctls(); - DrmMemoryManagerFixture::TearDown(); - } - std::unique_ptr> backup; -}; -} // namespace NEO diff --git a/opencl/test/unit_test/xe_hpc_core/excludes_ocl_xe_hpc_core.cpp b/opencl/test/unit_test/xe_hpc_core/excludes_ocl_xe_hpc_core.cpp index 74e51c0bfb..52c8732e98 100644 --- a/opencl/test/unit_test/xe_hpc_core/excludes_ocl_xe_hpc_core.cpp +++ b/opencl/test/unit_test/xe_hpc_core/excludes_ocl_xe_hpc_core.cpp @@ -16,8 +16,6 @@ HWTEST_EXCLUDE_PRODUCT(PipeControlHelperTests, givenHwHelperwhenAskingForDcFlush HWTEST_EXCLUDE_PRODUCT(EnqueueCopyBufferToImageStatelessTest, givenBigBufferWhenCopyingBufferToImageStatelessThenSuccessIsReturned, IGFX_XE_HPC_CORE); HWTEST_EXCLUDE_PRODUCT(EnqueueCopyImageToBufferHwStatelessTest, givenBigBufferWhenCopyingImageToBufferStatelessThenSuccessIsReturned, IGFX_XE_HPC_CORE); HWTEST_EXCLUDE_PRODUCT(BuiltInTests, givenBigOffsetAndSizeWhenBuilderCopyImageToBufferStatelessIsUsedThenParamsAreCorrect, IGFX_XE_HPC_CORE); -HWTEST_EXCLUDE_PRODUCT(DrmMemoryManagerTest, givenDrmAllocationWithHostPtrWhenItIsCreatedWithIncorrectCacheRegionThenReturnNull, IGFX_XE_HPC_CORE); -HWTEST_EXCLUDE_PRODUCT(DrmMemoryManagerTest, givenDrmAllocationWithWithAlignmentFromUserptrWhenItIsCreatedWithIncorrectCacheRegionThenReturnNull, IGFX_XE_HPC_CORE); HWTEST_EXCLUDE_PRODUCT(ClDeviceHelperTests, givenDeviceWithoutClosBasedCacheReservationSupportWhenQueryingNumCacheClosDeviceInfoThenReturnZeroCacheClosRegions, IGFX_XE_HPC_CORE); HWTEST_EXCLUDE_PRODUCT(HwHelperTest, whenGettingNumberOfCacheRegionsThenReturnZero, IGFX_XE_HPC_CORE); HWTEST_EXCLUDE_PRODUCT(LocalWorkSizeTest, givenDispatchInfoWhenWorkSizeInfoIsCreatedThenTestEuFusionFtr, IGFX_XE_HPC_CORE); diff --git a/shared/test/unit_test/os_interface/linux/CMakeLists.txt b/shared/test/unit_test/os_interface/linux/CMakeLists.txt index 2d23b03731..c4cb2e07af 100644 --- a/shared/test/unit_test/os_interface/linux/CMakeLists.txt +++ b/shared/test/unit_test/os_interface/linux/CMakeLists.txt @@ -18,6 +18,7 @@ set(NEO_CORE_OS_INTERFACE_TESTS_LINUX ${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_engine_info_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_mapper_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_mock_impl.h ${CMAKE_CURRENT_SOURCE_DIR}/drm_os_memory_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_pci_speed_info_tests.cpp @@ -79,6 +80,7 @@ if("${BRANCH_TYPE}" STREQUAL "") ${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_info_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_query_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ioctl_helper_tests_upstream.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager_localmem_upstream_tests.cpp ) endif() diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_localmem_upstream_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_upstream_tests.cpp similarity index 98% rename from opencl/test/unit_test/os_interface/linux/drm_memory_manager_localmem_upstream_tests.cpp rename to shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_upstream_tests.cpp index 98ce020c14..d818f8cfb2 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_localmem_upstream_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_upstream_tests.cpp @@ -13,21 +13,41 @@ #include "shared/source/os_interface/linux/drm_memory_operations_handler.h" #include "shared/source/os_interface/os_interface.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/helpers/ult_hw_config.h" +#include "shared/test/common/helpers/variable_backup.h" #include "shared/test/common/mocks/linux/mock_drm_memory_manager.h" #include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/mocks/mock_gmm.h" +#include "shared/test/common/os_interface/linux/drm_memory_manager_tests.h" #include "shared/test/common/os_interface/linux/drm_mock_memory_info.h" #include "shared/test/common/test_macros/test.h" #include "shared/test/unit_test/os_interface/linux/drm_mock_impl.h" -#include "opencl/test/unit_test/mocks/mock_context.h" -#include "opencl/test/unit_test/mocks/mock_platform.h" -#include "opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests_impl.h" - #include "gtest/gtest.h" namespace NEO { +class DrmMemoryManagerFixtureImpl : public DrmMemoryManagerFixture { + public: + DrmMockCustom *mockExp; + + void SetUp() override { + backup = std::make_unique>(&ultHwConfig); + ultHwConfig.csrBaseCallCreatePreemption = false; + + MemoryManagementFixture::SetUp(); + executionEnvironment = MockDevice::prepareExecutionEnvironment(defaultHwInfo.get(), numRootDevices - 1); + mockExp = new DrmMockCustom(*executionEnvironment->rootDeviceEnvironments[0]); + DrmMemoryManagerFixture::SetUp(mockExp, true); + } + + void TearDown() override { + mockExp->testIoctls(); + DrmMemoryManagerFixture::TearDown(); + } + std::unique_ptr> backup; +}; + BufferObject *createBufferObjectInMemoryRegion(Drm *drm, Gmm *gmm, AllocationType allocationType, uint64_t gpuAddress, size_t size, uint32_t memoryBanks, size_t maxOsContextCount); class DrmMemoryManagerLocalMemoryTest : public ::testing::Test { @@ -1040,22 +1060,4 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenAllocationWithUnifiedMemoryAllocati EXPECT_EQ(MemoryManager::AllocationStatus::Error, status); memoryManager->freeGraphicsMemory(allocation); } - -TEST(ResidencyTests, whenBuffersIsCreatedWithMakeResidentFlagThenItSuccessfulyCreates) { - VariableBackup backup(&ultHwConfig); - ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false; - ultHwConfig.forceOsAgnosticMemoryManager = false; - DebugManagerStateRestore restorer; - DebugManager.flags.MakeAllBuffersResident.set(true); - - initPlatform(); - auto device = platform()->getClDevice(0u); - - MockContext context(device, false); - auto retValue = CL_SUCCESS; - auto clBuffer = clCreateBuffer(&context, 0u, 4096u, nullptr, &retValue); - ASSERT_EQ(retValue, CL_SUCCESS); - clReleaseMemObject(clBuffer); -} - } // namespace NEO diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp similarity index 86% rename from opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp rename to shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp index f4fff615ae..cd8ae20cc4 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2022 Intel Corporation + * Copyright (C) 2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,30 +7,10 @@ #include "shared/test/common/os_interface/linux/drm_memory_manager_tests.h" -#include "shared/source/built_ins/sip.h" -#include "shared/source/command_stream/device_command_stream.h" -#include "shared/source/command_stream/linear_stream.h" -#include "shared/source/command_stream/preemption.h" -#include "shared/source/gmm_helper/gmm_helper.h" -#include "shared/source/helpers/aligned_memory.h" -#include "shared/source/helpers/constants.h" -#include "shared/source/helpers/ptr_math.h" -#include "shared/source/helpers/timestamp_packet.h" -#include "shared/source/memory_manager/host_ptr_manager.h" -#include "shared/source/memory_manager/residency.h" -#include "shared/source/os_interface/linux/allocator_helper.h" -#include "shared/source/os_interface/linux/drm_allocation.h" -#include "shared/source/os_interface/linux/drm_buffer_object.h" -#include "shared/source/os_interface/linux/drm_command_stream.h" -#include "shared/source/os_interface/linux/drm_memory_manager.h" +#include "shared/source/helpers/surface_format_info.h" #include "shared/source/os_interface/linux/os_context_linux.h" -#include "shared/source/os_interface/os_context.h" -#include "shared/source/utilities/tag_allocator.h" #include "shared/test/common/fixtures/memory_allocator_multi_device_fixture.h" -#include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/helpers/engine_descriptor_helper.h" -#include "shared/test/common/helpers/ult_hw_config.h" -#include "shared/test/common/helpers/unit_test_helper.h" #include "shared/test/common/libult/linux/drm_mock.h" #include "shared/test/common/mocks/linux/mock_drm_allocation.h" #include "shared/test/common/mocks/mock_allocation_properties.h" @@ -40,22 +20,27 @@ #include "shared/test/common/test_macros/test.h" #include "shared/test/unit_test/helpers/gtest_helpers.h" -#include "opencl/source/event/event.h" -#include "opencl/source/helpers/cl_memory_properties_helpers.h" -#include "opencl/source/mem_obj/buffer.h" -#include "opencl/source/mem_obj/image.h" -#include "opencl/test/unit_test/mocks/mock_cl_device.h" -#include "opencl/test/unit_test/mocks/mock_context.h" -#include "opencl/test/unit_test/mocks/mock_platform.h" - #include "gtest/gtest.h" -#include +#include #include +#include -namespace NEO { - +namespace { using MemoryManagerMultiDeviceSharedHandleTest = MemoryAllocatorMultiDeviceFixture<2>; +using DrmMemoryManagerTest = Test; +using DrmMemoryManagerWithLocalMemoryTest = Test; +using DrmMemoryManagerWithExplicitExpectationsTest = Test; +using DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest = Test; +using DrmMemoryManagerUSMHostAllocationTests = Test; + +AllocationProperties createAllocationProperties(uint32_t rootDeviceIndex, size_t size, bool forcePin) { + MockAllocationProperties properties(rootDeviceIndex, size); + properties.alignment = MemoryConstants::preferredAlignment; + properties.flags.forcePin = forcePin; + return properties; +} +} // namespace TEST_P(MemoryManagerMultiDeviceSharedHandleTest, whenCreatingAllocationFromSharedHandleWithSameHandleAndSameRootDeviceThenSameBOIsUsed) { uint32_t handle0 = 0; @@ -153,18 +138,6 @@ TEST_P(MemoryManagerMultiDeviceSharedHandleTest, whenCreatingAllocationFromShare memoryManager->freeGraphicsMemory(gfxAllocation1); } -AllocationProperties createAllocationProperties(uint32_t rootDeviceIndex, size_t size, bool forcePin) { - MockAllocationProperties properties(rootDeviceIndex, size); - properties.alignment = MemoryConstants::preferredAlignment; - properties.flags.forcePin = forcePin; - return properties; -} - -typedef Test DrmMemoryManagerTest; -typedef Test DrmMemoryManagerWithLocalMemoryTest; -typedef Test DrmMemoryManagerWithExplicitExpectationsTest; -typedef Test DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest; - TEST_F(DrmMemoryManagerTest, givenEnableDirectSubmissionWhenCreateDrmMemoryManagerThenGemCloseWorkerInactive) { DebugManagerStateRestore dbgState; DebugManager.flags.EnableDirectSubmission.set(1); @@ -1334,162 +1307,6 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedFor32BitAllocationWhenLi memoryManager->freeGraphicsMemory(allocation); } -struct ClDrmMemoryManagerTest : public DrmMemoryManagerTest { - void SetUp() override { - MemoryManagementFixture::SetUp(); - - executionEnvironment = MockClDevice::prepareExecutionEnvironment(defaultHwInfo.get(), numRootDevices - 1); - DrmMemoryManagerFixture::SetUp(new DrmMockCustom(*executionEnvironment->rootDeviceEnvironments[0]), false); - pClDevice = new MockClDevice{device}; // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks) - device->incRefInternal(); - } - void TearDown() override { - delete pClDevice; - DrmMemoryManagerTest::TearDown(); - } - - MockClDevice *pClDevice = nullptr; -}; - -TEST_F(ClDrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferAllocationThen32BitBufferIsReturned) { - DebugManagerStateRestore dbgRestorer; - mock->ioctl_expected.gemUserptr = 1; - mock->ioctl_expected.gemWait = 1; - mock->ioctl_expected.gemClose = 1; - - DebugManager.flags.Force32bitAddressing.set(true); - MockContext context(pClDevice); - memoryManager->setForce32BitAllocations(true); - - auto size = MemoryConstants::pageSize; - auto retVal = CL_SUCCESS; - - auto buffer = Buffer::create( - &context, - CL_MEM_ALLOC_HOST_PTR, - size, - nullptr, - retVal); - EXPECT_EQ(CL_SUCCESS, retVal); - - EXPECT_TRUE(buffer->isMemObjZeroCopy()); - auto bufferAddress = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuAddress(); - auto baseAddress = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuBaseAddress(); - - EXPECT_LT(ptrDiff(bufferAddress, baseAddress), MemoryConstants::max32BitAddress); - - delete buffer; -} - -TEST_F(ClDrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferCreatedFromHostPtrThen32BitBufferIsReturned) { - DebugManagerStateRestore dbgRestorer; - mock->ioctl_expected.gemUserptr = 1; - mock->ioctl_expected.gemWait = 1; - mock->ioctl_expected.gemClose = 1; - - DebugManager.flags.Force32bitAddressing.set(true); - MockContext context(pClDevice); - memoryManager->setForce32BitAllocations(true); - - auto size = MemoryConstants::pageSize; - void *ptr = reinterpret_cast(0x1000); - auto ptrOffset = MemoryConstants::cacheLineSize; - uintptr_t offsetedPtr = (uintptr_t)ptr + ptrOffset; - auto retVal = CL_SUCCESS; - - auto buffer = Buffer::create( - &context, - CL_MEM_USE_HOST_PTR, - size, - reinterpret_cast(offsetedPtr), - retVal); - EXPECT_EQ(CL_SUCCESS, retVal); - - EXPECT_TRUE(buffer->isMemObjZeroCopy()); - auto bufferAddress = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuAddress(); - auto drmAllocation = static_cast(buffer->getGraphicsAllocation(rootDeviceIndex)); - - auto baseAddress = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuBaseAddress(); - EXPECT_LT(ptrDiff(bufferAddress, baseAddress), MemoryConstants::max32BitAddress); - - EXPECT_TRUE(drmAllocation->is32BitAllocation()); - - auto allocationCpuPtr = drmAllocation->getUnderlyingBuffer(); - auto allocationPageOffset = ptrDiff(allocationCpuPtr, alignDown(allocationCpuPtr, MemoryConstants::pageSize)); - - auto allocationGpuPtr = drmAllocation->getGpuAddress(); - auto allocationGpuOffset = ptrDiff(allocationGpuPtr, alignDown(allocationGpuPtr, MemoryConstants::pageSize)); - - auto bufferObject = drmAllocation->getBO(); - - EXPECT_EQ(drmAllocation->getUnderlyingBuffer(), reinterpret_cast(offsetedPtr)); - - // Gpu address should be different - EXPECT_NE(offsetedPtr, drmAllocation->getGpuAddress()); - // Gpu address offset iqual to cpu offset - EXPECT_EQ(allocationGpuOffset, ptrOffset); - - EXPECT_EQ(allocationPageOffset, ptrOffset); - - auto boAddress = bufferObject->peekAddress(); - EXPECT_EQ(alignDown(boAddress, MemoryConstants::pageSize), boAddress); - - delete buffer; -} - -TEST_F(ClDrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferCreatedFrom64BitHostPtrThen32BitBufferIsReturned) { - DebugManagerStateRestore dbgRestorer; - { - if (is32bit) { - mock->ioctl_expected.total = -1; - } else { - mock->ioctl_expected.gemUserptr = 1; - mock->ioctl_expected.gemWait = 1; - mock->ioctl_expected.gemClose = 1; - - DebugManager.flags.Force32bitAddressing.set(true); - MockContext context(pClDevice); - memoryManager->setForce32BitAllocations(true); - - auto size = MemoryConstants::pageSize; - void *ptr = reinterpret_cast(0x100000000000); - auto ptrOffset = MemoryConstants::cacheLineSize; - uintptr_t offsetedPtr = (uintptr_t)ptr + ptrOffset; - auto retVal = CL_SUCCESS; - - auto buffer = Buffer::create( - &context, - CL_MEM_USE_HOST_PTR, - size, - reinterpret_cast(offsetedPtr), - retVal); - EXPECT_EQ(CL_SUCCESS, retVal); - - EXPECT_TRUE(buffer->isMemObjZeroCopy()); - auto bufferAddress = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuAddress(); - - auto baseAddress = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuBaseAddress(); - EXPECT_LT(ptrDiff(bufferAddress, baseAddress), MemoryConstants::max32BitAddress); - - auto drmAllocation = static_cast(buffer->getGraphicsAllocation(rootDeviceIndex)); - - EXPECT_TRUE(drmAllocation->is32BitAllocation()); - - auto allocationCpuPtr = drmAllocation->getUnderlyingBuffer(); - auto allocationPageOffset = ptrDiff(allocationCpuPtr, alignDown(allocationCpuPtr, MemoryConstants::pageSize)); - auto bufferObject = drmAllocation->getBO(); - - EXPECT_EQ(allocationPageOffset, ptrOffset); - - auto boAddress = bufferObject->peekAddress(); - EXPECT_EQ(alignDown(boAddress, MemoryConstants::pageSize), boAddress); - - delete buffer; - DebugManager.flags.Force32bitAddressing.set(false); - } - } -} - TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenLimitedRangeAllocatorSetThenHeapSizeAndEndAddrCorrectlySetForGivenGpuRange) { memoryManager->forceLimitedRangeAllocator(0xFFFFFFFFF); @@ -1564,113 +1381,6 @@ TEST_F(DrmMemoryManagerTest, givenLimitedRangeAllocatorWhenAskedForInternal32Bit mock->ioctl_res_ext = &mock->NONE; } -TEST_F(ClDrmMemoryManagerTest, GivenSizeAbove2GBWhenUseHostPtrAndAllocHostPtrAreCreatedThenFirstSucceedsAndSecondFails) { - DebugManagerStateRestore dbgRestorer; - mock->ioctl_expected.total = -1; - DebugManager.flags.Force32bitAddressing.set(true); - MockContext context(pClDevice); - memoryManager->setForce32BitAllocations(true); - - size_t size = 2 * GB; - void *ptr = reinterpret_cast(0x100000000000); - auto retVal = CL_SUCCESS; - - auto buffer = Buffer::create( - &context, - CL_MEM_USE_HOST_PTR, - size, - ptr, - retVal); - - size_t size2 = 4 * GB - MemoryConstants::pageSize; // Keep size aligned - - auto buffer2 = Buffer::create( - &context, - CL_MEM_ALLOC_HOST_PTR, - size2, - nullptr, - retVal); - - EXPECT_NE(retVal, CL_SUCCESS); - EXPECT_EQ(nullptr, buffer2); - - if (buffer) { - auto bufferPtr = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuAddress(); - - EXPECT_TRUE(buffer->getGraphicsAllocation(rootDeviceIndex)->is32BitAllocation()); - auto baseAddress = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuBaseAddress(); - EXPECT_LT(ptrDiff(bufferPtr, baseAddress), MemoryConstants::max32BitAddress); - } - - delete buffer; -} - -TEST_F(ClDrmMemoryManagerTest, GivenSizeAbove2GBWhenAllocHostPtrAndUseHostPtrAreCreatedThenFirstSucceedsAndSecondFails) { - DebugManagerStateRestore dbgRestorer; - mock->ioctl_expected.total = -1; - DebugManager.flags.Force32bitAddressing.set(true); - MockContext context(pClDevice); - memoryManager->setForce32BitAllocations(true); - - size_t size = 2 * GB; - void *ptr = reinterpret_cast(0x100000000000); - auto retVal = CL_SUCCESS; - - auto buffer = Buffer::create( - &context, - CL_MEM_ALLOC_HOST_PTR, - size, - nullptr, - retVal); - - size_t size2 = 4 * GB - MemoryConstants::pageSize; // Keep size aligned - - auto buffer2 = Buffer::create( - &context, - CL_MEM_USE_HOST_PTR, - size2, - ptr, - retVal); - - EXPECT_NE(retVal, CL_SUCCESS); - EXPECT_EQ(nullptr, buffer2); - - if (buffer) { - auto bufferPtr = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuAddress(); - - EXPECT_TRUE(buffer->getGraphicsAllocation(rootDeviceIndex)->is32BitAllocation()); - auto baseAddress = buffer->getGraphicsAllocation(rootDeviceIndex)->getGpuBaseAddress(); - EXPECT_LT(ptrDiff(bufferPtr, baseAddress), MemoryConstants::max32BitAddress); - } - - delete buffer; -} - -TEST_F(ClDrmMemoryManagerTest, givenDrmBufferWhenItIsQueriedForInternalAllocationThenBoIsReturned) { - mock->ioctl_expected.total = -1; - mock->outputFd = 1337; - MockContext context(pClDevice); - - size_t size = 1u; - auto retVal = CL_SUCCESS; - - auto buffer = Buffer::create( - &context, - CL_MEM_ALLOC_HOST_PTR, - size, - nullptr, - retVal); - - uint64_t handle = 0llu; - - retVal = clGetMemObjectInfo(buffer, CL_MEM_ALLOCATION_HANDLE_INTEL, sizeof(handle), &handle, nullptr); - EXPECT_EQ(retVal, CL_SUCCESS); - - EXPECT_EQ(static_cast(1337), handle); - - clReleaseMemObject(buffer); -} - TEST_F(DrmMemoryManagerTest, GivenExhaustedInternalHeapWhenAllocate32BitIsCalledThenNullIsReturned) { DebugManagerStateRestore dbgStateRestore; DebugManager.flags.Force32bitAddressing.set(true); @@ -1733,429 +1443,6 @@ TEST_F(DrmMemoryManagerTest, GivenMemoryManagerWhenAllocateGraphicsMemoryForImag memoryManager->freeGraphicsMemory(imageGraphicsAllocation); } -HWTEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageWithMipCountZeroIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) { - if (!UnitTestHelper::tiledImagesSupported) { - GTEST_SKIP(); - } - mock->ioctl_expected.gemCreate = 1; - mock->ioctl_expected.gemSetTiling = 1; - mock->ioctl_expected.gemWait = 1; - mock->ioctl_expected.gemClose = 1; - - MockContext context(pClDevice); - - cl_image_format imageFormat; - imageFormat.image_channel_data_type = CL_UNORM_INT8; - imageFormat.image_channel_order = CL_R; - - cl_image_desc imageDesc = {}; - - imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D; - imageDesc.image_width = 64u; - imageDesc.image_height = 64u; - - auto retVal = CL_SUCCESS; - - cl_mem_flags flags = CL_MEM_WRITE_ONLY; - auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); - std::unique_ptr dstImage(Image::create( - &context, ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()), - flags, 0, surfaceFormat, &imageDesc, nullptr, retVal)); - EXPECT_EQ(CL_SUCCESS, retVal); - ASSERT_NE(nullptr, dstImage); - auto imageGraphicsAllocation = dstImage->getGraphicsAllocation(rootDeviceIndex); - ASSERT_NE(nullptr, imageGraphicsAllocation); - EXPECT_TRUE(imageGraphicsAllocation->getDefaultGmm()->resourceParams.Usage == - GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_IMAGE); - - DrmAllocation *drmAllocation = static_cast(imageGraphicsAllocation); - auto imageSize = drmAllocation->getUnderlyingBufferSize(); - auto rowPitch = dstImage->getImageDesc().image_row_pitch; - - EXPECT_EQ(1u, this->mock->createParamsHandle); - EXPECT_EQ(imageSize, this->mock->createParamsSize); - __u32 tilingMode = I915_TILING_Y; - EXPECT_EQ(tilingMode, this->mock->setTilingMode); - EXPECT_EQ(rowPitch, this->mock->setTilingStride); - EXPECT_EQ(1u, this->mock->setTilingHandle); -} - -HWTEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageWithMipCountNonZeroIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) { - if (!UnitTestHelper::tiledImagesSupported) { - GTEST_SKIP(); - } - mock->ioctl_expected.gemCreate = 1; - mock->ioctl_expected.gemSetTiling = 1; - mock->ioctl_expected.gemWait = 1; - mock->ioctl_expected.gemClose = 1; - - MockContext context(pClDevice); - - cl_image_format imageFormat; - imageFormat.image_channel_data_type = CL_UNORM_INT8; - imageFormat.image_channel_order = CL_R; - - cl_image_desc imageDesc = {}; - - imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D; - imageDesc.image_width = 64u; - imageDesc.image_height = 64u; - imageDesc.num_mip_levels = 1u; - - auto retVal = CL_SUCCESS; - - cl_mem_flags flags = CL_MEM_WRITE_ONLY; - auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); - std::unique_ptr dstImage(Image::create( - &context, ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()), - flags, 0, surfaceFormat, &imageDesc, nullptr, retVal)); - EXPECT_EQ(CL_SUCCESS, retVal); - ASSERT_NE(nullptr, dstImage); - EXPECT_EQ(static_cast(imageDesc.num_mip_levels), dstImage->peekMipCount()); - auto imageGraphicsAllocation = dstImage->getGraphicsAllocation(rootDeviceIndex); - ASSERT_NE(nullptr, imageGraphicsAllocation); - EXPECT_TRUE(imageGraphicsAllocation->getDefaultGmm()->resourceParams.Usage == - GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_IMAGE); - - DrmAllocation *drmAllocation = static_cast(imageGraphicsAllocation); - auto imageSize = drmAllocation->getUnderlyingBufferSize(); - auto rowPitch = dstImage->getImageDesc().image_row_pitch; - - EXPECT_EQ(1u, this->mock->createParamsHandle); - EXPECT_EQ(imageSize, this->mock->createParamsSize); - __u32 tilingMode = I915_TILING_Y; - EXPECT_EQ(tilingMode, this->mock->setTilingMode); - EXPECT_EQ(rowPitch, this->mock->setTilingStride); - EXPECT_EQ(1u, this->mock->setTilingHandle); -} - -TEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageIsBeingCreatedAndAllocationFailsThenReturnNullptr) { - MockContext context(pClDevice); - - cl_image_format imageFormat; - imageFormat.image_channel_data_type = CL_UNORM_INT8; - imageFormat.image_channel_order = CL_R; - - cl_image_desc imageDesc = {}; - - imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D; - imageDesc.image_width = 64u; - imageDesc.image_height = 64u; - - auto retVal = CL_SUCCESS; - - InjectedFunction method = [&](size_t failureIndex) { - cl_mem_flags flags = CL_MEM_WRITE_ONLY; - auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); - std::unique_ptr dstImage(Image::create( - &context, ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()), - flags, 0, surfaceFormat, &imageDesc, nullptr, retVal)); - if (MemoryManagement::nonfailingAllocation == failureIndex) { - EXPECT_NE(nullptr, dstImage.get()); - } else { - EXPECT_EQ(nullptr, dstImage.get()); - } - }; - - injectFailures(method); - mock->reset(); -} - -HWTEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageIsBeingCreatedFromHostPtrThenAllocateGraphicsMemoryForImageIsUsed) { - if (!UnitTestHelper::tiledImagesSupported) { - GTEST_SKIP(); - } - - device->setPreemptionMode(PreemptionMode::Disabled); - - auto csr = static_cast *>(device->getDefaultEngine().commandStreamReceiver); - csr->callHwFlush = false; - - mock->ioctl_expected.gemCreate = 1; - mock->ioctl_expected.gemSetTiling = 1; - mock->ioctl_expected.gemWait = 2; - mock->ioctl_expected.gemClose = 2; - mock->ioctl_expected.gemUserptr = 1; - mock->ioctl_expected.execbuffer2 = 0; - - // builtins kernels - mock->ioctl_expected.gemUserptr += 5; - - // command buffers - mock->ioctl_expected.gemUserptr += 2; - additionalDestroyDeviceIoctls.gemClose += 2; - additionalDestroyDeviceIoctls.gemWait += 2; - - // indirect heaps - mock->ioctl_expected.gemUserptr += 3; - additionalDestroyDeviceIoctls.gemClose += 3; - additionalDestroyDeviceIoctls.gemWait += 3; - - if (device->getDefaultEngine().commandStreamReceiver->peekTimestampPacketWriteEnabled()) { - mock->ioctl_expected.gemUserptr++; - additionalDestroyDeviceIoctls.gemClose++; - additionalDestroyDeviceIoctls.gemWait++; - } - - if (device->getDefaultEngine().commandStreamReceiver->getClearColorAllocation() != nullptr) { - mock->ioctl_expected.gemUserptr++; - additionalDestroyDeviceIoctls.gemClose++; - additionalDestroyDeviceIoctls.gemWait++; - } - - MockContext context(pClDevice); - - cl_image_format imageFormat; - imageFormat.image_channel_data_type = CL_UNORM_INT8; - imageFormat.image_channel_order = CL_R; - - cl_image_desc imageDesc = {}; - - imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D; - imageDesc.image_width = 64u; - imageDesc.image_height = 64u; - - auto data = alignedMalloc(64u * 64u * 4 * 8, MemoryConstants::pageSize); - - auto retVal = CL_SUCCESS; - - cl_mem_flags flags = CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR; - auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); - std::unique_ptr dstImage(Image::create( - &context, ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()), - flags, 0, surfaceFormat, &imageDesc, data, retVal)); - EXPECT_EQ(CL_SUCCESS, retVal); - ASSERT_NE(nullptr, dstImage); - auto imageGraphicsAllocation = dstImage->getGraphicsAllocation(rootDeviceIndex); - ASSERT_NE(nullptr, imageGraphicsAllocation); - EXPECT_TRUE(imageGraphicsAllocation->getDefaultGmm()->resourceParams.Usage == - GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_IMAGE); - - DrmAllocation *drmAllocation = static_cast(imageGraphicsAllocation); - auto imageSize = drmAllocation->getUnderlyingBufferSize(); - auto rowPitch = dstImage->getImageDesc().image_row_pitch; - - EXPECT_EQ(1u, this->mock->createParamsHandle); - EXPECT_EQ(imageSize, this->mock->createParamsSize); - __u32 tilingMode = I915_TILING_Y; - EXPECT_EQ(tilingMode, this->mock->setTilingMode); - EXPECT_EQ(rowPitch, this->mock->setTilingStride); - EXPECT_EQ(1u, this->mock->setTilingHandle); - - alignedFree(data); -} - -TEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhenMemoryAllocatedForImageThenUnmapSizeCorrectlySetWhenLimitedRangeAllocationUsedOrNotUsed) { - mock->ioctl_expected.gemUserptr = 2; - mock->ioctl_expected.gemWait = 2; - mock->ioctl_expected.gemClose = 2; - - MockContext context(pClDevice); - - cl_image_format imageFormat; - imageFormat.image_channel_data_type = CL_UNORM_INT8; - imageFormat.image_channel_order = CL_R; - - cl_image_desc imageDesc = {}; - - imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D; - imageDesc.image_width = 64u; - - auto data = alignedMalloc(64u * 4 * 8, MemoryConstants::pageSize); - - auto retVal = CL_SUCCESS; - - cl_mem_flags flags = CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR; - auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); - std::unique_ptr dstImage(Image::create( - &context, ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()), - flags, 0, surfaceFormat, &imageDesc, data, retVal)); - EXPECT_EQ(CL_SUCCESS, retVal); - ASSERT_NE(nullptr, dstImage); - auto imageGraphicsAllocation = dstImage->getGraphicsAllocation(rootDeviceIndex); - ASSERT_NE(nullptr, imageGraphicsAllocation); - - alignedFree(data); -} - -TEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhenNonTiledImgWithMipCountZeroisBeingCreatedThenAllocateGraphicsMemoryIsUsed) { - mock->ioctl_expected.gemUserptr = 2; - mock->ioctl_expected.gemWait = 2; - mock->ioctl_expected.gemClose = 2; - - MockContext context(pClDevice); - - cl_image_format imageFormat; - imageFormat.image_channel_data_type = CL_UNORM_INT8; - imageFormat.image_channel_order = CL_R; - - cl_image_desc imageDesc = {}; - - imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D; - imageDesc.image_width = 64u; - - auto data = alignedMalloc(64u * 4 * 8, MemoryConstants::pageSize); - - auto retVal = CL_SUCCESS; - this->mock->createParamsHandle = 0; - this->mock->createParamsSize = 0; - - cl_mem_flags flags = CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR; - auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); - std::unique_ptr dstImage(Image::create( - &context, ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()), - flags, 0, surfaceFormat, &imageDesc, data, retVal)); - EXPECT_EQ(CL_SUCCESS, retVal); - ASSERT_NE(nullptr, dstImage); - auto imageGraphicsAllocation = dstImage->getGraphicsAllocation(rootDeviceIndex); - ASSERT_NE(nullptr, imageGraphicsAllocation); - EXPECT_TRUE(imageGraphicsAllocation->getDefaultGmm()->resourceParams.Usage == - GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_IMAGE); - - EXPECT_EQ(0u, this->mock->createParamsHandle); - EXPECT_EQ(0u, this->mock->createParamsSize); - __u32 tilingMode = I915_TILING_NONE; - EXPECT_EQ(tilingMode, this->mock->setTilingMode); - EXPECT_EQ(0u, this->mock->setTilingStride); - EXPECT_EQ(0u, this->mock->setTilingHandle); - - EXPECT_EQ(Sharing::nonSharedResource, imageGraphicsAllocation->peekSharedHandle()); - - alignedFree(data); -} - -TEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhenNonTiledImgWithMipCountNonZeroisBeingCreatedThenAllocateGraphicsMemoryIsUsed) { - mock->ioctl_expected.gemUserptr = 1; - mock->ioctl_expected.gemWait = 1; - mock->ioctl_expected.gemClose = 1; - - MockContext context(pClDevice); - - cl_image_format imageFormat; - imageFormat.image_channel_data_type = CL_UNORM_INT8; - imageFormat.image_channel_order = CL_R; - - cl_image_desc imageDesc = {}; - - imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D; - imageDesc.image_width = 64u; - imageDesc.num_mip_levels = 1u; - - auto data = alignedMalloc(64u * 4 * 8, MemoryConstants::pageSize); - - auto retVal = CL_SUCCESS; - - this->mock->createParamsHandle = 0; - this->mock->createParamsSize = 0; - - cl_mem_flags flags = CL_MEM_WRITE_ONLY; - auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); - std::unique_ptr dstImage(Image::create( - &context, ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()), - flags, 0, surfaceFormat, &imageDesc, data, retVal)); - EXPECT_EQ(CL_SUCCESS, retVal); - ASSERT_NE(nullptr, dstImage); - EXPECT_EQ(static_cast(imageDesc.num_mip_levels), dstImage->peekMipCount()); - auto imageGraphicsAllocation = dstImage->getGraphicsAllocation(rootDeviceIndex); - ASSERT_NE(nullptr, imageGraphicsAllocation); - EXPECT_TRUE(imageGraphicsAllocation->getDefaultGmm()->resourceParams.Usage == - GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_IMAGE); - - EXPECT_EQ(0u, this->mock->createParamsHandle); - EXPECT_EQ(0u, this->mock->createParamsSize); - __u32 tilingMode = I915_TILING_NONE; - EXPECT_EQ(tilingMode, this->mock->setTilingMode); - EXPECT_EQ(0u, this->mock->setTilingStride); - EXPECT_EQ(0u, this->mock->setTilingHandle); - - EXPECT_EQ(Sharing::nonSharedResource, imageGraphicsAllocation->peekSharedHandle()); - - alignedFree(data); -} - -TEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhen1DarrayImageIsBeingCreatedFromHostPtrThenTilingIsNotCalled) { - mock->ioctl_expected.gemUserptr = 2; - mock->ioctl_expected.gemWait = 2; - mock->ioctl_expected.gemClose = 2; - - MockContext context(pClDevice); - - cl_image_format imageFormat; - imageFormat.image_channel_data_type = CL_UNORM_INT8; - imageFormat.image_channel_order = CL_R; - - cl_image_desc imageDesc = {}; - - imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D; - imageDesc.image_width = 64u; - - auto data = alignedMalloc(64u * 4 * 8, MemoryConstants::pageSize); - - auto retVal = CL_SUCCESS; - this->mock->createParamsHandle = 0; - this->mock->createParamsSize = 0; - - cl_mem_flags flags = CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR; - auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); - std::unique_ptr dstImage(Image::create( - &context, ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()), - flags, 0, surfaceFormat, &imageDesc, data, retVal)); - auto imageGraphicsAllocation = dstImage->getGraphicsAllocation(rootDeviceIndex); - ASSERT_NE(nullptr, imageGraphicsAllocation); - - EXPECT_EQ(0u, this->mock->createParamsHandle); - EXPECT_EQ(0u, this->mock->createParamsSize); - __u32 tilingMode = I915_TILING_NONE; - EXPECT_EQ(tilingMode, this->mock->setTilingMode); - EXPECT_EQ(0u, this->mock->setTilingStride); - EXPECT_EQ(0u, this->mock->setTilingHandle); - - EXPECT_EQ(Sharing::nonSharedResource, imageGraphicsAllocation->peekSharedHandle()); - - alignedFree(data); -} - -TEST_F(ClDrmMemoryManagerTest, givenHostPointerNotRequiringCopyWhenAllocateGraphicsMemoryForImageIsCalledThenGraphicsAllocationIsReturned) { - mock->ioctl_expected.gemUserptr = 1; - mock->ioctl_expected.gemWait = 1; - mock->ioctl_expected.gemClose = 1; - - ImageDescriptor imgDesc = {}; - imgDesc.imageType = ImageType::Image1D; - imgDesc.imageWidth = MemoryConstants::pageSize; - imgDesc.imageHeight = 1; - - cl_image_format imageFormat = {}; - imageFormat.image_channel_data_type = CL_UNSIGNED_INT8; - imageFormat.image_channel_order = CL_R; - - cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR; - MockContext context(pClDevice); - auto surfaceFormat = &Image::getSurfaceFormatFromTable(flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features)->surfaceFormat; - - auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, surfaceFormat); - imgInfo.rowPitch = imgDesc.imageWidth * surfaceFormat->ImageElementSizeInBytes; - imgInfo.slicePitch = imgInfo.rowPitch * imgDesc.imageHeight; - imgInfo.size = imgInfo.slicePitch; - imgInfo.linearStorage = true; - - auto hostPtr = alignedMalloc(imgDesc.imageWidth * imgDesc.imageHeight * 4, MemoryConstants::pageSize); - bool copyRequired = MockMemoryManager::isCopyRequired(imgInfo, hostPtr); - EXPECT_FALSE(copyRequired); - - AllocationData allocationData; - allocationData.imgInfo = &imgInfo; - allocationData.hostPtr = hostPtr; - allocationData.rootDeviceIndex = rootDeviceIndex; - - auto imageAllocation = memoryManager->allocateGraphicsMemoryForImage(allocationData); - ASSERT_NE(nullptr, imageAllocation); - EXPECT_EQ(hostPtr, imageAllocation->getUnderlyingBuffer()); - - memoryManager->freeGraphicsMemory(imageAllocation); - alignedFree(hostPtr); -} - TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndOsHandleWhenCreateIsCalledThenGraphicsAllocationIsReturned) { mock->ioctl_expected.primeFdToHandle = 1; mock->ioctl_expected.gemWait = 1; @@ -2252,130 +1539,6 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndOsHandleWhenCreateIsCalledA memoryManager->freeGraphicsMemory(graphicsAllocation); } -TEST_F(ClDrmMemoryManagerTest, givenOsHandleWithNonTiledObjectWhenCreateFromSharedHandleIsCalledThenNonTiledGmmIsCreatedAndSetInAllocation) { - mock->ioctl_expected.primeFdToHandle = 1; - mock->ioctl_expected.gemWait = 1; - mock->ioctl_expected.gemClose = 1; - mock->ioctl_expected.gemGetTiling = 1; - mock->getTilingModeOut = I915_TILING_NONE; - - osHandle handle = 1u; - uint32_t boHandle = 2u; - mock->outputHandle = boHandle; - - cl_mem_flags flags = CL_MEM_READ_ONLY; - cl_image_desc imgDesc = {}; - cl_image_format gmmImgFormat = {CL_NV12_INTEL, CL_UNORM_INT8}; - const ClSurfaceFormatInfo *gmmSurfaceFormat = nullptr; - ImageInfo imgInfo = {}; - - imgDesc.image_width = 4; - imgDesc.image_height = 4; - imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D; - - imgInfo.imgDesc = Image::convertDescriptor(imgDesc); - MockContext context(pClDevice); - gmmSurfaceFormat = Image::getSurfaceFormatFromTable(flags, &gmmImgFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); - imgInfo.surfaceFormat = &gmmSurfaceFormat->surfaceFormat; - imgInfo.plane = GMM_PLANE_Y; - - AllocationProperties properties(rootDeviceIndex, false, imgInfo, AllocationType::SHARED_IMAGE, context.getDevice(0)->getDeviceBitfield()); - - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false); - ASSERT_NE(nullptr, graphicsAllocation); - EXPECT_EQ(boHandle, mock->getTilingHandleIn); - EXPECT_EQ(AllocationType::SHARED_IMAGE, graphicsAllocation->getAllocationType()); - - auto gmm = graphicsAllocation->getDefaultGmm(); - ASSERT_NE(nullptr, gmm); - EXPECT_EQ(1u, gmm->resourceParams.Flags.Info.Linear); - EXPECT_EQ(0u, gmm->resourceParams.Flags.Info.TiledY); - - memoryManager->freeGraphicsMemory(graphicsAllocation); -} - -TEST_F(ClDrmMemoryManagerTest, givenOsHandleWithTileYObjectWhenCreateFromSharedHandleIsCalledThenTileYGmmIsCreatedAndSetInAllocation) { - mock->ioctl_expected.primeFdToHandle = 1; - mock->ioctl_expected.gemWait = 1; - mock->ioctl_expected.gemClose = 1; - mock->ioctl_expected.gemGetTiling = 1; - mock->getTilingModeOut = I915_TILING_Y; - - osHandle handle = 1u; - uint32_t boHandle = 2u; - mock->outputHandle = boHandle; - - cl_mem_flags flags = CL_MEM_READ_ONLY; - cl_image_desc imgDesc = {}; - cl_image_format gmmImgFormat = {CL_NV12_INTEL, CL_UNORM_INT8}; - const ClSurfaceFormatInfo *gmmSurfaceFormat = nullptr; - ImageInfo imgInfo = {}; - - imgDesc.image_width = 4; - imgDesc.image_height = 4; - imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D; - - imgInfo.imgDesc = Image::convertDescriptor(imgDesc); - MockContext context(pClDevice); - gmmSurfaceFormat = Image::getSurfaceFormatFromTable(flags, &gmmImgFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); - imgInfo.surfaceFormat = &gmmSurfaceFormat->surfaceFormat; - imgInfo.plane = GMM_PLANE_Y; - - AllocationProperties properties(rootDeviceIndex, false, imgInfo, AllocationType::SHARED_IMAGE, context.getDevice(0)->getDeviceBitfield()); - - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false); - ASSERT_NE(nullptr, graphicsAllocation); - EXPECT_EQ(boHandle, mock->getTilingHandleIn); - EXPECT_EQ(AllocationType::SHARED_IMAGE, graphicsAllocation->getAllocationType()); - - auto gmm = graphicsAllocation->getDefaultGmm(); - ASSERT_NE(nullptr, gmm); - EXPECT_EQ(0u, gmm->resourceParams.Flags.Info.Linear); - - memoryManager->freeGraphicsMemory(graphicsAllocation); -} - -TEST_F(ClDrmMemoryManagerTest, givenDrmMemoryManagerWhenCreateFromSharedHandleFailsToCallGetTilingThenNonLinearStorageIsAssumed) { - mock->ioctl_expected.primeFdToHandle = 1; - mock->ioctl_expected.gemGetTiling = 1; - mock->ioctl_expected.gemWait = 1; - mock->ioctl_expected.gemClose = 1; - this->ioctlResExt = {mock->ioctl_cnt.total + 1, -1}; - mock->ioctl_res_ext = &ioctlResExt; - - osHandle handle = 1u; - uint32_t boHandle = 2u; - mock->outputHandle = boHandle; - - cl_mem_flags flags = CL_MEM_READ_ONLY; - cl_image_desc imgDesc = {}; - cl_image_format gmmImgFormat = {CL_NV12_INTEL, CL_UNORM_INT8}; - const ClSurfaceFormatInfo *gmmSurfaceFormat = nullptr; - ImageInfo imgInfo = {}; - - imgDesc.image_width = 4; - imgDesc.image_height = 4; - imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D; - - imgInfo.imgDesc = Image::convertDescriptor(imgDesc); - MockContext context(pClDevice); - gmmSurfaceFormat = Image::getSurfaceFormatFromTable(flags, &gmmImgFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); - imgInfo.surfaceFormat = &gmmSurfaceFormat->surfaceFormat; - imgInfo.plane = GMM_PLANE_Y; - - AllocationProperties properties(rootDeviceIndex, false, imgInfo, AllocationType::SHARED_IMAGE, context.getDevice(0)->getDeviceBitfield()); - - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, false); - ASSERT_NE(nullptr, graphicsAllocation); - EXPECT_EQ(boHandle, mock->getTilingHandleIn); - EXPECT_EQ(AllocationType::SHARED_IMAGE, graphicsAllocation->getAllocationType()); - - auto gmm = graphicsAllocation->getDefaultGmm(); - ASSERT_NE(nullptr, gmm); - EXPECT_EQ(0u, gmm->resourceParams.Flags.Info.Linear); - - memoryManager->freeGraphicsMemory(graphicsAllocation); -} TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndOsHandleWhenAllocationFailsThenReturnNullPtr) { osHandle handle = 1u; @@ -3047,51 +2210,6 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDefaultDrmMemoryManage EXPECT_EQ(nullptr, memoryManager->getAlignedMallocRestrictions()); } -#include -#include - -TEST(MmapFlags, givenVariousMmapParametersWhenGettingTimeDeltaThenTimeIsPrinted) { - // disabling this test in CI. - return; - typedef std::chrono::high_resolution_clock Time; - typedef std::chrono::nanoseconds ns; - typedef std::chrono::duration fsec; - - std::vector pointersForFree; - // allocate 4GB. - auto size = 4 * GB; - unsigned int maxTime = 0; - unsigned int minTime = -1; - unsigned int totalTime = 0; - - auto iterCount = 10; - - for (int i = 0; i < iterCount; i++) { - auto t0 = Time::now(); - auto gpuRange = mmap(nullptr, size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - auto t1 = Time::now(); - pointersForFree.push_back(gpuRange); - fsec fs = t1 - t0; - ns d = std::chrono::duration_cast(fs); - unsigned int duration = (unsigned int)d.count(); - totalTime += duration; - minTime = std::min(duration, minTime); - maxTime = std::max(duration, maxTime); - } - - std::cout << "\n" - << "min = " << minTime << "\nmax = " << maxTime << "\naverage = " << totalTime / iterCount << std::endl; - for (auto &ptr : pointersForFree) { - auto t0 = Time::now(); - munmap(ptr, size); - auto t1 = Time::now(); - fsec fs = t1 - t0; - ns d = std::chrono::duration_cast(fs); - unsigned int duration = (unsigned int)d.count(); - std::cout << "\nfreeing ptr " << ptr << " of size " << size << "time " << duration; - } -} - TEST_F(DrmMemoryManagerBasic, givenDefaultMemoryManagerWhenItIsCreatedThenAsyncDeleterEnabledIsTrue) { DrmMemoryManager memoryManager(gemCloseWorkerMode::gemCloseWorkerInactive, false, true, executionEnvironment); EXPECT_FALSE(memoryManager.isAsyncDeleterEnabled()); @@ -4097,22 +3215,6 @@ TEST(DrmMemoryManagerFreeGraphicsMemoryUnreferenceTest, givenDrmMemoryManagerAnd } } -TEST(DrmMemoryMangerTest, givenMultipleRootDeviceWhenMemoryManagerGetsDrmThenDrmIsFromCorrectRootDevice) { - DebugManagerStateRestore restorer; - DebugManager.flags.CreateMultipleRootDevices.set(4); - VariableBackup backup{&ultHwConfig}; - ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false; - initPlatform(); - - TestedDrmMemoryManager drmMemoryManager(*platform()->peekExecutionEnvironment()); - for (auto i = 0u; i < platform()->peekExecutionEnvironment()->rootDeviceEnvironments.size(); i++) { - auto drmFromRootDevice = platform()->peekExecutionEnvironment()->rootDeviceEnvironments[i]->osInterface->getDriverModel()->as(); - EXPECT_EQ(drmFromRootDevice, &drmMemoryManager.getDrm(i)); - EXPECT_EQ(i, drmMemoryManager.getRootDeviceIndex(drmFromRootDevice)); - } - EXPECT_EQ(CommonConstants::unspecifiedDeviceIndex, drmMemoryManager.getRootDeviceIndex(nullptr)); -} - TEST_F(DrmAllocationTests, givenResourceRegistrationEnabledWhenAllocationTypeShouldBeRegisteredThenBoHasBindExtHandleAdded) { DrmMockResources drm(*executionEnvironment->rootDeviceEnvironments[0]); @@ -5931,5 +5033,3 @@ TEST_F(DrmMemoryManagerTest, givenSingleSubDevicesBitfieldWhenAllocatingSbaTrack memoryManager->freeGraphicsMemory(sbaBuffer); } } - -} // namespace NEO diff --git a/shared/test/unit_test/xe_hpc_core/excludes_xe_hpc_core.cpp b/shared/test/unit_test/xe_hpc_core/excludes_xe_hpc_core.cpp index ec98ac4de7..400eac514d 100644 --- a/shared/test/unit_test/xe_hpc_core/excludes_xe_hpc_core.cpp +++ b/shared/test/unit_test/xe_hpc_core/excludes_xe_hpc_core.cpp @@ -9,6 +9,8 @@ HWTEST_EXCLUDE_PRODUCT(CommandEncodeStatesTest, givenSlmTotalSizeEqualZeroWhenDispatchingKernelThenSharedMemorySizeIsSetCorrectly, IGFX_XE_HPC_CORE); HWTEST_EXCLUDE_PRODUCT(CommandEncodeStatesTest, givenOverrideSlmTotalSizeDebugVariableWhenDispatchingKernelThenSharedMemorySizeIsSetCorrectly, IGFX_XE_HPC_CORE); +HWTEST_EXCLUDE_PRODUCT(DrmMemoryManagerTest, givenDrmAllocationWithHostPtrWhenItIsCreatedWithIncorrectCacheRegionThenReturnNull, IGFX_XE_HPC_CORE); +HWTEST_EXCLUDE_PRODUCT(DrmMemoryManagerTest, givenDrmAllocationWithWithAlignmentFromUserptrWhenItIsCreatedWithIncorrectCacheRegionThenReturnNull, IGFX_XE_HPC_CORE); HWTEST_EXCLUDE_PRODUCT(WalkerPartitionTests, givenMiAtomicWhenItIsProgrammedThenAllFieldsAreSetCorrectly, IGFX_XE_HPC_CORE); HWTEST_EXCLUDE_PRODUCT(WalkerPartitionTests, givenProgramBatchBufferStartCommandWhenItIsCalledThenCommandIsProgrammedCorrectly, IGFX_XE_HPC_CORE); HWTEST_EXCLUDE_PRODUCT(XeHPAndLaterPreemptionTests, GivenDebuggerUsedWhenProgrammingStateSipThenStateSipIsAdded, IGFX_XE_HPC_CORE);