From f88267161edf652c348a6dee3f3e2785d2e7f5e4 Mon Sep 17 00:00:00 2001 From: Bartosz Dunajski Date: Wed, 19 Jan 2022 11:33:02 +0000 Subject: [PATCH] Add multicontext aub fixture Signed-off-by: Bartosz Dunajski --- .../aub_tests/fixtures/CMakeLists.txt | 3 + .../fixtures/multicontext_aub_fixture.cpp | 236 ++++++++++++++++++ .../fixtures/multicontext_aub_fixture.h | 112 +++++++++ .../multicontext_aub_fixture_extended.cpp | 15 ++ 4 files changed, 366 insertions(+) create mode 100644 opencl/test/unit_test/aub_tests/fixtures/multicontext_aub_fixture.cpp create mode 100644 opencl/test/unit_test/aub_tests/fixtures/multicontext_aub_fixture.h create mode 100644 opencl/test/unit_test/aub_tests/fixtures/multicontext_aub_fixture_extended.cpp diff --git a/opencl/test/unit_test/aub_tests/fixtures/CMakeLists.txt b/opencl/test/unit_test/aub_tests/fixtures/CMakeLists.txt index f386ec1cdb..6ba6dce2ee 100644 --- a/opencl/test/unit_test/aub_tests/fixtures/CMakeLists.txt +++ b/opencl/test/unit_test/aub_tests/fixtures/CMakeLists.txt @@ -9,6 +9,9 @@ target_sources(igdrcl_aub_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/aub_fixture.cpp ${CMAKE_CURRENT_SOURCE_DIR}/aub_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/hello_world_fixture.h + ${CMAKE_CURRENT_SOURCE_DIR}/multicontext_aub_fixture.cpp + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}multicontext_aub_fixture_extended.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/multicontext_aub_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/run_kernel_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/simple_arg_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/unified_memory_fixture.h diff --git a/opencl/test/unit_test/aub_tests/fixtures/multicontext_aub_fixture.cpp b/opencl/test/unit_test/aub_tests/fixtures/multicontext_aub_fixture.cpp new file mode 100644 index 0000000000..a211b54fb8 --- /dev/null +++ b/opencl/test/unit_test/aub_tests/fixtures/multicontext_aub_fixture.cpp @@ -0,0 +1,236 @@ +/* + * Copyright (C) 2022 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "opencl/test/unit_test/aub_tests/fixtures/multicontext_aub_fixture.h" + +#include "shared/source/command_stream/aub_command_stream_receiver.h" +#include "shared/source/helpers/api_specific_config.h" +#include "shared/source/helpers/hw_helper.h" +#include "shared/test/common/helpers/ult_hw_config.h" +#include "shared/test/common/helpers/variable_backup.h" +#include "shared/test/common/mocks/mock_device.h" +#include "shared/test/common/test_macros/test.h" +#include "shared/test/unit_test/tests_configuration.h" + +#include "opencl/source/cl_device/cl_device.h" +#include "opencl/source/platform/platform.h" +#include "opencl/test/unit_test/mocks/mock_context.h" +#include "opencl/test/unit_test/mocks/mock_platform.h" + +namespace NEO { + +void MulticontextAubFixture::SetUp(uint32_t numberOfTiles, EnabledCommandStreamers enabledCommandStreamers, bool enableCompression) { + this->numberOfEnabledTiles = numberOfTiles; + const ::testing::TestInfo *const testInfo = ::testing::UnitTest::GetInstance()->current_test_info(); + + cl_int retVal = CL_SUCCESS; + DebugManager.flags.CsrDispatchMode.set(static_cast(DispatchMode::BatchedDispatch)); + DebugManager.flags.CreateMultipleSubDevices.set(numberOfTiles); + if (testMode == TestMode::AubTestsWithTbx) { + DebugManager.flags.SetCommandStreamReceiver.set(static_cast(CommandStreamReceiverType::CSR_TBX_WITH_AUB)); + } else { + DebugManager.flags.SetCommandStreamReceiver.set(static_cast(CommandStreamReceiverType::CSR_AUB)); + } + + HardwareInfo localHwInfo = *defaultHwInfo; + if ((EnabledCommandStreamers::All == enabledCommandStreamers) && localHwInfo.gtSystemInfo.SliceCount < 8) { + overridePlatformConfigForAllEnginesSupport(localHwInfo); + } + + if (numberOfTiles > 1) { + localHwInfo.gtSystemInfo.MultiTileArchInfo.IsValid = (numberOfEnabledTiles > 1) ? 1 : 0; + localHwInfo.gtSystemInfo.MultiTileArchInfo.TileCount = numberOfEnabledTiles; + localHwInfo.gtSystemInfo.MultiTileArchInfo.TileMask = 0; + for (uint32_t i = 0; i < numberOfEnabledTiles; i++) { + localHwInfo.gtSystemInfo.MultiTileArchInfo.TileMask |= (1 << i); + } + } + + localHwInfo.capabilityTable.blitterOperationsSupported = true; + if (DebugManager.flags.EnableBlitterOperationsSupport.get() != -1) { + localHwInfo.capabilityTable.blitterOperationsSupported = !!DebugManager.flags.EnableBlitterOperationsSupport.get(); + } + + auto &hwHelper = HwHelper::get(localHwInfo.platform.eRenderCoreFamily); + auto engineType = getChosenEngineType(localHwInfo); + auto renderEngine = aub_stream::NUM_ENGINES; + for (auto &engine : hwHelper.getGpgpuEngineInstances(localHwInfo)) { + if (!EngineHelpers::isCcs(engine.first)) { + renderEngine = engine.first; + break; + } + } + ASSERT_NE(aub_stream::NUM_ENGINES, renderEngine); + + auto renderEngineName = hwHelper.getCsTraits(renderEngine).name; + + std::stringstream strfilename; + strfilename << ApiSpecificConfig::getAubPrefixForSpecificApi(); + strfilename << testInfo->test_case_name() << "_" << testInfo->name() << "_"; + if (EnabledCommandStreamers::Single == enabledCommandStreamers) { + strfilename << renderEngineName; + } else if (EnabledCommandStreamers::Dual == enabledCommandStreamers) { + strfilename << renderEngineName << "_CCS0"; + } else if (EnabledCommandStreamers::All == enabledCommandStreamers) { + strfilename << renderEngineName << "_CCS0_3"; // xehp_config_name_RCS_CCS0_3.aub + } + + auto filename = AUBCommandStreamReceiver::createFullFilePath(localHwInfo, strfilename.str(), rootDeviceIndex); + + DebugManager.flags.AUBDumpCaptureFileName.set(filename); + + auto createCommandQueueForEngine = [&](uint32_t tileNumber, size_t engineFamily, size_t engineIndex) { + cl_queue_properties properties[] = {CL_QUEUE_FAMILY_INTEL, engineFamily, CL_QUEUE_INDEX_INTEL, engineIndex, 0}; + auto clQueue = clCreateCommandQueueWithProperties(context.get(), tileDevices[tileNumber], properties, &retVal); + EXPECT_EQ(CL_SUCCESS, retVal); + return std::unique_ptr(castToObject(clQueue)); + }; + + DebugManager.flags.RenderCompressedBuffersEnabled.set(enableCompression); + DebugManager.flags.RenderCompressedImagesEnabled.set(enableCompression); + DebugManager.flags.EnableBlitterForEnqueueOperations.set(false); + + platformsImpl->clear(); + VariableBackup backup(&ultHwConfig); + + ultHwConfig.useHwCsr = true; + constructPlatform()->peekExecutionEnvironment()->prepareRootDeviceEnvironments(1u); + platform()->peekExecutionEnvironment()->rootDeviceEnvironments[rootDeviceIndex]->setHwInfo(&localHwInfo); + initPlatform(); + + rootDevice = platform()->getClDevice(0); + EXPECT_EQ(rootDeviceIndex, rootDevice->getRootDeviceIndex()); + { + cl_device_id deviceId = rootDevice; + ClDeviceVector clDeviceVector{&deviceId, 1}; + if (numberOfTiles > 1) { + for (uint32_t i = 0; i < numberOfTiles; i++) { + clDeviceVector.push_back(rootDevice->getNearestGenericSubDevice(i)); + } + } + context.reset(MockContext::create(nullptr, clDeviceVector, nullptr, nullptr, retVal)); + EXPECT_EQ(CL_SUCCESS, retVal); + } + + commandQueues.resize(numberOfTiles); + for (uint32_t tile = 0; tile < numberOfTiles; tile++) { + tileDevices.push_back(rootDevice->getNearestGenericSubDevice(tile)); + EXPECT_NE(nullptr, tileDevices[tile]); + if (EnabledCommandStreamers::Single == enabledCommandStreamers) { + if (EngineHelpers::isCcs(engineType)) { + auto familyQueue = tileDevices[tile]->getDevice().getEngineGroupIndexFromEngineGroupType(EngineGroupType::Compute); + commandQueues[tile].push_back(createCommandQueueForEngine(tile, familyQueue, 0)); + } else { + auto familyQueue = tileDevices[tile]->getDevice().getEngineGroupIndexFromEngineGroupType(EngineGroupType::RenderCompute); + commandQueues[tile].push_back(createCommandQueueForEngine(tile, familyQueue, 0)); + } + } else if (EnabledCommandStreamers::Dual == enabledCommandStreamers) { + auto rcsQueue = tileDevices[tile]->getDevice().getEngineGroupIndexFromEngineGroupType(EngineGroupType::RenderCompute); + auto ccsQueue = tileDevices[tile]->getDevice().getEngineGroupIndexFromEngineGroupType(EngineGroupType::Compute); + commandQueues[tile].push_back(createCommandQueueForEngine(tile, rcsQueue, 0)); + commandQueues[tile].push_back(createCommandQueueForEngine(tile, ccsQueue, 0)); + } else if (EnabledCommandStreamers::All == enabledCommandStreamers) { + auto rcsQueue = tileDevices[tile]->getDevice().getEngineGroupIndexFromEngineGroupType(EngineGroupType::RenderCompute); + auto ccsQueue = tileDevices[tile]->getDevice().getEngineGroupIndexFromEngineGroupType(EngineGroupType::Compute); + commandQueues[tile].push_back(createCommandQueueForEngine(tile, rcsQueue, 0)); + commandQueues[tile].push_back(createCommandQueueForEngine(tile, ccsQueue, 0)); + commandQueues[tile].push_back(createCommandQueueForEngine(tile, ccsQueue, 1)); + commandQueues[tile].push_back(createCommandQueueForEngine(tile, ccsQueue, 2)); + commandQueues[tile].push_back(createCommandQueueForEngine(tile, ccsQueue, 3)); + } + } + + { + cl_int retVal = CL_SUCCESS; + cl_device_id deviceId = rootDevice; + multiTileDefaultContext.reset(MockContext::create(nullptr, ClDeviceVector(&deviceId, 1), nullptr, nullptr, retVal)); + EXPECT_EQ(CL_SUCCESS, retVal); + } +} + +void MulticontextAubFixture::TearDown() { + auto filename = DebugManager.flags.AUBDumpCaptureFileName.get(); + + std::string tileString = std::to_string(numberOfEnabledTiles) + "tx"; + + if (numberOfEnabledTiles > 1) { + EXPECT_NE(std::string::npos, filename.find(tileString)); + } else { + EXPECT_EQ(std::string::npos, filename.find(tileString)); + } +} + +void MulticontextAubFixture::overridePlatformConfigForAllEnginesSupport(HardwareInfo &localHwInfo) { + const ::testing::TestInfo *const testInfo = ::testing::UnitTest::GetInstance()->current_test_info(); + printf("\nWARNING: Platform configuration for %s_%s test forced to %dtx8x4x16\n", + testInfo->test_case_name(), testInfo->name(), numberOfEnabledTiles); + + bool setupCalled = false; + + if (localHwInfo.platform.eRenderCoreFamily == IGFX_XE_HP_CORE) { +#ifdef SUPPORT_XE_HP_SDV + if (localHwInfo.platform.eProductFamily == IGFX_XE_HP_SDV) { + setupCalled = true; + XE_HP_SDV_CONFIG::setupHardwareInfoMultiTile(&localHwInfo, true, true); + + // Mock values + localHwInfo.gtSystemInfo.SliceCount = 8; + localHwInfo.gtSystemInfo.SubSliceCount = 32; + localHwInfo.gtSystemInfo.EUCount = 512; + + localHwInfo.gtSystemInfo.CCSInfo.IsValid = true; + localHwInfo.gtSystemInfo.CCSInfo.NumberOfCCSEnabled = 4; + localHwInfo.gtSystemInfo.CCSInfo.Instances.CCSEnableMask = 0b1111; + } +#endif + } + + if (localHwInfo.platform.eRenderCoreFamily == IGFX_XE_HPG_CORE) { +#ifdef SUPPORT_DG2 + if (localHwInfo.platform.eProductFamily == IGFX_DG2) { + ASSERT_TRUE(numberOfEnabledTiles == 1); + setupCalled = true; + + DG2_CONFIG::setupHardwareInfoMultiTile(&localHwInfo, true, false); + + // Mock values + localHwInfo.gtSystemInfo.SliceCount = 8; + localHwInfo.gtSystemInfo.SubSliceCount = 32; + localHwInfo.gtSystemInfo.EUCount = 512; + + localHwInfo.gtSystemInfo.CCSInfo.IsValid = true; + localHwInfo.gtSystemInfo.CCSInfo.NumberOfCCSEnabled = 4; + localHwInfo.gtSystemInfo.CCSInfo.Instances.CCSEnableMask = 0b1111; + } +#endif + } + + if (localHwInfo.platform.eRenderCoreFamily == IGFX_XE_HPC_CORE) { +#ifdef SUPPORT_PVC + if (localHwInfo.platform.eProductFamily == IGFX_PVC) { + setupCalled = true; + + PVC_CONFIG::setupHardwareInfoMultiTile(&localHwInfo, true, true); + + // Mock values + localHwInfo.gtSystemInfo.SliceCount = 8; + localHwInfo.gtSystemInfo.SubSliceCount = 64; + localHwInfo.gtSystemInfo.EUCount = 512; + + localHwInfo.gtSystemInfo.CCSInfo.IsValid = true; + localHwInfo.gtSystemInfo.CCSInfo.NumberOfCCSEnabled = 4; + localHwInfo.gtSystemInfo.CCSInfo.Instances.CCSEnableMask = 0b1111; + } +#endif + } + + adjustPlatformOverride(localHwInfo, setupCalled); + + ASSERT_TRUE(setupCalled); +} + +} // namespace NEO diff --git a/opencl/test/unit_test/aub_tests/fixtures/multicontext_aub_fixture.h b/opencl/test/unit_test/aub_tests/fixtures/multicontext_aub_fixture.h new file mode 100644 index 0000000000..e88aef4bf0 --- /dev/null +++ b/opencl/test/unit_test/aub_tests/fixtures/multicontext_aub_fixture.h @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2022 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once +#include "shared/source/command_stream/command_stream_receiver_with_aub_dump.h" +#include "shared/source/command_stream/tbx_command_stream_receiver_hw.h" +#include "shared/source/helpers/hw_info.h" +#include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/unit_test/tests_configuration.h" + +#include "opencl/source/command_queue/command_queue.h" +#include "opencl/test/unit_test/mocks/mock_context.h" + +#include "gtest/gtest.h" + +#include +#include + +namespace NEO { +class MockDevice; + +struct MulticontextAubFixture { + enum class EnabledCommandStreamers { + Single, // default only + Dual, // RCS + CCS0 + All, // RCS + CCS0-3 + }; + + void SetUp(uint32_t numberOfTiles, EnabledCommandStreamers enabledCommandStreamers, bool enableCompression); + void TearDown(); + + template + CommandStreamReceiverSimulatedCommonHw *getSimulatedCsr(uint32_t tile, uint32_t engine) { + using CsrWithAubDump = CommandStreamReceiverWithAUBDump>; + using SimulatedCsr = CommandStreamReceiverSimulatedCommonHw; + SimulatedCsr *simulatedCsr = nullptr; + + if (testMode == TestMode::AubTestsWithTbx) { + auto csrWithAubDump = static_cast(&commandQueues[tile][engine]->getGpgpuCommandStreamReceiver()); + simulatedCsr = static_cast(csrWithAubDump); + } else { + simulatedCsr = static_cast(&commandQueues[tile][engine]->getGpgpuCommandStreamReceiver()); + } + + return simulatedCsr; + } + + template + void expectMemory(void *gfxAddress, const void *srcAddress, size_t length, uint32_t tile, uint32_t engine) { + CommandStreamReceiverSimulatedCommonHw *csrSimulated = getSimulatedCsr(tile, engine); + + if (testMode == TestMode::AubTestsWithTbx) { + auto tbxCsr = csrSimulated; + EXPECT_TRUE(tbxCsr->expectMemoryEqual(gfxAddress, srcAddress, length)); + csrSimulated = static_cast *>( + static_cast> *>(csrSimulated)->aubCSR.get()); + } + + if (csrSimulated) { + csrSimulated->expectMemoryEqual(gfxAddress, srcAddress, length); + } + } + + template + void expectMemoryNotEqual(void *gfxAddress, const void *srcAddress, size_t length, uint32_t tile, uint32_t engine) { + CommandStreamReceiverSimulatedCommonHw *csrSimulated = getSimulatedCsr(tile, engine); + + if (testMode == TestMode::AubTestsWithTbx) { + auto tbxCsr = csrSimulated; + EXPECT_TRUE(tbxCsr->expectMemoryNotEqual(gfxAddress, srcAddress, length)); + csrSimulated = static_cast *>( + static_cast> *>(csrSimulated)->aubCSR.get()); + } + + if (csrSimulated) { + csrSimulated->expectMemoryNotEqual(gfxAddress, srcAddress, length); + } + } + + template + void expectMemoryCompressed(void *gfxAddress, const void *srcAddress, size_t length, uint32_t tile, uint32_t engine) { + CommandStreamReceiverSimulatedCommonHw *csrSimulated = getSimulatedCsr(tile, engine); + + if (testMode == TestMode::AubTestsWithTbx) { + auto tbxCsr = csrSimulated; + EXPECT_TRUE(tbxCsr->expectMemoryCompressed(gfxAddress, srcAddress, length)); + csrSimulated = static_cast *>( + static_cast> *>(csrSimulated)->aubCSR.get()); + } + + if (csrSimulated) { + csrSimulated->expectMemoryCompressed(gfxAddress, srcAddress, length); + } + } + + void overridePlatformConfigForAllEnginesSupport(HardwareInfo &localHwInfo); + void adjustPlatformOverride(HardwareInfo &localHwInfo, bool &setupCalled); + DebugManagerStateRestore restore; + + const uint32_t rootDeviceIndex = 0u; + uint32_t numberOfEnabledTiles = 0; + std::vector tileDevices; + ClDevice *rootDevice = nullptr; + std::unique_ptr context; + std::unique_ptr multiTileDefaultContext; + std::vector>> commandQueues; +}; +} // namespace NEO diff --git a/opencl/test/unit_test/aub_tests/fixtures/multicontext_aub_fixture_extended.cpp b/opencl/test/unit_test/aub_tests/fixtures/multicontext_aub_fixture_extended.cpp new file mode 100644 index 0000000000..05a7e52a91 --- /dev/null +++ b/opencl/test/unit_test/aub_tests/fixtures/multicontext_aub_fixture_extended.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2022 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "opencl/test/unit_test/aub_tests/fixtures/multicontext_aub_fixture.h" + +namespace NEO { + +void MulticontextAubFixture::adjustPlatformOverride(HardwareInfo &localHwInfo, bool &setupCalled) { +} + +} // namespace NEO