From 73f687c2643518d377fb0a2775e6830f5d6148cb Mon Sep 17 00:00:00 2001 From: Bartosz Dunajski Date: Fri, 10 Dec 2021 11:39:19 +0000 Subject: [PATCH] PVC L0 unit tests Signed-off-by: Bartosz Dunajski --- .../unit_tests/xe_hpc_core/CMakeLists.txt | 16 + .../enable_l0_mocks_xe_hpc_core.cpp | 19 + .../xe_hpc_core/test_cmdlist_xe_hpc_core.cpp | 313 +++++++++++++++ .../xe_hpc_core/test_cmdqueue_xe_hpc_core.cpp | 272 +++++++++++++ .../xe_hpc_core/test_device_xe_hpc_core.cpp | 362 ++++++++++++++++++ .../xe_hpc_core/test_module_xe_hpc_core.cpp | 50 +++ 6 files changed, 1032 insertions(+) create mode 100644 level_zero/core/test/unit_tests/xe_hpc_core/CMakeLists.txt create mode 100644 level_zero/core/test/unit_tests/xe_hpc_core/enable_l0_mocks_xe_hpc_core.cpp create mode 100644 level_zero/core/test/unit_tests/xe_hpc_core/test_cmdlist_xe_hpc_core.cpp create mode 100644 level_zero/core/test/unit_tests/xe_hpc_core/test_cmdqueue_xe_hpc_core.cpp create mode 100644 level_zero/core/test/unit_tests/xe_hpc_core/test_device_xe_hpc_core.cpp create mode 100644 level_zero/core/test/unit_tests/xe_hpc_core/test_module_xe_hpc_core.cpp diff --git a/level_zero/core/test/unit_tests/xe_hpc_core/CMakeLists.txt b/level_zero/core/test/unit_tests/xe_hpc_core/CMakeLists.txt new file mode 100644 index 0000000000..0dccf90680 --- /dev/null +++ b/level_zero/core/test/unit_tests/xe_hpc_core/CMakeLists.txt @@ -0,0 +1,16 @@ +# +# Copyright (C) 2021 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +if(TESTS_XE_HPC_CORE) + target_sources(${TARGET_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/enable_l0_mocks_xe_hpc_core.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_cmdlist_xe_hpc_core.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_cmdqueue_xe_hpc_core.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_device_xe_hpc_core.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_module_xe_hpc_core.cpp + ) +endif() diff --git a/level_zero/core/test/unit_tests/xe_hpc_core/enable_l0_mocks_xe_hpc_core.cpp b/level_zero/core/test/unit_tests/xe_hpc_core/enable_l0_mocks_xe_hpc_core.cpp new file mode 100644 index 0000000000..5c03dec6b9 --- /dev/null +++ b/level_zero/core/test/unit_tests/xe_hpc_core/enable_l0_mocks_xe_hpc_core.cpp @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "level_zero/core/test/unit_tests/mocks/mock_l0_debugger.h" + +namespace NEO { +struct XE_HPC_COREFamily; +using GfxFamily = XE_HPC_COREFamily; +} // namespace NEO + +namespace L0 { +namespace ult { +static MockDebuggerL0HwPopulateFactory mockDebuggerXeHpcCore; +} +} // namespace L0 \ No newline at end of file diff --git a/level_zero/core/test/unit_tests/xe_hpc_core/test_cmdlist_xe_hpc_core.cpp b/level_zero/core/test/unit_tests/xe_hpc_core/test_cmdlist_xe_hpc_core.cpp new file mode 100644 index 0000000000..4c059820e0 --- /dev/null +++ b/level_zero/core/test/unit_tests/xe_hpc_core/test_cmdlist_xe_hpc_core.cpp @@ -0,0 +1,313 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/os_interface/hw_info_config.h" +#include "shared/test/common/cmd_parse/gen_cmd_parse.h" +#include "shared/test/common/helpers/debug_manager_state_restore.h" + +#include "test.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 { +namespace ult { + +using CommandListAppendLaunchKernelXeHpcCore = Test; +HWTEST2_F(CommandListAppendLaunchKernelXeHpcCore, givenKernelUsingSyncBufferWhenAppendLaunchCooperativeKernelIsCalledThenCorrectValueIsReturned, IsXeHpcCore) { + auto &hwInfo = *device->getNEODevice()->getRootDeviceEnvironment().getMutableHardwareInfo(); + auto &hwConfig = *NEO::HwInfoConfig::get(hwInfo.platform.eProductFamily); + Mock<::L0::Kernel> kernel; + auto pMockModule = std::unique_ptr(new Mock(device, nullptr)); + kernel.module = pMockModule.get(); + + kernel.setGroupSize(1, 1, 1); + ze_group_count_t groupCount{8, 1, 1}; + auto pCommandList = std::make_unique>>(); + auto result = pCommandList->initialize(device, NEO::EngineGroupType::CooperativeCompute, 0u); + ASSERT_EQ(ZE_RESULT_SUCCESS, result); + + auto &kernelAttributes = kernel.immutableData.kernelDescriptor->kernelAttributes; + kernelAttributes.flags.usesSyncBuffer = true; + kernelAttributes.numGrfRequired = GrfConfig::DefaultGrfNumber; + bool isCooperative = true; + result = pCommandList->appendLaunchKernelWithParams(kernel.toHandle(), &groupCount, nullptr, false, false, isCooperative); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + + { + VariableBackup engineGroupType{&pCommandList->engineGroupType}; + VariableBackup hwRevId{&hwInfo.platform.usRevId}; + engineGroupType = EngineGroupType::RenderCompute; + hwRevId = hwConfig.getHwRevIdFromStepping(REVISION_B, hwInfo); + result = pCommandList->appendLaunchKernelWithParams(kernel.toHandle(), &groupCount, nullptr, false, false, isCooperative); + EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result); + + ze_group_count_t groupCount1{1, 1, 1}; + result = pCommandList->appendLaunchKernelWithParams(kernel.toHandle(), &groupCount1, nullptr, false, false, isCooperative); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + } +} + +using CommandListStatePrefetchXeHpcCore = Test; + +HWTEST2_F(CommandListStatePrefetchXeHpcCore, givenDebugFlagSetWhenPrefetchApiCalledThenProgramStatePrefetch, IsXeHpcCore) { + using STATE_PREFETCH = typename FamilyType::STATE_PREFETCH; + DebugManagerStateRestore restore; + + auto pCommandList = std::make_unique>>(); + auto result = pCommandList->initialize(device, NEO::EngineGroupType::Compute, 0u); + ASSERT_EQ(ZE_RESULT_SUCCESS, result); + + constexpr size_t size = MemoryConstants::cacheLineSize * 2; + constexpr size_t alignment = MemoryConstants::pageSize64k; + constexpr size_t offset = MemoryConstants::cacheLineSize; + constexpr uint32_t mocsIndexForL3 = (2 << 1); + void *ptr = nullptr; + + ze_device_mem_alloc_desc_t deviceDesc = {}; + context->allocDeviceMem(device->toHandle(), &deviceDesc, size + offset, alignment, &ptr); + EXPECT_NE(nullptr, ptr); + + auto hwInfo = device->getNEODevice()->getRootDeviceEnvironment().getMutableHardwareInfo(); + hwInfo->platform.usRevId |= FamilyType::pvcBaseDieRevMask; + + auto cmdListBaseOffset = pCommandList->commandContainer.getCommandStream()->getUsed(); + + { + auto ret = pCommandList->appendMemoryPrefetch(ptrOffset(ptr, offset), size); + EXPECT_EQ(ZE_RESULT_SUCCESS, ret); + + EXPECT_EQ(cmdListBaseOffset, pCommandList->commandContainer.getCommandStream()->getUsed()); + } + + { + DebugManager.flags.AddStatePrefetchCmdToMemoryPrefetchAPI.set(1); + + auto ret = pCommandList->appendMemoryPrefetch(ptrOffset(ptr, offset), size); + EXPECT_EQ(ZE_RESULT_SUCCESS, ret); + + EXPECT_EQ(cmdListBaseOffset + sizeof(STATE_PREFETCH), pCommandList->commandContainer.getCommandStream()->getUsed()); + + auto statePrefetchCmd = reinterpret_cast(ptrOffset(pCommandList->commandContainer.getCommandStream()->getCpuBase(), cmdListBaseOffset)); + + EXPECT_EQ(statePrefetchCmd->getAddress(), reinterpret_cast(ptrOffset(ptr, offset))); + EXPECT_FALSE(statePrefetchCmd->getKernelInstructionPrefetch()); + EXPECT_EQ(mocsIndexForL3, statePrefetchCmd->getMemoryObjectControlState()); + EXPECT_EQ(1u, statePrefetchCmd->getPrefetchSize()); + + EXPECT_EQ(reinterpret_cast(ptr), pCommandList->commandContainer.getResidencyContainer().back()->getGpuAddress()); + } + + context->freeMem(ptr); +} + +HWTEST2_F(CommandListStatePrefetchXeHpcCore, givenCommandBufferIsExhaustedWhenPrefetchApiCalledThenProgramStatePrefetch, IsXeHpcCore) { + using STATE_PREFETCH = typename FamilyType::STATE_PREFETCH; + using MI_BATCH_BUFFER_END = typename FamilyType::MI_BATCH_BUFFER_END; + + DebugManagerStateRestore restore; + + auto pCommandList = std::make_unique>>(); + auto result = pCommandList->initialize(device, NEO::EngineGroupType::Compute, 0u); + ASSERT_EQ(ZE_RESULT_SUCCESS, result); + + constexpr size_t size = MemoryConstants::cacheLineSize * 2; + constexpr size_t alignment = MemoryConstants::pageSize64k; + constexpr size_t offset = MemoryConstants::cacheLineSize; + constexpr uint32_t mocsIndexForL3 = (2 << 1); + void *ptr = nullptr; + + ze_device_mem_alloc_desc_t deviceDesc = {}; + context->allocDeviceMem(device->toHandle(), &deviceDesc, size + offset, alignment, &ptr); + EXPECT_NE(nullptr, ptr); + + auto hwInfo = device->getNEODevice()->getRootDeviceEnvironment().getMutableHardwareInfo(); + hwInfo->platform.usRevId |= FamilyType::pvcBaseDieRevMask; + + auto firstBatchBufferAllocation = pCommandList->commandContainer.getCommandStream()->getGraphicsAllocation(); + + auto useSize = pCommandList->commandContainer.getCommandStream()->getAvailableSpace(); + useSize -= sizeof(MI_BATCH_BUFFER_END); + pCommandList->commandContainer.getCommandStream()->getSpace(useSize); + + DebugManager.flags.AddStatePrefetchCmdToMemoryPrefetchAPI.set(1); + + auto ret = pCommandList->appendMemoryPrefetch(ptrOffset(ptr, offset), size); + EXPECT_EQ(ZE_RESULT_SUCCESS, ret); + auto secondBatchBufferAllocation = pCommandList->commandContainer.getCommandStream()->getGraphicsAllocation(); + + EXPECT_NE(firstBatchBufferAllocation, secondBatchBufferAllocation); + + auto statePrefetchCmd = reinterpret_cast(pCommandList->commandContainer.getCommandStream()->getCpuBase()); + + EXPECT_EQ(statePrefetchCmd->getAddress(), reinterpret_cast(ptrOffset(ptr, offset))); + EXPECT_FALSE(statePrefetchCmd->getKernelInstructionPrefetch()); + EXPECT_EQ(mocsIndexForL3, statePrefetchCmd->getMemoryObjectControlState()); + EXPECT_EQ(1u, statePrefetchCmd->getPrefetchSize()); + + NEO::ResidencyContainer::iterator it = pCommandList->commandContainer.getResidencyContainer().end(); + it--; + EXPECT_EQ(secondBatchBufferAllocation->getGpuAddress(), (*it)->getGpuAddress()); + it--; + EXPECT_EQ(reinterpret_cast(ptr), (*it)->getGpuAddress()); + + context->freeMem(ptr); +} + +using CommandListEventFenceTestsXeHpcCore = Test; + +HWTEST2_F(CommandListEventFenceTestsXeHpcCore, givenCommandListWithProfilingEventAfterCommandOnPvcRev00ThenMiFenceIsNotAdded, IsXeHpcCore) { + using GfxFamily = typename NEO::GfxFamilyMapper::GfxFamily; + using MI_MEM_FENCE = typename FamilyType::MI_MEM_FENCE; + + auto commandList = std::make_unique>>(); + commandList->initialize(device, NEO::EngineGroupType::Compute, 0u); + ze_event_pool_desc_t eventPoolDesc = {}; + eventPoolDesc.count = 1; + eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP; + + auto hwInfo = commandList->commandContainer.getDevice()->getExecutionEnvironment()->rootDeviceEnvironments[0]->getMutableHardwareInfo(); + hwInfo->platform.usRevId = 0x00; + + ze_event_desc_t eventDesc = {}; + eventDesc.index = 0; + eventDesc.signal = 0; + eventDesc.wait = 0; + ze_result_t result = ZE_RESULT_SUCCESS; + auto eventPool = std::unique_ptr(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result)); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + auto event = std::unique_ptr(L0::Event::create(eventPool.get(), &eventDesc, device)); + commandList->appendEventForProfiling(event->toHandle(), false); + + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, ptrOffset(commandList->commandContainer.getCommandStream()->getCpuBase(), 0), commandList->commandContainer.getCommandStream()->getUsed())); + + auto itor = find(cmdList.begin(), cmdList.end()); + EXPECT_EQ(cmdList.end(), itor); +} + +HWTEST2_F(CommandListEventFenceTestsXeHpcCore, givenCommandListWithProfilingEventAfterCommandOnPvcRev03ThenMiFenceIsAdded, IsXeHpcCore) { + using GfxFamily = typename NEO::GfxFamilyMapper::GfxFamily; + using MI_MEM_FENCE = typename FamilyType::MI_MEM_FENCE; + + auto commandList = std::make_unique>>(); + commandList->initialize(device, NEO::EngineGroupType::Compute, 0u); + ze_event_pool_desc_t eventPoolDesc = {}; + eventPoolDesc.count = 1; + eventPoolDesc.flags = ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP; + + auto hwInfo = commandList->commandContainer.getDevice()->getExecutionEnvironment()->rootDeviceEnvironments[0]->getMutableHardwareInfo(); + hwInfo->platform.usRevId = 0x03; + + ze_event_desc_t eventDesc = {}; + eventDesc.index = 0; + eventDesc.signal = 0; + eventDesc.wait = 0; + ze_result_t result = ZE_RESULT_SUCCESS; + auto eventPool = std::unique_ptr(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result)); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + auto event = std::unique_ptr(L0::Event::create(eventPool.get(), &eventDesc, device)); + commandList->appendEventForProfiling(event->toHandle(), false); + + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, ptrOffset(commandList->commandContainer.getCommandStream()->getCpuBase(), 0), commandList->commandContainer.getCommandStream()->getUsed())); + + auto itor = find(cmdList.begin(), cmdList.end()); + EXPECT_NE(cmdList.end(), itor); +} + +HWTEST2_F(CommandListEventFenceTestsXeHpcCore, givenCommandListWithRegularEventAfterCommandOnPvcRev03ThenMiFenceIsAdded, IsXeHpcCore) { + using GfxFamily = typename NEO::GfxFamilyMapper::GfxFamily; + using MI_MEM_FENCE = typename FamilyType::MI_MEM_FENCE; + + auto commandList = std::make_unique>>(); + commandList->initialize(device, NEO::EngineGroupType::Compute, 0u); + ze_event_pool_desc_t eventPoolDesc = {}; + eventPoolDesc.count = 1; + + auto hwInfo = commandList->commandContainer.getDevice()->getExecutionEnvironment()->rootDeviceEnvironments[0]->getMutableHardwareInfo(); + hwInfo->platform.usRevId = 0x03; + + ze_event_desc_t eventDesc = {}; + eventDesc.index = 0; + eventDesc.signal = 0; + eventDesc.wait = 0; + ze_result_t result = ZE_RESULT_SUCCESS; + auto eventPool = std::unique_ptr(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result)); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + auto event = std::unique_ptr(L0::Event::create(eventPool.get(), &eventDesc, device)); + commandList->appendSignalEventPostWalker(event->toHandle()); + + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, ptrOffset(commandList->commandContainer.getCommandStream()->getCpuBase(), 0), commandList->commandContainer.getCommandStream()->getUsed())); + + auto itor = find(cmdList.begin(), cmdList.end()); + EXPECT_NE(cmdList.end(), itor); +} + +using CommandListAppendRangesBarrierXeHpcCore = Test; + +HWTEST2_F(CommandListAppendRangesBarrierXeHpcCore, givenCallToAppendRangesBarrierThenPipeControlProgrammed, IsXeHpcCore) { + using GfxFamily = typename NEO::GfxFamilyMapper::GfxFamily; + using PIPE_CONTROL = typename GfxFamily::PIPE_CONTROL; + auto commandList = std::make_unique>>(); + commandList->initialize(device, NEO::EngineGroupType::Copy, 0u); + uint64_t gpuAddress = 0x1200; + void *buffer = reinterpret_cast(gpuAddress); + size_t size = 0x1100; + + NEO::MockGraphicsAllocation mockAllocation(buffer, gpuAddress, size); + NEO::SvmAllocationData allocData(0); + allocData.size = size; + allocData.gpuAllocations.addAllocation(&mockAllocation); + device->getDriverHandle()->getSvmAllocsManager()->insertSVMAlloc(allocData); + const void *ranges[] = {buffer}; + const size_t sizes[] = {size}; + commandList->applyMemoryRangesBarrier(1, sizes, ranges); + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, ptrOffset(commandList->commandContainer.getCommandStream()->getCpuBase(), 0), commandList->commandContainer.getCommandStream()->getUsed())); + auto itor = find(cmdList.begin(), cmdList.end()); + EXPECT_NE(cmdList.end(), itor); + auto pipeControlCmd = reinterpret_cast(*itor); + EXPECT_TRUE(pipeControlCmd->getHdcPipelineFlush()); + EXPECT_TRUE(pipeControlCmd->getUnTypedDataPortCacheFlush()); +} + +using CommandListAppendBarrierXeHpcCore = Test; + +HWTEST2_F(CommandListAppendBarrierXeHpcCore, givenCommandListWhenAppendingBarrierThenPipeControlIsProgrammedAndHdcAndUnTypedFlushesAreSet, IsPVC) { + using GfxFamily = typename NEO::GfxFamilyMapper::GfxFamily; + using PIPE_CONTROL = typename GfxFamily::PIPE_CONTROL; + auto commandList = std::make_unique>>(); + commandList->initialize(device, NEO::EngineGroupType::RenderCompute, 0u); + ze_result_t returnValue = commandList->appendBarrier(nullptr, 0, nullptr); + EXPECT_EQ(returnValue, ZE_RESULT_SUCCESS); + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, ptrOffset(commandList->commandContainer.getCommandStream()->getCpuBase(), 0), commandList->commandContainer.getCommandStream()->getUsed())); + + // PC for STATE_BASE_ADDRESS from list initialization + auto itor = find(cmdList.begin(), cmdList.end()); + EXPECT_NE(cmdList.end(), itor); + itor++; + + // PC for appendBarrier + itor = find(itor, cmdList.end()); + EXPECT_NE(cmdList.end(), itor); + + auto pipeControlCmd = reinterpret_cast(*itor); + EXPECT_TRUE(pipeControlCmd->getHdcPipelineFlush()); + EXPECT_TRUE(pipeControlCmd->getUnTypedDataPortCacheFlush()); +} + +} // namespace ult +} // namespace L0 diff --git a/level_zero/core/test/unit_tests/xe_hpc_core/test_cmdqueue_xe_hpc_core.cpp b/level_zero/core/test/unit_tests/xe_hpc_core/test_cmdqueue_xe_hpc_core.cpp new file mode 100644 index 0000000000..d8bc732234 --- /dev/null +++ b/level_zero/core/test/unit_tests/xe_hpc_core/test_cmdqueue_xe_hpc_core.cpp @@ -0,0 +1,272 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/os_interface/hw_info_config.h" +#include "shared/test/common/cmd_parse/gen_cmd_parse.h" +#include "shared/test/common/helpers/default_hw_info.h" +#include "shared/test/common/mocks/mock_command_stream_receiver.h" + +#include "test.h" + +#include "level_zero/core/source/driver/driver_handle_imp.h" +#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" +#include "level_zero/core/test/unit_tests/mocks/mock_built_ins.h" +#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" +#include "level_zero/core/test/unit_tests/mocks/mock_module.h" + +namespace L0 { +namespace ult { + +struct CommandQueueCreateMultiOrdinalFixture : public DeviceFixture { + void SetUp() { + NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo; + hwInfo.featureTable.flags.ftrCCSNode = true; + hwInfo.featureTable.ftrBcsInfo = 0; + hwInfo.gtSystemInfo.CCSInfo.NumberOfCCSEnabled = 4; + + neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo); + NEO::DeviceVector devices; + devices.push_back(std::unique_ptr(neoDevice)); + driverHandle = std::make_unique>(); + driverHandle->initialize(std::move(devices)); + device = driverHandle->devices[0]; + } + + void TearDown() { + } + + std::unique_ptr> driverHandle; + NEO::MockDevice *neoDevice = nullptr; + L0::Device *device = nullptr; +}; + +using CommandQueueCommandsPvc = Test; + +HWTEST2_F(CommandQueueCommandsPvc, givenCommandQueueWhenExecutingCommandListsThenGlobalFenceAllocationIsResident, IsXeHpcCore) { + using STATE_SYSTEM_MEM_FENCE_ADDRESS = typename FamilyType::STATE_SYSTEM_MEM_FENCE_ADDRESS; + ze_command_queue_desc_t desc = {}; + MockCsrHw2 csr(*neoDevice->getExecutionEnvironment(), 0, neoDevice->getDeviceBitfield()); + csr.initializeTagAllocation(); + csr.setupContext(*neoDevice->getDefaultEngine().osContext); + csr.createGlobalFenceAllocation(); + + auto commandQueue = new MockCommandQueueHw(device, &csr, &desc); + commandQueue->initialize(false, false); + + ze_result_t returnValue; + std::unique_ptr commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::Compute, 0u, returnValue)); + auto commandListHandle = commandList->toHandle(); + commandQueue->executeCommandLists(1, &commandListHandle, nullptr, false); + + auto globalFence = csr.getGlobalFenceAllocation(); + + bool found = false; + for (auto alloc : csr.copyOfAllocations) { + if (alloc == globalFence) { + found = true; + break; + } + } + EXPECT_TRUE(found); + commandQueue->destroy(); +} + +HWTEST2_F(CommandQueueCommandsPvc, givenCommandQueueWhenExecutingCommandListsThenStateSystemMemFenceAddressCmdIsGenerated, IsXeHpcCore) { + using STATE_SYSTEM_MEM_FENCE_ADDRESS = typename FamilyType::STATE_SYSTEM_MEM_FENCE_ADDRESS; + ze_command_queue_desc_t desc = {}; + auto csr = neoDevice->getDefaultEngine().commandStreamReceiver; + + auto commandQueue = new MockCommandQueueHw(device, csr, &desc); + commandQueue->initialize(false, false); + + ze_result_t returnValue; + std::unique_ptr commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::Compute, 0u, returnValue)); + auto commandListHandle = commandList->toHandle(); + commandQueue->executeCommandLists(1, &commandListHandle, nullptr, false); + + auto globalFence = csr->getGlobalFenceAllocation(); + + auto used = commandQueue->commandStream->getUsed(); + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, commandQueue->commandStream->getCpuBase(), used)); + + auto itor = find(cmdList.begin(), cmdList.end()); + ASSERT_NE(cmdList.end(), itor); + + auto systemMemFenceAddressCmd = genCmdCast(*itor); + EXPECT_EQ(globalFence->getGpuAddress(), systemMemFenceAddressCmd->getSystemMemoryFenceAddress()); + + commandQueue->destroy(); +} + +HWTEST2_F(CommandQueueCommandsPvc, givenCommandQueueWhenExecutingCommandListsForTheSecondTimeThenStateSystemMemFenceAddressCmdIsNotGenerated, IsXeHpcCore) { + using STATE_SYSTEM_MEM_FENCE_ADDRESS = typename FamilyType::STATE_SYSTEM_MEM_FENCE_ADDRESS; + ze_command_queue_desc_t desc = {}; + auto csr = neoDevice->getDefaultEngine().commandStreamReceiver; + + auto commandQueue = new MockCommandQueueHw(device, csr, &desc); + commandQueue->initialize(false, false); + + ze_result_t returnValue; + std::unique_ptr commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::Compute, 0u, returnValue)); + auto commandListHandle = commandList->toHandle(); + commandQueue->executeCommandLists(1, &commandListHandle, nullptr, false); + auto used = commandQueue->commandStream->getUsed(); + commandQueue->executeCommandLists(1, &commandListHandle, nullptr, false); + auto sizeUsed2 = commandQueue->commandStream->getUsed(); + + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, ptrOffset(commandQueue->commandStream->getCpuBase(), used), sizeUsed2)); + + auto itor = find(cmdList.begin(), cmdList.end()); + EXPECT_EQ(cmdList.end(), itor); + + commandQueue->destroy(); +} + +HWTEST2_F(CommandQueueCommandsPvc, givenLinkedCopyEngineOrdinalWhenCreatingThenSetAsCopyOnly, IsXeHpcCore) { + ze_result_t returnValue; + auto hwInfo = *NEO::defaultHwInfo; + hwInfo.featureTable.ftrBcsInfo.set(1, true); + hwInfo.capabilityTable.blitterOperationsSupported = true; + + auto testNeoDevice = NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo); + + auto testL0Device = std::unique_ptr(L0::Device::create(driverHandle.get(), testNeoDevice, false, &returnValue)); + + ze_context_handle_t hContext; + ze_context_desc_t desc = {}; + + ze_result_t result = driverHandle->createContext(&desc, 0u, nullptr, &hContext); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + + ze_command_queue_desc_t cmdQueueDesc = {}; + ze_command_queue_handle_t cmdQueue; + + cmdQueueDesc.ordinal = static_cast(testNeoDevice->getEngineGroupIndexFromEngineGroupType(NEO::EngineGroupType::LinkedCopy)); + + result = zeCommandQueueCreate(hContext, testL0Device.get(), &cmdQueueDesc, &cmdQueue); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + + auto cmdQ = L0::CommandQueue::fromHandle(cmdQueue); + + EXPECT_TRUE(cmdQ->peekIsCopyOnlyCommandQueue()); + + cmdQ->destroy(); + L0::Context::fromHandle(hContext)->destroy(); +} + +HWTEST2_F(CommandQueueCommandsPvc, whenExecuteCommandListsIsCalledThenAdditionalCfeStatesAreCorrectlyProgrammed, IsXeHpcCore) { + if (!XE_HPC_CORE::isXtTemporary(*defaultHwInfo)) { + GTEST_SKIP(); + } + + DebugManagerStateRestore restorer; + DebugManager.flags.AllowMixingRegularAndCooperativeKernels.set(1); + DebugManager.flags.AllowPatchingVfeStateInCommandLists.set(1); + using CFE_STATE = typename FamilyType::CFE_STATE; + + auto hwInfo = *NEO::defaultHwInfo; + const auto &hwInfoConfig = *NEO::HwInfoConfig::get(hwInfo.platform.eProductFamily); + auto bStep = hwInfoConfig.getHwRevIdFromStepping(REVISION_B, hwInfo); + if (bStep != CommonConstants::invalidStepping) { + hwInfo.platform.usRevId = bStep; + } + if constexpr (IsPVC::isMatched()) { + hwInfo.platform.usRevId |= FamilyType::pvcBaseDieRevMask; + } + auto neoDevice = NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo); + auto mockBuiltIns = new MockBuiltins(); + neoDevice->executionEnvironment->rootDeviceEnvironments[0]->builtins.reset(mockBuiltIns); + NEO::DeviceVector devices; + devices.push_back(std::unique_ptr(neoDevice)); + auto driverHandle = std::make_unique>(); + driverHandle->initialize(std::move(devices)); + auto device = driverHandle->devices[0]; + + ze_command_queue_desc_t desc = {}; + NEO::CommandStreamReceiver *csr; + device->getCsrForOrdinalAndIndex(&csr, 0u, 0u); + auto commandQueue = new MockCommandQueueHw{device, csr, &desc}; + commandQueue->initialize(false, false); + + Mock<::L0::Kernel> defaultKernel; + auto pMockModule1 = std::unique_ptr(new Mock(device, nullptr)); + defaultKernel.module = pMockModule1.get(); + + Mock<::L0::Kernel> cooperativeKernel; + auto pMockModule2 = std::unique_ptr(new Mock(device, nullptr)); + cooperativeKernel.module = pMockModule2.get(); + cooperativeKernel.immutableData.kernelDescriptor->kernelAttributes.flags.usesSyncBuffer = true; + cooperativeKernel.immutableData.kernelDescriptor->kernelAttributes.numGrfRequired = GrfConfig::DefaultGrfNumber; + cooperativeKernel.setGroupSize(1, 1, 1); + + ze_group_count_t threadGroupDimensions{1, 1, 1}; + auto commandListAB = std::make_unique>>(); + commandListAB->initialize(device, NEO::EngineGroupType::CooperativeCompute, 0u); + commandListAB->appendLaunchKernelWithParams(&defaultKernel, &threadGroupDimensions, nullptr, false, false, false); + commandListAB->appendLaunchKernelWithParams(&cooperativeKernel, &threadGroupDimensions, nullptr, false, false, true); + auto hCommandListAB = commandListAB->toHandle(); + + auto commandListBA = std::make_unique>>(); + commandListBA->initialize(device, NEO::EngineGroupType::CooperativeCompute, 0u); + commandListBA->appendLaunchKernelWithParams(&cooperativeKernel, &threadGroupDimensions, nullptr, false, false, true); + commandListBA->appendLaunchKernelWithParams(&defaultKernel, &threadGroupDimensions, nullptr, false, false, false); + auto hCommandListBA = commandListBA->toHandle(); + + // Set state B + csr->getStreamProperties().frontEndState.setProperties(true, false, false, *NEO::defaultHwInfo); + // Execute command list AB + commandQueue->executeCommandLists(1, &hCommandListAB, nullptr, false); + + // Expect state A programmed by command queue + GenCmdList cmdList; + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, commandQueue->commandStream->getCpuBase(), commandQueue->commandStream->getUsed())); + auto cfeStates = findAll(cmdList.begin(), cmdList.end()); + EXPECT_EQ(1u, cfeStates.size()); + EXPECT_EQ(false, genCmdCast(*cfeStates[0])->getComputeDispatchAllWalkerEnable()); + + // Expect state B programmed by command list + cmdList.clear(); + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, commandListAB->commandContainer.getCommandStream()->getCpuBase(), commandListAB->commandContainer.getCommandStream()->getUsed())); + cfeStates = findAll(cmdList.begin(), cmdList.end()); + EXPECT_EQ(1u, cfeStates.size()); + EXPECT_EQ(true, genCmdCast(*cfeStates[0])->getComputeDispatchAllWalkerEnable()); + + // Set state A + csr->getStreamProperties().frontEndState.setProperties(false, false, false, *NEO::defaultHwInfo); + // Execute command list BA + commandQueue->executeCommandLists(1, &hCommandListBA, nullptr, false); + + // Expect state B programmed by command queue + cmdList.clear(); + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, commandQueue->commandStream->getCpuBase(), commandQueue->commandStream->getUsed())); + cfeStates = findAll(cmdList.begin(), cmdList.end()); + EXPECT_EQ(2u, cfeStates.size()); + EXPECT_EQ(false, genCmdCast(*cfeStates[0])->getComputeDispatchAllWalkerEnable()); + EXPECT_EQ(true, genCmdCast(*cfeStates[1])->getComputeDispatchAllWalkerEnable()); + + // Expect state A programmed by command list + cmdList.clear(); + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer( + cmdList, commandListBA->commandContainer.getCommandStream()->getCpuBase(), commandListBA->commandContainer.getCommandStream()->getUsed())); + cfeStates = findAll(cmdList.begin(), cmdList.end()); + EXPECT_EQ(1u, cfeStates.size()); + EXPECT_EQ(false, genCmdCast(*cfeStates[0])->getComputeDispatchAllWalkerEnable()); + + commandQueue->destroy(); +} + +} // namespace ult +} // namespace L0 diff --git a/level_zero/core/test/unit_tests/xe_hpc_core/test_device_xe_hpc_core.cpp b/level_zero/core/test/unit_tests/xe_hpc_core/test_device_xe_hpc_core.cpp new file mode 100644 index 0000000000..41dbd22f72 --- /dev/null +++ b/level_zero/core/test/unit_tests/xe_hpc_core/test_device_xe_hpc_core.cpp @@ -0,0 +1,362 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/debug_settings/debug_settings_manager.h" +#include "shared/test/common/mocks/ult_device_factory.h" + +#include "test.h" + +#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" + +namespace L0 { +namespace ult { + +HWTEST_EXCLUDE_PRODUCT(AppendMemoryCopy, givenCopyOnlyCommandListAndHostPointersWhenMemoryCopyCalledThenPipeControlWithDcFlushAddedIsNotAddedAfterBlitCopy, IGFX_XE_HPC_CORE); + +using DeviceFixturePVC = Test; + +HWTEST2_F(DeviceFixturePVC, whenCallingGetMemoryPropertiesWithNonNullPtrThenPropertiesAreReturned, IsXeHpcCore) { + uint32_t count = 0; + ze_result_t res = device->getMemoryProperties(&count, nullptr); + EXPECT_EQ(res, ZE_RESULT_SUCCESS); + EXPECT_EQ(1u, count); + + ze_device_memory_properties_t memProperties = {}; + res = device->getMemoryProperties(&count, &memProperties); + EXPECT_EQ(res, ZE_RESULT_SUCCESS); + EXPECT_EQ(1u, count); + + EXPECT_EQ(memProperties.maxClockRate, 3200u); + EXPECT_EQ(memProperties.maxBusWidth, this->neoDevice->getDeviceInfo().addressBits); + EXPECT_EQ(memProperties.totalSize, this->neoDevice->getDeviceInfo().globalMemSize); +} + +HWTEST2_F(DeviceFixturePVC, whenCallingGetMemoryPropertiesWithNonNullPtrAndBdRevisionIsNotA0ThenmaxClockRateReturnedIsZero, IsXeHpcCore) { + uint32_t count = 0; + auto device = driverHandle->devices[0]; + auto hwInfo = device->getNEODevice()->getRootDeviceEnvironment().getMutableHardwareInfo(); + hwInfo->platform.usRevId = FamilyType::pvcBaseDieA0Masked ^ FamilyType::pvcBaseDieRevMask; + + ze_result_t res = device->getMemoryProperties(&count, nullptr); + EXPECT_EQ(res, ZE_RESULT_SUCCESS); + EXPECT_EQ(1u, count); + + ze_device_memory_properties_t memProperties = {}; + res = device->getMemoryProperties(&count, &memProperties); + EXPECT_EQ(res, ZE_RESULT_SUCCESS); + EXPECT_EQ(1u, count); + + EXPECT_EQ(memProperties.maxClockRate, 0u); +} + +using DeviceQueueGroupTest = Test; + +HWTEST2_F(DeviceQueueGroupTest, givenNoBlitterSupportAndNoCCSThenOneQueueGroupIsReturned, IsXeHpcCore) { + const uint32_t rootDeviceIndex = 0u; + NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get(); + hwInfo.featureTable.flags.ftrCCSNode = false; + hwInfo.capabilityTable.blitterOperationsSupported = false; + auto *neoMockDevice = NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo, rootDeviceIndex); + Mock deviceImp(neoMockDevice, neoMockDevice->getExecutionEnvironment()); + + uint32_t count = 0; + ze_result_t res = deviceImp.getCommandQueueGroupProperties(&count, nullptr); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + EXPECT_GE(count, 1u); +} + +HWTEST2_F(DeviceQueueGroupTest, givenNoBlitterSupportAndCCSThenTwoQueueGroupsAreReturned, IsXeHpcCore) { + const uint32_t rootDeviceIndex = 0u; + NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get(); + hwInfo.featureTable.flags.ftrCCSNode = true; + hwInfo.capabilityTable.blitterOperationsSupported = false; + auto *neoMockDevice = NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo, rootDeviceIndex); + Mock deviceImp(neoMockDevice, neoMockDevice->getExecutionEnvironment()); + + uint32_t count = 0; + ze_result_t res = deviceImp.getCommandQueueGroupProperties(&count, nullptr); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + EXPECT_GE(count, 2u); +} + +HWTEST2_F(DeviceQueueGroupTest, givenBlitterSupportAndCCSThenFourQueueGroupsAreReturned, IsXeHpcCore) { + const uint32_t rootDeviceIndex = 0u; + NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get(); + hwInfo.featureTable.flags.ftrCCSNode = true; + hwInfo.capabilityTable.blitterOperationsSupported = true; + hwInfo.featureTable.ftrBcsInfo.set(); + auto *neoMockDevice = NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo, rootDeviceIndex); + Mock deviceImp(neoMockDevice, neoMockDevice->getExecutionEnvironment()); + + uint32_t count = 0; + ze_result_t res = deviceImp.getCommandQueueGroupProperties(&count, nullptr); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + EXPECT_GE(count, 4u); + + std::vector properties(count); + res = deviceImp.getCommandQueueGroupProperties(&count, properties.data()); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + + auto &engineGroups = neoMockDevice->getEngineGroups(); + for (uint32_t i = 0; i < count; i++) { + if (engineGroups[i].engineGroupType == NEO::EngineGroupType::RenderCompute) { + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE); + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY); + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COOPERATIVE_KERNELS); + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_METRICS); + EXPECT_EQ(properties[i].numQueues, 1u); + EXPECT_EQ(properties[i].maxMemoryFillPatternSize, std::numeric_limits::max()); + } else if (engineGroups[i].engineGroupType == NEO::EngineGroupType::Compute) { + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE); + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY); + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COOPERATIVE_KERNELS); + uint32_t numerOfCCSEnabled = hwInfo.gtSystemInfo.CCSInfo.NumberOfCCSEnabled; + EXPECT_EQ(properties[i].numQueues, numerOfCCSEnabled); + EXPECT_EQ(properties[i].maxMemoryFillPatternSize, std::numeric_limits::max()); + } else if (engineGroups[i].engineGroupType == NEO::EngineGroupType::Copy) { + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY); + EXPECT_EQ(properties[i].numQueues, 1u); + EXPECT_EQ(properties[i].maxMemoryFillPatternSize, sizeof(uint8_t)); + } else if (engineGroups[i].engineGroupType == NEO::EngineGroupType::LinkedCopy) { + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY); + EXPECT_EQ(properties[i].numQueues, hwInfo.featureTable.ftrBcsInfo.count() - 1u); + EXPECT_EQ(properties[i].maxMemoryFillPatternSize, sizeof(uint8_t)); + } + } +} + +HWTEST2_F(DeviceQueueGroupTest, givenBlitterSupportWithBcsVirtualEnginesEnabledThenOneByteFillPatternReturned, IsXeHpcCore) { + DebugManagerStateRestore restore; + DebugManager.flags.UseDrmVirtualEnginesForBcs.set(1); + const uint32_t rootDeviceIndex = 0u; + NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get(); + hwInfo.featureTable.flags.ftrCCSNode = true; + hwInfo.capabilityTable.blitterOperationsSupported = true; + hwInfo.featureTable.ftrBcsInfo.set(); + auto *neoMockDevice = NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo, rootDeviceIndex); + Mock deviceImp(neoMockDevice, neoMockDevice->getExecutionEnvironment()); + + uint32_t count = 0; + ze_result_t res = deviceImp.getCommandQueueGroupProperties(&count, nullptr); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + EXPECT_GE(count, 4u); + + std::vector properties(count); + res = deviceImp.getCommandQueueGroupProperties(&count, properties.data()); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + + auto &engineGroups = neoMockDevice->getEngineGroups(); + for (uint32_t i = 0; i < count; i++) { + if (engineGroups[i].engineGroupType == NEO::EngineGroupType::Copy) { + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY); + EXPECT_EQ(properties[i].numQueues, 1u); + EXPECT_EQ(properties[i].maxMemoryFillPatternSize, sizeof(uint8_t)); + } + } +} + +HWTEST2_F(DeviceQueueGroupTest, givenBlitterSupportWithBcsVirtualEnginesDisabledThenCorrectFillPatternReturned, IsXeHpcCore) { + DebugManagerStateRestore restore; + DebugManager.flags.UseDrmVirtualEnginesForBcs.set(0); + const uint32_t rootDeviceIndex = 0u; + NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get(); + hwInfo.featureTable.flags.ftrCCSNode = true; + hwInfo.capabilityTable.blitterOperationsSupported = true; + hwInfo.featureTable.ftrBcsInfo.set(); + auto *neoMockDevice = NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo, rootDeviceIndex); + Mock deviceImp(neoMockDevice, neoMockDevice->getExecutionEnvironment()); + + uint32_t count = 0; + ze_result_t res = deviceImp.getCommandQueueGroupProperties(&count, nullptr); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + EXPECT_GE(count, 4u); + + std::vector properties(count); + res = deviceImp.getCommandQueueGroupProperties(&count, properties.data()); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + + auto &engineGroups = neoMockDevice->getEngineGroups(); + for (uint32_t i = 0; i < count; i++) { + if (engineGroups[i].engineGroupType == NEO::EngineGroupType::Copy) { + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY); + EXPECT_EQ(properties[i].numQueues, 1u); + EXPECT_EQ(properties[i].maxMemoryFillPatternSize, 4 * sizeof(uint32_t)); + } + } +} + +HWTEST2_F(DeviceQueueGroupTest, givenBlitterSupportCCSAndLinkedBcsDisabledThenThreeQueueGroupsAreReturned, IsXeHpcCore) { + const uint32_t rootDeviceIndex = 0u; + NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get(); + hwInfo.featureTable.flags.ftrCCSNode = true; + hwInfo.capabilityTable.blitterOperationsSupported = true; + hwInfo.featureTable.ftrBcsInfo.set(0); + auto *neoMockDevice = NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo, rootDeviceIndex); + Mock deviceImp(neoMockDevice, neoMockDevice->getExecutionEnvironment()); + + uint32_t count = 0; + ze_result_t res = deviceImp.getCommandQueueGroupProperties(&count, nullptr); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + EXPECT_GE(count, 3u); + + std::vector properties(count); + res = deviceImp.getCommandQueueGroupProperties(&count, properties.data()); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + + auto &engineGroups = neoMockDevice->getEngineGroups(); + for (uint32_t i = 0; i < count; i++) { + if (engineGroups[i].engineGroupType == NEO::EngineGroupType::RenderCompute) { + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE); + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY); + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COOPERATIVE_KERNELS); + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_METRICS); + EXPECT_EQ(properties[i].numQueues, 1u); + EXPECT_EQ(properties[i].maxMemoryFillPatternSize, std::numeric_limits::max()); + } else if (engineGroups[i].engineGroupType == NEO::EngineGroupType::Compute) { + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE); + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY); + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COOPERATIVE_KERNELS); + uint32_t numerOfCCSEnabled = hwInfo.gtSystemInfo.CCSInfo.NumberOfCCSEnabled; + EXPECT_EQ(properties[i].numQueues, numerOfCCSEnabled); + EXPECT_EQ(properties[i].maxMemoryFillPatternSize, std::numeric_limits::max()); + } else if (engineGroups[i].engineGroupType == NEO::EngineGroupType::Copy) { + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY); + EXPECT_EQ(properties[i].numQueues, 1u); + EXPECT_EQ(properties[i].maxMemoryFillPatternSize, sizeof(uint8_t)); + } + } +} + +HWTEST2_F(DeviceQueueGroupTest, givenBlitterDisabledAndAllBcsSetThenTwoQueueGroupsAreReturned, IsXeHpcCore) { + DebugManagerStateRestore dbgRestorer; + DebugManager.flags.EnableBlitterOperationsSupport.set(0); + const uint32_t rootDeviceIndex = 0u; + NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get(); + hwInfo.featureTable.flags.ftrCCSNode = true; + hwInfo.featureTable.ftrBcsInfo.set(); + auto *neoMockDevice = NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo, rootDeviceIndex); + Mock deviceImp(neoMockDevice, neoMockDevice->getExecutionEnvironment()); + + uint32_t count = 0; + ze_result_t res = deviceImp.getCommandQueueGroupProperties(&count, nullptr); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + EXPECT_EQ(count, 2u); +} + +class DeviceCopyQueueGroupFixture : public DeviceFixture { + public: + void SetUp() { + DebugManager.flags.EnableBlitterOperationsSupport.set(0); + DeviceFixture::SetUp(); + } + + void TearDown() { + DeviceFixture::TearDown(); + } + DebugManagerStateRestore restorer; +}; + +using DeviceCopyQueueGroupTest = Test; + +HWTEST2_F(DeviceCopyQueueGroupTest, + givenBlitterSupportAndEnableBlitterOperationsSupportSetToZeroThenNoCopyEngineIsReturned, IsXeHpcCore) { + const uint32_t rootDeviceIndex = 0u; + NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get(); + hwInfo.featureTable.flags.ftrCCSNode = false; + hwInfo.capabilityTable.blitterOperationsSupported = true; + hwInfo.featureTable.ftrBcsInfo.set(0); + auto *neoMockDevice = NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo, + rootDeviceIndex); + Mock deviceImp(neoMockDevice, neoMockDevice->getExecutionEnvironment()); + + uint32_t count = 0; + ze_result_t res = deviceImp.getCommandQueueGroupProperties(&count, nullptr); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + + std::vector properties(count); + res = deviceImp.getCommandQueueGroupProperties(&count, properties.data()); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + + for (auto &engineGroup : neoMockDevice->getEngineGroups()) { + EXPECT_NE(NEO::EngineGroupType::Copy, engineGroup.engineGroupType); + } +} + +class DeviceQueueGroupTestPVC : public DeviceFixture, public testing::TestWithParam { + public: + void SetUp() override { + DeviceFixture::SetUp(); + } + + void TearDown() override { + DeviceFixture::TearDown(); + } +}; + +HWTEST2_P(DeviceQueueGroupTestPVC, givenVaryingBlitterSupportAndCCSThenBCSGroupContainsCorrectNumberOfEngines, IsXeHpcCore) { + const uint32_t rootDeviceIndex = 0u; + NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get(); + hwInfo.featureTable.flags.ftrCCSNode = true; + hwInfo.capabilityTable.blitterOperationsSupported = true; + hwInfo.featureTable.ftrBcsInfo = maxNBitValue(2); + hwInfo.featureTable.ftrBcsInfo.set(GetParam()); + auto *neoMockDevice = NEO::MockDevice::createWithNewExecutionEnvironment(&hwInfo, rootDeviceIndex); + Mock deviceImp(neoMockDevice, neoMockDevice->getExecutionEnvironment()); + + uint32_t count = 0; + ze_result_t res = deviceImp.getCommandQueueGroupProperties(&count, nullptr); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + EXPECT_GE(count, 3u); + + std::vector properties(count); + res = deviceImp.getCommandQueueGroupProperties(&count, properties.data()); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + + auto &engineGroups = neoMockDevice->getEngineGroups(); + for (uint32_t i = 0; i < count; i++) { + if (engineGroups[i].engineGroupType == NEO::EngineGroupType::RenderCompute) { + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE); + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY); + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COOPERATIVE_KERNELS); + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_METRICS); + EXPECT_EQ(properties[i].numQueues, 1u); + EXPECT_EQ(properties[i].maxMemoryFillPatternSize, std::numeric_limits::max()); + } else if (engineGroups[i].engineGroupType == NEO::EngineGroupType::Compute) { + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE); + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY); + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COOPERATIVE_KERNELS); + uint32_t numerOfCCSEnabled = hwInfo.gtSystemInfo.CCSInfo.NumberOfCCSEnabled; + EXPECT_EQ(properties[i].numQueues, numerOfCCSEnabled); + EXPECT_EQ(properties[i].maxMemoryFillPatternSize, std::numeric_limits::max()); + } else if (engineGroups[i].engineGroupType == NEO::EngineGroupType::Copy) { + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY); + EXPECT_EQ(properties[i].numQueues, 1u); + EXPECT_EQ(properties[i].maxMemoryFillPatternSize, sizeof(uint8_t)); + } else if (engineGroups[i].engineGroupType == NEO::EngineGroupType::LinkedCopy) { + EXPECT_TRUE(properties[i].flags & ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY); + EXPECT_EQ(properties[i].numQueues, hwInfo.featureTable.ftrBcsInfo.count() - 1u); + EXPECT_EQ(properties[i].maxMemoryFillPatternSize, sizeof(uint8_t)); + } + } +} + +INSTANTIATE_TEST_CASE_P( + DeviceQueueGroupTestPVCValues, + DeviceQueueGroupTestPVC, + testing::Values(0, 1, 2, 3)); + +HWTEST2_F(DeviceFixturePVC, givenReturnedDevicePropertiesThenExpectedPropertyFlagsSet, IsPVC) { + ze_device_properties_t deviceProps = {ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES}; + + device->getProperties(&deviceProps); + EXPECT_EQ(ZE_DEVICE_PROPERTY_FLAG_ONDEMANDPAGING, deviceProps.flags & ZE_DEVICE_PROPERTY_FLAG_ONDEMANDPAGING); + EXPECT_EQ(0u, deviceProps.flags & ZE_DEVICE_PROPERTY_FLAG_ECC); + EXPECT_EQ(0u, deviceProps.flags & ZE_DEVICE_PROPERTY_FLAG_SUBDEVICE); + EXPECT_EQ(0u, deviceProps.flags & ZE_DEVICE_PROPERTY_FLAG_INTEGRATED); +} +} // namespace ult +} // namespace L0 diff --git a/level_zero/core/test/unit_tests/xe_hpc_core/test_module_xe_hpc_core.cpp b/level_zero/core/test/unit_tests/xe_hpc_core/test_module_xe_hpc_core.cpp new file mode 100644 index 0000000000..ed0aaaf166 --- /dev/null +++ b/level_zero/core/test/unit_tests/xe_hpc_core/test_module_xe_hpc_core.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/kernel/kernel_properties.h" + +#include "test.h" + +#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" + +namespace L0 { +namespace ult { + +using KernelPropertyTest = Test; + +HWTEST2_F(KernelPropertyTest, givenKernelExtendedPropertiesStructureWhenKernelPropertiesCalledThenPropertiesAreCorrectlySet, IsXeHpcCore) { + ze_device_module_properties_t kernelProperties = {}; + ze_float_atomic_ext_properties_t kernelExtendedProperties = {}; + kernelExtendedProperties.stype = ZE_STRUCTURE_TYPE_FLOAT_ATOMIC_EXT_PROPERTIES; + kernelProperties.pNext = &kernelExtendedProperties; + ze_result_t res = device->getKernelProperties(&kernelProperties); + EXPECT_EQ(res, ZE_RESULT_SUCCESS); + + EXPECT_TRUE(kernelExtendedProperties.fp16Flags & FP_ATOMIC_EXT_FLAG_GLOBAL_LOAD_STORE); + EXPECT_TRUE(kernelExtendedProperties.fp16Flags & FP_ATOMIC_EXT_FLAG_GLOBAL_ADD); + EXPECT_TRUE(kernelExtendedProperties.fp16Flags & FP_ATOMIC_EXT_FLAG_GLOBAL_MIN_MAX); + EXPECT_FALSE(kernelExtendedProperties.fp16Flags & FP_ATOMIC_EXT_FLAG_LOCAL_LOAD_STORE); + EXPECT_FALSE(kernelExtendedProperties.fp16Flags & FP_ATOMIC_EXT_FLAG_LOCAL_ADD); + EXPECT_FALSE(kernelExtendedProperties.fp16Flags & FP_ATOMIC_EXT_FLAG_LOCAL_MIN_MAX); + + EXPECT_TRUE(kernelExtendedProperties.fp32Flags & FP_ATOMIC_EXT_FLAG_GLOBAL_LOAD_STORE); + EXPECT_TRUE(kernelExtendedProperties.fp32Flags & FP_ATOMIC_EXT_FLAG_GLOBAL_ADD); + EXPECT_TRUE(kernelExtendedProperties.fp32Flags & FP_ATOMIC_EXT_FLAG_GLOBAL_MIN_MAX); + EXPECT_FALSE(kernelExtendedProperties.fp32Flags & FP_ATOMIC_EXT_FLAG_LOCAL_LOAD_STORE); + EXPECT_FALSE(kernelExtendedProperties.fp32Flags & FP_ATOMIC_EXT_FLAG_LOCAL_ADD); + EXPECT_FALSE(kernelExtendedProperties.fp32Flags & FP_ATOMIC_EXT_FLAG_LOCAL_MIN_MAX); + + EXPECT_TRUE(kernelExtendedProperties.fp64Flags & FP_ATOMIC_EXT_FLAG_GLOBAL_LOAD_STORE); + EXPECT_TRUE(kernelExtendedProperties.fp64Flags & FP_ATOMIC_EXT_FLAG_GLOBAL_ADD); + EXPECT_TRUE(kernelExtendedProperties.fp64Flags & FP_ATOMIC_EXT_FLAG_GLOBAL_MIN_MAX); + EXPECT_FALSE(kernelExtendedProperties.fp64Flags & FP_ATOMIC_EXT_FLAG_LOCAL_LOAD_STORE); + EXPECT_FALSE(kernelExtendedProperties.fp64Flags & FP_ATOMIC_EXT_FLAG_LOCAL_ADD); + EXPECT_FALSE(kernelExtendedProperties.fp64Flags & FP_ATOMIC_EXT_FLAG_LOCAL_MIN_MAX); +} + +} // namespace ult +} // namespace L0 \ No newline at end of file