diff --git a/level_zero/core/test/unit_tests/fixtures/CMakeLists.txt b/level_zero/core/test/unit_tests/fixtures/CMakeLists.txt index ea501ae5d4..1b8df4a857 100644 --- a/level_zero/core/test/unit_tests/fixtures/CMakeLists.txt +++ b/level_zero/core/test/unit_tests/fixtures/CMakeLists.txt @@ -16,10 +16,13 @@ set(L0_FIXTURES_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/device_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/event_fixture.cpp ${CMAKE_CURRENT_SOURCE_DIR}/event_fixture.h + ${CMAKE_CURRENT_SOURCE_DIR}/host_pointer_manager_fixture.cpp ${CMAKE_CURRENT_SOURCE_DIR}/host_pointer_manager_fixture.h + ${CMAKE_CURRENT_SOURCE_DIR}/kernel_max_cooperative_groups_count_fixture.cpp ${CMAKE_CURRENT_SOURCE_DIR}/kernel_max_cooperative_groups_count_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/module_fixture.cpp ${CMAKE_CURRENT_SOURCE_DIR}/module_fixture.h + ${CMAKE_CURRENT_SOURCE_DIR}/memory_ipc_fixture.cpp ${CMAKE_CURRENT_SOURCE_DIR}/memory_ipc_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/multi_tile_fixture.cpp ${CMAKE_CURRENT_SOURCE_DIR}/multi_tile_fixture.h diff --git a/level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.cpp b/level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.cpp index b14b36acd7..2f720e4f98 100644 --- a/level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.cpp +++ b/level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.cpp @@ -8,6 +8,7 @@ #include "level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.h" #include "shared/source/built_ins/sip.h" +#include "shared/source/command_container/implicit_scaling.h" #include "shared/source/helpers/gfx_core_helper.h" #include "shared/source/helpers/ray_tracing_helper.h" #include "shared/source/memory_manager/internal_allocation_storage.h" @@ -19,6 +20,8 @@ #include "level_zero/core/source/driver/driver_imp.h" #include "level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper.h" #include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h" +#include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h" +#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h" #include "level_zero/core/test/unit_tests/mocks/mock_event.h" #include "gtest/gtest.h" @@ -26,6 +29,8 @@ namespace L0 { namespace ult { +CommandListFixture::CommandListFixture() = default; +CommandListFixture ::~CommandListFixture() = default; void CommandListFixture::setUp() { DeviceFixture::setUp(); ze_result_t returnValue; 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 3cfb880b0b..3aefeebdfb 100644 --- a/level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.h +++ b/level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.h @@ -7,29 +7,24 @@ #pragma once -#include "shared/source/command_container/implicit_scaling.h" #include "shared/test/common/cmd_parse/gen_cmd_parse.h" -#include "shared/test/common/helpers/unit_test_helper.h" #include "shared/test/common/helpers/variable_backup.h" -#include "level_zero/core/source/event/event.h" #include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" #include "level_zero/core/test/unit_tests/fixtures/module_fixture.h" -#include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h" -#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h" -#include "level_zero/core/test/unit_tests/mocks/mock_event.h" namespace L0 { namespace ult { - class CommandListFixture : public DeviceFixture { public: + CommandListFixture(); + ~CommandListFixture() override; void setUp(); void tearDown(); - std::unique_ptr commandList; + std::unique_ptr> commandList; std::unique_ptr eventPool; - std::unique_ptr event; + std::unique_ptr> event; }; struct MultiTileCommandListFixtureInit : public SingleRootMultiSubDeviceFixture { @@ -39,7 +34,7 @@ struct MultiTileCommandListFixtureInit : public SingleRootMultiSubDeviceFixture SingleRootMultiSubDeviceFixture::tearDown(); } - std::unique_ptr commandList; + std::unique_ptr> commandList; std::unique_ptr eventPool; std::unique_ptr event; std::unique_ptr> apiSupportBackup; @@ -78,11 +73,11 @@ struct ModuleMutableCommandListFixture : public ModuleImmutableDataFixture { uint32_t getMocs(bool l3On); std::unique_ptr mockKernelImmData; - std::unique_ptr commandList; - std::unique_ptr commandListImmediate; + std::unique_ptr> commandList; + std::unique_ptr> commandListImmediate; std::unique_ptr kernel; std::unique_ptr> backupHwInfo; - L0::ult::CommandQueue *commandQueue; + WhiteBox *commandQueue; size_t expectedSbaCmds = 0; NEO::EngineGroupType engineGroupType; @@ -121,7 +116,7 @@ struct CmdListPipelineSelectStateFixture : public ModuleMutableCommandListFixtur template void testBodySystolicAndScratchOnSecondCommandList(); - std::unique_ptr commandList2; + std::unique_ptr> commandList2; }; struct CmdListStateComputeModeStateFixture : public ModuleMutableCommandListFixture { @@ -150,7 +145,7 @@ struct CommandListGlobalHeapsFixtureInit : public CommandListStateBaseAddressFix void setUp(); void setUpParams(int32_t globalHeapMode); void tearDown(); - std::unique_ptr commandListPrivateHeap; + std::unique_ptr> commandListPrivateHeap; }; template @@ -164,7 +159,7 @@ struct ImmediateCmdListSharedHeapsFixture : public ModuleMutableCommandListFixtu void setUp(); void tearDown(); - std::unique_ptr commandListImmediateCoexisting; + std::unique_ptr> commandListImmediateCoexisting; std::unique_ptr eventPool; std::unique_ptr event; }; @@ -184,7 +179,7 @@ struct ImmediateCmdListSharedHeapsFlushTaskFixtureInit : public ImmediateCmdList template void testBody(NonKernelOperation operation); - void appendNonKernelOperation(L0::ult::CommandList *currentCmdList, NonKernelOperation operation); + void appendNonKernelOperation(WhiteBox *currentCmdList, NonKernelOperation operation); void validateDispatchFlags(bool nonKernel, NEO::ImmediateDispatchFlags &recordedImmediateFlushTaskFlags, const NEO::IndirectHeap *recordedSsh); @@ -335,8 +330,8 @@ struct PrimaryBatchBufferPreamblelessCmdListFixture : public PrimaryBatchBufferC void setUp(); void tearDown(); - std::unique_ptr commandList2; - std::unique_ptr commandList3; + std::unique_ptr> commandList2; + std::unique_ptr> commandList3; }; struct ImmediateFlushTaskCmdListFixture : public ModuleMutableCommandListFixture { diff --git a/level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.inl b/level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.inl index 8f8f3d24c5..3485e6d53f 100644 --- a/level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.inl +++ b/level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.inl @@ -7,6 +7,7 @@ #include "shared/source/command_container/cmdcontainer.h" #include "shared/source/command_stream/thread_arbitration_policy.h" +#include "shared/source/helpers/register_offsets.h" #include "shared/source/indirect_heap/indirect_heap.h" #include "shared/source/kernel/grf_config.h" #include "shared/test/common/helpers/unit_test_helper.h" @@ -15,6 +16,8 @@ #include "shared/test/common/mocks/mock_memory_operations_handler.h" #include "level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.h" +#include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h" +#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h" namespace L0 { 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 04060c71b9..4161a0b8de 100644 --- a/level_zero/core/test/unit_tests/fixtures/device_fixture.h +++ b/level_zero/core/test/unit_tests/fixtures/device_fixture.h @@ -34,7 +34,7 @@ namespace ult { class MockBuiltins; struct DeviceFixture { - + virtual ~DeviceFixture() = default; void setUp(); void setUpImpl(NEO::HardwareInfo *hwInfo); void tearDown(); diff --git a/level_zero/core/test/unit_tests/fixtures/host_pointer_manager_fixture.cpp b/level_zero/core/test/unit_tests/fixtures/host_pointer_manager_fixture.cpp new file mode 100644 index 0000000000..acf695fad2 --- /dev/null +++ b/level_zero/core/test/unit_tests/fixtures/host_pointer_manager_fixture.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2022-2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero/core/test/unit_tests/fixtures/host_pointer_manager_fixture.h" + +#include "shared/test/common/mocks/mock_device.h" +#include "shared/test/common/mocks/mock_memory_operations_handler.h" + +#include "level_zero/core/source/context/context.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" + +#include "gtest/gtest.h" + +namespace L0 { +namespace ult { + +void HostPointerManagerFixure::setUp() { + + NEO::DeviceVector devices; + neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment(NEO::defaultHwInfo.get()); + auto mockBuiltIns = new MockBuiltins(); + neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns); + neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->memoryOperationsInterface = + std::make_unique(); + mockMemoryInterface = static_cast( + neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->memoryOperationsInterface.get()); + devices.push_back(std::unique_ptr(neoDevice)); + + hostDriverHandle = std::make_unique(); + hostDriverHandle->initialize(std::move(devices)); + device = hostDriverHandle->devices[0]; + openHostPointerManager = static_cast(hostDriverHandle->hostPointerManager.get()); + + heapPointer = hostDriverHandle->getMemoryManager()->allocateSystemMemory(heapSize, MemoryConstants::pageSize); + ASSERT_NE(nullptr, heapPointer); + + ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0}; + ze_result_t ret = hostDriverHandle->createContext(&desc, 0u, nullptr, &hContext); + EXPECT_EQ(ZE_RESULT_SUCCESS, ret); + context = L0::Context::fromHandle(hContext); +} + +void HostPointerManagerFixure::tearDown() { + context->destroy(); + + hostDriverHandle->getMemoryManager()->freeSystemMemory(heapPointer); +} + +} // namespace ult +} // namespace L0 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 a0aea6e6ff..efc526684a 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2022 Intel Corporation + * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -8,64 +8,35 @@ #pragma once #include "shared/source/helpers/constants.h" -#include "shared/source/os_interface/device_factory.h" -#include "shared/source/os_interface/os_inc_base.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" -#include "shared/test/common/helpers/default_hw_info.h" -#include "shared/test/common/mocks/mock_compilers.h" -#include "shared/test/common/mocks/mock_device.h" -#include "shared/test/common/mocks/mock_memory_operations_handler.h" -#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" +#include "level_zero/core/test/unit_tests/white_box.h" +#include +namespace NEO { +class MockDevice; +class MockMemoryOperationsHandlerTests; +} // namespace NEO namespace L0 { +struct Context; +struct Device; +struct DriverHandleImp; +class HostPointerManager; namespace ult { struct HostPointerManagerFixure { - void setUp() { - - NEO::DeviceVector devices; - neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment(NEO::defaultHwInfo.get()); - auto mockBuiltIns = new MockBuiltins(); - neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns); - neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->memoryOperationsInterface = - std::make_unique(); - mockMemoryInterface = static_cast( - neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->memoryOperationsInterface.get()); - devices.push_back(std::unique_ptr(neoDevice)); - - hostDriverHandle = std::make_unique(); - hostDriverHandle->initialize(std::move(devices)); - device = hostDriverHandle->devices[0]; - openHostPointerManager = static_cast(hostDriverHandle->hostPointerManager.get()); - - heapPointer = hostDriverHandle->getMemoryManager()->allocateSystemMemory(heapSize, MemoryConstants::pageSize); - ASSERT_NE(nullptr, heapPointer); - - ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0}; - ze_result_t ret = hostDriverHandle->createContext(&desc, 0u, nullptr, &hContext); - EXPECT_EQ(ZE_RESULT_SUCCESS, ret); - context = L0::Context::fromHandle(hContext); - } - - void tearDown() { - context->destroy(); - - hostDriverHandle->getMemoryManager()->freeSystemMemory(heapPointer); - } + void setUp(); + void tearDown(); DebugManagerStateRestore debugRestore; - std::unique_ptr hostDriverHandle; + std::unique_ptr> hostDriverHandle; - L0::ult::HostPointerManager *openHostPointerManager = nullptr; + WhiteBox *openHostPointerManager = nullptr; NEO::MockDevice *neoDevice = nullptr; L0::Device *device = nullptr; NEO::MockMemoryOperationsHandlerTests *mockMemoryInterface = nullptr; ze_context_handle_t hContext; - L0::Context *context; + L0::Context *context = nullptr; void *heapPointer = nullptr; size_t heapSize = 4 * MemoryConstants::pageSize; diff --git a/level_zero/core/test/unit_tests/fixtures/kernel_max_cooperative_groups_count_fixture.cpp b/level_zero/core/test/unit_tests/fixtures/kernel_max_cooperative_groups_count_fixture.cpp new file mode 100644 index 0000000000..526c8f8880 --- /dev/null +++ b/level_zero/core/test/unit_tests/fixtures/kernel_max_cooperative_groups_count_fixture.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero/core/test/unit_tests/fixtures/kernel_max_cooperative_groups_count_fixture.h" + +#include "shared/source/execution_environment/root_device_environment.h" +#include "shared/source/helpers/gfx_core_helper.h" + +#include "level_zero/core/source/module/module_imp.h" + +namespace L0 { +namespace ult { +void KernelImpSuggestMaxCooperativeGroupCountFixture::setUp() { + DeviceFixture::setUp(); + kernelInfo.kernelDescriptor = &kernelDescriptor; + auto &hardwareInfo = device->getHwInfo(); + auto &helper = device->getNEODevice()->getRootDeviceEnvironment().getHelper(); + availableThreadCount = helper.calculateAvailableThreadCount(hardwareInfo, numGrf); + + dssCount = hardwareInfo.gtSystemInfo.DualSubSliceCount; + if (dssCount == 0) { + dssCount = hardwareInfo.gtSystemInfo.SubSliceCount; + } + availableSlm = dssCount * KB * hardwareInfo.capabilityTable.slmSize; + maxBarrierCount = static_cast(helper.getMaxBarrierRegisterPerSlice()); + + kernelInfo.kernelDescriptor->kernelAttributes.simdSize = simd; + kernelInfo.kernelDescriptor->kernelAttributes.numGrfRequired = numGrf; +} + +uint32_t KernelImpSuggestMaxCooperativeGroupCountFixture::getMaxWorkGroupCount() { + kernelInfo.kernelDescriptor->kernelAttributes.slmInlineSize = usedSlm; + kernelInfo.kernelDescriptor->kernelAttributes.barrierCount = usesBarriers; + + Mock kernel; + kernel.kernelImmData = &kernelInfo; + auto module = std::make_unique(device, nullptr, ModuleType::User); + kernel.module = module.get(); + + kernel.groupSize[0] = lws[0]; + kernel.groupSize[1] = lws[1]; + kernel.groupSize[2] = lws[2]; + uint32_t totalGroupCount = 0; + kernel.KernelImp::suggestMaxCooperativeGroupCount(&totalGroupCount, NEO::EngineGroupType::CooperativeCompute, true); + return totalGroupCount; +} +} // namespace ult +} // namespace L0 \ No newline at end of file diff --git a/level_zero/core/test/unit_tests/fixtures/kernel_max_cooperative_groups_count_fixture.h b/level_zero/core/test/unit_tests/fixtures/kernel_max_cooperative_groups_count_fixture.h index f1a1db41b9..20a93a8250 100644 --- a/level_zero/core/test/unit_tests/fixtures/kernel_max_cooperative_groups_count_fixture.h +++ b/level_zero/core/test/unit_tests/fixtures/kernel_max_cooperative_groups_count_fixture.h @@ -6,17 +6,14 @@ */ #pragma once -#include "shared/source/execution_environment/root_device_environment.h" -#include "shared/source/helpers/gfx_core_helper.h" #include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" #include "level_zero/core/test/unit_tests/mocks/mock_kernel.h" -#include "level_zero/core/test/unit_tests/mocks/mock_module.h" namespace L0 { namespace ult { -class KernelImpSuggestMaxCooperativeGroupCountTests : public Test { +class KernelImpSuggestMaxCooperativeGroupCountFixture : public DeviceFixture { public: const uint32_t numGrf = 128; const uint32_t simd = 8; @@ -31,40 +28,9 @@ class KernelImpSuggestMaxCooperativeGroupCountTests : public Test WhiteBox<::L0::KernelImmutableData> kernelInfo; NEO::KernelDescriptor kernelDescriptor; - void SetUp() override { - Test::SetUp(); - kernelInfo.kernelDescriptor = &kernelDescriptor; - auto &hardwareInfo = device->getHwInfo(); - auto &helper = device->getNEODevice()->getRootDeviceEnvironment().getHelper(); - availableThreadCount = helper.calculateAvailableThreadCount(hardwareInfo, numGrf); + void setUp(); - dssCount = hardwareInfo.gtSystemInfo.DualSubSliceCount; - if (dssCount == 0) { - dssCount = hardwareInfo.gtSystemInfo.SubSliceCount; - } - availableSlm = dssCount * KB * hardwareInfo.capabilityTable.slmSize; - maxBarrierCount = static_cast(helper.getMaxBarrierRegisterPerSlice()); - - kernelInfo.kernelDescriptor->kernelAttributes.simdSize = simd; - kernelInfo.kernelDescriptor->kernelAttributes.numGrfRequired = numGrf; - } - - uint32_t getMaxWorkGroupCount() { - kernelInfo.kernelDescriptor->kernelAttributes.slmInlineSize = usedSlm; - kernelInfo.kernelDescriptor->kernelAttributes.barrierCount = usesBarriers; - - Mock kernel; - kernel.kernelImmData = &kernelInfo; - auto module = std::make_unique(device, nullptr, ModuleType::User); - kernel.module = module.get(); - - kernel.groupSize[0] = lws[0]; - kernel.groupSize[1] = lws[1]; - kernel.groupSize[2] = lws[2]; - uint32_t totalGroupCount = 0; - kernel.KernelImp::suggestMaxCooperativeGroupCount(&totalGroupCount, NEO::EngineGroupType::CooperativeCompute, true); - return totalGroupCount; - } + uint32_t getMaxWorkGroupCount(); }; } // namespace ult -} // namespace L0 \ No newline at end of file +} // namespace L0 diff --git a/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.cpp b/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.cpp new file mode 100644 index 0000000000..6d6fe813f2 --- /dev/null +++ b/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.cpp @@ -0,0 +1,553 @@ +/* + * Copyright (C) 2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h" + +#include "shared/source/gmm_helper/gmm_helper.h" +#include "shared/source/memory_manager/gfx_partition.h" +#include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/mocks/mock_compilers.h" +#include "shared/test/common/mocks/mock_device.h" +#include "shared/test/common/mocks/mock_memory_manager.h" + +#include "level_zero/core/source/context/context_imp.h" +#include "level_zero/core/source/device/device_imp.h" +#include "level_zero/core/source/driver/driver_handle_imp.h" +#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h" +#include "level_zero/core/test/unit_tests/mocks/mock_kernel.h" + +#include "gtest/gtest.h" + +namespace L0 { +namespace ult { + +void *DriverHandleGetFdMock::importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::AllocationType allocationType, void *basePointer, NEO::GraphicsAllocation **pAloc, NEO::SvmAllocationData &mappedPeerAllocData) { + this->allocationTypeRequested = allocationType; + if (mockFd == allocationMap.second) { + return allocationMap.first; + } + return nullptr; +} + +ze_result_t ContextFdMock::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 res = L0::ContextImp::allocDeviceMem(hDevice, deviceDesc, size, alignment, ptr); + if (ZE_RESULT_SUCCESS == res) { + driverHandle->allocationMap.first = *ptr; + driverHandle->allocationMap.second = driverHandle->mockFd; + } + + return res; +} + +ze_result_t ContextFdMock::allocHostMem(const ze_host_mem_alloc_desc_t *hostDesc, + size_t size, + size_t alignment, void **ptr) { + ze_result_t res = L0::ContextImp::allocHostMem(hostDesc, size, alignment, ptr); + if (ZE_RESULT_SUCCESS == res) { + driverHandle->allocationMap.first = *ptr; + driverHandle->allocationMap.second = driverHandle->mockFd; + } + + return res; +} + +ze_result_t ContextFdMock::getMemAllocProperties(const void *ptr, + ze_memory_allocation_properties_t *pMemAllocProperties, + ze_device_handle_t *phDevice) { + ze_result_t res = ContextImp::getMemAllocProperties(ptr, pMemAllocProperties, phDevice); + if (ZE_RESULT_SUCCESS == res && pMemAllocProperties->pNext && !memPropTest) { + ze_base_properties_t *baseProperties = + reinterpret_cast(pMemAllocProperties->pNext); + if (baseProperties->stype == ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_EXPORT_FD) { + ze_external_memory_export_fd_t *extendedMemoryExportProperties = + reinterpret_cast(pMemAllocProperties->pNext); + extendedMemoryExportProperties->fd = driverHandle->mockFd; + } + } + + return res; +} + +ze_result_t ContextFdMock::getImageAllocProperties(Image *image, + ze_image_allocation_ext_properties_t *pAllocProperties) { + + ze_result_t res = ContextImp::getImageAllocProperties(image, pAllocProperties); + if (ZE_RESULT_SUCCESS == res && pAllocProperties->pNext) { + ze_base_properties_t *baseProperties = + reinterpret_cast(pAllocProperties->pNext); + if (baseProperties->stype == ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_EXPORT_FD) { + ze_external_memory_export_fd_t *extendedMemoryExportProperties = + reinterpret_cast(pAllocProperties->pNext); + extendedMemoryExportProperties->fd = driverHandle->mockFd; + } + } + + return res; +} + +void MemoryExportImportTest::SetUp() { + + neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment(NEO::defaultHwInfo.get()); + auto mockBuiltIns = new MockBuiltins(); + neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns); + NEO::DeviceVector devices; + devices.push_back(std::unique_ptr(neoDevice)); + driverHandle = std::make_unique(); + driverHandle->initialize(std::move(devices)); + device = driverHandle->devices[0]; + + context = std::make_unique(driverHandle.get()); + EXPECT_NE(context, nullptr); + context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle())); + auto neoDevice = device->getNEODevice(); + context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex()); + context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); +} + +void *DriverHandleGetMemHandleMock::importNTHandle(ze_device_handle_t hDevice, void *handle, NEO::AllocationType allocationType) { + if (mockHandle == allocationHandleMap.second) { + return allocationHandleMap.first; + } + return nullptr; +} +void *DriverHandleGetMemHandleMock::importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, + NEO::AllocationType allocationType, void *basePointer, NEO::GraphicsAllocation **pAloc, NEO::SvmAllocationData &mappedPeerAllocData) { + if (mockFd == allocationFdMap.second) { + return allocationFdMap.first; + } + return nullptr; +} + +ze_result_t ContextMemHandleMock::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 res = L0::ContextImp::allocDeviceMem(hDevice, deviceDesc, size, alignment, ptr); + if (ZE_RESULT_SUCCESS == res) { + driverHandle->allocationFdMap.first = *ptr; + driverHandle->allocationFdMap.second = driverHandle->mockFd; + driverHandle->allocationHandleMap.first = *ptr; + driverHandle->allocationHandleMap.second = driverHandle->mockHandle; + } + + return res; +} + +ze_result_t ContextMemHandleMock::getMemAllocProperties(const void *ptr, + ze_memory_allocation_properties_t *pMemAllocProperties, + ze_device_handle_t *phDevice) { + ze_result_t res = ContextImp::getMemAllocProperties(ptr, pMemAllocProperties, phDevice); + if (ZE_RESULT_SUCCESS == res && pMemAllocProperties->pNext) { + ze_base_properties_t *baseProperties = + reinterpret_cast(pMemAllocProperties->pNext); + if (baseProperties->stype == ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_EXPORT_FD) { + ze_external_memory_export_fd_t *extendedMemoryExportProperties = + reinterpret_cast(pMemAllocProperties->pNext); + extendedMemoryExportProperties->fd = driverHandle->mockFd; + } + } + + return res; +} + +ze_result_t ContextMemHandleMock::getImageAllocProperties(Image *image, + ze_image_allocation_ext_properties_t *pAllocProperties) { + + ze_result_t res = ContextImp::getImageAllocProperties(image, pAllocProperties); + if (ZE_RESULT_SUCCESS == res && pAllocProperties->pNext) { + ze_base_properties_t *baseProperties = + reinterpret_cast(pAllocProperties->pNext); + if (baseProperties->stype == ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_EXPORT_FD) { + ze_external_memory_export_fd_t *extendedMemoryExportProperties = + reinterpret_cast(pAllocProperties->pNext); + extendedMemoryExportProperties->fd = driverHandle->mockFd; + } + } + + return res; +} + +void MemoryExportImportWSLTest::SetUp() { + + neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment(NEO::defaultHwInfo.get()); + auto mockBuiltIns = new MockBuiltins(); + neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns); + NEO::DeviceVector devices; + devices.push_back(std::unique_ptr(neoDevice)); + driverHandle = std::make_unique(); + prevMemoryManager = driverHandle->getMemoryManager(); + currMemoryManager = new MemoryManagerMemHandleMock(); + driverHandle->setMemoryManager(currMemoryManager); + driverHandle->initialize(std::move(devices)); + device = driverHandle->devices[0]; + + context = std::make_unique(driverHandle.get()); + EXPECT_NE(context, nullptr); + context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle())); + auto neoDevice = device->getNEODevice(); + context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex()); + context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); +} + +void MemoryExportImportWSLTest::TearDown() { + driverHandle->setMemoryManager(prevMemoryManager); + delete currMemoryManager; +} + +void *DriverHandleGetWinHandleMock::importNTHandle(ze_device_handle_t hDevice, void *handle, NEO::AllocationType allocationType) { + if (mockHandle == allocationMap.second) { + return allocationMap.first; + } + return nullptr; +} + +ze_result_t ContextHandleMock::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 res = L0::ContextImp::allocDeviceMem(hDevice, deviceDesc, size, alignment, ptr); + if (ZE_RESULT_SUCCESS == res) { + driverHandle->allocationMap.first = *ptr; + driverHandle->allocationMap.second = driverHandle->mockHandle; + } + + return res; +} + +ze_result_t ContextHandleMock::getMemAllocProperties(const void *ptr, + ze_memory_allocation_properties_t *pMemAllocProperties, + ze_device_handle_t *phDevice) { + ze_result_t res = ContextImp::getMemAllocProperties(ptr, pMemAllocProperties, phDevice); + if (ZE_RESULT_SUCCESS == res && pMemAllocProperties->pNext) { + ze_external_memory_export_win32_handle_t *extendedMemoryExportProperties = + reinterpret_cast(pMemAllocProperties->pNext); + extendedMemoryExportProperties->handle = reinterpret_cast(reinterpret_cast(driverHandle->mockHandle)); + } + + return res; +} + +ze_result_t ContextHandleMock::getImageAllocProperties(Image *image, + ze_image_allocation_ext_properties_t *pAllocProperties) { + + ze_result_t res = ContextImp::getImageAllocProperties(image, pAllocProperties); + if (ZE_RESULT_SUCCESS == res && pAllocProperties->pNext) { + ze_external_memory_export_win32_handle_t *extendedMemoryExportProperties = + reinterpret_cast(pAllocProperties->pNext); + extendedMemoryExportProperties->handle = reinterpret_cast(reinterpret_cast(driverHandle->mockHandle)); + } + + return res; +} + +ze_result_t ContextHandleMock::freeMem(const void *ptr) { + L0::ContextImp::freeMem(ptr); + return ZE_RESULT_SUCCESS; +} + +void MemoryExportImportWinHandleTest::SetUp() { + + neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment(NEO::defaultHwInfo.get()); + auto mockBuiltIns = new MockBuiltins(); + neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns); + NEO::DeviceVector devices; + devices.push_back(std::unique_ptr(neoDevice)); + driverHandle = std::make_unique(); + driverHandle->initialize(std::move(devices)); + device = driverHandle->devices[0]; + + context = std::make_unique(driverHandle.get()); + EXPECT_NE(context, nullptr); + context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle())); + auto neoDevice = device->getNEODevice(); + context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex()); + context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); +} + +void *DriverHandleGetIpcHandleMock::importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, + uint64_t handle, NEO::AllocationType allocationType, void *basePointer, NEO::GraphicsAllocation **pAlloc, + NEO::SvmAllocationData &mappedPeerAllocData) { + EXPECT_EQ(handle, static_cast(mockFd)); + if (mockFd == allocationMap.second) { + return allocationMap.first; + } + return nullptr; +} +ze_result_t ContextGetIpcHandleMock::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 res = L0::ContextImp::allocDeviceMem(hDevice, deviceDesc, size, alignment, ptr); + if (ZE_RESULT_SUCCESS == res) { + driverHandle->allocationMap.first = *ptr; + driverHandle->allocationMap.second = driverHandle->mockFd; + } + + return res; +} + +ze_result_t ContextGetIpcHandleMock::getIpcMemHandle(const void *ptr, ze_ipc_mem_handle_t *pIpcHandle) { + uint64_t handle = driverHandle->mockFd; + NEO::SvmAllocationData *allocData = this->driverHandle->svmAllocsManager->getSVMAlloc(ptr); + + IpcMemoryData &ipcData = *reinterpret_cast(pIpcHandle->data); + ipcData = {}; + ipcData.handle = handle; + auto type = Context::parseUSMType(allocData->memoryType); + if (type == ZE_MEMORY_TYPE_HOST) { + ipcData.type = static_cast(InternalIpcMemoryType::IPC_HOST_UNIFIED_MEMORY); + } + + return ZE_RESULT_SUCCESS; +} + +NEO::GraphicsAllocation *MemoryManagerOpenIpcMock::allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) { + return allocateGraphicsMemoryWithProperties(properties, nullptr); +} + +NEO::GraphicsAllocation *MemoryManagerOpenIpcMock::allocateGraphicsMemoryWithProperties(const AllocationProperties &properties, const void *externalPtr) { + auto ptr = reinterpret_cast(sharedHandleAddress++); + auto gmmHelper = getGmmHelper(0); + auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr)); + auto alloc = new IpcImplicitScalingMockGraphicsAllocation(properties.rootDeviceIndex, + NEO::AllocationType::BUFFER, + ptr, + 0x1000, + 0u, + MemoryPool::System4KBPages, + MemoryManager::maxOsContextCount, + canonizedGpuAddress); + alloc->setGpuBaseAddress(0xabcd); + return alloc; +} + +NEO::GraphicsAllocation *MemoryManagerOpenIpcMock::createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) { + if (failOnCreateGraphicsAllocationFromSharedHandle) { + return nullptr; + } + auto ptr = reinterpret_cast(sharedHandleAddress++); + auto gmmHelper = getGmmHelper(0); + auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr)); + auto alloc = new IpcImplicitScalingMockGraphicsAllocation(properties.rootDeviceIndex, + NEO::AllocationType::BUFFER, + ptr, + 0x1000, + 0u, + MemoryPool::System4KBPages, + MemoryManager::maxOsContextCount, + canonizedGpuAddress); + alloc->setGpuBaseAddress(0xabcd); + return alloc; +} +NEO::GraphicsAllocation *MemoryManagerOpenIpcMock::createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) { + if (failOnCreateGraphicsAllocationFromSharedHandle) { + return nullptr; + } + auto ptr = reinterpret_cast(sharedHandleAddress++); + auto gmmHelper = getGmmHelper(0); + auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr)); + auto alloc = new IpcImplicitScalingMockGraphicsAllocation(properties.rootDeviceIndex, + NEO::AllocationType::BUFFER, + ptr, + 0x1000, + 0u, + MemoryPool::System4KBPages, + MemoryManager::maxOsContextCount, + canonizedGpuAddress); + alloc->setGpuBaseAddress(0xabcd); + return alloc; +} +NEO::GraphicsAllocation *MemoryManagerOpenIpcMock::createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) { + auto ptr = reinterpret_cast(sharedHandleAddress++); + auto gmmHelper = getGmmHelper(0); + auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr)); + auto alloc = new IpcImplicitScalingMockGraphicsAllocation(0u, + NEO::AllocationType::BUFFER, + ptr, + 0x1000, + 0u, + MemoryPool::System4KBPages, + MemoryManager::maxOsContextCount, + canonizedGpuAddress); + alloc->setGpuBaseAddress(0xabcd); + return alloc; +}; + +ze_result_t ContextIpcMock::getIpcMemHandle(const void *ptr, ze_ipc_mem_handle_t *pIpcHandle) { + uint64_t handle = mockFd; + NEO::SvmAllocationData *allocData = this->driverHandle->svmAllocsManager->getSVMAlloc(ptr); + + IpcMemoryData &ipcData = *reinterpret_cast(pIpcHandle->data); + ipcData = {}; + ipcData.handle = handle; + auto type = Context::parseUSMType(allocData->memoryType); + if (type == ZE_MEMORY_TYPE_HOST) { + ipcData.type = static_cast(InternalIpcMemoryType::IPC_HOST_UNIFIED_MEMORY); + } + + return ZE_RESULT_SUCCESS; +} + +void MemoryOpenIpcHandleTest::SetUp() { + + neoDevice = + NEO::MockDevice::createWithNewExecutionEnvironment(NEO::defaultHwInfo.get()); + auto mockBuiltIns = new MockBuiltins(); + neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns); + NEO::DeviceVector devices; + 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 = std::make_unique(driverHandle.get()); + EXPECT_NE(context, nullptr); + context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle())); + auto neoDevice = device->getNEODevice(); + context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex()); + context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); +} + +void MemoryOpenIpcHandleTest::TearDown() { + driverHandle->setMemoryManager(prevMemoryManager); + delete currMemoryManager; +} + +NEO::GraphicsAllocation *MemoryManagerIpcImplicitScalingMock::allocateGraphicsMemoryInPreferredPool(const AllocationProperties &properties, const void *hostPtr) { + auto ptr = reinterpret_cast(sharedHandleAddress++); + auto gmmHelper = getGmmHelper(0); + auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr)); + auto alloc = new IpcImplicitScalingMockGraphicsAllocation(0u, + NEO::AllocationType::BUFFER, + ptr, + 0x1000, + 0u, + MemoryPool::System4KBPages, + MemoryManager::maxOsContextCount, + canonizedGpuAddress); + alloc->setGpuBaseAddress(0xabcd); + return alloc; +} + +NEO::GraphicsAllocation *MemoryManagerIpcImplicitScalingMock::allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) { + auto ptr = reinterpret_cast(sharedHandleAddress++); + auto gmmHelper = getGmmHelper(0); + auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr)); + auto alloc = new IpcImplicitScalingMockGraphicsAllocation(0u, + NEO::AllocationType::BUFFER, + ptr, + 0x1000, + 0u, + MemoryPool::System4KBPages, + MemoryManager::maxOsContextCount, + canonizedGpuAddress); + alloc->setGpuBaseAddress(0xabcd); + return alloc; +} + +NEO::GraphicsAllocation *MemoryManagerIpcImplicitScalingMock::createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) { + if (failOnCreateGraphicsAllocationFromSharedHandle) { + return nullptr; + } + auto ptr = reinterpret_cast(sharedHandleAddress++); + auto gmmHelper = getGmmHelper(0); + auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr)); + auto alloc = new IpcImplicitScalingMockGraphicsAllocation(0u, + NEO::AllocationType::BUFFER, + ptr, + 0x1000, + 0u, + MemoryPool::System4KBPages, + MemoryManager::maxOsContextCount, + canonizedGpuAddress); + alloc->setGpuBaseAddress(0xabcd); + return alloc; +} + +NEO::GraphicsAllocation *MemoryManagerIpcImplicitScalingMock::createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) { + if (failOnCreateGraphicsAllocationFromNTHandle) { + return nullptr; + } + + auto ptr = reinterpret_cast(sharedHandleAddress++); + auto gmmHelper = getGmmHelper(0); + auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr)); + auto alloc = new IpcImplicitScalingMockGraphicsAllocation(0u, + NEO::AllocationType::BUFFER, + ptr, + 0x1000, + 0u, + MemoryPool::System4KBPages, + MemoryManager::maxOsContextCount, + canonizedGpuAddress); + alloc->setGpuBaseAddress(0xabcd); + return alloc; +} +NEO::GraphicsAllocation *MemoryManagerIpcImplicitScalingMock::createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) { + if (failOnCreateGraphicsAllocationFromSharedHandle) { + return nullptr; + } + auto ptr = reinterpret_cast(sharedHandleAddress++); + auto gmmHelper = getGmmHelper(0); + auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr)); + auto alloc = new IpcImplicitScalingMockGraphicsAllocation(0u, + NEO::AllocationType::BUFFER, + ptr, + 0x1000, + 0u, + MemoryPool::System4KBPages, + MemoryManager::maxOsContextCount, + canonizedGpuAddress); + alloc->setGpuBaseAddress(0xabcd); + return alloc; +} + +void MemoryExportImportImplicitScalingTest::SetUp() { + DebugManagerStateRestore restorer; + DebugManager.flags.EnableImplicitScaling.set(1); + + neoDevice = + NEO::MockDevice::createWithNewExecutionEnvironment(NEO::defaultHwInfo.get()); + auto mockBuiltIns = new MockBuiltins(); + neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns); + NEO::DeviceVector devices; + devices.push_back(std::unique_ptr(neoDevice)); + driverHandle = std::make_unique(); + driverHandle->initialize(std::move(devices)); + prevMemoryManager = driverHandle->getMemoryManager(); + currMemoryManager = new MemoryManagerIpcImplicitScalingMock(*neoDevice->executionEnvironment); + driverHandle->setMemoryManager(currMemoryManager); + + prevSvmAllocsManager = driverHandle->svmAllocsManager; + currSvmAllocsManager = new NEO::SVMAllocsManager(currMemoryManager, false); + driverHandle->svmAllocsManager = currSvmAllocsManager; + + device = driverHandle->devices[0]; + + context = std::make_unique(driverHandle.get()); + EXPECT_NE(context, nullptr); + context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle())); + auto neoDevice = device->getNEODevice(); + context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex()); + context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); +} + +void MemoryExportImportImplicitScalingTest::TearDown() { + driverHandle->svmAllocsManager = prevSvmAllocsManager; + delete currSvmAllocsManager; + driverHandle->setMemoryManager(prevMemoryManager); + delete currMemoryManager; +} + +} // namespace ult +} // namespace L0 diff --git a/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h b/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h index 5e8f6d3d9a..2f8b17fa82 100644 --- a/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h +++ b/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h @@ -6,33 +6,27 @@ */ #pragma once - -#include "shared/source/gmm_helper/gmm_helper.h" -#include "shared/source/memory_manager/gfx_partition.h" +#include "shared/source/gmm_helper/gmm.h" +#include "shared/source/memory_manager/memory_allocation.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" -#include "shared/test/common/mocks/mock_compilers.h" -#include "shared/test/common/mocks/mock_device.h" -#include "shared/test/common/mocks/mock_memory_manager.h" #include "level_zero/core/source/context/context_imp.h" #include "level_zero/core/source/device/device_imp.h" #include "level_zero/core/source/driver/driver_handle_imp.h" -#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h" -#include "level_zero/core/test/unit_tests/mocks/mock_kernel.h" #include "gtest/gtest.h" +namespace NEO { +class MockDevice; +class MemoryManagerMemHandleMock; +} // namespace NEO + namespace L0 { namespace ult { struct DriverHandleGetFdMock : public L0::DriverHandleImp { - void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::AllocationType allocationType, void *basePointer, NEO::GraphicsAllocation **pAloc, NEO::SvmAllocationData &mappedPeerAllocData) override { - this->allocationTypeRequested = allocationType; - if (mockFd == allocationMap.second) { - return allocationMap.first; - } - return nullptr; - } + void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, + NEO::AllocationType allocationType, void *basePointer, NEO::GraphicsAllocation **pAloc, NEO::SvmAllocationData &mappedPeerAllocData) override; const int mockFd = 57; std::pair allocationMap; @@ -46,61 +40,18 @@ struct ContextFdMock : public L0::ContextImp { 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) override { - ze_result_t res = L0::ContextImp::allocDeviceMem(hDevice, deviceDesc, size, alignment, ptr); - if (ZE_RESULT_SUCCESS == res) { - driverHandle->allocationMap.first = *ptr; - driverHandle->allocationMap.second = driverHandle->mockFd; - } - - return res; - } + size_t alignment, void **ptr) override; ze_result_t allocHostMem(const ze_host_mem_alloc_desc_t *hostDesc, size_t size, - size_t alignment, void **ptr) override { - ze_result_t res = L0::ContextImp::allocHostMem(hostDesc, size, alignment, ptr); - if (ZE_RESULT_SUCCESS == res) { - driverHandle->allocationMap.first = *ptr; - driverHandle->allocationMap.second = driverHandle->mockFd; - } - - return res; - } + size_t alignment, void **ptr) override; ze_result_t getMemAllocProperties(const void *ptr, ze_memory_allocation_properties_t *pMemAllocProperties, - ze_device_handle_t *phDevice) override { - ze_result_t res = ContextImp::getMemAllocProperties(ptr, pMemAllocProperties, phDevice); - if (ZE_RESULT_SUCCESS == res && pMemAllocProperties->pNext && !memPropTest) { - ze_base_properties_t *baseProperties = - reinterpret_cast(pMemAllocProperties->pNext); - if (baseProperties->stype == ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_EXPORT_FD) { - ze_external_memory_export_fd_t *extendedMemoryExportProperties = - reinterpret_cast(pMemAllocProperties->pNext); - extendedMemoryExportProperties->fd = driverHandle->mockFd; - } - } - - return res; - } + ze_device_handle_t *phDevice) override; ze_result_t getImageAllocProperties(Image *image, - ze_image_allocation_ext_properties_t *pAllocProperties) override { - - ze_result_t res = ContextImp::getImageAllocProperties(image, pAllocProperties); - if (ZE_RESULT_SUCCESS == res && pAllocProperties->pNext) { - ze_base_properties_t *baseProperties = - reinterpret_cast(pAllocProperties->pNext); - if (baseProperties->stype == ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_EXPORT_FD) { - ze_external_memory_export_fd_t *extendedMemoryExportProperties = - reinterpret_cast(pAllocProperties->pNext); - extendedMemoryExportProperties->fd = driverHandle->mockFd; - } - } - - return res; - } + ze_image_allocation_ext_properties_t *pAllocProperties) override; ze_result_t closeIpcMemHandle(const void *ptr) override { return ZE_RESULT_SUCCESS; @@ -110,24 +61,7 @@ struct ContextFdMock : public L0::ContextImp { }; struct MemoryExportImportTest : public ::testing::Test { - void SetUp() override { - - neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment(NEO::defaultHwInfo.get()); - auto mockBuiltIns = new MockBuiltins(); - neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns); - NEO::DeviceVector devices; - devices.push_back(std::unique_ptr(neoDevice)); - driverHandle = std::make_unique(); - driverHandle->initialize(std::move(devices)); - device = driverHandle->devices[0]; - - context = std::make_unique(driverHandle.get()); - EXPECT_NE(context, nullptr); - context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle())); - auto neoDevice = device->getNEODevice(); - context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex()); - context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); - } + void SetUp() override; void TearDown() override { } @@ -139,18 +73,10 @@ struct MemoryExportImportTest : public ::testing::Test { }; struct DriverHandleGetMemHandleMock : public L0::DriverHandleImp { - void *importNTHandle(ze_device_handle_t hDevice, void *handle, NEO::AllocationType allocationType) override { - if (mockHandle == allocationHandleMap.second) { - return allocationHandleMap.first; - } - return nullptr; - } - void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::AllocationType allocationType, void *basePointer, NEO::GraphicsAllocation **pAloc, NEO::SvmAllocationData &mappedPeerAllocData) override { - if (mockFd == allocationFdMap.second) { - return allocationFdMap.first; - } - return nullptr; - } + void *importNTHandle(ze_device_handle_t hDevice, void *handle, NEO::AllocationType allocationType) override; + void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, + NEO::AllocationType allocationType, void *basePointer, + NEO::GraphicsAllocation **pAloc, NEO::SvmAllocationData &mappedPeerAllocData) override; const int mockFd = 57; std::pair allocationFdMap; @@ -165,51 +91,14 @@ struct ContextMemHandleMock : public L0::ContextImp { 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) override { - ze_result_t res = L0::ContextImp::allocDeviceMem(hDevice, deviceDesc, size, alignment, ptr); - if (ZE_RESULT_SUCCESS == res) { - driverHandle->allocationFdMap.first = *ptr; - driverHandle->allocationFdMap.second = driverHandle->mockFd; - driverHandle->allocationHandleMap.first = *ptr; - driverHandle->allocationHandleMap.second = driverHandle->mockHandle; - } - - return res; - } + size_t alignment, void **ptr) override; ze_result_t getMemAllocProperties(const void *ptr, ze_memory_allocation_properties_t *pMemAllocProperties, - ze_device_handle_t *phDevice) override { - ze_result_t res = ContextImp::getMemAllocProperties(ptr, pMemAllocProperties, phDevice); - if (ZE_RESULT_SUCCESS == res && pMemAllocProperties->pNext) { - ze_base_properties_t *baseProperties = - reinterpret_cast(pMemAllocProperties->pNext); - if (baseProperties->stype == ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_EXPORT_FD) { - ze_external_memory_export_fd_t *extendedMemoryExportProperties = - reinterpret_cast(pMemAllocProperties->pNext); - extendedMemoryExportProperties->fd = driverHandle->mockFd; - } - } - - return res; - } + ze_device_handle_t *phDevice) override; ze_result_t getImageAllocProperties(Image *image, - ze_image_allocation_ext_properties_t *pAllocProperties) override { - - ze_result_t res = ContextImp::getImageAllocProperties(image, pAllocProperties); - if (ZE_RESULT_SUCCESS == res && pAllocProperties->pNext) { - ze_base_properties_t *baseProperties = - reinterpret_cast(pAllocProperties->pNext); - if (baseProperties->stype == ZE_STRUCTURE_TYPE_EXTERNAL_MEMORY_EXPORT_FD) { - ze_external_memory_export_fd_t *extendedMemoryExportProperties = - reinterpret_cast(pAllocProperties->pNext); - extendedMemoryExportProperties->fd = driverHandle->mockFd; - } - } - - return res; - } + ze_image_allocation_ext_properties_t *pAllocProperties) override; ze_result_t closeIpcMemHandle(const void *ptr) override { return ZE_RESULT_SUCCESS; @@ -219,32 +108,10 @@ struct ContextMemHandleMock : public L0::ContextImp { }; struct MemoryExportImportWSLTest : public ::testing::Test { - void SetUp() override { + void SetUp() override; - neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment(NEO::defaultHwInfo.get()); - auto mockBuiltIns = new MockBuiltins(); - neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns); - NEO::DeviceVector devices; - devices.push_back(std::unique_ptr(neoDevice)); - driverHandle = std::make_unique(); - prevMemoryManager = driverHandle->getMemoryManager(); - currMemoryManager = new MemoryManagerMemHandleMock(); - driverHandle->setMemoryManager(currMemoryManager); - driverHandle->initialize(std::move(devices)); - device = driverHandle->devices[0]; + void TearDown() override; - context = std::make_unique(driverHandle.get()); - EXPECT_NE(context, nullptr); - context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle())); - auto neoDevice = device->getNEODevice(); - context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex()); - context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); - } - - void TearDown() override { - driverHandle->setMemoryManager(prevMemoryManager); - delete currMemoryManager; - } std::unique_ptr driverHandle; NEO::MockDevice *neoDevice = nullptr; L0::Device *device = nullptr; @@ -255,12 +122,7 @@ struct MemoryExportImportWSLTest : public ::testing::Test { }; struct DriverHandleGetWinHandleMock : public L0::DriverHandleImp { - void *importNTHandle(ze_device_handle_t hDevice, void *handle, NEO::AllocationType allocationType) override { - if (mockHandle == allocationMap.second) { - return allocationMap.first; - } - return nullptr; - } + void *importNTHandle(ze_device_handle_t hDevice, void *handle, NEO::AllocationType allocationType) override; uint64_t mockHandle = 57; std::pair allocationMap; @@ -273,69 +135,22 @@ struct ContextHandleMock : public L0::ContextImp { 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) override { - ze_result_t res = L0::ContextImp::allocDeviceMem(hDevice, deviceDesc, size, alignment, ptr); - if (ZE_RESULT_SUCCESS == res) { - driverHandle->allocationMap.first = *ptr; - driverHandle->allocationMap.second = driverHandle->mockHandle; - } - - return res; - } + size_t alignment, void **ptr) override; ze_result_t getMemAllocProperties(const void *ptr, ze_memory_allocation_properties_t *pMemAllocProperties, - ze_device_handle_t *phDevice) override { - ze_result_t res = ContextImp::getMemAllocProperties(ptr, pMemAllocProperties, phDevice); - if (ZE_RESULT_SUCCESS == res && pMemAllocProperties->pNext) { - ze_external_memory_export_win32_handle_t *extendedMemoryExportProperties = - reinterpret_cast(pMemAllocProperties->pNext); - extendedMemoryExportProperties->handle = reinterpret_cast(reinterpret_cast(driverHandle->mockHandle)); - } - - return res; - } + ze_device_handle_t *phDevice) override; ze_result_t getImageAllocProperties(Image *image, - ze_image_allocation_ext_properties_t *pAllocProperties) override { + ze_image_allocation_ext_properties_t *pAllocProperties) override; - ze_result_t res = ContextImp::getImageAllocProperties(image, pAllocProperties); - if (ZE_RESULT_SUCCESS == res && pAllocProperties->pNext) { - ze_external_memory_export_win32_handle_t *extendedMemoryExportProperties = - reinterpret_cast(pAllocProperties->pNext); - extendedMemoryExportProperties->handle = reinterpret_cast(reinterpret_cast(driverHandle->mockHandle)); - } - - return res; - } - - ze_result_t freeMem(const void *ptr) override { - L0::ContextImp::freeMem(ptr); - return ZE_RESULT_SUCCESS; - } + ze_result_t freeMem(const void *ptr) override; DriverHandleGetWinHandleMock *driverHandle = nullptr; }; struct MemoryExportImportWinHandleTest : public ::testing::Test { - void SetUp() override { - - neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment(NEO::defaultHwInfo.get()); - auto mockBuiltIns = new MockBuiltins(); - neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns); - NEO::DeviceVector devices; - devices.push_back(std::unique_ptr(neoDevice)); - driverHandle = std::make_unique(); - driverHandle->initialize(std::move(devices)); - device = driverHandle->devices[0]; - - context = std::make_unique(driverHandle.get()); - EXPECT_NE(context, nullptr); - context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle())); - auto neoDevice = device->getNEODevice(); - context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex()); - context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); - } + void SetUp() override; void TearDown() override { } @@ -347,13 +162,8 @@ struct MemoryExportImportWinHandleTest : public ::testing::Test { }; struct DriverHandleGetIpcHandleMock : public DriverHandleImp { - void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, NEO::AllocationType allocationType, void *basePointer, NEO::GraphicsAllocation **pAlloc, NEO::SvmAllocationData &mappedPeerAllocData) override { - EXPECT_EQ(handle, static_cast(mockFd)); - if (mockFd == allocationMap.second) { - return allocationMap.first; - } - return nullptr; - } + void *importFdHandle(NEO::Device *neoDevice, ze_ipc_memory_flags_t flags, uint64_t handle, + NEO::AllocationType allocationType, void *basePointer, NEO::GraphicsAllocation **pAlloc, NEO::SvmAllocationData &mappedPeerAllocData) override; const int mockFd = 999; std::pair allocationMap; @@ -366,30 +176,9 @@ struct ContextGetIpcHandleMock : public L0::ContextImp { 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) override { - ze_result_t res = L0::ContextImp::allocDeviceMem(hDevice, deviceDesc, size, alignment, ptr); - if (ZE_RESULT_SUCCESS == res) { - driverHandle->allocationMap.first = *ptr; - driverHandle->allocationMap.second = driverHandle->mockFd; - } + size_t alignment, void **ptr) override; - return res; - } - - ze_result_t getIpcMemHandle(const void *ptr, ze_ipc_mem_handle_t *pIpcHandle) override { - uint64_t handle = driverHandle->mockFd; - NEO::SvmAllocationData *allocData = this->driverHandle->svmAllocsManager->getSVMAlloc(ptr); - - IpcMemoryData &ipcData = *reinterpret_cast(pIpcHandle->data); - ipcData = {}; - ipcData.handle = handle; - auto type = Context::parseUSMType(allocData->memoryType); - if (type == ZE_MEMORY_TYPE_HOST) { - ipcData.type = static_cast(InternalIpcMemoryType::IPC_HOST_UNIFIED_MEMORY); - } - - return ZE_RESULT_SUCCESS; - } + ze_result_t getIpcMemHandle(const void *ptr, ze_ipc_mem_handle_t *pIpcHandle) override; DriverHandleGetIpcHandleMock *driverHandle = nullptr; }; @@ -477,77 +266,16 @@ class MemoryManagerOpenIpcMock : public MemoryManagerIpcMock { public: MemoryManagerOpenIpcMock(NEO::ExecutionEnvironment &executionEnvironment) : MemoryManagerIpcMock(executionEnvironment) {} - NEO::GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) override { - return allocateGraphicsMemoryWithProperties(properties, nullptr); - } + NEO::GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) override; - NEO::GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties, const void *externalPtr) override { - auto ptr = reinterpret_cast(sharedHandleAddress++); - auto gmmHelper = getGmmHelper(0); - auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr)); - auto alloc = new IpcImplicitScalingMockGraphicsAllocation(properties.rootDeviceIndex, - NEO::AllocationType::BUFFER, - ptr, - 0x1000, - 0u, - MemoryPool::System4KBPages, - MemoryManager::maxOsContextCount, - canonizedGpuAddress); - alloc->setGpuBaseAddress(0xabcd); - return alloc; - } + NEO::GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties, const void *externalPtr) override; - NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { - if (failOnCreateGraphicsAllocationFromSharedHandle) { - return nullptr; - } - auto ptr = reinterpret_cast(sharedHandleAddress++); - auto gmmHelper = getGmmHelper(0); - auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr)); - auto alloc = new IpcImplicitScalingMockGraphicsAllocation(properties.rootDeviceIndex, - NEO::AllocationType::BUFFER, - ptr, - 0x1000, - 0u, - MemoryPool::System4KBPages, - MemoryManager::maxOsContextCount, - canonizedGpuAddress); - alloc->setGpuBaseAddress(0xabcd); - return alloc; - } - NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { - if (failOnCreateGraphicsAllocationFromSharedHandle) { - return nullptr; - } - auto ptr = reinterpret_cast(sharedHandleAddress++); - auto gmmHelper = getGmmHelper(0); - auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr)); - auto alloc = new IpcImplicitScalingMockGraphicsAllocation(properties.rootDeviceIndex, - NEO::AllocationType::BUFFER, - ptr, - 0x1000, - 0u, - MemoryPool::System4KBPages, - MemoryManager::maxOsContextCount, - canonizedGpuAddress); - alloc->setGpuBaseAddress(0xabcd); - return alloc; - } - NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { - auto ptr = reinterpret_cast(sharedHandleAddress++); - auto gmmHelper = getGmmHelper(0); - auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr)); - auto alloc = new IpcImplicitScalingMockGraphicsAllocation(0u, - NEO::AllocationType::BUFFER, - ptr, - 0x1000, - 0u, - MemoryPool::System4KBPages, - MemoryManager::maxOsContextCount, - canonizedGpuAddress); - alloc->setGpuBaseAddress(0xabcd); - return alloc; - }; + NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, + const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, + bool reuseSharedAllocation, void *mapPointer) override; + NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, + AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override; + NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override; void freeGraphicsMemory(GraphicsAllocation *gfxAllocation) override { delete gfxAllocation; @@ -567,52 +295,15 @@ struct ContextIpcMock : public L0::ContextImp { driverHandle = inDriverHandle; } - ze_result_t getIpcMemHandle(const void *ptr, ze_ipc_mem_handle_t *pIpcHandle) override { - uint64_t handle = mockFd; - NEO::SvmAllocationData *allocData = this->driverHandle->svmAllocsManager->getSVMAlloc(ptr); - - IpcMemoryData &ipcData = *reinterpret_cast(pIpcHandle->data); - ipcData = {}; - ipcData.handle = handle; - auto type = Context::parseUSMType(allocData->memoryType); - if (type == ZE_MEMORY_TYPE_HOST) { - ipcData.type = static_cast(InternalIpcMemoryType::IPC_HOST_UNIFIED_MEMORY); - } - - return ZE_RESULT_SUCCESS; - } + ze_result_t getIpcMemHandle(const void *ptr, ze_ipc_mem_handle_t *pIpcHandle) override; const int mockFd = 999; }; struct MemoryOpenIpcHandleTest : public ::testing::Test { - void SetUp() override { + void SetUp() override; + void TearDown() override; - neoDevice = - NEO::MockDevice::createWithNewExecutionEnvironment(NEO::defaultHwInfo.get()); - auto mockBuiltIns = new MockBuiltins(); - neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns); - NEO::DeviceVector devices; - 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 = std::make_unique(driverHandle.get()); - EXPECT_NE(context, nullptr); - context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle())); - auto neoDevice = device->getNEODevice(); - context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex()); - context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); - } - - void TearDown() override { - driverHandle->setMemoryManager(prevMemoryManager); - delete currMemoryManager; - } NEO::MemoryManager *prevMemoryManager = nullptr; NEO::MemoryManager *currMemoryManager = nullptr; std::unique_ptr driverHandle; @@ -663,94 +354,16 @@ class MemoryManagerIpcImplicitScalingMock : public NEO::MemoryManager { void *lockResourceImpl(NEO::GraphicsAllocation &graphicsAllocation) override { return nullptr; }; void unlockResourceImpl(NEO::GraphicsAllocation &graphicsAllocation) override{}; - NEO::GraphicsAllocation *allocateGraphicsMemoryInPreferredPool(const AllocationProperties &properties, const void *hostPtr) override { - auto ptr = reinterpret_cast(sharedHandleAddress++); - auto gmmHelper = getGmmHelper(0); - auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr)); - auto alloc = new IpcImplicitScalingMockGraphicsAllocation(0u, - NEO::AllocationType::BUFFER, - ptr, - 0x1000, - 0u, - MemoryPool::System4KBPages, - MemoryManager::maxOsContextCount, - canonizedGpuAddress); - alloc->setGpuBaseAddress(0xabcd); - return alloc; - } + NEO::GraphicsAllocation *allocateGraphicsMemoryInPreferredPool(const AllocationProperties &properties, const void *hostPtr) override; - NEO::GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) override { - auto ptr = reinterpret_cast(sharedHandleAddress++); - auto gmmHelper = getGmmHelper(0); - auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr)); - auto alloc = new IpcImplicitScalingMockGraphicsAllocation(0u, - NEO::AllocationType::BUFFER, - ptr, - 0x1000, - 0u, - MemoryPool::System4KBPages, - MemoryManager::maxOsContextCount, - canonizedGpuAddress); - alloc->setGpuBaseAddress(0xabcd); - return alloc; - } + NEO::GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties) override; - NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { - if (failOnCreateGraphicsAllocationFromSharedHandle) { - return nullptr; - } - auto ptr = reinterpret_cast(sharedHandleAddress++); - auto gmmHelper = getGmmHelper(0); - auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr)); - auto alloc = new IpcImplicitScalingMockGraphicsAllocation(0u, - NEO::AllocationType::BUFFER, - ptr, - 0x1000, - 0u, - MemoryPool::System4KBPages, - MemoryManager::maxOsContextCount, - canonizedGpuAddress); - alloc->setGpuBaseAddress(0xabcd); - return alloc; - } + NEO::GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector &handles, + AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override; - NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override { - if (failOnCreateGraphicsAllocationFromNTHandle) { - return nullptr; - } - - auto ptr = reinterpret_cast(sharedHandleAddress++); - auto gmmHelper = getGmmHelper(0); - auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr)); - auto alloc = new IpcImplicitScalingMockGraphicsAllocation(0u, - NEO::AllocationType::BUFFER, - ptr, - 0x1000, - 0u, - MemoryPool::System4KBPages, - MemoryManager::maxOsContextCount, - canonizedGpuAddress); - alloc->setGpuBaseAddress(0xabcd); - return alloc; - } - NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override { - if (failOnCreateGraphicsAllocationFromSharedHandle) { - return nullptr; - } - auto ptr = reinterpret_cast(sharedHandleAddress++); - auto gmmHelper = getGmmHelper(0); - auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr)); - auto alloc = new IpcImplicitScalingMockGraphicsAllocation(0u, - NEO::AllocationType::BUFFER, - ptr, - 0x1000, - 0u, - MemoryPool::System4KBPages, - MemoryManager::maxOsContextCount, - canonizedGpuAddress); - alloc->setGpuBaseAddress(0xabcd); - return alloc; - } + NEO::GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, AllocationType allocType) override; + NEO::GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, + bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation, void *mapPointer) override; void freeGraphicsMemory(NEO::GraphicsAllocation *alloc, bool isImportedAllocation) override { delete alloc; @@ -763,42 +376,9 @@ class MemoryManagerIpcImplicitScalingMock : public NEO::MemoryManager { }; struct MemoryExportImportImplicitScalingTest : public ::testing::Test { - void SetUp() override { - DebugManagerStateRestore restorer; - DebugManager.flags.EnableImplicitScaling.set(1); + void SetUp() override; - neoDevice = - NEO::MockDevice::createWithNewExecutionEnvironment(NEO::defaultHwInfo.get()); - auto mockBuiltIns = new MockBuiltins(); - neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns); - NEO::DeviceVector devices; - devices.push_back(std::unique_ptr(neoDevice)); - driverHandle = std::make_unique(); - driverHandle->initialize(std::move(devices)); - prevMemoryManager = driverHandle->getMemoryManager(); - currMemoryManager = new MemoryManagerIpcImplicitScalingMock(*neoDevice->executionEnvironment); - driverHandle->setMemoryManager(currMemoryManager); - - prevSvmAllocsManager = driverHandle->svmAllocsManager; - currSvmAllocsManager = new NEO::SVMAllocsManager(currMemoryManager, false); - driverHandle->svmAllocsManager = currSvmAllocsManager; - - device = driverHandle->devices[0]; - - context = std::make_unique(driverHandle.get()); - EXPECT_NE(context, nullptr); - context->getDevices().insert(std::make_pair(device->getRootDeviceIndex(), device->toHandle())); - auto neoDevice = device->getNEODevice(); - context->rootDeviceIndices.pushUnique(neoDevice->getRootDeviceIndex()); - context->deviceBitfields.insert({neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield()}); - } - - void TearDown() override { - driverHandle->svmAllocsManager = prevSvmAllocsManager; - delete currSvmAllocsManager; - driverHandle->setMemoryManager(prevMemoryManager); - delete currMemoryManager; - } + void TearDown() override; NEO::SVMAllocsManager *prevSvmAllocsManager; NEO::SVMAllocsManager *currSvmAllocsManager; diff --git a/level_zero/core/test/unit_tests/fixtures/multi_tile_fixture.h b/level_zero/core/test/unit_tests/fixtures/multi_tile_fixture.h index 82dcc97a5c..d9c6747837 100644 --- a/level_zero/core/test/unit_tests/fixtures/multi_tile_fixture.h +++ b/level_zero/core/test/unit_tests/fixtures/multi_tile_fixture.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Intel Corporation + * Copyright (C) 2022-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,11 +7,7 @@ #pragma once -#include "shared/test/common/helpers/variable_backup.h" - #include "level_zero/core/test/unit_tests/fixtures/module_fixture.h" -#include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h" -#include "level_zero/core/test/unit_tests/mocks/mock_module.h" namespace L0 { struct ContextImp; 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 9c98836cc1..39d8829fa2 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 @@ -10,6 +10,7 @@ #include "shared/test/common/test_macros/hw_test.h" #include "level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.h" +#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h" namespace L0 { namespace ult { diff --git a/level_zero/core/test/unit_tests/mocks/CMakeLists.txt b/level_zero/core/test/unit_tests/mocks/CMakeLists.txt index 338b0c5540..04c673944a 100644 --- a/level_zero/core/test/unit_tests/mocks/CMakeLists.txt +++ b/level_zero/core/test/unit_tests/mocks/CMakeLists.txt @@ -32,6 +32,7 @@ set(L0_MOCKS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/mock_gmm_resource_info_l0.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_host_pointer_manager.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_image.h + ${CMAKE_CURRENT_SOURCE_DIR}/mock_kernel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_kernel.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_memory_manager.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_module.h diff --git a/level_zero/core/test/unit_tests/mocks/mock_built_ins.h b/level_zero/core/test/unit_tests/mocks/mock_built_ins.h index d50c974120..31fd65cbe1 100644 --- a/level_zero/core/test/unit_tests/mocks/mock_built_ins.h +++ b/level_zero/core/test/unit_tests/mocks/mock_built_ins.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,6 +7,7 @@ #pragma once #include "shared/source/built_ins/built_ins.h" +#include "shared/source/built_ins/sip.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" namespace L0 { 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 index c44b4db054..ec83d000bd 100644 --- a/level_zero/core/test/unit_tests/mocks/mock_driver_handle.cpp +++ b/level_zero/core/test/unit_tests/mocks/mock_driver_handle.cpp @@ -81,6 +81,19 @@ void Mock::setupDevices(std::vector> } } +NEO::GraphicsAllocation *Mock::getDriverSystemMemoryAllocation(void *ptr, + size_t size, + uint32_t rootDeviceIndex, + uintptr_t *gpuAddress) { + auto svmData = svmAllocsManager->getSVMAlloc(ptr); + if (svmData != nullptr) { + if (gpuAddress != nullptr) { + *gpuAddress = reinterpret_cast(ptr); + } + return svmData->gpuAllocations.getGraphicsAllocation(rootDeviceIndex); + } + return nullptr; +} Mock::~Mock(){}; } // namespace ult 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 index 1cfddfe91d..6f067d8ab2 100644 --- a/level_zero/core/test/unit_tests/mocks/mock_driver_handle.h +++ b/level_zero/core/test/unit_tests/mocks/mock_driver_handle.h @@ -6,7 +6,6 @@ */ #pragma once -#include "shared/source/memory_manager/unified_memory_manager.h" #include "shared/test/common/test_macros/mock_method_macros.h" #include "level_zero/core/source/driver/driver_handle_imp.h" @@ -55,16 +54,7 @@ struct Mock : public DriverHandle { 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; - } + uintptr_t *gpuAddress) override; }; } // namespace ult } // namespace L0 diff --git a/level_zero/core/test/unit_tests/mocks/mock_kernel.cpp b/level_zero/core/test/unit_tests/mocks/mock_kernel.cpp new file mode 100644 index 0000000000..21db95f3dc --- /dev/null +++ b/level_zero/core/test/unit_tests/mocks/mock_kernel.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero/core/test/unit_tests/mocks/mock_kernel.h" + +#include "shared/source/device_binary_format/patchtokens_decoder.h" +#include "shared/source/kernel/kernel_descriptor_from_patchtokens.h" +#include "shared/source/memory_manager/memory_manager.h" + +namespace L0 { +namespace ult { + +Mock<::L0::KernelImp>::Mock() : BaseClass() { + NEO::PatchTokenBinary::KernelFromPatchtokens kernelTokens; + iOpenCL::SKernelBinaryHeaderCommon kernelHeader; + kernelTokens.header = &kernelHeader; + + iOpenCL::SPatchExecutionEnvironment execEnv = {}; + execEnv.NumGRFRequired = 128; + execEnv.LargestCompiledSIMDSize = 8; + kernelTokens.tokens.executionEnvironment = &execEnv; + + this->kernelImmData = &immutableData; + + auto allocation = new NEO::GraphicsAllocation(0, + NEO::AllocationType::KERNEL_ISA, + nullptr, + 0, + 0, + 4096, + NEO::MemoryPool::System4KBPages, + NEO::MemoryManager::maxOsContextCount); + + immutableData.isaGraphicsAllocation.reset(allocation); + + NEO::populateKernelDescriptor(descriptor, kernelTokens, 8); + immutableData.kernelDescriptor = &descriptor; + immutableData.kernelInfo = &info; + crossThreadData.reset(new uint8_t[100]); +} +Mock<::L0::KernelImp>::~Mock() { + delete immutableData.isaGraphicsAllocation.release(); +} + +} // namespace ult +} // namespace L0 diff --git a/level_zero/core/test/unit_tests/mocks/mock_kernel.h b/level_zero/core/test/unit_tests/mocks/mock_kernel.h index e63817d70a..8a31469e77 100644 --- a/level_zero/core/test/unit_tests/mocks/mock_kernel.h +++ b/level_zero/core/test/unit_tests/mocks/mock_kernel.h @@ -6,10 +6,6 @@ */ #pragma once -#include "shared/source/device_binary_format/patchtokens_decoder.h" -#include "shared/source/kernel/kernel_descriptor.h" -#include "shared/source/kernel/kernel_descriptor_from_patchtokens.h" -#include "shared/source/memory_manager/memory_manager.h" #include "shared/source/program/kernel_info.h" #include "shared/test/common/test_macros/mock_method_macros.h" @@ -89,37 +85,8 @@ struct Mock<::L0::KernelImp> : public WhiteBox<::L0::KernelImp> { (uint32_t argIndex, ze_image_handle_t argVal), (argIndex, argVal)); - Mock() : BaseClass() { - NEO::PatchTokenBinary::KernelFromPatchtokens kernelTokens; - iOpenCL::SKernelBinaryHeaderCommon kernelHeader; - kernelTokens.header = &kernelHeader; - - iOpenCL::SPatchExecutionEnvironment execEnv = {}; - execEnv.NumGRFRequired = 128; - execEnv.LargestCompiledSIMDSize = 8; - kernelTokens.tokens.executionEnvironment = &execEnv; - - this->kernelImmData = &immutableData; - - auto allocation = new NEO::GraphicsAllocation(0, - NEO::AllocationType::KERNEL_ISA, - nullptr, - 0, - 0, - 4096, - NEO::MemoryPool::System4KBPages, - NEO::MemoryManager::maxOsContextCount); - - immutableData.isaGraphicsAllocation.reset(allocation); - - NEO::populateKernelDescriptor(descriptor, kernelTokens, 8); - immutableData.kernelDescriptor = &descriptor; - immutableData.kernelInfo = &info; - crossThreadData.reset(new uint8_t[100]); - } - ~Mock() override { - delete immutableData.isaGraphicsAllocation.release(); - } + Mock(); + ~Mock() override; void setBufferSurfaceState(uint32_t argIndex, void *address, NEO::GraphicsAllocation *alloc) override {} void evaluateIfRequiresGenerationOfLocalIdsByRuntime(const NEO::KernelDescriptor &kernelDescriptor) override { diff --git a/level_zero/core/test/unit_tests/mocks/mock_memory_manager.h b/level_zero/core/test/unit_tests/mocks/mock_memory_manager.h index f1cb9bc546..244df1e82c 100644 --- a/level_zero/core/test/unit_tests/mocks/mock_memory_manager.h +++ b/level_zero/core/test/unit_tests/mocks/mock_memory_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2022 Intel Corporation + * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -13,11 +13,6 @@ #include -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Winconsistent-missing-override" -#endif - namespace L0 { namespace ult { @@ -32,7 +27,3 @@ using MemoryManagerMock = WhiteBox<::NEO::OsAgnosticMemoryManager>; } // namespace ult } // namespace L0 - -#if defined(__clang__) -#pragma clang diagnostic pop -#endif diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp index 08953cdc31..7b63eddf3f 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp @@ -19,6 +19,7 @@ #include "level_zero/core/source/image/image_hw.h" #include "level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.h" #include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h" +#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h" #include "level_zero/core/test/unit_tests/mocks/mock_kernel.h" namespace L0 { diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_3.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_3.cpp index beed547db0..b451bd380a 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_3.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_3.cpp @@ -10,6 +10,7 @@ #include "shared/source/helpers/aligned_memory.h" #include "shared/source/memory_manager/internal_allocation_storage.h" #include "shared/test/common/cmd_parse/gen_cmd_parse.h" +#include "shared/test/common/helpers/unit_test_helper.h" #include "shared/test/common/libult/ult_command_stream_receiver.h" #include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_direct_submission_hw.h" diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_4.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_4.cpp index 063539e3af..0d7e73f182 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_4.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_4.cpp @@ -16,6 +16,7 @@ #include "shared/test/common/cmd_parse/gen_cmd_parse.h" #include "shared/test/common/helpers/unit_test_helper.h" #include "shared/test/common/mocks/mock_command_encoder.h" +#include "shared/test/common/mocks/mock_graphics_allocation.h" #include "shared/test/common/test_macros/hw_test.h" #include "level_zero/core/source/event/event.h" diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_5.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_5.cpp index 634678d35b..b644ce8116 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_5.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_5.cpp @@ -21,6 +21,7 @@ #include "level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.h" #include "level_zero/core/test/unit_tests/mocks/mock_builtin_functions_lib_impl_timestamps.h" #include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h" +#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h" #include "level_zero/core/test/unit_tests/mocks/mock_device_for_spirv.h" #include "level_zero/core/test/unit_tests/mocks/mock_event.h" #include "level_zero/core/test/unit_tests/mocks/mock_kernel.h" diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_6.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_6.cpp index ce69b08799..6108ecd2a7 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_6.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_6.cpp @@ -23,6 +23,7 @@ #include "level_zero/core/source/builtin/builtin_functions_lib.h" #include "level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.h" #include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h" +#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h" #include "level_zero/core/test/unit_tests/mocks/mock_event.h" #include "level_zero/core/test/unit_tests/mocks/mock_image.h" #include "level_zero/core/test/unit_tests/mocks/mock_kernel.h" diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_7.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_7.cpp index 5bb3644fd3..9ef834c58c 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_7.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_7.cpp @@ -14,6 +14,7 @@ #include "shared/test/common/mocks/mock_command_stream_receiver.h" #include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_driver_model.h" +#include "shared/test/common/mocks/mock_graphics_allocation.h" #include "shared/test/common/mocks/mock_ostime.h" #include "shared/test/common/mocks/ult_device_factory.h" #include "shared/test/common/test_macros/hw_test.h" diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_barrier.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_barrier.cpp index 7d9d7ca9ef..3986976880 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_barrier.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_barrier.cpp @@ -6,6 +6,7 @@ */ #include "shared/source/command_container/command_encoder.h" +#include "shared/source/helpers/api_specific_config.h" #include "shared/source/helpers/gfx_core_helper.h" #include "shared/test/common/helpers/unit_test_helper.h" #include "shared/test/common/test_macros/hw_test.h" diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_launch_kernel_1.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_launch_kernel_1.cpp index 56da2537ed..0eb4f1bd69 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_launch_kernel_1.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_launch_kernel_1.cpp @@ -7,6 +7,7 @@ #include "shared/source/command_container/command_encoder.h" #include "shared/source/helpers/api_specific_config.h" +#include "shared/source/helpers/gfx_core_helper.h" #include "shared/source/helpers/preamble.h" #include "shared/source/helpers/register_offsets.h" #include "shared/source/indirect_heap/indirect_heap.h" diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_memory.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_memory.cpp index 9e1bc6ea45..326babd5ce 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_memory.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_memory.cpp @@ -7,6 +7,7 @@ #include "shared/source/command_container/encode_surface_state.h" #include "shared/source/helpers/gfx_core_helper.h" +#include "shared/source/helpers/register_offsets.h" #include "shared/source/memory_manager/internal_allocation_storage.h" #include "shared/test/common/cmd_parse/gen_cmd_parse.h" #include "shared/test/common/test_macros/hw_test.h" diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_signal_event.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_signal_event.cpp index 8799a363d4..5baa57af2c 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_signal_event.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_signal_event.cpp @@ -5,6 +5,7 @@ * */ +#include "shared/source/command_container/implicit_scaling.h" #include "shared/source/helpers/definitions/command_encoder_args.h" #include "shared/source/helpers/gfx_core_helper.h" #include "shared/test/common/cmd_parse/gen_cmd_parse.h" @@ -17,6 +18,7 @@ #include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" #include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h" #include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h" +#include "level_zero/core/test/unit_tests/mocks/mock_event.h" namespace L0 { namespace ult { diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_copy_event_xehp_and_later.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_copy_event_xehp_and_later.cpp index 913cf22ecd..9279024a84 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_copy_event_xehp_and_later.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_copy_event_xehp_and_later.cpp @@ -5,8 +5,12 @@ * */ +#include "shared/source/command_container/implicit_scaling.h" +#include "shared/source/helpers/api_specific_config.h" #include "shared/source/helpers/gfx_core_helper.h" +#include "shared/source/helpers/timestamp_packet.h" #include "shared/test/common/cmd_parse/gen_cmd_parse.h" +#include "shared/test/common/helpers/unit_test_helper.h" #include "shared/test/common/test_macros/hw_test.h" #include "level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper.h" 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 5413a63ca0..018b894e66 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 @@ -6,6 +6,7 @@ */ #include "shared/source/built_ins/sip.h" +#include "shared/source/helpers/register_offsets.h" #include "shared/source/memory_manager/memory_manager.h" #include "shared/test/common/cmd_parse/gen_cmd_parse.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_fill_event_xehp_and_later.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_fill_event_xehp_and_later.cpp index 4a85c9bb76..7ec186fb0d 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_fill_event_xehp_and_later.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_fill_event_xehp_and_later.cpp @@ -5,12 +5,17 @@ * */ +#include "shared/source/command_container/implicit_scaling.h" +#include "shared/source/helpers/api_specific_config.h" #include "shared/source/helpers/gfx_core_helper.h" +#include "shared/source/helpers/timestamp_packet.h" #include "shared/test/common/cmd_parse/gen_cmd_parse.h" +#include "shared/test/common/helpers/unit_test_helper.h" #include "shared/test/common/test_macros/hw_test.h" #include "level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper.h" #include "level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.h" +#include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h" #include diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_xehp_and_later.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_xehp_and_later.cpp index 5ba50fca3e..64c10f3860 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_xehp_and_later.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_xehp_and_later.cpp @@ -9,6 +9,7 @@ #include "shared/source/command_stream/scratch_space_controller_base.h" #include "shared/source/gmm_helper/gmm_helper.h" #include "shared/source/gmm_helper/gmm_lib.h" +#include "shared/source/helpers/api_specific_config.h" #include "shared/source/helpers/definitions/command_encoder_args.h" #include "shared/source/helpers/preamble.h" #include "shared/source/indirect_heap/indirect_heap.h" @@ -24,6 +25,7 @@ #include "level_zero/core/source/gfx_core_helpers/l0_gfx_core_helper.h" #include "level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.h" #include "level_zero/core/test/unit_tests/mocks/mock_cmdlist.h" +#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h" #include "level_zero/core/test/unit_tests/mocks/mock_module.h" #include "test_traits_common.h" 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 6b97bedbd8..53a61010b7 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 @@ -9,11 +9,14 @@ #include "shared/source/gmm_helper/gmm.h" #include "shared/source/helpers/blit_properties.h" #include "shared/source/memory_manager/gfx_partition.h" +#include "shared/source/os_interface/device_factory.h" #include "shared/test/common/mocks/mock_command_stream_receiver.h" #include "shared/test/common/mocks/mock_compilers.h" #include "shared/test/common/mocks/mock_cpu_page_fault_manager.h" +#include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" #include "shared/test/common/mocks/mock_memory_manager.h" +#include "shared/test/common/mocks/mock_memory_operations_handler.h" #include "shared/test/common/mocks/mock_svm_manager.h" #include "shared/test/common/test_macros/hw_test.h" diff --git a/level_zero/core/test/unit_tests/sources/context/test_context_drm.cpp b/level_zero/core/test/unit_tests/sources/context/test_context_drm.cpp index e43844ecd7..a0fa551b6d 100644 --- a/level_zero/core/test/unit_tests/sources/context/test_context_drm.cpp +++ b/level_zero/core/test/unit_tests/sources/context/test_context_drm.cpp @@ -9,6 +9,7 @@ #include "shared/test/common/mocks/mock_command_stream_receiver.h" #include "shared/test/common/mocks/mock_compilers.h" #include "shared/test/common/mocks/mock_cpu_page_fault_manager.h" +#include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" #include "shared/test/common/mocks/mock_memory_manager.h" #include "shared/test/common/mocks/mock_svm_manager.h" diff --git a/level_zero/core/test/unit_tests/sources/context/test_context_drm_or_wddm.cpp b/level_zero/core/test/unit_tests/sources/context/test_context_drm_or_wddm.cpp index 5ce64a2e83..8fdd872abc 100644 --- a/level_zero/core/test/unit_tests/sources/context/test_context_drm_or_wddm.cpp +++ b/level_zero/core/test/unit_tests/sources/context/test_context_drm_or_wddm.cpp @@ -9,6 +9,7 @@ #include "shared/test/common/mocks/mock_command_stream_receiver.h" #include "shared/test/common/mocks/mock_compilers.h" #include "shared/test/common/mocks/mock_cpu_page_fault_manager.h" +#include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_driver_model.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" #include "shared/test/common/mocks/mock_memory_manager.h" diff --git a/level_zero/core/test/unit_tests/sources/context/test_context_wddm.cpp b/level_zero/core/test/unit_tests/sources/context/test_context_wddm.cpp index af040777ec..140984bd46 100644 --- a/level_zero/core/test/unit_tests/sources/context/test_context_wddm.cpp +++ b/level_zero/core/test/unit_tests/sources/context/test_context_wddm.cpp @@ -9,6 +9,7 @@ #include "shared/test/common/mocks/mock_command_stream_receiver.h" #include "shared/test/common/mocks/mock_compilers.h" #include "shared/test/common/mocks/mock_cpu_page_fault_manager.h" +#include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" #include "shared/test/common/mocks/mock_memory_manager.h" #include "shared/test/common/mocks/mock_svm_manager.h" diff --git a/level_zero/core/test/unit_tests/sources/driver/host_pointer_manager_tests.cpp b/level_zero/core/test/unit_tests/sources/driver/host_pointer_manager_tests.cpp index 88688f67c8..ed7e3af970 100644 --- a/level_zero/core/test/unit_tests/sources/driver/host_pointer_manager_tests.cpp +++ b/level_zero/core/test/unit_tests/sources/driver/host_pointer_manager_tests.cpp @@ -7,9 +7,14 @@ #include "shared/source/built_ins/sip.h" #include "shared/source/helpers/aligned_memory.h" +#include "shared/source/memory_manager/unified_memory_manager.h" +#include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_memory_manager.h" +#include "shared/test/common/mocks/mock_memory_operations_handler.h" #include "shared/test/common/test_macros/test.h" +#include "level_zero/core/source/context/context.h" +#include "level_zero/core/source/device/device.h" #include "level_zero/core/source/driver/driver_handle_imp.h" #include "level_zero/core/test/unit_tests/fixtures/host_pointer_manager_fixture.h" #include "level_zero/core/test/unit_tests/mocks/mock_host_pointer_manager.h" 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 cd69cb915c..f9947994c3 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 @@ -10,6 +10,7 @@ #include "shared/source/helpers/gfx_core_helper.h" #include "shared/source/helpers/string.h" #include "shared/source/memory_manager/allocation_properties.h" +#include "shared/source/memory_manager/memory_allocation.h" #include "shared/source/memory_manager/os_agnostic_memory_manager.h" #include "shared/source/os_interface/device_factory.h" #include "shared/source/os_interface/os_inc_base.h" @@ -18,6 +19,7 @@ #include "shared/test/common/helpers/ult_hw_config.h" #include "shared/test/common/helpers/variable_backup.h" #include "shared/test/common/mocks/mock_compilers.h" +#include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/mocks/mock_io_functions.h" #include "shared/test/common/mocks/ult_device_factory.h" @@ -30,6 +32,7 @@ #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.h" +#include "level_zero/core/test/unit_tests/mocks/mock_driver_handle.h" #include diff --git a/level_zero/core/test/unit_tests/sources/kernel/test_kernel_2.cpp b/level_zero/core/test/unit_tests/sources/kernel/test_kernel_2.cpp index 0e0e9f4b50..c604c9dcf1 100644 --- a/level_zero/core/test/unit_tests/sources/kernel/test_kernel_2.cpp +++ b/level_zero/core/test/unit_tests/sources/kernel/test_kernel_2.cpp @@ -436,6 +436,8 @@ TEST(zeKernelGetProperties, WhenGettingKernelPropertiesThenSuccessIsReturned) { EXPECT_EQ(ZE_RESULT_SUCCESS, result); } +using KernelImpSuggestMaxCooperativeGroupCountTests = Test; + HWTEST_F(KernelImpSuggestMaxCooperativeGroupCountTests, GivenNoBarriersOrSlmUsedWhenCalculatingMaxCooperativeGroupCountThenResultIsCalculatedWithSimd) { auto workGroupSize = lws[0] * lws[1] * lws[2]; auto expected = availableThreadCount / Math::divideAndRoundUp(workGroupSize, simd); diff --git a/level_zero/core/test/unit_tests/sources/memory/linux/test_memory_linux.cpp b/level_zero/core/test/unit_tests/sources/memory/linux/test_memory_linux.cpp index 076bf3bfa8..a09fc856a4 100644 --- a/level_zero/core/test/unit_tests/sources/memory/linux/test_memory_linux.cpp +++ b/level_zero/core/test/unit_tests/sources/memory/linux/test_memory_linux.cpp @@ -6,6 +6,7 @@ */ #include "shared/source/built_ins/sip.h" +#include "shared/source/gmm_helper/gmm_helper.h" #include "shared/source/memory_manager/gfx_partition.h" #include "shared/source/os_interface/linux/drm_allocation.h" #include "shared/source/os_interface/linux/drm_buffer_object.h" @@ -13,6 +14,7 @@ #include "shared/source/os_interface/linux/drm_memory_manager.h" #include "shared/test/common/libult/linux/drm_mock.h" #include "shared/test/common/mocks/linux/mock_drm_allocation.h" +#include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_driver_model.h" #include "shared/test/common/mocks/ult_device_factory.h" 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 5e208ba183..90647bcf5a 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 @@ -20,6 +20,7 @@ #include "shared/test/common/helpers/raii_product_helper.h" #include "shared/test/common/helpers/test_files.h" #include "shared/test/common/mocks/mock_compilers.h" +#include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_driver_model.h" #include "shared/test/common/mocks/mock_memory_manager.h" #include "shared/test/common/mocks/mock_modules_zebin.h" diff --git a/level_zero/core/test/unit_tests/sources/memory/test_memory_drm.cpp b/level_zero/core/test/unit_tests/sources/memory/test_memory_drm.cpp index fe5fee27c2..9d44d0e823 100644 --- a/level_zero/core/test/unit_tests/sources/memory/test_memory_drm.cpp +++ b/level_zero/core/test/unit_tests/sources/memory/test_memory_drm.cpp @@ -6,9 +6,11 @@ */ #include "shared/source/built_ins/sip.h" +#include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_driver_model.h" #include "level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h" +#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h" namespace L0 { namespace ult { diff --git a/level_zero/core/test/unit_tests/sources/memory/test_memory_drm_or_wddm.cpp b/level_zero/core/test/unit_tests/sources/memory/test_memory_drm_or_wddm.cpp index 3df9b7c69e..5dff2d75b1 100644 --- a/level_zero/core/test/unit_tests/sources/memory/test_memory_drm_or_wddm.cpp +++ b/level_zero/core/test/unit_tests/sources/memory/test_memory_drm_or_wddm.cpp @@ -6,9 +6,12 @@ */ #include "shared/source/built_ins/sip.h" +#include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_driver_model.h" +#include "shared/test/common/mocks/mock_memory_manager.h" #include "level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h" +#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h" namespace L0 { namespace ult { diff --git a/level_zero/core/test/unit_tests/sources/memory/test_memory_wddm.cpp b/level_zero/core/test/unit_tests/sources/memory/test_memory_wddm.cpp index e24a753c88..778f665115 100644 --- a/level_zero/core/test/unit_tests/sources/memory/test_memory_wddm.cpp +++ b/level_zero/core/test/unit_tests/sources/memory/test_memory_wddm.cpp @@ -7,8 +7,10 @@ #include "shared/source/built_ins/sip.h" #include "shared/source/gmm_helper/gmm.h" +#include "shared/test/common/mocks/mock_device.h" #include "level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.h" +#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h" namespace L0 { namespace ult { diff --git a/level_zero/core/test/unit_tests/xe_hpc_core/pvc/test_kernel_pvc.cpp b/level_zero/core/test/unit_tests/xe_hpc_core/pvc/test_kernel_pvc.cpp index 919e1b6688..1a35b3a3a8 100644 --- a/level_zero/core/test/unit_tests/xe_hpc_core/pvc/test_kernel_pvc.cpp +++ b/level_zero/core/test/unit_tests/xe_hpc_core/pvc/test_kernel_pvc.cpp @@ -18,7 +18,7 @@ HWTEST_EXCLUDE_PRODUCT(KernelImpSuggestMaxCooperativeGroupCountTests, GivenUsedS HWTEST_EXCLUDE_PRODUCT(KernelImpSuggestMaxCooperativeGroupCountTests, GivenBarriersWhenCalculatingMaxCooperativeGroupCountThenResultIsCalculatedWithRegardToBarriersCount, IGFX_PVC); HWTEST_EXCLUDE_PRODUCT(KernelImpSuggestMaxCooperativeGroupCountTests, GivenNoBarriersOrSlmUsedWhenCalculatingMaxCooperativeGroupCountThenResultIsCalculatedWithSimd, IGFX_PVC); -using KernelImpSuggestMaxCooperativeGroupCountTestsPvc = KernelImpSuggestMaxCooperativeGroupCountTests; +using KernelImpSuggestMaxCooperativeGroupCountTestsPvc = Test; PVCTEST_F(KernelImpSuggestMaxCooperativeGroupCountTestsPvc, GivenNoBarriersOrSlmUsedWhenCalculatingMaxCooperativeGroupCountThenResultIsCalculatedWithSimd) { auto workGroupSize = lws[0] * lws[1] * lws[2]; diff --git a/shared/test/common/mocks/mock_memory_operations_handler.h b/shared/test/common/mocks/mock_memory_operations_handler.h index b148421243..51238842f6 100644 --- a/shared/test/common/mocks/mock_memory_operations_handler.h +++ b/shared/test/common/mocks/mock_memory_operations_handler.h @@ -6,6 +6,7 @@ */ #pragma once +#include "shared/source/memory_manager/graphics_allocation.h" #include "shared/source/memory_manager/memory_operations_handler.h" #include "shared/source/os_interface/os_context.h" #include "shared/test/common/test_macros/mock_method_macros.h"