diff --git a/level_zero/core/source/context/context.h b/level_zero/core/source/context/context.h index de5eae731c..ad10ed2496 100644 --- a/level_zero/core/source/context/context.h +++ b/level_zero/core/source/context/context.h @@ -128,10 +128,6 @@ struct Context : _ze_context_handle_t { virtual ze_result_t createImage(ze_device_handle_t hDevice, const ze_image_desc_t *desc, ze_image_handle_t *phImage) = 0; - virtual NEO::MemoryManager *getMemoryManager() = 0; - virtual void setMemoryManager(NEO::MemoryManager *memoryManager) = 0; - virtual NEO::SVMAllocsManager *getSvmAllocsManager() = 0; - virtual void setSvmAllocsManager(NEO::SVMAllocsManager *) = 0; static Context *fromHandle(ze_context_handle_t handle) { return static_cast(handle); } inline ze_context_handle_t toHandle() { return this; } diff --git a/level_zero/core/source/context/context_imp.cpp b/level_zero/core/source/context/context_imp.cpp index 5c4a0cac45..c68d949bd6 100644 --- a/level_zero/core/source/context/context_imp.cpp +++ b/level_zero/core/source/context/context_imp.cpp @@ -18,11 +18,6 @@ namespace L0 { ze_result_t ContextImp::destroy() { - if (this->svmAllocsManager) { - delete this->svmAllocsManager; - this->svmAllocsManager = nullptr; - } - delete this; return ZE_RESULT_SUCCESS; @@ -83,8 +78,8 @@ ze_result_t ContextImp::allocHostMem(const ze_host_mem_alloc_desc_t *hostDesc, this->rootDeviceIndices, this->deviceBitfields); - auto usmPtr = this->driverHandle->getSvmAllocsManager()->createHostUnifiedMemoryAllocation(size, - unifiedMemoryProperties); + auto usmPtr = this->driverHandle->svmAllocsManager->createHostUnifiedMemoryAllocation(size, + unifiedMemoryProperties); if (usmPtr == nullptr) { return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY; } @@ -162,7 +157,7 @@ ze_result_t ContextImp::allocDeviceMem(ze_device_handle_t hDevice, } void *usmPtr = - this->driverHandle->getSvmAllocsManager()->createUnifiedMemoryAllocation(size, unifiedMemoryProperties); + this->driverHandle->svmAllocsManager->createUnifiedMemoryAllocation(size, unifiedMemoryProperties); if (usmPtr == nullptr) { return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; } @@ -221,9 +216,9 @@ ze_result_t ContextImp::allocSharedMem(ze_device_handle_t hDevice, } auto usmPtr = - this->driverHandle->getSvmAllocsManager()->createSharedUnifiedMemoryAllocation(size, - unifiedMemoryProperties, - static_cast(neoDevice->getSpecializedDevice())); + this->driverHandle->svmAllocsManager->createSharedUnifiedMemoryAllocation(size, + unifiedMemoryProperties, + static_cast(neoDevice->getSpecializedDevice())); if (usmPtr == nullptr) { return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; @@ -234,7 +229,7 @@ ze_result_t ContextImp::allocSharedMem(ze_device_handle_t hDevice, } ze_result_t ContextImp::freeMem(const void *ptr) { - auto allocation = this->driverHandle->getSvmAllocsManager()->getSVMAlloc(ptr); + auto allocation = this->driverHandle->svmAllocsManager->getSVMAlloc(ptr); if (allocation == nullptr) { return ZE_RESULT_ERROR_INVALID_ARGUMENT; } @@ -249,13 +244,13 @@ ze_result_t ContextImp::freeMem(const void *ptr) { auto peerAllocData = &iter->second; auto peerAlloc = peerAllocData->gpuAllocations.getDefaultGraphicsAllocation(); auto peerPtr = reinterpret_cast(peerAlloc->getGpuAddress()); - this->driverHandle->getSvmAllocsManager()->freeSVMAlloc(peerPtr); + this->driverHandle->svmAllocsManager->freeSVMAlloc(peerPtr); } } - this->driverHandle->getSvmAllocsManager()->freeSVMAlloc(const_cast(ptr)); - if (this->driverHandle->getSvmAllocsManager()->getSvmMapOperation(ptr)) { - this->driverHandle->getSvmAllocsManager()->removeSvmMapOperation(ptr); + this->driverHandle->svmAllocsManager->freeSVMAlloc(const_cast(ptr)); + if (this->driverHandle->svmAllocsManager->getSvmMapOperation(ptr)) { + this->driverHandle->svmAllocsManager->removeSvmMapOperation(ptr); } return ZE_RESULT_SUCCESS; } @@ -331,7 +326,7 @@ ze_result_t ContextImp::evictImage(ze_device_handle_t hDevice, ze_image_handle_t ze_result_t ContextImp::getMemAddressRange(const void *ptr, void **pBase, size_t *pSize) { - NEO::SvmAllocationData *allocData = this->driverHandle->getSvmAllocsManager()->getSVMAlloc(ptr); + NEO::SvmAllocationData *allocData = this->driverHandle->svmAllocsManager->getSVMAlloc(ptr); if (allocData) { NEO::GraphicsAllocation *alloc; alloc = allocData->gpuAllocations.getDefaultGraphicsAllocation(); @@ -356,7 +351,7 @@ ze_result_t ContextImp::closeIpcMemHandle(const void *ptr) { ze_result_t ContextImp::getIpcMemHandle(const void *ptr, ze_ipc_mem_handle_t *pIpcHandle) { - NEO::SvmAllocationData *allocData = this->driverHandle->getSvmAllocsManager()->getSVMAlloc(ptr); + NEO::SvmAllocationData *allocData = this->driverHandle->svmAllocsManager->getSVMAlloc(ptr); if (allocData) { uint64_t handle = allocData->gpuAllocations.getDefaultGraphicsAllocation()->peekInternalHandle(this->driverHandle->getMemoryManager()); memcpy_s(reinterpret_cast(pIpcHandle->data), @@ -390,7 +385,7 @@ ze_result_t ContextImp::openIpcMemHandle(ze_device_handle_t hDevice, ze_result_t ContextImp::getMemAllocProperties(const void *ptr, ze_memory_allocation_properties_t *pMemAllocProperties, ze_device_handle_t *phDevice) { - auto alloc = driverHandle->getSvmAllocsManager()->getSVMAlloc(ptr); + auto alloc = driverHandle->svmAllocsManager->getSVMAlloc(ptr); if (nullptr == alloc) { pMemAllocProperties->type = ZE_MEMORY_TYPE_UNKNOWN; return ZE_RESULT_SUCCESS; diff --git a/level_zero/core/source/context/context_imp.h b/level_zero/core/source/context/context_imp.h index 1f2ad8751b..f77b24d3d2 100644 --- a/level_zero/core/source/context/context_imp.h +++ b/level_zero/core/source/context/context_imp.h @@ -115,28 +115,11 @@ struct ContextImp : Context { return devices; } - NEO::MemoryManager *getMemoryManager() override { - return this->memoryManager; - } - void setMemoryManager(NEO::MemoryManager *memoryManager) override { - this->memoryManager = memoryManager; - } - NEO::SVMAllocsManager *getSvmAllocsManager() override { - return this->svmAllocsManager; - } - - void setSvmAllocsManager(NEO::SVMAllocsManager *svmManager) override { - this->svmAllocsManager = svmManager; - } - std::set rootDeviceIndices = {}; std::map deviceBitfields; bool isDeviceDefinedForThisContext(Device *inDevice); - NEO::MemoryManager *memoryManager = nullptr; - NEO::SVMAllocsManager *svmAllocsManager = nullptr; - protected: std::map devices; DriverHandleImp *driverHandle = nullptr; diff --git a/level_zero/core/source/driver/driver_handle.h b/level_zero/core/source/driver/driver_handle.h index ab2b123bb3..4ed9d17838 100644 --- a/level_zero/core/source/driver/driver_handle.h +++ b/level_zero/core/source/driver/driver_handle.h @@ -47,7 +47,6 @@ struct DriverHandle : _ze_driver_handle_t { bool *allocationRangeCovered) = 0; virtual NEO::SVMAllocsManager *getSvmAllocsManager() = 0; - virtual void setSvmAllocsManager(NEO::SVMAllocsManager *) = 0; virtual ze_result_t sysmanEventsListen(uint32_t timeout, uint32_t count, zes_device_handle_t *phDevices, uint32_t *pNumDeviceEvents, zes_event_type_flags_t *pEvents) = 0; virtual ze_result_t sysmanEventsListenEx(uint64_t timeout, uint32_t count, zes_device_handle_t *phDevices, diff --git a/level_zero/core/source/driver/driver_handle_imp.cpp b/level_zero/core/source/driver/driver_handle_imp.cpp index 3496b187aa..30038ddf81 100644 --- a/level_zero/core/source/driver/driver_handle_imp.cpp +++ b/level_zero/core/source/driver/driver_handle_imp.cpp @@ -53,48 +53,26 @@ ze_result_t DriverHandleImp::createContext(const ze_context_desc_t *desc, } } - bool multiOsContextDriver = false; for (auto devicePair : context->getDevices()) { auto neoDevice = devicePair.second->getNEODevice(); - multiOsContextDriver |= devicePair.second->isMultiDeviceCapable(); context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); } - if (this->mainContext == nullptr) { - this->mainContext = context; - - if (this->getMemoryManager() == nullptr) { - this->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager()); - } - - this->setSvmAllocsManager(new NEO::SVMAllocsManager(this->getMemoryManager(), multiOsContextDriver)); - - this->getMemoryManager()->setForceNonSvmForExternalHostPtr(true); - - if (NEO::DebugManager.flags.EnableHostPointerImport.get() == 1) { - createHostPointerManager(); - } - } - return ZE_RESULT_SUCCESS; } NEO::MemoryManager *DriverHandleImp::getMemoryManager() { - return this->mainContext->getMemoryManager(); + return this->memoryManager; } void DriverHandleImp::setMemoryManager(NEO::MemoryManager *memoryManager) { - this->mainContext->setMemoryManager(memoryManager); + this->memoryManager = memoryManager; } NEO::SVMAllocsManager *DriverHandleImp::getSvmAllocsManager() { - return this->mainContext->getSvmAllocsManager(); -} - -void DriverHandleImp::setSvmAllocsManager(NEO::SVMAllocsManager *svmManager) { - this->mainContext->setSvmAllocsManager(svmManager); + return this->svmAllocsManager; } ze_result_t DriverHandleImp::getApiVersion(ze_api_version_t *version) { @@ -155,6 +133,10 @@ DriverHandleImp::~DriverHandleImp() { for (auto &device : this->devices) { delete device; } + if (this->svmAllocsManager) { + delete this->svmAllocsManager; + this->svmAllocsManager = nullptr; + } } ze_result_t DriverHandleImp::initialize(std::vector> neoDevices) { @@ -169,6 +151,13 @@ ze_result_t DriverHandleImp::initialize(std::vector continue; } + if (this->memoryManager == nullptr) { + this->memoryManager = neoDevice->getMemoryManager(); + if (this->memoryManager == nullptr) { + return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY; + } + } + const auto rootDeviceIndex = neoDevice->getRootDeviceIndex(); auto rootDeviceEnvironment = neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[rootDeviceIndex].get(); @@ -200,12 +189,21 @@ ze_result_t DriverHandleImp::initialize(std::vector return ZE_RESULT_ERROR_UNINITIALIZED; } + this->svmAllocsManager = new NEO::SVMAllocsManager(memoryManager, multiOsContextDriver); + if (this->svmAllocsManager == nullptr) { + return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY; + } + this->numDevices = static_cast(this->devices.size()); extensionFunctionsLookupMap = getExtensionFunctionsLookupMap(); uuidTimestamp = static_cast(std::chrono::system_clock::now().time_since_epoch().count()); + if (NEO::DebugManager.flags.EnableHostPointerImport.get() == 1) { + createHostPointerManager(); + } + return ZE_RESULT_SUCCESS; } @@ -225,6 +223,8 @@ DriverHandle *DriverHandle::create(std::vector> dev GlobalDriver = driverHandle; + driverHandle->getMemoryManager()->setForceNonSvmForExternalHostPtr(true); + return driverHandle; } @@ -250,8 +250,8 @@ bool DriverHandleImp::findAllocationDataForRange(const void *buffer, NEO::SvmAllocationData **allocData) { // Make sure the host buffer does not overlap any existing allocation const char *baseAddress = reinterpret_cast(buffer); - NEO::SvmAllocationData *beginAllocData = getSvmAllocsManager()->getSVMAlloc(baseAddress); - NEO::SvmAllocationData *endAllocData = getSvmAllocsManager()->getSVMAlloc(baseAddress + size - 1); + NEO::SvmAllocationData *beginAllocData = svmAllocsManager->getSVMAlloc(baseAddress); + NEO::SvmAllocationData *endAllocData = svmAllocsManager->getSVMAlloc(baseAddress + size - 1); if (allocData) { if (beginAllocData) { @@ -275,8 +275,8 @@ std::vector DriverHandleImp::findAllocationsWithinRang std::vector allocDataArray; const char *baseAddress = reinterpret_cast(buffer); // Check if the host buffer overlaps any existing allocation - NEO::SvmAllocationData *beginAllocData = this->getSvmAllocsManager()->getSVMAlloc(baseAddress); - NEO::SvmAllocationData *endAllocData = this->getSvmAllocsManager()->getSVMAlloc(baseAddress + size - 1); + NEO::SvmAllocationData *beginAllocData = svmAllocsManager->getSVMAlloc(baseAddress); + NEO::SvmAllocationData *endAllocData = svmAllocsManager->getSVMAlloc(baseAddress + size - 1); // Add the allocation that matches the beginning address if (beginAllocData) { diff --git a/level_zero/core/source/driver/driver_handle_imp.h b/level_zero/core/source/driver/driver_handle_imp.h index 2dc60b9731..e73ed72f3d 100644 --- a/level_zero/core/source/driver/driver_handle_imp.h +++ b/level_zero/core/source/driver/driver_handle_imp.h @@ -10,13 +10,11 @@ #include "shared/source/os_interface/os_library.h" #include "level_zero/api/extensions/public/ze_exp_ext.h" -#include "level_zero/core/source/context/context.h" #include "level_zero/core/source/driver/driver_handle.h" #include "level_zero/core/source/get_extension_function_lookup_map.h" namespace L0 { class HostPointerManager; -struct Context; struct DriverHandleImp : public DriverHandle { ~DriverHandleImp() override; @@ -40,7 +38,6 @@ struct DriverHandleImp : public DriverHandle { ze_result_t openEventPoolIpcHandle(ze_ipc_event_pool_handle_t hIpc, ze_event_pool_handle_t *phEventPool) override; ze_result_t checkMemoryAccessFromDevice(Device *device, const void *ptr) override; NEO::SVMAllocsManager *getSvmAllocsManager() override; - void setSvmAllocsManager(NEO::SVMAllocsManager *) override; ze_result_t initialize(std::vector> neoDevices); bool findAllocationDataForRange(const void *buffer, size_t size, @@ -93,9 +90,10 @@ struct DriverHandleImp : public DriverHandle { uint64_t uuidTimestamp = 0u; - uint32_t numDevices = 0; + NEO::MemoryManager *memoryManager = nullptr; + NEO::SVMAllocsManager *svmAllocsManager = nullptr; - Context *mainContext = nullptr; + uint32_t numDevices = 0; std::set rootDeviceIndices = {}; std::map deviceBitfields; diff --git a/level_zero/core/source/event/event.cpp b/level_zero/core/source/event/event.cpp index 29552df251..e9ce50e9b3 100644 --- a/level_zero/core/source/event/event.cpp +++ b/level_zero/core/source/event/event.cpp @@ -96,7 +96,7 @@ ze_result_t EventPoolImp::initialize(DriverHandle *driver, Context *context, uin alignedSize, allocationType, false, - (deviceBitfield.count() > 1) && driverHandleImp->getSvmAllocsManager()->getMultiOsContextSupport(), + (deviceBitfield.count() > 1) && driverHandleImp->svmAllocsManager->getMultiOsContextSupport(), deviceBitfield}; unifiedMemoryProperties.flags.isUSMHostAllocation = true; unifiedMemoryProperties.flags.isUSMDeviceAllocation = false; diff --git a/level_zero/core/source/memory/memory.cpp b/level_zero/core/source/memory/memory.cpp index 1bc17fc58c..daaae4db61 100644 --- a/level_zero/core/source/memory/memory.cpp +++ b/level_zero/core/source/memory/memory.cpp @@ -51,7 +51,7 @@ void *DriverHandleImp::importFdHandle(ze_device_handle_t hDevice, ze_ipc_memory_ } ze_result_t DriverHandleImp::checkMemoryAccessFromDevice(Device *device, const void *ptr) { - auto allocation = this->getSvmAllocsManager()->getSVMAlloc(ptr); + auto allocation = svmAllocsManager->getSVMAlloc(ptr); if (allocation == nullptr) { return ZE_RESULT_ERROR_INVALID_ARGUMENT; } diff --git a/level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.h b/level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.h index 06fde406c2..48c19a88fc 100644 --- a/level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.h +++ b/level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.h @@ -31,23 +31,17 @@ class CommandListFixture : public DeviceFixture { eventDesc.wait = 0; eventDesc.signal = 0; - eventPool = EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc); - event = Event::create(eventPool, &eventDesc, device); + eventPool = std::unique_ptr(EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc)); + event = std::unique_ptr(Event::create(eventPool.get(), &eventDesc, device)); } void TearDown() override { - if (event) { - event->destroy(); - } - if (eventPool) { - eventPool->destroy(); - } DeviceFixture::TearDown(); } std::unique_ptr commandList; - EventPool *eventPool = nullptr; - Event *event = nullptr; + std::unique_ptr eventPool; + std::unique_ptr event; }; } // namespace ult diff --git a/level_zero/core/test/unit_tests/fixtures/device_fixture.h b/level_zero/core/test/unit_tests/fixtures/device_fixture.h index 43cf908720..715a0a1359 100644 --- a/level_zero/core/test/unit_tests/fixtures/device_fixture.h +++ b/level_zero/core/test/unit_tests/fixtures/device_fixture.h @@ -15,10 +15,7 @@ #include "opencl/test/unit_test/mocks/mock_compilers.h" #include "level_zero/core/source/context/context_imp.h" -#include "level_zero/core/test/unit_tests/mock.h" -#include "level_zero/core/test/unit_tests/mocks/mock_device.h" -#include "level_zero/core/test/unit_tests/mocks/mock_memory_manager.h" -#include "level_zero/core/test/unit_tests/white_box.h" +#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h" namespace L0 { struct Context; diff --git a/level_zero/core/test/unit_tests/fixtures/host_pointer_manager_fixture.h b/level_zero/core/test/unit_tests/fixtures/host_pointer_manager_fixture.h index 07875da62a..2b212761e3 100644 --- a/level_zero/core/test/unit_tests/fixtures/host_pointer_manager_fixture.h +++ b/level_zero/core/test/unit_tests/fixtures/host_pointer_manager_fixture.h @@ -19,6 +19,7 @@ #include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" #include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h" +#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h" #include "level_zero/core/test/unit_tests/mocks/mock_host_pointer_manager.h" namespace L0 { @@ -38,29 +39,29 @@ struct HostPointerManagerFixure { devices.push_back(std::unique_ptr(neoDevice)); DebugManager.flags.EnableHostPointerImport.set(1); - hostDriverHandle = std::make_unique(); + hostDriverHandle = std::make_unique(); hostDriverHandle->initialize(std::move(devices)); - - ze_context_desc_t desc; - ze_result_t ret = hostDriverHandle->createContext(&desc, 0u, nullptr, &hContext); - EXPECT_EQ(ZE_RESULT_SUCCESS, ret); - context = L0::Context::fromHandle(hContext); - device = hostDriverHandle->devices[0]; EXPECT_NE(nullptr, hostDriverHandle->hostPointerManager.get()); openHostPointerManager = static_cast(hostDriverHandle->hostPointerManager.get()); heapPointer = hostDriverHandle->getMemoryManager()->allocateSystemMemory(heapSize, MemoryConstants::pageSize); ASSERT_NE(nullptr, heapPointer); + + ze_context_desc_t desc; + ze_result_t ret = hostDriverHandle->createContext(&desc, 0u, nullptr, &hContext); + EXPECT_EQ(ZE_RESULT_SUCCESS, ret); + context = L0::Context::fromHandle(hContext); } void TearDown() { - hostDriverHandle->getMemoryManager()->freeSystemMemory(heapPointer); context->destroy(); + + hostDriverHandle->getMemoryManager()->freeSystemMemory(heapPointer); } DebugManagerStateRestore debugRestore; - std::unique_ptr hostDriverHandle; + std::unique_ptr hostDriverHandle; L0::ult::HostPointerManager *openHostPointerManager = nullptr; NEO::MockDevice *neoDevice = nullptr; diff --git a/level_zero/core/test/unit_tests/fixtures/module_fixture.h b/level_zero/core/test/unit_tests/fixtures/module_fixture.h index b27912f1eb..1443eee547 100644 --- a/level_zero/core/test/unit_tests/fixtures/module_fixture.h +++ b/level_zero/core/test/unit_tests/fixtures/module_fixture.h @@ -147,11 +147,11 @@ struct ModuleImmutableDataFixture : public DeviceFixture { ModuleBuildLog *moduleBuildLog = nullptr; - module = new MockModule(device, - moduleBuildLog, - ModuleType::User, - perHwThreadPrivateMemorySize, - mockKernelImmData); + module = std::make_unique(device, + moduleBuildLog, + ModuleType::User, + perHwThreadPrivateMemorySize, + mockKernelImmData); module->type = isInternal ? ModuleType::Builtin : ModuleType::User; bool result = module->initialize(&moduleDesc, device->getNEODevice()); @@ -165,16 +165,13 @@ struct ModuleImmutableDataFixture : public DeviceFixture { } void TearDown() override { - if (module) { - module->destroy(); - } DeviceFixture::TearDown(); } const std::string binaryFilename = "test_kernel"; const std::string kernelName = "test"; const uint32_t numKernelArguments = 6; - MockModule *module = nullptr; + std::unique_ptr module; MockImmutableMemoryManager *memoryManager; }; @@ -204,36 +201,27 @@ struct ModuleFixture : public DeviceFixture { ModuleBuildLog *moduleBuildLog = nullptr; - if (module) { - module->destroy(); - } - module = Module::create(device, &moduleDesc, moduleBuildLog, type); + module.reset(Module::create(device, &moduleDesc, moduleBuildLog, type)); } void createKernel() { ze_kernel_desc_t desc = {}; desc.pKernelName = kernelName.c_str(); - kernel = new WhiteBox<::L0::Kernel>(); - kernel->module = module; + kernel = std::make_unique>(); + kernel->module = module.get(); kernel->initialize(&desc); } void TearDown() override { - if (kernel) { - kernel->destroy(); - } - if (module) { - module->destroy(); - } DeviceFixture::TearDown(); } const std::string binaryFilename = "test_kernel"; const std::string kernelName = "test"; const uint32_t numKernelArguments = 6; - L0::Module *module = nullptr; - WhiteBox<::L0::Kernel> *kernel = nullptr; + std::unique_ptr module; + std::unique_ptr> kernel; }; struct MultiDeviceModuleFixture : public MultiDeviceFixture { @@ -260,35 +248,29 @@ struct MultiDeviceModuleFixture : public MultiDeviceFixture { ModuleBuildLog *moduleBuildLog = nullptr; auto device = driverHandle->devices[rootDeviceIndex]; - modules[rootDeviceIndex] = Module::create(device, - &moduleDesc, - moduleBuildLog, ModuleType::User); + modules[rootDeviceIndex].reset(Module::create(device, + &moduleDesc, + moduleBuildLog, ModuleType::User)); } void createKernel(uint32_t rootDeviceIndex) { ze_kernel_desc_t desc = {}; desc.pKernelName = kernelName.c_str(); - kernel = new WhiteBox<::L0::Kernel>(); - kernel->module = modules[rootDeviceIndex]; + kernel = std::make_unique>(); + kernel->module = modules[rootDeviceIndex].get(); kernel->initialize(&desc); } void TearDown() override { - if (kernel) { - kernel->destroy(); - } - for (auto &module : modules) { - module->destroy(); - } MultiDeviceFixture::TearDown(); } const std::string binaryFilename = "test_kernel"; const std::string kernelName = "test"; const uint32_t numKernelArguments = 6; - std::vector modules; - WhiteBox<::L0::Kernel> *kernel = nullptr; + std::vector> modules; + std::unique_ptr> kernel; }; struct ImportHostPointerModuleFixture : public ModuleFixture { diff --git a/level_zero/core/test/unit_tests/gen11/test_cmdqueue_thread_arbitration_policy_gen11.cpp b/level_zero/core/test/unit_tests/gen11/test_cmdqueue_thread_arbitration_policy_gen11.cpp index be38968d9b..07c717ebd0 100644 --- a/level_zero/core/test/unit_tests/gen11/test_cmdqueue_thread_arbitration_policy_gen11.cpp +++ b/level_zero/core/test/unit_tests/gen11/test_cmdqueue_thread_arbitration_policy_gen11.cpp @@ -13,7 +13,6 @@ #include "opencl/test/unit_test/mocks/mock_compilers.h" #include "test.h" -#include "level_zero/core/source/context/context_imp.h" #include "level_zero/core/source/driver/driver_imp.h" #include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" #include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h" @@ -39,13 +38,8 @@ struct CommandQueueThreadArbitrationPolicyTests : public ::testing::Test { auto driverHandleUlt = whitebox_cast(DriverHandle::create(std::move(devices), L0EnvVariables{}, &returnValue)); driverHandle.reset(driverHandleUlt); - ASSERT_NE(nullptr, driverHandle); - ze_context_handle_t hContext; - ze_context_desc_t desc = {}; - returnValue = driverHandle->createContext(&desc, 0u, nullptr, &hContext); - EXPECT_EQ(ZE_RESULT_SUCCESS, returnValue); - context = static_cast(Context::fromHandle(hContext)); + ASSERT_NE(nullptr, driverHandle); ze_device_handle_t hDevice; uint32_t count = 1; @@ -69,7 +63,6 @@ struct CommandQueueThreadArbitrationPolicyTests : public ::testing::Test { void TearDown() override { commandList->destroy(); commandQueue->destroy(); - context->destroy(); L0::GlobalDriver = nullptr; } @@ -79,7 +72,6 @@ struct CommandQueueThreadArbitrationPolicyTests : public ::testing::Test { std::unique_ptr> driverHandle; NEO::MockDevice *neoDevice = nullptr; L0::Device *device; - L0::ContextImp *context = nullptr; }; HWTEST2_F(CommandQueueThreadArbitrationPolicyTests, diff --git a/level_zero/core/test/unit_tests/gen12lp/test_events_gen12lp.cpp b/level_zero/core/test/unit_tests/gen12lp/test_events_gen12lp.cpp index 3a3ed9008b..4cc8bbea23 100644 --- a/level_zero/core/test/unit_tests/gen12lp/test_events_gen12lp.cpp +++ b/level_zero/core/test/unit_tests/gen12lp/test_events_gen12lp.cpp @@ -32,20 +32,18 @@ struct TimestampEvent : public Test { eventDesc.signal = 0; eventDesc.wait = 0; - eventPool = L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc); + eventPool = std::unique_ptr(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc)); ASSERT_NE(nullptr, eventPool); - event = L0::Event::create(eventPool, &eventDesc, device); + event = std::unique_ptr(L0::Event::create(eventPool.get(), &eventDesc, device)); ASSERT_NE(nullptr, event); } void TearDown() override { - event->destroy(); - eventPool->destroy(); DeviceFixture::TearDown(); } - L0::EventPool *eventPool = nullptr; - L0::Event *event = nullptr; + std::unique_ptr eventPool; + std::unique_ptr event; }; GEN12LPTEST_F(TimestampEvent, givenEventTimestampsWhenQueryKernelTimestampThenCorrectDataAreSet) { diff --git a/level_zero/core/test/unit_tests/gen9/test_cmdqueue_gen9.cpp b/level_zero/core/test/unit_tests/gen9/test_cmdqueue_gen9.cpp index 7817807c8d..bcd31f195f 100644 --- a/level_zero/core/test/unit_tests/gen9/test_cmdqueue_gen9.cpp +++ b/level_zero/core/test/unit_tests/gen9/test_cmdqueue_gen9.cpp @@ -14,7 +14,6 @@ #include "test.h" #include "level_zero/core/source/cmdqueue/cmdqueue_imp.h" -#include "level_zero/core/source/context/context_imp.h" #include "level_zero/core/source/driver/driver_handle_imp.h" #include "level_zero/core/source/driver/driver_imp.h" #include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" @@ -41,13 +40,8 @@ struct CommandQueueThreadArbitrationPolicyTests : public ::testing::Test { auto driverHandleUlt = whitebox_cast(DriverHandle::create(std::move(devices), L0EnvVariables{}, &returnValue)); driverHandle.reset(driverHandleUlt); - ASSERT_NE(nullptr, driverHandle); - ze_context_handle_t hContext; - ze_context_desc_t desc = {}; - returnValue = driverHandle->createContext(&desc, 0u, nullptr, &hContext); - EXPECT_EQ(ZE_RESULT_SUCCESS, returnValue); - context = static_cast(Context::fromHandle(hContext)); + ASSERT_NE(nullptr, driverHandle); ze_device_handle_t hDevice; uint32_t count = 1; @@ -71,7 +65,6 @@ struct CommandQueueThreadArbitrationPolicyTests : public ::testing::Test { void TearDown() override { commandList->destroy(); commandQueue->destroy(); - context->destroy(); L0::GlobalDriver = nullptr; } @@ -81,7 +74,6 @@ struct CommandQueueThreadArbitrationPolicyTests : public ::testing::Test { std::unique_ptr> driverHandle; NEO::MockDevice *neoDevice = nullptr; L0::Device *device; - L0::ContextImp *context = nullptr; }; HWTEST2_F(CommandQueueThreadArbitrationPolicyTests, diff --git a/level_zero/core/test/unit_tests/mocks/CMakeLists.txt b/level_zero/core/test/unit_tests/mocks/CMakeLists.txt index 17ff27c814..4866bf7b80 100644 --- a/level_zero/core/test/unit_tests/mocks/CMakeLists.txt +++ b/level_zero/core/test/unit_tests/mocks/CMakeLists.txt @@ -25,6 +25,8 @@ set(L0_MOCKS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/mock_device_recompile_built_ins.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_driver.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_driver.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/mock_driver_handle.h + ${CMAKE_CURRENT_SOURCE_DIR}/mock_driver_handle.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_event.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_event.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_resource_info_l0.cpp diff --git a/level_zero/core/test/unit_tests/mocks/mock_driver_handle.cpp b/level_zero/core/test/unit_tests/mocks/mock_driver_handle.cpp new file mode 100644 index 0000000000..dcec1ef5ed --- /dev/null +++ b/level_zero/core/test/unit_tests/mocks/mock_driver_handle.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2019-2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h" + +#include "shared/test/common/mocks/mock_graphics_allocation.h" + +#include "level_zero/core/source/driver/host_pointer_manager.h" + +namespace L0 { +namespace ult { + +using MockDriverHandle = Mock; +using namespace testing; +using ::testing::Invoke; +using ::testing::Return; + +Mock::Mock() = default; + +NEO::MemoryManager *Mock::getMemoryManager() { + return memoryManager; +} + +NEO::SVMAllocsManager *Mock::getSvmAllocManager() { + return svmAllocsManager; +} + +ze_result_t Mock::getDevice(uint32_t *pCount, ze_device_handle_t *phDevices) { + if (*pCount == 0) { // User wants to know number of devices + *pCount = this->num_devices; + return ZE_RESULT_SUCCESS; + } + + if (phDevices == nullptr) // User is expected to allocate space + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + + phDevices[0] = &this->device; + + return ZE_RESULT_SUCCESS; +} + +ze_result_t Mock::allocDeviceMem(ze_device_handle_t hDevice, const ze_device_mem_alloc_desc_t *deviceDesc, + size_t size, size_t alignment, void **ptr) { + NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::DEVICE_UNIFIED_MEMORY, rootDeviceIndices, deviceBitfields); + + auto allocation = svmAllocsManager->createUnifiedMemoryAllocation(size, unifiedMemoryProperties); + + if (allocation == nullptr) { + return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; + } + + *ptr = allocation; + + return ZE_RESULT_SUCCESS; +} + +ze_result_t Mock::freeMem(const void *ptr) { + auto allocation = svmAllocsManager->getSVMAlloc(ptr); + if (allocation == nullptr) { + return ZE_RESULT_ERROR_INVALID_ARGUMENT; + } + svmAllocsManager->freeSVMAlloc(const_cast(ptr)); + if (svmAllocsManager->getSvmMapOperation(ptr)) { + svmAllocsManager->removeSvmMapOperation(ptr); + } + return ZE_RESULT_SUCCESS; +} + +void Mock::setupDevices(std::vector> neoDevices) { + this->numDevices = static_cast(neoDevices.size()); + for (auto &neoDevice : neoDevices) { + ze_result_t returnValue = ZE_RESULT_SUCCESS; + this->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); + this->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); + auto device = Device::create(this, neoDevice.release(), std::numeric_limits::max(), false, &returnValue); + this->devices.push_back(device); + } +} + +Mock::~Mock(){}; + +} // namespace ult +} // namespace L0 diff --git a/level_zero/core/test/unit_tests/mocks/mock_driver_handle.h b/level_zero/core/test/unit_tests/mocks/mock_driver_handle.h new file mode 100644 index 0000000000..baf3e496c7 --- /dev/null +++ b/level_zero/core/test/unit_tests/mocks/mock_driver_handle.h @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2019-2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once +#include "level_zero/core/source/driver/driver_handle_imp.h" +#include "level_zero/core/test/unit_tests/mock.h" +#include "level_zero/core/test/unit_tests/mocks/mock_device.h" +#include "level_zero/core/test/unit_tests/mocks/mock_memory_manager.h" +#include "level_zero/core/test/unit_tests/white_box.h" + +namespace L0 { +namespace ult { + +template <> +struct WhiteBox<::L0::DriverHandle> : public ::L0::DriverHandleImp { + using ::L0::DriverHandleImp::enableProgramDebugging; +}; + +using DriverHandle = WhiteBox<::L0::DriverHandle>; +#define ADDMETHOD_NOBASE(funcName, retType, defaultReturn, funcParams) \ + retType funcName##Result = defaultReturn; \ + uint32_t funcName##Called = 0u; \ + retType funcName funcParams override { \ + funcName##Called++; \ + return funcName##Result; \ + } + +template <> +struct Mock : public DriverHandleImp { + Mock(); + ~Mock() override; + + ADDMETHOD_NOBASE(getProperties, ze_result_t, ZE_RESULT_SUCCESS, (ze_driver_properties_t * properties)) + ADDMETHOD_NOBASE(getApiVersion, ze_result_t, ZE_RESULT_SUCCESS, (ze_api_version_t * version)) + ADDMETHOD_NOBASE(getIPCProperties, ze_result_t, ZE_RESULT_SUCCESS, (ze_driver_ipc_properties_t * pIPCProperties)) + + uint32_t num_devices = 1; + Mock device; + + void setupDevices(std::vector> devices); + + ze_result_t freeMem(const void *ptr); + ze_result_t getDevice(uint32_t *pCount, + ze_device_handle_t *phDevices) override; + NEO::MemoryManager *getMemoryManager() override; + NEO::SVMAllocsManager *getSvmAllocManager(); + ze_result_t allocDeviceMem(ze_device_handle_t hDevice, + const ze_device_mem_alloc_desc_t *deviceDesc, + size_t size, + size_t alignment, + void **ptr); + + ze_result_t importExternalPointer(void *ptr, size_t size) override { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + ze_result_t releaseImportedPointer(void *ptr) override { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + ze_result_t getHostPointerBaseAddress(void *ptr, void **baseAddress) override { + return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; + } + + NEO::GraphicsAllocation *findHostPointerAllocation(void *ptr, size_t size, uint32_t rootDeviceIndex) override { + return nullptr; + } + NEO::GraphicsAllocation *getDriverSystemMemoryAllocation(void *ptr, + size_t size, + uint32_t rootDeviceIndex, + uintptr_t *gpuAddress) override { + auto svmData = svmAllocsManager->getSVMAlloc(ptr); + if (svmData != nullptr) { + if (gpuAddress != nullptr) { + *gpuAddress = reinterpret_cast(ptr); + } + return svmData->gpuAllocations.getGraphicsAllocation(rootDeviceIndex); + } + return nullptr; + } +}; +#undef ADDMETHOD_NOBASE +} // namespace ult +} // namespace L0 diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_launch_kernel.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_launch_kernel.cpp index 75f1a2016c..5963cffa8a 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_launch_kernel.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_launch_kernel.cpp @@ -200,7 +200,7 @@ HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithPrintfUsedWhenAppendedToC EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_EQ(1u, commandList->getPrintfFunctionContainer().size()); - EXPECT_EQ(kernel, commandList->getPrintfFunctionContainer()[0]); + EXPECT_EQ(kernel.get(), commandList->getPrintfFunctionContainer()[0]); } HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithPrintfUsedWhenAppendedToCommandListMultipleTimesThenKernelIsStoredOnce) { @@ -215,7 +215,7 @@ HWTEST_F(CommandListAppendLaunchKernel, givenKernelWithPrintfUsedWhenAppendedToC EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_EQ(1u, commandList->getPrintfFunctionContainer().size()); - EXPECT_EQ(kernel, commandList->getPrintfFunctionContainer()[0]); + EXPECT_EQ(kernel.get(), commandList->getPrintfFunctionContainer()[0]); result = commandList->appendLaunchKernel(kernel->toHandle(), &groupCount, nullptr, 0, nullptr); EXPECT_EQ(ZE_RESULT_SUCCESS, result); @@ -526,9 +526,9 @@ HWTEST_F(CommandListAppendLaunchKernel, givenIndirectDispatchWhenAppendingThenWo using MI_LOAD_REGISTER_REG = typename FamilyType::MI_LOAD_REGISTER_REG; using MI_LOAD_REGISTER_IMM = typename FamilyType::MI_LOAD_REGISTER_IMM; - Mock<::L0::Kernel> mockKernel; - mockKernel.descriptor.payloadMappings.dispatchTraits.numWorkGroups[0] = 2; - mockKernel.descriptor.payloadMappings.dispatchTraits.globalWorkSize[0] = 2; + Mock<::L0::Kernel> kernel; + kernel.descriptor.payloadMappings.dispatchTraits.numWorkGroups[0] = 2; + kernel.descriptor.payloadMappings.dispatchTraits.globalWorkSize[0] = 2; ze_result_t returnValue; std::unique_ptr commandList(L0::CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, returnValue)); @@ -537,7 +537,7 @@ HWTEST_F(CommandListAppendLaunchKernel, givenIndirectDispatchWhenAppendingThenWo auto result = context->allocDeviceMem(device->toHandle(), &deviceDesc, 16384u, 4096u, &alloc); ASSERT_EQ(ZE_RESULT_SUCCESS, result); - result = commandList->appendLaunchKernelIndirect(mockKernel.toHandle(), + result = commandList->appendLaunchKernelIndirect(kernel.toHandle(), static_cast(alloc), nullptr, 0, nullptr); EXPECT_EQ(ZE_RESULT_SUCCESS, result); diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_wait_on_events.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_wait_on_events.cpp index ad7cd11317..3816d8e47f 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_wait_on_events.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_wait_on_events.cpp @@ -112,7 +112,7 @@ HWTEST_F(CommandListAppendWaitOnEvent, givenEventWithWaitScopeFlagDeviceWhenAppe 0, ZE_EVENT_SCOPE_FLAG_DEVICE}; - auto event = std::unique_ptr(Event::create(eventPool, &eventDesc, device)); + auto event = std::unique_ptr(Event::create(eventPool.get(), &eventDesc, device)); ze_event_handle_t hEventHandle = event->toHandle(); auto result = commandList->appendWaitOnEvents(1, &hEventHandle); diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_blit.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_blit.cpp index 1fd5d35af3..fcdad32d98 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_blit.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_blit.cpp @@ -85,19 +85,11 @@ HWTEST2_F(AppendMemoryCopy, givenCopyOnlyCommandListWhenAppenBlitFillThenCopyBlt using GfxFamily = typename NEO::GfxFamilyMapper::GfxFamily; using XY_COLOR_BLT = typename GfxFamily::XY_COLOR_BLT; MockCommandListForMemFill commandList; - MockDriverHandle driverHandleMock; NEO::DeviceVector neoDevices; neoDevices.push_back(std::unique_ptr(neoDevice)); driverHandleMock.initialize(std::move(neoDevices)); device->setDriverHandle(&driverHandleMock); - - ze_context_handle_t hContext; - ze_context_desc_t desc; - ze_result_t res = driverHandleMock.createContext(&desc, 0u, nullptr, &hContext); - EXPECT_EQ(ZE_RESULT_SUCCESS, res); - L0::ContextImp *contextDriverMock = static_cast(Context::fromHandle(hContext)); - commandList.initialize(device, NEO::EngineGroupType::Copy); uint16_t pattern = 1; void *ptr = reinterpret_cast(0x1234); @@ -107,7 +99,6 @@ HWTEST2_F(AppendMemoryCopy, givenCopyOnlyCommandListWhenAppenBlitFillThenCopyBlt cmdList, ptrOffset(commandList.commandContainer.getCommandStream()->getCpuBase(), 0), commandList.commandContainer.getCommandStream()->getUsed())); auto itor = find(cmdList.begin(), cmdList.end()); EXPECT_NE(cmdList.end(), itor); - contextDriverMock->destroy(); device->setDriverHandle(driverHandle.get()); } diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_fill.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_fill.cpp index f93a7e036c..4cb01c6183 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_fill.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_fill.cpp @@ -80,18 +80,11 @@ class AppendFillFixture : public DeviceFixture, public ::testing::Test { driverHandle = std::make_unique>(); driverHandle->initialize(std::move(devices)); device = driverHandle->devices[0]; - - ze_context_handle_t hContext; - ze_context_desc_t desc; - ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext); - EXPECT_EQ(ZE_RESULT_SUCCESS, res); - context = static_cast(Context::fromHandle(hContext)); } void TearDown() override { delete[] immediateDstPtr; delete[] dstPtr; - context->destroy(); } std::unique_ptr> driverHandle; @@ -101,7 +94,6 @@ class AppendFillFixture : public DeviceFixture, public ::testing::Test { static constexpr size_t patternSize = 8; uint8_t *dstPtr = nullptr; uint8_t pattern[patternSize] = {1, 2, 3, 4}; - L0::ContextImp *context = nullptr; static constexpr size_t immediateAllocSize = 106; uint8_t immediatePattern = 4; diff --git a/level_zero/core/test/unit_tests/sources/context/test_context.cpp b/level_zero/core/test/unit_tests/sources/context/test_context.cpp index 330c939fc2..cb4b976ce9 100644 --- a/level_zero/core/test/unit_tests/sources/context/test_context.cpp +++ b/level_zero/core/test/unit_tests/sources/context/test_context.cpp @@ -17,6 +17,7 @@ #include "level_zero/core/source/image/image.h" #include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" #include "level_zero/core/test/unit_tests/fixtures/host_pointer_manager_fixture.h" +#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h" #include "gtest/gtest.h" @@ -158,9 +159,23 @@ struct ContextHostAllocTests : public ::testing::Test { driverHandle = std::make_unique(); ze_result_t res = driverHandle->initialize(std::move(devices)); EXPECT_EQ(ZE_RESULT_SUCCESS, res); + + prevSvmAllocsManager = driverHandle->svmAllocsManager; + currSvmAllocsManager = new SVMAllocsManagerContextMock(driverHandle->memoryManager); + driverHandle->svmAllocsManager = currSvmAllocsManager; + + zeDevices.resize(numberOfDevicesInContext); + driverHandle->getDevice(&numberOfDevicesInContext, zeDevices.data()); + + for (uint32_t i = 0; i < numberOfDevicesInContext; i++) { + L0::DeviceImp *deviceImp = static_cast(L0::Device::fromHandle(zeDevices[i])); + currSvmAllocsManager->expectedRootDeviceIndexes.push_back(deviceImp->getRootDeviceIndex()); + } } void TearDown() override { + driverHandle->svmAllocsManager = prevSvmAllocsManager; + delete currSvmAllocsManager; } DebugManagerStateRestore restorer; @@ -174,9 +189,6 @@ struct ContextHostAllocTests : public ::testing::Test { TEST_F(ContextHostAllocTests, whenAllocatingHostMemoryOnlyIndexesOfDevicesWithinTheContextAreUsed) { - zeDevices.resize(numberOfDevicesInContext); - driverHandle->getDevice(&numberOfDevicesInContext, zeDevices.data()); - L0::ContextImp *context = nullptr; ze_context_handle_t hContext; ze_context_desc_t desc; @@ -187,15 +199,6 @@ TEST_F(ContextHostAllocTests, EXPECT_EQ(ZE_RESULT_SUCCESS, res); context = static_cast(Context::fromHandle(hContext)); - prevSvmAllocsManager = context->getSvmAllocsManager(); - currSvmAllocsManager = new SVMAllocsManagerContextMock(context->getMemoryManager()); - context->setSvmAllocsManager(currSvmAllocsManager); - - for (uint32_t i = 0; i < numberOfDevicesInContext; i++) { - L0::DeviceImp *deviceImp = static_cast(L0::Device::fromHandle(zeDevices[i])); - currSvmAllocsManager->expectedRootDeviceIndexes.push_back(deviceImp->getRootDeviceIndex()); - } - void *hostPtr = nullptr; ze_host_mem_alloc_desc_t hostDesc = {}; size_t size = 1024; @@ -206,9 +209,6 @@ TEST_F(ContextHostAllocTests, res = context->freeMem(hostPtr); EXPECT_EQ(ZE_RESULT_SUCCESS, res); - context->setSvmAllocsManager(prevSvmAllocsManager); - delete currSvmAllocsManager; - context->destroy(); } diff --git a/level_zero/core/test/unit_tests/sources/debugger/active_debugger_fixture.h b/level_zero/core/test/unit_tests/sources/debugger/active_debugger_fixture.h index 6687c7f8ad..f1ec675a50 100644 --- a/level_zero/core/test/unit_tests/sources/debugger/active_debugger_fixture.h +++ b/level_zero/core/test/unit_tests/sources/debugger/active_debugger_fixture.h @@ -14,13 +14,13 @@ #include "opencl/test/unit_test/mocks/mock_source_level_debugger.h" #include "level_zero/core/source/cmdqueue/cmdqueue_hw.h" -#include "level_zero/core/source/context/context_imp.h" #include "level_zero/core/source/driver/driver_handle_imp.h" #include "level_zero/core/source/fence/fence.h" #include "level_zero/core/source/module/module.h" #include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h" #include "level_zero/core/test/unit_tests/mocks/mock_device.h" #include "level_zero/core/test/unit_tests/mocks/mock_driver.h" +#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h" #include "level_zero/core/test/unit_tests/mocks/mock_memory_manager.h" namespace L0 { @@ -54,12 +54,6 @@ struct ActiveDebuggerFixture { ASSERT_NE(nullptr, driverHandle); - ze_context_handle_t hContext; - ze_context_desc_t desc; - ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext); - EXPECT_EQ(ZE_RESULT_SUCCESS, res); - context = static_cast(Context::fromHandle(hContext)); - ze_device_handle_t hDevice; uint32_t count = 1; ze_result_t result = driverHandle->getDevice(&count, &hDevice); @@ -68,7 +62,6 @@ struct ActiveDebuggerFixture { ASSERT_NE(nullptr, deviceL0); } void TearDown() { // NOLINT(readability-identifier-naming) - context->destroy(); L0::GlobalDriver = nullptr; } @@ -77,7 +70,6 @@ struct ActiveDebuggerFixture { L0::Device *deviceL0; MockActiveSourceLevelDebugger *debugger = nullptr; HardwareInfo hwInfo; - L0::ContextImp *context = nullptr; }; } // namespace ult } // namespace L0 diff --git a/level_zero/core/test/unit_tests/sources/debugger/l0_debugger_fixture.h b/level_zero/core/test/unit_tests/sources/debugger/l0_debugger_fixture.h index 6457513aa1..df30b315ac 100644 --- a/level_zero/core/test/unit_tests/sources/debugger/l0_debugger_fixture.h +++ b/level_zero/core/test/unit_tests/sources/debugger/l0_debugger_fixture.h @@ -38,23 +38,15 @@ struct L0DebuggerFixture { driverHandle->initialize(std::move(devices)); device = driverHandle->devices[0]; - - ze_context_handle_t hContext; - ze_context_desc_t desc; - ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext); - EXPECT_EQ(ZE_RESULT_SUCCESS, res); - context = static_cast(Context::fromHandle(hContext)); } void TearDown() { - context->destroy(); } std::unique_ptr> driverHandle; NEO::MockDevice *neoDevice = nullptr; L0::Device *device = nullptr; NEO::HardwareInfo hwInfo; - L0::ContextImp *context = nullptr; }; struct L0DebuggerHwFixture : public L0DebuggerFixture { diff --git a/level_zero/core/test/unit_tests/sources/device/test_device.cpp b/level_zero/core/test/unit_tests/sources/device/test_device.cpp index 3f37df1ccf..4e2ae799f4 100644 --- a/level_zero/core/test/unit_tests/sources/device/test_device.cpp +++ b/level_zero/core/test/unit_tests/sources/device/test_device.cpp @@ -23,11 +23,8 @@ #include "level_zero/core/source/context/context_imp.h" #include "level_zero/core/source/driver/driver_handle_imp.h" #include "level_zero/core/source/driver/host_pointer_manager.h" -#include "level_zero/core/test/unit_tests/mock.h" #include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h" -#include "level_zero/core/test/unit_tests/mocks/mock_device.h" -#include "level_zero/core/test/unit_tests/mocks/mock_memory_manager.h" -#include "level_zero/core/test/unit_tests/white_box.h" +#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h" #include "gtest/gtest.h" @@ -195,16 +192,6 @@ struct DeviceTest : public ::testing::Test { driverHandle = std::make_unique>(); driverHandle->initialize(std::move(devices)); device = driverHandle->devices[0]; - - ze_context_handle_t hContext; - ze_context_desc_t desc; - ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext); - EXPECT_EQ(ZE_RESULT_SUCCESS, res); - context = static_cast(Context::fromHandle(hContext)); - } - - void TearDown() override { - context->destroy(); } DebugManagerStateRestore restorer; @@ -213,7 +200,6 @@ struct DeviceTest : public ::testing::Test { L0::Device *device = nullptr; const uint32_t rootDeviceIndex = 1u; const uint32_t numRootDevices = 2u; - L0::ContextImp *context = nullptr; }; TEST_F(DeviceTest, givenEmptySVmAllocStorageWhenAllocateManagedMemoryFromHostPtrThenBufferHostAllocationIsCreated) { @@ -262,19 +248,12 @@ struct DeviceHostPointerTest : public ::testing::Test { driverHandle = std::make_unique>(); driverHandle->initialize(std::move(devices)); - ze_context_handle_t hContext; - ze_context_desc_t desc; - ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext); - EXPECT_EQ(ZE_RESULT_SUCCESS, res); - context = static_cast(Context::fromHandle(hContext)); - static_cast(driverHandle.get()->getMemoryManager())->isMockHostMemoryManager = true; static_cast(driverHandle.get()->getMemoryManager())->forceFailureInAllocationWithHostPointer = true; device = driverHandle->devices[0]; } void TearDown() override { - context->destroy(); } NEO::ExecutionEnvironment *executionEnvironment = nullptr; @@ -283,7 +262,6 @@ struct DeviceHostPointerTest : public ::testing::Test { L0::Device *device = nullptr; const uint32_t rootDeviceIndex = 1u; const uint32_t numRootDevices = 2u; - L0::ContextImp *context = nullptr; }; TEST_F(DeviceHostPointerTest, givenHostPointerNotAcceptedByKernelThenNewAllocationIsCreatedAndHostPointerCopied) { diff --git a/level_zero/core/test/unit_tests/sources/driver/test_driver.cpp b/level_zero/core/test/unit_tests/sources/driver/test_driver.cpp index 2ac10749aa..918c82e3fc 100644 --- a/level_zero/core/test/unit_tests/sources/driver/test_driver.cpp +++ b/level_zero/core/test/unit_tests/sources/driver/test_driver.cpp @@ -165,11 +165,10 @@ TEST(DriverTest, givenNullEnvVariableWhenCreatingDriverThenEnableProgramDebuggin L0EnvVariables envVariables = {}; envVariables.programDebugging = false; - auto driverHandle = DriverHandle::create(std::move(devices), envVariables, &returnValue); + auto driverHandle = whitebox_cast(DriverHandle::create(std::move(devices), envVariables, &returnValue)); EXPECT_NE(nullptr, driverHandle); - DriverHandleImp *driverHandleImp = static_cast(driverHandle); - EXPECT_FALSE(driverHandleImp->enableProgramDebugging); + EXPECT_FALSE(driverHandle->enableProgramDebugging); delete driverHandle; L0::GlobalDriver = nullptr; @@ -263,11 +262,10 @@ TEST(DriverTest, givenProgramDebuggingEnvVarNonZeroWhenCreatingDriverThenEnableP L0EnvVariables envVariables = {}; envVariables.programDebugging = true; - auto driverHandle = DriverHandle::create(std::move(devices), envVariables, &returnValue); + auto driverHandle = whitebox_cast(DriverHandle::create(std::move(devices), envVariables, &returnValue)); EXPECT_NE(nullptr, driverHandle); - DriverHandleImp *driverHandleImp = static_cast(driverHandle); - EXPECT_TRUE(driverHandleImp->enableProgramDebugging); + EXPECT_TRUE(driverHandle->enableProgramDebugging); delete driverHandle; L0::GlobalDriver = nullptr; @@ -383,21 +381,13 @@ struct DriverHandleTest : public ::testing::Test { driverHandle = whitebox_cast(DriverHandle::create(std::move(devices), envVariables, &returnValue)); L0::GlobalDriverHandle = driverHandle; - - ze_context_handle_t hContext; - ze_context_desc_t desc; - ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext); - EXPECT_EQ(ZE_RESULT_SUCCESS, res); - context = static_cast(Context::fromHandle(hContext)); } void TearDown() override { - context->destroy(); delete driverHandle; L0::GlobalDriver = nullptr; L0::GlobalDriverHandle = nullptr; } - L0::DriverHandle *driverHandle = nullptr; - L0::ContextImp *context = nullptr; + L0::DriverHandle *driverHandle; }; TEST_F(DriverHandleTest, givenInitializedDriverWhenZeDriverGetIsCalledThenDriverHandleCountIsObtained) { @@ -461,9 +451,11 @@ TEST_F(DriverHandleTest, givenInitializedDriverWhenZeDriverGetIsCalledThenGlobal } TEST_F(DriverHandleTest, givenInitializedDriverWhenGetDeviceIsCalledThenOneDeviceIsObtained) { + ze_result_t result; uint32_t count = 1; + ze_device_handle_t device; - ze_result_t result = driverHandle->getDevice(&count, &device); + result = driverHandle->getDevice(&count, &device); EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_NE(nullptr, &device); } @@ -473,37 +465,40 @@ TEST_F(DriverHandleTest, givenValidDriverHandleWhenGetSvmAllocManagerIsCalledThe EXPECT_NE(nullptr, svmAllocsManager); } -TEST_F(DriverHandleTest, whenZeDriverGetPropertiesIsCalledThenSuccessIsReturned) { - ze_driver_properties_t properties = {}; - ze_result_t result = zeDriverGetProperties(driverHandle->toHandle(), &properties); - EXPECT_EQ(ZE_RESULT_SUCCESS, result); +TEST(zeDriverHandleGetProperties, whenZeDriverGetPropertiesIsCalledThenGetPropertiesIsCalled) { + ze_result_t result; + Mock driverHandle; + ze_driver_properties_t properties; + ze_result_t expectedResult = ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS; + + driverHandle.getPropertiesResult = expectedResult; + result = zeDriverGetProperties(driverHandle.toHandle(), &properties); + EXPECT_EQ(expectedResult, result); + EXPECT_EQ(1u, driverHandle.getPropertiesCalled); } -TEST_F(DriverHandleTest, whenZeDriverGetApiIsCalledThenSuccessIsReturned) { - ze_api_version_t version = {}; - ze_result_t result = zeDriverGetApiVersion(driverHandle->toHandle(), &version); - EXPECT_EQ(ZE_RESULT_SUCCESS, result); +TEST(zeDriverHandleGetApiVersion, whenZeDriverGetApiIsCalledThenGetApiVersionIsCalled) { + ze_result_t result; + Mock driverHandle; + ze_api_version_t version; + ze_result_t expectedResult = ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS; + + driverHandle.getApiVersionResult = expectedResult; + result = zeDriverGetApiVersion(driverHandle.toHandle(), &version); + EXPECT_EQ(expectedResult, result); + EXPECT_EQ(1u, driverHandle.getApiVersionCalled); } -TEST_F(DriverHandleTest, whenGettingApiVersionThenCorrectApiVersionIsReturned) { - ze_api_version_t version = {}; - ze_result_t result = driverHandle->getApiVersion(&version); - EXPECT_EQ(ZE_RESULT_SUCCESS, result); - EXPECT_EQ(ZE_API_VERSION_1_1, version); -} +TEST(zeDriverGetIpcProperties, whenZeDriverGetIpcPropertiesIsCalledThenGetIPCPropertiesIsCalled) { + ze_result_t result; + Mock driverHandle; + ze_driver_ipc_properties_t ipcProperties; + ze_result_t expectedResult = ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS; -TEST_F(DriverHandleTest, whenZeDriverGetIpcPropertiesIsCalledThenSuccessIsReturned) { - ze_driver_ipc_properties_t ipcProperties = {}; - ze_result_t result = zeDriverGetIpcProperties(driverHandle->toHandle(), &ipcProperties); - EXPECT_EQ(ZE_RESULT_SUCCESS, result); + driverHandle.getIPCPropertiesResult = expectedResult; + result = zeDriverGetIpcProperties(driverHandle.toHandle(), &ipcProperties); + EXPECT_EQ(expectedResult, result); + EXPECT_EQ(1u, driverHandle.getIPCPropertiesCalled); } - -TEST_F(DriverHandleTest, whenGettingIpcPropertiesThenCorrectPropertiesAreReturned) { - ze_driver_ipc_properties_t ipcProperties = {}; - ze_result_t result = driverHandle->getIPCProperties(&ipcProperties); - EXPECT_EQ(ZE_RESULT_SUCCESS, result); - EXPECT_EQ(ZE_IPC_PROPERTY_FLAG_MEMORY, ipcProperties.flags); -} - } // namespace ult } // namespace L0 diff --git a/level_zero/core/test/unit_tests/sources/event/test_event.cpp b/level_zero/core/test/unit_tests/sources/event/test_event.cpp index fe49608893..a3aac8dd7a 100644 --- a/level_zero/core/test/unit_tests/sources/event/test_event.cpp +++ b/level_zero/core/test/unit_tests/sources/event/test_event.cpp @@ -70,32 +70,21 @@ struct EventPoolFailTests : public ::testing::Test { devices.push_back(std::unique_ptr(neoDevice)); driverHandle = std::make_unique(); driverHandle->initialize(std::move(devices)); + prevMemoryManager = driverHandle->getMemoryManager(); + currMemoryManager = new MemoryManagerEventPoolFailMock(*neoDevice->executionEnvironment); + driverHandle->setMemoryManager(currMemoryManager); device = driverHandle->devices[0]; context = std::make_unique(driverHandle.get()); EXPECT_NE(context, nullptr); - - { - context->getDevices().insert(std::make_pair(device->toHandle(), device)); - auto neoDevice = device->getNEODevice(); - context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); - context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); - } - - context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager()); - - prevMemoryManager = context->getMemoryManager(); - currMemoryManager = new MemoryManagerEventPoolFailMock(*neoDevice->executionEnvironment); - context->setMemoryManager(currMemoryManager); - - driverHandle->mainContext = context.get(); - - driverHandle->setMemoryManager(context->getMemoryManager()); - driverHandle->setSvmAllocsManager(context->getSvmAllocsManager()); + context->getDevices().insert(std::make_pair(device->toHandle(), device)); + auto neoDevice = device->getNEODevice(); + context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); + context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); } void TearDown() override { - context->setMemoryManager(prevMemoryManager); + driverHandle->setMemoryManager(prevMemoryManager); delete currMemoryManager; } NEO::MemoryManager *prevMemoryManager = nullptr; @@ -326,20 +315,18 @@ class EventSynchronizeTest : public Test { eventDesc.signal = 0; eventDesc.wait = 0; - eventPool = L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc); + eventPool = std::unique_ptr(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc)); ASSERT_NE(nullptr, eventPool); - event = L0::Event::create(eventPool, &eventDesc, device); + event = std::unique_ptr(L0::Event::create(eventPool.get(), &eventDesc, device)); ASSERT_NE(nullptr, event); } void TearDown() override { - event->destroy(); - eventPool->destroy(); DeviceFixture::TearDown(); } - L0::EventPool *eventPool = nullptr; - L0::Event *event = nullptr; + std::unique_ptr eventPool = nullptr; + std::unique_ptr event; }; TEST_F(EventSynchronizeTest, givenCallToEventHostSynchronizeWithTimeoutZeroAndStateInitialHostSynchronizeReturnsNotReady) { @@ -381,17 +368,13 @@ HWTEST_F(EventAubCsrTest, givenCallToEventHostSynchronizeWithAubModeCsrReturnsSu driverHandle = std::make_unique>(); driverHandle->initialize(std::move(devices)); device = driverHandle->devices[0]; - - ze_context_handle_t hContext; - ze_context_desc_t desc; - ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext); - EXPECT_EQ(ZE_RESULT_SUCCESS, res); - L0::ContextImp *context = static_cast(Context::fromHandle(hContext)); - int32_t tag; auto aubCsr = new MockCsrAub(tag, *neoDevice->executionEnvironment, neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()); neoDevice->resetCommandStreamReceiver(aubCsr); + std::unique_ptr eventPool = nullptr; + std::unique_ptr event; + ze_event_pool_desc_t eventPoolDesc = {}; eventPoolDesc.count = 1; eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_HOST_VISIBLE; @@ -401,17 +384,13 @@ HWTEST_F(EventAubCsrTest, givenCallToEventHostSynchronizeWithAubModeCsrReturnsSu eventDesc.signal = 0; eventDesc.wait = 0; - L0::EventPool *eventPool = L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc); + eventPool = std::unique_ptr(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc)); ASSERT_NE(nullptr, eventPool); - L0::Event *event = L0::Event::create(eventPool, &eventDesc, device); + event = std::unique_ptr(L0::Event::create(eventPool.get(), &eventDesc, device)); ASSERT_NE(nullptr, event); ze_result_t result = event->hostSynchronize(10); EXPECT_EQ(ZE_RESULT_SUCCESS, result); - - event->destroy(); - eventPool->destroy(); - context->destroy(); } struct EventCreateAllocationResidencyTest : public ::testing::Test { @@ -449,20 +428,18 @@ class TimestampEventCreate : public Test { eventDesc.signal = 0; eventDesc.wait = 0; - eventPool = L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc); + eventPool = std::unique_ptr(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc)); ASSERT_NE(nullptr, eventPool); - event = L0::Event::create(eventPool, &eventDesc, device); + event = std::unique_ptr(L0::Event::create(eventPool.get(), &eventDesc, device)); ASSERT_NE(nullptr, event); } void TearDown() override { - event->destroy(); - eventPool->destroy(); DeviceFixture::TearDown(); } - L0::EventPool *eventPool = nullptr; - L0::Event *event = nullptr; + std::unique_ptr eventPool; + std::unique_ptr event; }; TEST_F(TimestampEventCreate, givenEventCreatedWithTimestampThenIsTimestampEventFlagSet) { @@ -576,7 +553,7 @@ TEST_F(TimestampEventCreate, givenEventWhenQueryKernelTimestampThenNotReadyRetur } }; - auto mockEvent = std::make_unique(eventPool, 1u, device); + auto mockEvent = std::make_unique(eventPool.get(), 1u, device); ze_kernel_timestamp_result_t resultTimestamp = {}; @@ -606,11 +583,11 @@ TEST_F(EventPoolCreateMultiDevice, whenCreatingEventPoolWithMultipleDevicesThenE result = zeDeviceGet(driverHandle.get(), &deviceCount, devices); EXPECT_EQ(ZE_RESULT_SUCCESS, result); - L0::EventPool *eventPool = EventPool::create(driverHandle.get(), - context, - deviceCount, - devices, - &eventPoolDesc); + std::unique_ptr eventPool(EventPool::create(driverHandle.get(), + context, + deviceCount, + devices, + &eventPoolDesc)); EXPECT_NE(nullptr, eventPool); auto allocation = &eventPool->getAllocation(); @@ -619,8 +596,6 @@ TEST_F(EventPoolCreateMultiDevice, whenCreatingEventPoolWithMultipleDevicesThenE EXPECT_EQ(allocation->getGraphicsAllocations().size(), numRootDevices); delete[] devices; - - eventPool->destroy(); } TEST_F(EventPoolCreateMultiDevice, whenCreatingEventPoolWithNoDevicesThenEventPoolCreateSucceedsAndAllDeviceAreUsed) { @@ -680,16 +655,15 @@ struct EventPoolCreateNegativeTest : public ::testing::Test { driverHandle = std::make_unique>(); driverHandle->initialize(std::move(devices)); + static_cast(driverHandle.get()->getMemoryManager())->isMockEventPoolCreateMemoryManager = true; + + device = driverHandle->devices[0]; ze_context_handle_t hContext; ze_context_desc_t desc; ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext); EXPECT_EQ(ZE_RESULT_SUCCESS, res); context = static_cast(Context::fromHandle(hContext)); - - static_cast(driverHandle.get()->getMemoryManager())->isMockEventPoolCreateMemoryManager = true; - - device = driverHandle->devices[0]; } void TearDown() override { context->destroy(); diff --git a/level_zero/core/test/unit_tests/sources/fence/test_fence.cpp b/level_zero/core/test/unit_tests/sources/fence/test_fence.cpp index eb20137698..33aca2460e 100644 --- a/level_zero/core/test/unit_tests/sources/fence/test_fence.cpp +++ b/level_zero/core/test/unit_tests/sources/fence/test_fence.cpp @@ -136,13 +136,6 @@ HWTEST_F(FenceAubCsrTest, givenCallToFenceHostSynchronizeWithAubModeCsrReturnsSu devices.push_back(std::unique_ptr(neoDevice)); driverHandle = std::make_unique>(); driverHandle->initialize(std::move(devices)); - - ze_context_handle_t hContext; - ze_context_desc_t desc; - ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext); - EXPECT_EQ(ZE_RESULT_SUCCESS, res); - L0::ContextImp *context = static_cast(Context::fromHandle(hContext)); - device = driverHandle->devices[0]; int32_t tag; auto aubCsr = new MockCsrAub(tag, *neoDevice->executionEnvironment, neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()); @@ -154,8 +147,6 @@ HWTEST_F(FenceAubCsrTest, givenCallToFenceHostSynchronizeWithAubModeCsrReturnsSu ze_result_t result = fence->hostSynchronize(10); EXPECT_EQ(ZE_RESULT_SUCCESS, result); fence->destroy(); - - context->destroy(); } } // namespace ult diff --git a/level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp b/level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp index 05d62fb312..f97ea83df9 100644 --- a/level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp +++ b/level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp @@ -44,15 +44,14 @@ TEST_F(KernelInitTest, givenKernelToInitWhenItHasUnknownArgThenUnknowKernelArgHa std::make_unique(perHwThreadPrivateMemorySizeRequested); createModuleFromBinary(perHwThreadPrivateMemorySizeRequested, false, mockKernelImmData.get()); - ModuleImmutableDataFixture::MockKernel *kernel = new ModuleImmutableDataFixture::MockKernel(module); + std::unique_ptr kernel; + kernel = std::make_unique(module.get()); ze_kernel_desc_t desc = {}; desc.pKernelName = kernelName.c_str(); mockKernelImmData->resizeExplicitArgs(1); kernel->initialize(&desc); EXPECT_EQ(kernel->kernelArgHandlers[0], &KernelImp::setArgUnknown); EXPECT_EQ(mockKernelImmData->getDescriptor().payloadMappings.explicitArgs[0].type, NEO::ArgDescriptor::ArgTUnknown); - - delete kernel; } TEST(KernelArgTest, givenKernelWhenSetArgUnknownCalledThenSuccessRteurned) { @@ -259,7 +258,7 @@ HWTEST_F(KernelImmutableDataTests, givenKernelInitializedWithNoPrivateMemoryThen createModuleFromBinary(perHwThreadPrivateMemorySizeRequested, isInternal, mockKernelImmData.get()); std::unique_ptr kernel; - kernel = std::make_unique(module); + kernel = std::make_unique(module.get()); createKernel(kernel.get()); @@ -275,7 +274,7 @@ HWTEST_F(KernelImmutableDataTests, givenKernelInitializedWithPrivateMemoryThenPr createModuleFromBinary(perHwThreadPrivateMemorySizeRequested, isInternal, mockKernelImmData.get()); std::unique_ptr kernel; - kernel = std::make_unique(module); + kernel = std::make_unique(module.get()); createKernel(kernel.get()); @@ -310,7 +309,7 @@ HWTEST_F(KernelImmutableDataIsaCopyTests, whenUserKernelIsCreatedThenIsaIsaCopie mockMemoryManager->copyMemoryToAllocationCalledTimes); std::unique_ptr kernel; - kernel = std::make_unique(module); + kernel = std::make_unique(module.get()); createKernel(kernel.get()); @@ -340,7 +339,7 @@ HWTEST_F(KernelImmutableDataIsaCopyTests, whenInternalKernelIsCreatedThenIsaIsCo mockMemoryManager->copyMemoryToAllocationCalledTimes); std::unique_ptr kernel; - kernel = std::make_unique(module); + kernel = std::make_unique(module.get()); createKernel(kernel.get()); @@ -365,8 +364,8 @@ HWTEST_F(KernelImmutableDataIsaCopyTests, whenImmutableDataIsInitializedForUserK mockKernelImmData->initialize(mockKernelImmData->mockKernelInfo, device, device->getNEODevice()->getDeviceInfo().computeUnitsUsedForScratch, - module->translationUnit->globalConstBuffer, - module->translationUnit->globalVarBuffer, + module.get()->translationUnit->globalConstBuffer, + module.get()->translationUnit->globalVarBuffer, isInternal); EXPECT_EQ(previouscopyMemoryToAllocationCalledTimes + 1u, @@ -388,8 +387,8 @@ HWTEST_F(KernelImmutableDataIsaCopyTests, whenImmutableDataIsInitializedForInter mockKernelImmData->initialize(mockKernelImmData->mockKernelInfo, device, device->getNEODevice()->getDeviceInfo().computeUnitsUsedForScratch, - module->translationUnit->globalConstBuffer, - module->translationUnit->globalVarBuffer, + module.get()->translationUnit->globalConstBuffer, + module.get()->translationUnit->globalVarBuffer, isInternal); EXPECT_EQ(previouscopyMemoryToAllocationCalledTimes, @@ -416,8 +415,8 @@ HWTEST_F(KernelImmutableDataWithNullHeapTests, whenImmutableDataIsInitializedFor mockKernelImmData->initialize(mockKernelImmData->mockKernelInfo, device, device->getNEODevice()->getDeviceInfo().computeUnitsUsedForScratch, - module->translationUnit->globalConstBuffer, - module->translationUnit->globalVarBuffer, + module.get()->translationUnit->globalConstBuffer, + module.get()->translationUnit->globalVarBuffer, isInternal); EXPECT_EQ(previouscopyMemoryToAllocationCalledTimes, @@ -444,8 +443,8 @@ HWTEST_F(KernelImmutableDataWithNullHeapTests, whenImmutableDataIsInitializedFor mockKernelImmData->initialize(mockKernelImmData->mockKernelInfo, device, device->getNEODevice()->getDeviceInfo().computeUnitsUsedForScratch, - module->translationUnit->globalConstBuffer, - module->translationUnit->globalVarBuffer, + module.get()->translationUnit->globalConstBuffer, + module.get()->translationUnit->globalVarBuffer, isInternal); EXPECT_EQ(previouscopyMemoryToAllocationCalledTimes, @@ -476,7 +475,7 @@ HWTEST_F(KernelImmutableDataWithNullHeapTests, whenInternalKernelIsCreatedWithNu mockMemoryManager->copyMemoryToAllocationCalledTimes); std::unique_ptr kernel; - kernel = std::make_unique(module); + kernel = std::make_unique(module.get()); auto previousKernelHeap = mockKernelImmData->kernelInfo->heapInfo.pKernelHeap; mockKernelImmData->kernelInfo->heapInfo.pKernelHeap = nullptr; @@ -560,7 +559,7 @@ HWTEST_F(KernelIndirectPropertiesFromIGCTests, whenInitializingKernelWithNoKerne createModuleFromBinary(perHwThreadPrivateMemorySizeRequested, isInternal, mockKernelImmData.get()); std::unique_ptr kernel; - kernel = std::make_unique(module); + kernel = std::make_unique(module.get()); ze_kernel_desc_t desc = {}; desc.pKernelName = kernelName.c_str(); @@ -588,7 +587,7 @@ HWTEST_F(KernelIndirectPropertiesFromIGCTests, whenInitializingKernelWithKernelL { std::unique_ptr kernel; - kernel = std::make_unique(module); + kernel = std::make_unique(module.get()); ze_kernel_desc_t desc = {}; desc.pKernelName = kernelName.c_str(); @@ -604,7 +603,7 @@ HWTEST_F(KernelIndirectPropertiesFromIGCTests, whenInitializingKernelWithKernelL { std::unique_ptr kernel; - kernel = std::make_unique(module); + kernel = std::make_unique(module.get()); ze_kernel_desc_t desc = {}; desc.pKernelName = kernelName.c_str(); @@ -620,7 +619,7 @@ HWTEST_F(KernelIndirectPropertiesFromIGCTests, whenInitializingKernelWithKernelL { std::unique_ptr kernel; - kernel = std::make_unique(module); + kernel = std::make_unique(module.get()); ze_kernel_desc_t desc = {}; desc.pKernelName = kernelName.c_str(); @@ -933,7 +932,7 @@ HWTEST_F(KernelPropertiesTests, givenValidKernelAndNoMediavfestateThenSpillMemSi ze_result_t res = kernel->getProperties(&kernelProperties); EXPECT_EQ(ZE_RESULT_SUCCESS, res); - L0::ModuleImp *moduleImp = reinterpret_cast(module); + L0::ModuleImp *moduleImp = reinterpret_cast(module.get()); NEO::KernelInfo *ki = nullptr; for (uint32_t i = 0; i < moduleImp->getTranslationUnit()->programInfo.kernelInfos.size(); i++) { ki = moduleImp->getTranslationUnit()->programInfo.kernelInfos[i]; @@ -956,7 +955,7 @@ HWTEST_F(KernelPropertiesTests, givenValidKernelAndNollocateStatelessPrivateSurf ze_result_t res = kernel->getProperties(&kernelProperties); EXPECT_EQ(ZE_RESULT_SUCCESS, res); - L0::ModuleImp *moduleImp = reinterpret_cast(module); + L0::ModuleImp *moduleImp = reinterpret_cast(module.get()); NEO::KernelInfo *ki = nullptr; for (uint32_t i = 0; i < moduleImp->getTranslationUnit()->programInfo.kernelInfos.size(); i++) { ki = moduleImp->getTranslationUnit()->programInfo.kernelInfos[i]; @@ -1223,7 +1222,7 @@ HWTEST2_F(KernelImpPatchBindlessTest, GivenKernelImpWhenSetSurfaceStateBindlessT desc.pKernelName = kernelName.c_str(); WhiteBoxKernelHw mockKernel; - mockKernel.module = module; + mockKernel.module = module.get(); mockKernel.initialize(&desc); auto &arg = const_cast(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].template as()); arg.bindless = 0x40; @@ -1254,7 +1253,7 @@ HWTEST2_F(KernelImpPatchBindlessTest, GivenKernelImpWhenSetSurfaceStateBindfulTh desc.pKernelName = kernelName.c_str(); WhiteBoxKernelHw mockKernel; - mockKernel.module = module; + mockKernel.module = module.get(); mockKernel.initialize(&desc); auto &arg = const_cast(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].template as()); @@ -1294,7 +1293,7 @@ TEST_F(KernelImpPatchBindlessTest, GivenValidBindlessOffsetWhenSetArgBufferWithA desc.pKernelName = kernelName.c_str(); MyMockKernel mockKernel; - mockKernel.module = module; + mockKernel.module = module.get(); mockKernel.initialize(&desc); auto &arg = const_cast(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].as()); @@ -1313,7 +1312,7 @@ TEST_F(KernelImpPatchBindlessTest, GivenValidBindfulOffsetWhenSetArgBufferWithAl desc.pKernelName = kernelName.c_str(); MyMockKernel mockKernel; - mockKernel.module = module; + mockKernel.module = module.get(); mockKernel.initialize(&desc); auto &arg = const_cast(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].as()); @@ -1332,7 +1331,7 @@ TEST_F(KernelImpPatchBindlessTest, GivenUndefiedBidfulAndBindlesstOffsetWhenSetA desc.pKernelName = kernelName.c_str(); MyMockKernel mockKernel; - mockKernel.module = module; + mockKernel.module = module.get(); mockKernel.initialize(&desc); auto &arg = const_cast(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].as()); @@ -1353,7 +1352,7 @@ TEST_F(KernelBindlessUncachedMemoryTests, givenBindlessKernelAndAllocDataNoTfoun desc.pKernelName = kernelName.c_str(); MyMockKernel mockKernel; - mockKernel.module = module; + mockKernel.module = module.get(); mockKernel.initialize(&desc); auto &arg = const_cast(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].as()); @@ -1372,7 +1371,7 @@ TEST_F(KernelBindlessUncachedMemoryTests, desc.pKernelName = kernelName.c_str(); MyMockKernel mockKernel; - mockKernel.module = module; + mockKernel.module = module.get(); mockKernel.initialize(&desc); auto &arg = const_cast(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].as()); @@ -1422,7 +1421,7 @@ TEST_F(KernelBindlessUncachedMemoryTests, desc.pKernelName = kernelName.c_str(); MyMockKernel mockKernel; - mockKernel.module = module; + mockKernel.module = module.get(); mockKernel.initialize(&desc); auto &arg = const_cast(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].as()); @@ -1474,7 +1473,7 @@ TEST_F(KernelBindlessUncachedMemoryTests, desc.pKernelName = kernelName.c_str(); MyMockKernel mockKernel; - mockKernel.module = module; + mockKernel.module = module.get(); mockKernel.initialize(&desc); auto &arg = const_cast(mockKernel.kernelImmData->getDescriptor().payloadMappings.explicitArgs[0].as()); @@ -1658,8 +1657,8 @@ TEST_F(KernelPrintHandlerTest, whenPrintPrintfOutputIsCalledThenPrintfBufferIsUs ze_kernel_desc_t desc = {}; desc.pKernelName = kernelName.c_str(); - kernel = new WhiteBox<::L0::Kernel>(); - kernel->module = module; + kernel = std::make_unique>(); + kernel->module = module.get(); kernel->initialize(&desc); EXPECT_FALSE(kernel->printfBuffer == nullptr); diff --git a/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp b/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp index 5484445a73..03f48ae294 100644 --- a/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp +++ b/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp @@ -122,26 +122,21 @@ struct OutOfMemoryTests : public ::testing::Test { devices.push_back(std::unique_ptr(neoDevice)); driverHandle = std::make_unique(); driverHandle->initialize(std::move(devices)); + prevSvmAllocsManager = driverHandle->svmAllocsManager; + currSvmAllocsManager = new SVMAllocsManagerOutOFMemoryMock(driverHandle->memoryManager); + driverHandle->svmAllocsManager = currSvmAllocsManager; device = driverHandle->devices[0]; - context = new ContextImp(driverHandle.get()); + context = std::make_unique(driverHandle.get()); EXPECT_NE(context, nullptr); context->getDevices().insert(std::make_pair(device->toHandle(), device)); auto neoDevice = device->getNEODevice(); context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); - context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager()); - context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), false)); - driverHandle->mainContext = context; - - prevSvmAllocsManager = context->getSvmAllocsManager(); - currSvmAllocsManager = new SVMAllocsManagerOutOFMemoryMock(context->getMemoryManager()); - context->setSvmAllocsManager(currSvmAllocsManager); } void TearDown() override { - context->setSvmAllocsManager(prevSvmAllocsManager); - context->destroy(); + driverHandle->svmAllocsManager = prevSvmAllocsManager; delete currSvmAllocsManager; } NEO::SVMAllocsManager *prevSvmAllocsManager; @@ -149,7 +144,7 @@ struct OutOfMemoryTests : public ::testing::Test { std::unique_ptr driverHandle; NEO::MockDevice *neoDevice = nullptr; L0::Device *device = nullptr; - L0::ContextImp *context = nullptr; + std::unique_ptr context; }; TEST_F(OutOfMemoryTests, @@ -203,26 +198,21 @@ struct MemoryRelaxedSizeTests : public ::testing::Test { devices.push_back(std::unique_ptr(neoDevice)); driverHandle = std::make_unique(); driverHandle->initialize(std::move(devices)); + prevSvmAllocsManager = driverHandle->svmAllocsManager; + currSvmAllocsManager = new SVMAllocsManagerRelaxedSizeMock(driverHandle->memoryManager); + driverHandle->svmAllocsManager = currSvmAllocsManager; device = driverHandle->devices[0]; - context = new ContextRelaxedSizeMock(driverHandle.get()); + context = std::make_unique(driverHandle.get()); EXPECT_NE(context, nullptr); context->getDevices().insert(std::make_pair(device->toHandle(), device)); auto neoDevice = device->getNEODevice(); context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); - context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager()); - context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), false)); - driverHandle->mainContext = context; - - prevSvmAllocsManager = context->getSvmAllocsManager(); - currSvmAllocsManager = new SVMAllocsManagerRelaxedSizeMock(context->getMemoryManager()); - context->setSvmAllocsManager(currSvmAllocsManager); } void TearDown() override { - context->setSvmAllocsManager(prevSvmAllocsManager); - context->destroy(); + driverHandle->svmAllocsManager = prevSvmAllocsManager; delete currSvmAllocsManager; } NEO::SVMAllocsManager *prevSvmAllocsManager; @@ -230,7 +220,7 @@ struct MemoryRelaxedSizeTests : public ::testing::Test { std::unique_ptr driverHandle; NEO::MockDevice *neoDevice = nullptr; L0::Device *device = nullptr; - L0::ContextImp *context = nullptr; + std::unique_ptr context; }; TEST_F(MemoryRelaxedSizeTests, @@ -559,29 +549,21 @@ struct MemoryExportImportFailTest : public ::testing::Test { driverHandle->initialize(std::move(devices)); device = driverHandle->devices[0]; - context = new ContextFailFdMock(driverHandle.get()); + context = std::make_unique(driverHandle.get()); EXPECT_NE(context, nullptr); context->getDevices().insert(std::make_pair(device->toHandle(), device)); auto neoDevice = device->getNEODevice(); context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); - context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager()); - context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), false)); - driverHandle->mainContext = context; - - driverHandle->setMemoryManager(context->getMemoryManager()); - driverHandle->setSvmAllocsManager(context->getSvmAllocsManager()); - driverHandle->mainContext = context; } void TearDown() override { - context->destroy(); } std::unique_ptr driverHandle; NEO::MockDevice *neoDevice = nullptr; L0::Device *device = nullptr; ze_context_handle_t hContext; - ContextFailFdMock *context = nullptr; + std::unique_ptr context; }; TEST_F(MemoryExportImportFailTest, @@ -685,27 +667,21 @@ struct MemoryExportImportTest : public ::testing::Test { driverHandle->initialize(std::move(devices)); device = driverHandle->devices[0]; - context = new ContextFdMock(driverHandle.get()); + context = std::make_unique(driverHandle.get()); EXPECT_NE(context, nullptr); context->getDevices().insert(std::make_pair(device->toHandle(), device)); auto neoDevice = device->getNEODevice(); context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); - context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager()); - context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), false)); - driverHandle->mainContext = context; - driverHandle->setMemoryManager(context->getMemoryManager()); - driverHandle->setSvmAllocsManager(context->getSvmAllocsManager()); } void TearDown() override { - context->destroy(); } std::unique_ptr driverHandle; NEO::MockDevice *neoDevice = nullptr; L0::Device *device = nullptr; ze_context_handle_t hContext; - ContextFdMock *context = nullptr; + std::unique_ptr context; }; TEST_F(MemoryExportImportTest, @@ -1111,27 +1087,21 @@ struct MemoryGetIpcHandleTest : public ::testing::Test { driverHandle->initialize(std::move(devices)); device = driverHandle->devices[0]; - context = new ContextGetIpcHandleMock(driverHandle.get()); + context = std::make_unique(driverHandle.get()); EXPECT_NE(context, nullptr); context->getDevices().insert(std::make_pair(device->toHandle(), device)); auto neoDevice = device->getNEODevice(); context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); - context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager()); - context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), false)); - driverHandle->mainContext = context; - driverHandle->setMemoryManager(context->getMemoryManager()); - driverHandle->setSvmAllocsManager(context->getSvmAllocsManager()); } void TearDown() override { - context->destroy(); } std::unique_ptr driverHandle; NEO::MockDevice *neoDevice = nullptr; L0::Device *device = nullptr; - ContextGetIpcHandleMock *context = nullptr; + std::unique_ptr context; }; TEST_F(MemoryGetIpcHandleTest, @@ -1239,31 +1209,21 @@ struct MemoryOpenIpcHandleTest : public ::testing::Test { devices.push_back(std::unique_ptr(neoDevice)); driverHandle = std::make_unique(); driverHandle->initialize(std::move(devices)); + prevMemoryManager = driverHandle->getMemoryManager(); + currMemoryManager = new MemoryManagerOpenIpcMock(*neoDevice->executionEnvironment); + driverHandle->setMemoryManager(currMemoryManager); device = driverHandle->devices[0]; - context = new ContextIpcMock(driverHandle.get()); + context = std::make_unique(driverHandle.get()); EXPECT_NE(context, nullptr); context->getDevices().insert(std::make_pair(device->toHandle(), device)); - { - auto neoDevice = device->getNEODevice(); - context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); - context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); - } - context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager()); - context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), false)); - driverHandle->mainContext = context; - - prevMemoryManager = context->getMemoryManager(); - currMemoryManager = new MemoryManagerOpenIpcMock(*neoDevice->executionEnvironment); - context->setMemoryManager(currMemoryManager); - - driverHandle->setMemoryManager(context->getMemoryManager()); - driverHandle->setSvmAllocsManager(context->getSvmAllocsManager()); + auto neoDevice = device->getNEODevice(); + context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); + context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); } void TearDown() override { - context->setMemoryManager(prevMemoryManager); - context->destroy(); + driverHandle->setMemoryManager(prevMemoryManager); delete currMemoryManager; } NEO::MemoryManager *prevMemoryManager = nullptr; @@ -1271,7 +1231,7 @@ struct MemoryOpenIpcHandleTest : public ::testing::Test { std::unique_ptr driverHandle; NEO::MockDevice *neoDevice = nullptr; L0::Device *device = nullptr; - ContextIpcMock *context = nullptr; + std::unique_ptr context; }; struct MultipleDevicePeerAllocationTest : public ::testing::Test { @@ -1294,7 +1254,7 @@ struct MultipleDevicePeerAllocationTest : public ::testing::Test { ModuleBuildLog *moduleBuildLog = nullptr; - module = Module::create(device, &moduleDesc, moduleBuildLog, type); + module.reset(Module::create(device, &moduleDesc, moduleBuildLog, type)); } void SetUp() override { @@ -1316,9 +1276,11 @@ struct MultipleDevicePeerAllocationTest : public ::testing::Test { } driverHandle = std::make_unique(); driverHandle->initialize(std::move(devices)); + prevMemoryManager = driverHandle->getMemoryManager(); + currMemoryManager = new MemoryManagerOpenIpcMock(*executionEnvironment); + driverHandle->setMemoryManager(currMemoryManager); - context = new ContextImp(driverHandle.get()); - bool multiOsContextDriver = false; + context = std::make_unique(driverHandle.get()); EXPECT_NE(context, nullptr); for (auto i = 0u; i < numRootDevices; i++) { auto device = driverHandle->devices[i]; @@ -1326,39 +1288,20 @@ struct MultipleDevicePeerAllocationTest : public ::testing::Test { auto neoDevice = device->getNEODevice(); context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); - multiOsContextDriver |= device->isMultiDeviceCapable(); } - - context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager()); - context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), multiOsContextDriver)); - driverHandle->mainContext = context; - - prevMemoryManager = context->getMemoryManager(); - currMemoryManager = new MemoryManagerOpenIpcMock(*executionEnvironment); - context->setMemoryManager(currMemoryManager); - - driverHandle->setMemoryManager(context->getMemoryManager()); - driverHandle->setSvmAllocsManager(context->getSvmAllocsManager()); } void createKernel() { ze_kernel_desc_t desc = {}; desc.pKernelName = kernelName.c_str(); - kernel = new WhiteBox<::L0::Kernel>(); - kernel->module = module; + kernel = std::make_unique>(); + kernel->module = module.get(); kernel->initialize(&desc); } void TearDown() override { - if (kernel) { - kernel->destroy(); - } - if (module) { - module->destroy(); - } - context->setMemoryManager(prevMemoryManager); - context->destroy(); + driverHandle->setMemoryManager(prevMemoryManager); delete currMemoryManager; } @@ -1368,13 +1311,13 @@ struct MultipleDevicePeerAllocationTest : public ::testing::Test { std::unique_ptr driverHandle; std::unique_ptr deviceFactory; - L0::ContextImp *context = nullptr; + std::unique_ptr context; const std::string binaryFilename = "test_kernel"; const std::string kernelName = "test"; const uint32_t numKernelArguments = 6; - L0::Module *module = nullptr; - WhiteBox<::L0::Kernel> *kernel = nullptr; + std::unique_ptr module; + std::unique_ptr> kernel; const uint32_t numRootDevices = 2u; const uint32_t numSubDevices = 2u; @@ -1795,31 +1738,21 @@ struct MemoryFailedOpenIpcHandleTest : public ::testing::Test { devices.push_back(std::unique_ptr(neoDevice)); driverHandle = std::make_unique(); driverHandle->initialize(std::move(devices)); + prevMemoryManager = driverHandle->getMemoryManager(); + currMemoryManager = new MemoryManagerIpcMock(*neoDevice->executionEnvironment); + driverHandle->setMemoryManager(currMemoryManager); device = driverHandle->devices[0]; - context = new ContextImp(driverHandle.get()); + context = std::make_unique(driverHandle.get()); EXPECT_NE(context, nullptr); context->getDevices().insert(std::make_pair(device->toHandle(), device)); - { - auto neoDevice = device->getNEODevice(); - context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); - context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); - } - context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager()); - context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), false)); - driverHandle->mainContext = context; - - prevMemoryManager = context->getMemoryManager(); - currMemoryManager = new MemoryManagerIpcMock(*neoDevice->executionEnvironment); - context->setMemoryManager(currMemoryManager); - - driverHandle->setMemoryManager(context->getMemoryManager()); - driverHandle->setSvmAllocsManager(context->getSvmAllocsManager()); + auto neoDevice = device->getNEODevice(); + context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); + context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); } void TearDown() override { - context->setMemoryManager(prevMemoryManager); - context->destroy(); + driverHandle->setMemoryManager(prevMemoryManager); delete currMemoryManager; } NEO::MemoryManager *prevMemoryManager = nullptr; @@ -1827,7 +1760,7 @@ struct MemoryFailedOpenIpcHandleTest : public ::testing::Test { std::unique_ptr driverHandle; NEO::MockDevice *neoDevice = nullptr; L0::Device *device = nullptr; - L0::ContextImp *context; + std::unique_ptr context; }; TEST_F(MemoryFailedOpenIpcHandleTest, @@ -1967,7 +1900,7 @@ TEST_F(MemoryTest, givenNoDeviceWhenAllocatingSharedMemoryThenDeviceInAllocation &deviceDesc, &hostDesc, size, alignment, &ptr); - auto alloc = driverHandle->getSvmAllocsManager()->getSVMAlloc(ptr); + auto alloc = driverHandle->svmAllocsManager->getSVMAlloc(ptr); EXPECT_EQ(alloc->device, nullptr); EXPECT_EQ(ZE_RESULT_SUCCESS, result); @@ -2060,22 +1993,17 @@ struct MemoryBitfieldTest : testing::Test { ASSERT_NE(nullptr, driverHandle->devices[0]->toHandle()); EXPECT_NE(neoDevice->getDeviceBitfield(), memoryManager->recentlyPassedDeviceBitfield); - context = new ContextImp(driverHandle.get()); + context = std::make_unique(driverHandle.get()); EXPECT_NE(context, nullptr); context->getDevices().insert(std::make_pair(device->toHandle(), device)); auto neoDevice = device->getNEODevice(); context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); - - context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager()); - context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), false)); - driverHandle->mainContext = context; } void TearDown() override { auto result = context->freeMem(ptr); ASSERT_EQ(result, ZE_RESULT_SUCCESS); - context->destroy(); } std::unique_ptr> driverHandle; @@ -2085,7 +2013,7 @@ struct MemoryBitfieldTest : testing::Test { size_t size = 10; size_t alignment = 1u; void *ptr = nullptr; - L0::ContextImp *context = nullptr; + std::unique_ptr context; }; TEST_F(MemoryBitfieldTest, givenDeviceWithValidBitfieldWhenAllocatingDeviceMemoryThenPassProperBitfield) { @@ -2123,15 +2051,13 @@ TEST(MemoryBitfieldTests, givenDeviceWithValidBitfieldWhenAllocatingSharedMemory driverHandle->initialize(std::move(devices)); auto device = driverHandle->devices[0]; - ContextImp *context = new ContextImp(driverHandle.get()); + std::unique_ptr context; + context = std::make_unique(driverHandle.get()); EXPECT_NE(context, nullptr); context->getDevices().insert(std::make_pair(device->toHandle(), device)); auto neoDevice = device->getNEODevice(); context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); - context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager()); - context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), false)); - driverHandle->mainContext = context; memoryManager->recentlyPassedDeviceBitfield = {}; ASSERT_NE(nullptr, driverHandle->devices[1]->toHandle()); @@ -2162,7 +2088,6 @@ TEST(MemoryBitfieldTests, givenDeviceWithValidBitfieldWhenAllocatingSharedMemory EXPECT_NE(nullptr, ptr); result = context->freeMem(ptr); ASSERT_EQ(result, ZE_RESULT_SUCCESS); - context->destroy(); } struct AllocHostMemoryTest : public ::testing::Test { @@ -2433,7 +2358,7 @@ TEST_F(ImportFdUncachedTests, void *ptr = driverHandle->importFdHandle(device->toHandle(), flags, handle, nullptr); EXPECT_NE(nullptr, ptr); - auto allocData = driverHandle->getSvmAllocsManager()->getSVMAlloc(ptr); + auto allocData = driverHandle->svmAllocsManager->getSVMAlloc(ptr); EXPECT_EQ(allocData->allocationFlagsProperty.flags.locallyUncachedResource, 1u); context->freeMem(ptr); @@ -2446,7 +2371,7 @@ TEST_F(ImportFdUncachedTests, void *ptr = driverHandle->importFdHandle(device->toHandle(), flags, handle, nullptr); EXPECT_NE(nullptr, ptr); - auto allocData = driverHandle->getSvmAllocsManager()->getSVMAlloc(ptr); + auto allocData = driverHandle->svmAllocsManager->getSVMAlloc(ptr); EXPECT_EQ(allocData->allocationFlagsProperty.flags.locallyUncachedResource, 0u); context->freeMem(ptr); @@ -2472,31 +2397,21 @@ struct SharedAllocFailTests : public ::testing::Test { devices.push_back(std::unique_ptr(neoDevice)); driverHandle = std::make_unique(); driverHandle->initialize(std::move(devices)); + prevSvmAllocsManager = driverHandle->svmAllocsManager; + currSvmAllocsManager = new SVMAllocsManagerSharedAllocFailMock(driverHandle->memoryManager); + driverHandle->svmAllocsManager = currSvmAllocsManager; device = driverHandle->devices[0]; - context = new ContextImp(driverHandle.get()); + context = std::make_unique(driverHandle.get()); EXPECT_NE(context, nullptr); context->getDevices().insert(std::make_pair(device->toHandle(), device)); - { - auto neoDevice = device->getNEODevice(); - context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); - context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); - } - context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager()); - context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), false)); - driverHandle->mainContext = context; - - prevSvmAllocsManager = context->getSvmAllocsManager(); - currSvmAllocsManager = new SVMAllocsManagerSharedAllocFailMock(context->getMemoryManager()); - context->setSvmAllocsManager(currSvmAllocsManager); - - driverHandle->setMemoryManager(context->getMemoryManager()); - driverHandle->setSvmAllocsManager(context->getSvmAllocsManager()); + auto neoDevice = device->getNEODevice(); + context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); + context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); } void TearDown() override { - context->setSvmAllocsManager(prevSvmAllocsManager); - context->destroy(); + driverHandle->svmAllocsManager = prevSvmAllocsManager; delete currSvmAllocsManager; } NEO::SVMAllocsManager *prevSvmAllocsManager; @@ -2504,7 +2419,7 @@ struct SharedAllocFailTests : public ::testing::Test { std::unique_ptr driverHandle; NEO::MockDevice *neoDevice = nullptr; L0::Device *device = nullptr; - ContextImp *context; + std::unique_ptr context; }; TEST_F(SharedAllocFailTests, whenAllocatinSharedMemoryAndAllocationFailsThenOutOfDeviceMemoryIsReturned) { @@ -2531,7 +2446,7 @@ struct ContextMultiDeviceMock : public L0::ContextImp { ContextMultiDeviceMock(L0::DriverHandleImp *driverHandle) : L0::ContextImp(driverHandle) {} ze_result_t freeMem(const void *ptr) override { SVMAllocsManagerSharedAllocMultiDeviceMock *currSvmAllocsManager = - static_cast(this->driverHandle->getSvmAllocsManager()); + static_cast(this->driverHandle->svmAllocsManager); if (currSvmAllocsManager->createHostUnifiedMemoryAllocationTimes == 0) { return ContextImp::freeMem(ptr); } @@ -2549,43 +2464,32 @@ struct SharedAllocMultiDeviceTests : public ::testing::Test { driverHandle = std::make_unique(); ze_result_t res = driverHandle->initialize(std::move(devices)); EXPECT_EQ(ZE_RESULT_SUCCESS, res); + prevSvmAllocsManager = driverHandle->svmAllocsManager; + currSvmAllocsManager = new SVMAllocsManagerSharedAllocMultiDeviceMock(driverHandle->memoryManager); + driverHandle->svmAllocsManager = currSvmAllocsManager; - context = new ContextMultiDeviceMock(driverHandle.get()); + context = std::make_unique(driverHandle.get()); EXPECT_NE(context, nullptr); - bool multiOsContextDriver = false; for (uint32_t i = 0; i < numRootDevices; i++) { auto device = driverHandle->devices[i]; context->getDevices().insert(std::make_pair(device->toHandle(), device)); auto neoDevice = device->getNEODevice(); context->rootDeviceIndices.insert(neoDevice->getRootDeviceIndex()); context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); - multiOsContextDriver |= device->isMultiDeviceCapable(); } - - context->setMemoryManager(context->getDevices().begin()->second->getNEODevice()->getMemoryManager()); - context->setSvmAllocsManager(new NEO::SVMAllocsManager(context->getMemoryManager(), multiOsContextDriver)); - driverHandle->mainContext = context; - - prevSvmAllocsManager = context->getSvmAllocsManager(); - currSvmAllocsManager = new SVMAllocsManagerSharedAllocMultiDeviceMock(context->getMemoryManager()); - context->setSvmAllocsManager(currSvmAllocsManager); - - driverHandle->setMemoryManager(context->getMemoryManager()); - driverHandle->setSvmAllocsManager(context->getSvmAllocsManager()); } void TearDown() override { - context->setSvmAllocsManager(prevSvmAllocsManager); - context->destroy(); + driverHandle->svmAllocsManager = prevSvmAllocsManager; delete currSvmAllocsManager; } DebugManagerStateRestore restorer; - NEO::SVMAllocsManager *prevSvmAllocsManager = nullptr; - SVMAllocsManagerSharedAllocMultiDeviceMock *currSvmAllocsManager = nullptr; + NEO::SVMAllocsManager *prevSvmAllocsManager; + SVMAllocsManagerSharedAllocMultiDeviceMock *currSvmAllocsManager; std::unique_ptr driverHandle; - ContextMultiDeviceMock *context = nullptr; + std::unique_ptr context; const uint32_t numRootDevices = 4u; }; diff --git a/level_zero/core/test/unit_tests/sources/module/test_module.cpp b/level_zero/core/test/unit_tests/sources/module/test_module.cpp index 898ac5ebdc..70d4d87496 100644 --- a/level_zero/core/test/unit_tests/sources/module/test_module.cpp +++ b/level_zero/core/test/unit_tests/sources/module/test_module.cpp @@ -60,7 +60,7 @@ HWTEST_F(ModuleTest, givenZeroCountWhenGettingKernelNamesThenCountIsFilled) { uint32_t count = 0; auto result = module->getKernelNames(&count, nullptr); - auto whiteboxModule = whitebox_cast(module); + auto whiteboxModule = whitebox_cast(module.get()); EXPECT_EQ(whiteboxModule->kernelImmDatas.size(), count); EXPECT_EQ(ZE_RESULT_SUCCESS, result); @@ -576,7 +576,7 @@ TEST_F(ModulePropertyTest, givenCallToGetPropertiesWithUnresolvedSymbolsThenFlag NEO::Linker::RelocationInfo unresolvedRelocation; unresolvedRelocation.symbolName = "unresolved"; - whitebox_cast(module)->unresolvedExternalsInfo.push_back({unresolvedRelocation}); + whitebox_cast(module.get())->unresolvedExternalsInfo.push_back({unresolvedRelocation}); ze_module_property_flags_t expectedFlags = 0; expectedFlags |= ZE_MODULE_PROPERTY_FLAG_IMPORTS; @@ -690,7 +690,7 @@ class DeviceModuleSetArgBufferTest : public ModuleFixture, public ::testing::Tes void createKernelAndAllocMemory(uint32_t rootDeviceIndex, void **ptr, ze_kernel_handle_t *kernelHandle) { ze_kernel_desc_t kernelDesc = {}; kernelDesc.pKernelName = kernelName.c_str(); - ze_result_t res = module->createKernel(&kernelDesc, kernelHandle); + ze_result_t res = module.get()->createKernel(&kernelDesc, kernelHandle); EXPECT_EQ(ZE_RESULT_SUCCESS, res); ze_host_mem_alloc_desc_t hostDesc = {}; @@ -702,6 +702,7 @@ class DeviceModuleSetArgBufferTest : public ModuleFixture, public ::testing::Tes HWTEST_F(DeviceModuleSetArgBufferTest, givenValidMemoryUsedinFirstCallToSetArgBufferThenNullptrSetOnTheSecondCallThenArgBufferisUpdatedInEachCallAndSuccessIsReturned) { uint32_t rootDeviceIndex = 0; + createModuleFromBinary(); ze_kernel_handle_t kernelHandle; void *validBufferPtr = nullptr; @@ -751,7 +752,7 @@ class MultiDeviceModuleSetArgBufferTest : public MultiDeviceModuleFixture, publi void createKernelAndAllocMemory(uint32_t rootDeviceIndex, void **ptr, ze_kernel_handle_t *kernelHandle) { ze_kernel_desc_t kernelDesc = {}; kernelDesc.pKernelName = kernelName.c_str(); - ze_result_t res = modules[rootDeviceIndex]->createKernel(&kernelDesc, kernelHandle); + ze_result_t res = modules[rootDeviceIndex].get()->createKernel(&kernelDesc, kernelHandle); EXPECT_EQ(ZE_RESULT_SUCCESS, res); ze_host_mem_alloc_desc_t hostDesc = {}; @@ -770,10 +771,10 @@ HWTEST_F(MultiDeviceModuleSetArgBufferTest, void *ptr = nullptr; createKernelAndAllocMemory(rootDeviceIndex, &ptr, &kernelHandle); - L0::KernelImp *pKernel = reinterpret_cast(Kernel::fromHandle(kernelHandle)); - pKernel->setArgBuffer(0, sizeof(ptr), &ptr); + L0::KernelImp *kernel = reinterpret_cast(Kernel::fromHandle(kernelHandle)); + kernel->setArgBuffer(0, sizeof(ptr), &ptr); - for (auto alloc : pKernel->getResidencyContainer()) { + for (auto alloc : kernel->getResidencyContainer()) { if (alloc && alloc->getGpuAddress() == reinterpret_cast(ptr)) { EXPECT_EQ(rootDeviceIndex, alloc->getRootDeviceIndex()); } diff --git a/level_zero/tools/test/unit_tests/sources/metrics/test_metric_query_pool_1.cpp b/level_zero/tools/test/unit_tests/sources/metrics/test_metric_query_pool_1.cpp index 1a93e82283..c9c684da7b 100644 --- a/level_zero/tools/test/unit_tests/sources/metrics/test_metric_query_pool_1.cpp +++ b/level_zero/tools/test/unit_tests/sources/metrics/test_metric_query_pool_1.cpp @@ -12,6 +12,7 @@ #include "level_zero/core/source/driver/driver_imp.h" #include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h" #include "level_zero/core/test/unit_tests/mocks/mock_device.h" +#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h" #include "level_zero/tools/test/unit_tests/sources/metrics/mock_metric.h" #include "gmock/gmock.h" diff --git a/level_zero/tools/test/unit_tests/sources/metrics/test_metric_query_pool_2.cpp b/level_zero/tools/test/unit_tests/sources/metrics/test_metric_query_pool_2.cpp index d78e12678b..9a209c25bf 100644 --- a/level_zero/tools/test/unit_tests/sources/metrics/test_metric_query_pool_2.cpp +++ b/level_zero/tools/test/unit_tests/sources/metrics/test_metric_query_pool_2.cpp @@ -13,6 +13,7 @@ #include "level_zero/core/source/driver/driver_imp.h" #include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h" #include "level_zero/core/test/unit_tests/mocks/mock_device.h" +#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h" #include "level_zero/tools/test/unit_tests/sources/metrics/mock_metric.h" #include "gmock/gmock.h" diff --git a/level_zero/tools/test/unit_tests/sources/sysman/engine/linux/test_zes_engine.cpp b/level_zero/tools/test/unit_tests/sources/sysman/engine/linux/test_zes_engine.cpp index b1acc0016c..01712eb4dd 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/engine/linux/test_zes_engine.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/engine/linux/test_zes_engine.cpp @@ -30,10 +30,10 @@ class ZesEngineFixture : public SysmanDeviceFixture { void SetUp() override { SysmanDeviceFixture::SetUp(); - pMemoryManagerOriginal = context->getMemoryManager(); + pMemoryManagerOriginal = device->getDriverHandle()->getMemoryManager(); pMemoryManager = std::make_unique<::testing::NiceMock>(*neoDevice->getExecutionEnvironment()); pMemoryManager->localMemorySupported[0] = false; - context->setMemoryManager(pMemoryManager.get()); + device->getDriverHandle()->setMemoryManager(pMemoryManager.get()); pSysfsAccessOriginal = pLinuxSysmanImp->pSysfsAccess; pSysfsAccess = std::make_unique>>(); @@ -67,8 +67,8 @@ class ZesEngineFixture : public SysmanDeviceFixture { } void TearDown() override { - context->setMemoryManager(pMemoryManagerOriginal); SysmanDeviceFixture::TearDown(); + device->getDriverHandle()->setMemoryManager(pMemoryManagerOriginal); pLinuxSysmanImp->pDrm = pOriginalDrm; pLinuxSysmanImp->pPmuInterface = pOriginalPmuInterface; pLinuxSysmanImp->pSysfsAccess = pSysfsAccessOriginal; diff --git a/level_zero/tools/test/unit_tests/sources/sysman/pci/linux/test_zes_pci.cpp b/level_zero/tools/test/unit_tests/sources/sysman/pci/linux/test_zes_pci.cpp index 0c61b44910..58cfff9644 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/pci/linux/test_zes_pci.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/pci/linux/test_zes_pci.cpp @@ -50,7 +50,6 @@ class ZesPciFixture : public ::testing::Test { std::unique_ptr> driverHandle; NEO::MockDevice *neoDevice = nullptr; L0::Device *device = nullptr; - L0::Context *context = nullptr; void SetUp() override { neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment(NEO::defaultHwInfo.get()); @@ -62,12 +61,6 @@ class ZesPciFixture : public ::testing::Test { driverHandle->initialize(std::move(devices)); device = driverHandle->devices[0]; - ze_context_handle_t hContext; - ze_context_desc_t desc; - ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext); - EXPECT_EQ(ZE_RESULT_SUCCESS, res); - context = static_cast(Context::fromHandle(hContext)); - neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[device->getRootDeviceIndex()]->osInterface = std::make_unique(); auto osInterface = device->getOsInterface().get(); osInterface->setDrm(new SysmanMockDrm(const_cast(neoDevice->getRootDeviceEnvironment()))); @@ -117,7 +110,6 @@ class ZesPciFixture : public ::testing::Test { unsetenv("ZES_ENABLE_SYSMAN"); pLinuxSysmanImp->pSysfsAccess = pOriginalSysfsAccess; pLinuxSysmanImp->pFsAccess = pOriginalFsAccess; - context->destroy(); } SysmanDevice *pSysmanDevice = nullptr; SysmanDeviceImp *pSysmanDeviceImp = nullptr;