From 09dfcfcf853277ccd2c38cde6f8d9314763003c8 Mon Sep 17 00:00:00 2001 From: Szymon Morek Date: Fri, 1 Oct 2021 16:11:31 +0000 Subject: [PATCH] Remove duplicated tests in drm files 1/n Signed-off-by: Szymon Morek --- .../os_interface/linux/CMakeLists.txt | 3 +- .../linux/drm_command_stream_tests_2.cpp | 104 ++++++++ .../drm_memory_manager_local_memory_tests.cpp | 228 ------------------ ... => drm_memory_manager_localmem_tests.cpp} | 102 ++------ .../linux/drm_memory_manager_tests.cpp | 82 +++++++ 5 files changed, 205 insertions(+), 314 deletions(-) delete mode 100644 opencl/test/unit_test/os_interface/linux/drm_memory_manager_local_memory_tests.cpp rename opencl/test/unit_test/os_interface/linux/{drm_memory_manager_local_memory_tests_dg1.cpp => drm_memory_manager_localmem_tests.cpp} (94%) diff --git a/opencl/test/unit_test/os_interface/linux/CMakeLists.txt b/opencl/test/unit_test/os_interface/linux/CMakeLists.txt index 02bef45590..cd1fee6482 100644 --- a/opencl/test/unit_test/os_interface/linux/CMakeLists.txt +++ b/opencl/test/unit_test/os_interface/linux/CMakeLists.txt @@ -48,13 +48,12 @@ set(IGDRCL_SRCS_tests_os_interface_linux if(SUPPORT_DG1 AND "${BRANCH_TYPE}" STREQUAL "") list(APPEND IGDRCL_SRCS_tests_os_interface_linux ${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_info_tests_dg1.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager_local_memory_tests_dg1.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager_localmem_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_mock_drm_tip.cpp ) else() list(APPEND IGDRCL_SRCS_tests_os_interface_linux ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}drm_memory_info_tests.cpp - ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}drm_memory_manager_local_memory_tests.cpp ) endif() if(NEO__LIBVA_FOUND) diff --git a/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests_2.cpp b/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests_2.cpp index 47b66c79a6..730cad6613 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests_2.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests_2.cpp @@ -1183,3 +1183,107 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenVmBindAvailableUseWaitCall EXPECT_FALSE(testDrmCsr->isKmdWaitModeActive()); EXPECT_EQ(1u, mock->isVmBindAvailableCall.called); } + +HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenNoAllocsInMemoryOperationHandlerDefaultWhenFlushThenDrmMemoryOperationHandlerIsNotLocked) { + struct MockDrmMemoryOperationsHandler : public DrmMemoryOperationsHandler { + using DrmMemoryOperationsHandler::mutex; + }; + + struct MockDrmCsr : public DrmCommandStreamReceiver { + using DrmCommandStreamReceiver::DrmCommandStreamReceiver; + void flushInternal(const BatchBuffer &batchBuffer, const ResidencyContainer &allocationsForResidency) override { + auto memoryOperationsInterface = static_cast(this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]->memoryOperationsInterface.get()); + ASSERT_TRUE(memoryOperationsInterface->mutex.try_lock()); + memoryOperationsInterface->mutex.unlock(); + } + }; + + auto osContext = std::make_unique(*mock, 0u, + EngineDescriptorHelper::getDefaultDescriptor(HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*defaultHwInfo)[0], + PreemptionHelper::getDefaultPreemptionMode(*defaultHwInfo))); + + auto commandBuffer = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}); + LinearStream cs(commandBuffer); + CommandStreamReceiverHw::addBatchBufferEnd(cs, nullptr); + CommandStreamReceiverHw::alignToCacheLine(cs); + BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount, cs.getUsed(), &cs, nullptr, false}; + + MockDrmCsr mockCsr(*executionEnvironment, rootDeviceIndex, 1, gemCloseWorkerMode::gemCloseWorkerInactive); + mockCsr.setupContext(*osContext.get()); + mockCsr.flush(batchBuffer, mockCsr.getResidencyAllocations()); + + mm->freeGraphicsMemory(commandBuffer); +} + +HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenAllocsInMemoryOperationHandlerDefaultWhenFlushThenDrmMemoryOperationHandlerIsLocked) { + struct MockDrmMemoryOperationsHandler : public DrmMemoryOperationsHandler { + using DrmMemoryOperationsHandler::mutex; + }; + + struct MockDrmCsr : public DrmCommandStreamReceiver { + using DrmCommandStreamReceiver::DrmCommandStreamReceiver; + void flushInternal(const BatchBuffer &batchBuffer, const ResidencyContainer &allocationsForResidency) override { + auto memoryOperationsInterface = static_cast(this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]->memoryOperationsInterface.get()); + EXPECT_FALSE(memoryOperationsInterface->mutex.try_lock()); + } + }; + + auto osContext = std::make_unique(*mock, 0u, + EngineDescriptorHelper::getDefaultDescriptor(HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*defaultHwInfo)[0], + PreemptionHelper::getDefaultPreemptionMode(*defaultHwInfo))); + + auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}); + executionEnvironment->rootDeviceEnvironments[csr->getRootDeviceIndex()]->memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocation, 1)); + + auto commandBuffer = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}); + LinearStream cs(commandBuffer); + CommandStreamReceiverHw::addBatchBufferEnd(cs, nullptr); + CommandStreamReceiverHw::alignToCacheLine(cs); + BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount, cs.getUsed(), &cs, nullptr, false}; + + MockDrmCsr mockCsr(*executionEnvironment, rootDeviceIndex, 1, gemCloseWorkerMode::gemCloseWorkerInactive); + mockCsr.setupContext(*osContext.get()); + mockCsr.flush(batchBuffer, mockCsr.getResidencyAllocations()); + + mm->freeGraphicsMemory(commandBuffer); + mm->freeGraphicsMemory(allocation); +} + +HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenAllocInMemoryOperationsInterfaceWhenFlushThenAllocIsResident) { + auto commandBuffer = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}); + LinearStream cs(commandBuffer); + CommandStreamReceiverHw::addBatchBufferEnd(cs, nullptr); + CommandStreamReceiverHw::alignToCacheLine(cs); + BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount, cs.getUsed(), &cs, nullptr, false}; + + auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}); + executionEnvironment->rootDeviceEnvironments[csr->getRootDeviceIndex()]->memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocation, 1)); + + csr->flush(batchBuffer, csr->getResidencyAllocations()); + + const auto boRequirments = [&allocation](const auto &bo) { + return (static_cast(bo.handle) == static_cast(allocation)->getBO()->peekHandle() && + bo.offset == static_cast(allocation)->getBO()->peekAddress()); + }; + + auto &residency = static_cast *>(csr)->getExecStorage(); + EXPECT_TRUE(std::find_if(residency.begin(), residency.end(), boRequirments) != residency.end()); + EXPECT_EQ(residency.size(), 2u); + residency.clear(); + + csr->flush(batchBuffer, csr->getResidencyAllocations()); + EXPECT_TRUE(std::find_if(residency.begin(), residency.end(), boRequirments) != residency.end()); + EXPECT_EQ(residency.size(), 2u); + residency.clear(); + + csr->getResidencyAllocations().clear(); + executionEnvironment->rootDeviceEnvironments[csr->getRootDeviceIndex()]->memoryOperationsInterface->evict(device.get(), *allocation); + + csr->flush(batchBuffer, csr->getResidencyAllocations()); + + EXPECT_FALSE(std::find_if(residency.begin(), residency.end(), boRequirments) != residency.end()); + EXPECT_EQ(residency.size(), 1u); + + mm->freeGraphicsMemory(allocation); + mm->freeGraphicsMemory(commandBuffer); +} \ No newline at end of file diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_local_memory_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_local_memory_tests.cpp deleted file mode 100644 index d5fccecbc8..0000000000 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_local_memory_tests.cpp +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright (C) 2019-2021 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "shared/source/execution_environment/execution_environment.h" -#include "shared/source/os_interface/linux/drm_memory_manager.h" -#include "shared/source/os_interface/linux/drm_memory_operations_handler.h" -#include "shared/source/os_interface/os_interface.h" -#include "shared/test/common/helpers/engine_descriptor_helper.h" -#include "shared/test/common/helpers/ult_hw_config.h" -#include "shared/test/common/mocks/linux/mock_drm_memory_manager.h" -#include "shared/test/common/mocks/mock_execution_environment.h" - -#include "opencl/test/unit_test/mocks/mock_allocation_properties.h" -#include "opencl/test/unit_test/mocks/mock_context.h" -#include "opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h" -#include "opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.h" -#include "test.h" - -#include "gtest/gtest.h" - -using namespace NEO; - -TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenAllocateInDevicePoolIsCalledThenNullptrAndStatusRetryIsReturned) { - MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); - executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); - auto drm = Drm::create(nullptr, *executionEnvironment.rootDeviceEnvironments[0]); - executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(drm)); - executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, 0u); - TestedDrmMemoryManager memoryManager(executionEnvironment); - MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success; - AllocationData allocData; - allocData.size = MemoryConstants::pageSize; - allocData.flags.useSystemMemory = true; - allocData.flags.allocateMemory = true; - - auto allocation = memoryManager.allocateGraphicsMemoryInDevicePool(allocData, status); - EXPECT_EQ(nullptr, allocation); - EXPECT_EQ(MemoryManager::AllocationStatus::RetryInNonDevicePool, status); -} - -TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenLockResourceIsCalledOnNullBufferObjectThenReturnNullPtr) { - MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); - executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); - auto drm = Drm::create(nullptr, *executionEnvironment.rootDeviceEnvironments[0]); - executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(drm)); - executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, 0u); - TestedDrmMemoryManager memoryManager(executionEnvironment); - DrmAllocation drmAllocation(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, nullptr, 0u, 0u, MemoryPool::LocalMemory); - - auto ptr = memoryManager.lockResourceInLocalMemoryImpl(drmAllocation.getBO()); - EXPECT_EQ(nullptr, ptr); - - memoryManager.unlockResourceInLocalMemoryImpl(drmAllocation.getBO()); -} - -TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenFreeGraphicsMemoryIsCalledOnAllocationWithNullBufferObjectThenEarlyReturn) { - MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); - executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); - auto drm = Drm::create(nullptr, *executionEnvironment.rootDeviceEnvironments[0]); - executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(drm)); - executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, 0u); - TestedDrmMemoryManager memoryManager(executionEnvironment); - - auto drmAllocation = new DrmAllocation(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, nullptr, 0u, 0u, MemoryPool::LocalMemory); - EXPECT_NE(nullptr, drmAllocation); - - memoryManager.freeGraphicsMemoryImpl(drmAllocation); -} - -using DrmMemoryManagerWithLocalMemoryTest = Test; - -TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmMemoryManagerWithLocalMemoryWhenLockResourceIsCalledOnAllocationInLocalMemoryThenReturnNullPtr) { - DrmAllocation drmAllocation(rootDeviceIndex, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, nullptr, 0u, 0u, MemoryPool::LocalMemory); - - auto ptr = memoryManager->lockResource(&drmAllocation); - EXPECT_EQ(nullptr, ptr); - - memoryManager->unlockResource(&drmAllocation); -} - -using DrmMemoryManagerTest = Test; - -TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenCopyMemoryToAllocationThenAllocationIsFilledWithCorrectData) { - mock->ioctl_expected.gemUserptr = 1; - mock->ioctl_expected.gemWait = 1; - mock->ioctl_expected.gemClose = 1; - - std::vector dataToCopy(MemoryConstants::pageSize, 1u); - - auto allocation = memoryManager->allocateGraphicsMemoryWithProperties({rootDeviceIndex, dataToCopy.size(), GraphicsAllocation::AllocationType::BUFFER, device->getDeviceBitfield()}); - ASSERT_NE(nullptr, allocation); - - auto ret = memoryManager->copyMemoryToAllocation(allocation, 0, dataToCopy.data(), dataToCopy.size()); - EXPECT_TRUE(ret); - - EXPECT_EQ(0, memcmp(allocation->getUnderlyingBuffer(), dataToCopy.data(), dataToCopy.size())); - - memoryManager->freeGraphicsMemory(allocation); -} - -TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenGetLocalMemoryIsCalledThenSizeOfLocalMemoryIsReturned) { - EXPECT_EQ(0 * GB, memoryManager->getLocalMemorySize(rootDeviceIndex, 0xF)); -} - -HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenNoAllocsInMemoryOperationHandlerDefaultWhenFlushThenDrmMemoryOperationHandlerIsNotLocked) { - struct MockDrmMemoryOperationsHandler : public DrmMemoryOperationsHandler { - using DrmMemoryOperationsHandler::mutex; - }; - - struct MockDrmCsr : public DrmCommandStreamReceiver { - using DrmCommandStreamReceiver::DrmCommandStreamReceiver; - void flushInternal(const BatchBuffer &batchBuffer, const ResidencyContainer &allocationsForResidency) override { - auto memoryOperationsInterface = static_cast(this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]->memoryOperationsInterface.get()); - ASSERT_TRUE(memoryOperationsInterface->mutex.try_lock()); - memoryOperationsInterface->mutex.unlock(); - } - }; - - auto osContext = std::make_unique(*mock, 0u, - EngineDescriptorHelper::getDefaultDescriptor(HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*defaultHwInfo)[0], - PreemptionHelper::getDefaultPreemptionMode(*defaultHwInfo))); - - auto commandBuffer = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}); - LinearStream cs(commandBuffer); - CommandStreamReceiverHw::addBatchBufferEnd(cs, nullptr); - CommandStreamReceiverHw::alignToCacheLine(cs); - BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount, cs.getUsed(), &cs, nullptr, false}; - - MockDrmCsr mockCsr(*executionEnvironment, rootDeviceIndex, 1, gemCloseWorkerMode::gemCloseWorkerInactive); - mockCsr.setupContext(*osContext.get()); - mockCsr.flush(batchBuffer, mockCsr.getResidencyAllocations()); - - mm->freeGraphicsMemory(commandBuffer); -} - -HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenAllocsInMemoryOperationHandlerDefaultWhenFlushThenDrmMemoryOperationHandlerIsLocked) { - struct MockDrmMemoryOperationsHandler : public DrmMemoryOperationsHandler { - using DrmMemoryOperationsHandler::mutex; - }; - - struct MockDrmCsr : public DrmCommandStreamReceiver { - using DrmCommandStreamReceiver::DrmCommandStreamReceiver; - void flushInternal(const BatchBuffer &batchBuffer, const ResidencyContainer &allocationsForResidency) override { - auto memoryOperationsInterface = static_cast(this->executionEnvironment.rootDeviceEnvironments[this->rootDeviceIndex]->memoryOperationsInterface.get()); - EXPECT_FALSE(memoryOperationsInterface->mutex.try_lock()); - } - }; - - auto osContext = std::make_unique(*mock, 0u, - EngineDescriptorHelper::getDefaultDescriptor(HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*defaultHwInfo)[0], - PreemptionHelper::getDefaultPreemptionMode(*defaultHwInfo))); - - auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}); - executionEnvironment->rootDeviceEnvironments[csr->getRootDeviceIndex()]->memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocation, 1)); - - auto commandBuffer = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}); - LinearStream cs(commandBuffer); - CommandStreamReceiverHw::addBatchBufferEnd(cs, nullptr); - CommandStreamReceiverHw::alignToCacheLine(cs); - BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount, cs.getUsed(), &cs, nullptr, false}; - - MockDrmCsr mockCsr(*executionEnvironment, rootDeviceIndex, 1, gemCloseWorkerMode::gemCloseWorkerInactive); - mockCsr.setupContext(*osContext.get()); - mockCsr.flush(batchBuffer, mockCsr.getResidencyAllocations()); - - mm->freeGraphicsMemory(commandBuffer); - mm->freeGraphicsMemory(allocation); -} - -HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, givenAllocInMemoryOperationsInterfaceWhenFlushThenAllocIsResident) { - auto commandBuffer = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}); - LinearStream cs(commandBuffer); - CommandStreamReceiverHw::addBatchBufferEnd(cs, nullptr); - CommandStreamReceiverHw::alignToCacheLine(cs); - BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount, cs.getUsed(), &cs, nullptr, false}; - - auto allocation = mm->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize}); - executionEnvironment->rootDeviceEnvironments[csr->getRootDeviceIndex()]->memoryOperationsInterface->makeResident(device.get(), ArrayRef(&allocation, 1)); - - csr->flush(batchBuffer, csr->getResidencyAllocations()); - - const auto boRequirments = [&allocation](const auto &bo) { - return (static_cast(bo.handle) == static_cast(allocation)->getBO()->peekHandle() && - bo.offset == static_cast(allocation)->getBO()->peekAddress()); - }; - - auto &residency = static_cast *>(csr)->getExecStorage(); - EXPECT_TRUE(std::find_if(residency.begin(), residency.end(), boRequirments) != residency.end()); - EXPECT_EQ(residency.size(), 2u); - residency.clear(); - - csr->flush(batchBuffer, csr->getResidencyAllocations()); - EXPECT_TRUE(std::find_if(residency.begin(), residency.end(), boRequirments) != residency.end()); - EXPECT_EQ(residency.size(), 2u); - residency.clear(); - - csr->getResidencyAllocations().clear(); - executionEnvironment->rootDeviceEnvironments[csr->getRootDeviceIndex()]->memoryOperationsInterface->evict(device.get(), *allocation); - - csr->flush(batchBuffer, csr->getResidencyAllocations()); - - EXPECT_FALSE(std::find_if(residency.begin(), residency.end(), boRequirments) != residency.end()); - EXPECT_EQ(residency.size(), 1u); - - mm->freeGraphicsMemory(allocation); - mm->freeGraphicsMemory(commandBuffer); -} - -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/drm_memory_manager_local_memory_tests_dg1.cpp b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_localmem_tests.cpp similarity index 94% rename from opencl/test/unit_test/os_interface/linux/drm_memory_manager_local_memory_tests_dg1.cpp rename to opencl/test/unit_test/os_interface/linux/drm_memory_manager_localmem_tests.cpp index 7403c8543d..fb0f94de7b 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_local_memory_tests_dg1.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_localmem_tests.cpp @@ -16,6 +16,7 @@ #include "shared/test/common/mocks/linux/mock_drm_memory_manager.h" #include "shared/test/common/mocks/mock_execution_environment.h" +#include "opencl/test/unit_test/mocks/mock_context.h" #include "opencl/test/unit_test/mocks/mock_gmm.h" #include "opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests_dg1.h" #include "opencl/test/unit_test/os_interface/linux/drm_mock_dg1.h" @@ -24,90 +25,6 @@ #include "gtest/gtest.h" -using namespace NEO; - -TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenAllocateInDevicePoolIsCalledThenNullptrAndStatusRetryIsReturned) { - MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); - executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); - auto drm = Drm::create(nullptr, *executionEnvironment.rootDeviceEnvironments[0]); - executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(drm)); - executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, 0u); - TestedDrmMemoryManager memoryManager(executionEnvironment); - MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success; - AllocationData allocData; - allocData.size = MemoryConstants::pageSize; - allocData.flags.useSystemMemory = true; - allocData.flags.allocateMemory = true; - - auto allocation = memoryManager.allocateGraphicsMemoryInDevicePool(allocData, status); - EXPECT_EQ(nullptr, allocation); - EXPECT_EQ(MemoryManager::AllocationStatus::RetryInNonDevicePool, status); -} - -TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenLockResourceIsCalledOnNullBufferObjectThenReturnNullPtr) { - MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); - executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); - auto drm = Drm::create(nullptr, *executionEnvironment.rootDeviceEnvironments[0]); - executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(drm)); - executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, 0u); - TestedDrmMemoryManager memoryManager(executionEnvironment); - DrmAllocation drmAllocation(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, nullptr, 0u, 0u, MemoryPool::LocalMemory); - - auto ptr = memoryManager.lockResourceInLocalMemoryImpl(drmAllocation.getBO()); - EXPECT_EQ(nullptr, ptr); - - memoryManager.unlockResourceInLocalMemoryImpl(drmAllocation.getBO()); -} - -TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenFreeGraphicsMemoryIsCalledOnAllocationWithNullBufferObjectThenEarlyReturn) { - MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); - executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); - auto drm = Drm::create(nullptr, *executionEnvironment.rootDeviceEnvironments[0]); - executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(drm)); - executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, 0u); - TestedDrmMemoryManager memoryManager(executionEnvironment); - - auto drmAllocation = new DrmAllocation(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, nullptr, 0u, 0u, MemoryPool::LocalMemory); - EXPECT_NE(nullptr, drmAllocation); - - memoryManager.freeGraphicsMemoryImpl(drmAllocation); -} - -using DrmMemoryManagerWithLocalMemoryTest = Test; - -TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmMemoryManagerWithLocalMemoryWhenLockResourceIsCalledOnAllocationInLocalMemoryThenReturnNullPtr) { - DrmAllocation drmAllocation(rootDeviceIndex, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, nullptr, 0u, 0u, MemoryPool::LocalMemory); - - auto ptr = memoryManager->lockResource(&drmAllocation); - EXPECT_EQ(nullptr, ptr); - - memoryManager->unlockResource(&drmAllocation); -} - -using DrmMemoryManagerTest = Test; - -TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenCopyMemoryToAllocationThenAllocationIsFilledWithCorrectData) { - mock->ioctl_expected.gemUserptr = 1; - mock->ioctl_expected.gemWait = 1; - mock->ioctl_expected.gemClose = 1; - - std::vector dataToCopy(MemoryConstants::pageSize, 1u); - - auto allocation = memoryManager->allocateGraphicsMemoryWithProperties({rootDeviceIndex, dataToCopy.size(), GraphicsAllocation::AllocationType::BUFFER, device->getDeviceBitfield()}); - ASSERT_NE(nullptr, allocation); - - auto ret = memoryManager->copyMemoryToAllocation(allocation, 0, dataToCopy.data(), dataToCopy.size()); - EXPECT_TRUE(ret); - - EXPECT_EQ(0, memcmp(allocation->getUnderlyingBuffer(), dataToCopy.data(), dataToCopy.size())); - - memoryManager->freeGraphicsMemory(allocation); -} - -TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenGetLocalMemoryIsCalledThenSizeOfLocalMemoryIsReturned) { - EXPECT_EQ(0 * GB, memoryManager->getLocalMemorySize(rootDeviceIndex, 0xF)); -} - namespace NEO { BufferObject *createBufferObjectInMemoryRegion(Drm *drm, uint64_t gpuAddress, size_t size, uint32_t memoryBanks, size_t maxOsContextCount); @@ -1832,4 +1749,21 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, whenPrintBOCreateDestroyResultFlagIsSetW EXPECT_EQ(expectedOutput, output); } +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/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp index ec67504539..078efe621b 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp @@ -4592,4 +4592,86 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWithoutLocalMemoryAndCpuPtrWhe memoryManager.freeGraphicsMemory(allocation); } +TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenAllocateInDevicePoolIsCalledThenNullptrAndStatusRetryIsReturned) { + MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); + executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); + auto drm = Drm::create(nullptr, *executionEnvironment.rootDeviceEnvironments[0]); + executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(drm)); + executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, 0u); + TestedDrmMemoryManager memoryManager(executionEnvironment); + MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success; + AllocationData allocData; + allocData.size = MemoryConstants::pageSize; + allocData.flags.useSystemMemory = true; + allocData.flags.allocateMemory = true; + + auto allocation = memoryManager.allocateGraphicsMemoryInDevicePool(allocData, status); + EXPECT_EQ(nullptr, allocation); + EXPECT_EQ(MemoryManager::AllocationStatus::RetryInNonDevicePool, status); +} + +TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenLockResourceIsCalledOnNullBufferObjectThenReturnNullPtr) { + MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); + executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); + auto drm = Drm::create(nullptr, *executionEnvironment.rootDeviceEnvironments[0]); + executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(drm)); + executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, 0u); + TestedDrmMemoryManager memoryManager(executionEnvironment); + DrmAllocation drmAllocation(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, nullptr, 0u, 0u, MemoryPool::LocalMemory); + + auto ptr = memoryManager.lockResourceInLocalMemoryImpl(drmAllocation.getBO()); + EXPECT_EQ(nullptr, ptr); + + memoryManager.unlockResourceInLocalMemoryImpl(drmAllocation.getBO()); +} + +TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenFreeGraphicsMemoryIsCalledOnAllocationWithNullBufferObjectThenEarlyReturn) { + MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); + executionEnvironment.rootDeviceEnvironments[0]->osInterface = std::make_unique(); + auto drm = Drm::create(nullptr, *executionEnvironment.rootDeviceEnvironments[0]); + executionEnvironment.rootDeviceEnvironments[0]->osInterface->setDriverModel(std::unique_ptr(drm)); + executionEnvironment.rootDeviceEnvironments[0]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, 0u); + TestedDrmMemoryManager memoryManager(executionEnvironment); + + auto drmAllocation = new DrmAllocation(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, nullptr, 0u, 0u, MemoryPool::LocalMemory); + EXPECT_NE(nullptr, drmAllocation); + + memoryManager.freeGraphicsMemoryImpl(drmAllocation); +} + +using DrmMemoryManagerWithLocalMemoryTest = Test; + +TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmMemoryManagerWithLocalMemoryWhenLockResourceIsCalledOnAllocationInLocalMemoryThenReturnNullPtr) { + DrmAllocation drmAllocation(rootDeviceIndex, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, nullptr, 0u, 0u, MemoryPool::LocalMemory); + + auto ptr = memoryManager->lockResource(&drmAllocation); + EXPECT_EQ(nullptr, ptr); + + memoryManager->unlockResource(&drmAllocation); +} + +using DrmMemoryManagerTest = Test; + +TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenCopyMemoryToAllocationThenAllocationIsFilledWithCorrectData) { + mock->ioctl_expected.gemUserptr = 1; + mock->ioctl_expected.gemWait = 1; + mock->ioctl_expected.gemClose = 1; + + std::vector dataToCopy(MemoryConstants::pageSize, 1u); + + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties({rootDeviceIndex, dataToCopy.size(), GraphicsAllocation::AllocationType::BUFFER, device->getDeviceBitfield()}); + ASSERT_NE(nullptr, allocation); + + auto ret = memoryManager->copyMemoryToAllocation(allocation, 0, dataToCopy.data(), dataToCopy.size()); + EXPECT_TRUE(ret); + + EXPECT_EQ(0, memcmp(allocation->getUnderlyingBuffer(), dataToCopy.data(), dataToCopy.size())); + + memoryManager->freeGraphicsMemory(allocation); +} + +TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenGetLocalMemoryIsCalledThenSizeOfLocalMemoryIsReturned) { + EXPECT_EQ(0 * GB, memoryManager->getLocalMemorySize(rootDeviceIndex, 0xF)); +} + } // namespace NEO