diff --git a/level_zero/CMakeLists.txt b/level_zero/CMakeLists.txt index 150dbf76cf..13dda09833 100644 --- a/level_zero/CMakeLists.txt +++ b/level_zero/CMakeLists.txt @@ -234,7 +234,7 @@ if(BUILD_WITH_L0) ${COMPUTE_RUNTIME_DIR}/opencl/source/dll/create_tbx_sockets.cpp ${COMPUTE_RUNTIME_DIR}/opencl/source/dll/get_devices.cpp ${COMPUTE_RUNTIME_DIR}/opencl/source/dll/source_level_debugger_dll.cpp - ${COMPUTE_RUNTIME_DIR}/shared/source/helpers/built_ins_helper.cpp + ${COMPUTE_RUNTIME_DIR}/shared/source/built_ins/sip_init.cpp ${COMPUTE_RUNTIME_DIR}/shared/source/aub/aub_stream_interface.cpp ) diff --git a/level_zero/cmake/l0_tests.cmake b/level_zero/cmake/l0_tests.cmake index 4770b698af..0f8d171d17 100644 --- a/level_zero/cmake/l0_tests.cmake +++ b/level_zero/cmake/l0_tests.cmake @@ -66,7 +66,7 @@ add_library(compute_runtime_mockable_extra EXCLUDE_FROM_ALL ${CMAKE_CURRENT_LIST_DIR}/l0_tests.cmake ${NEO_SHARED_TEST_DIRECTORY}/unit_test/utilities/cpuintrinsics.cpp - ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/built_ins_helper.cpp + ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/sip_init.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/test_files.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/mocks/mock_compiler_interface_spirv.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/mocks/mock_compiler_interface_spirv.h diff --git a/level_zero/core/source/cmdqueue/cmdqueue_hw.inl b/level_zero/core/source/cmdqueue/cmdqueue_hw.inl index ebd9205cbf..7fcbf90ea4 100644 --- a/level_zero/core/source/cmdqueue/cmdqueue_hw.inl +++ b/level_zero/core/source/cmdqueue/cmdqueue_hw.inl @@ -286,7 +286,7 @@ ze_result_t CommandQueueHw::executeCommandLists( } if (sipKernelUsed) { - auto sipIsa = NEO::SipKernel::getSipKernelAllocation(*neoDevice); + auto sipIsa = NEO::SipKernel::getSipKernel(*neoDevice).getSipAllocation(); residencyContainer.push_back(sipIsa); } diff --git a/level_zero/core/source/device/device_imp.cpp b/level_zero/core/source/device/device_imp.cpp index e583ba808e..cf46253e1f 100644 --- a/level_zero/core/source/device/device_imp.cpp +++ b/level_zero/core/source/device/device_imp.cpp @@ -14,7 +14,6 @@ #include "shared/source/execution_environment/execution_environment.h" #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/gmm_helper/gmm_helper.h" -#include "shared/source/helpers/built_ins_helper.h" #include "shared/source/helpers/constants.h" #include "shared/source/helpers/engine_node_helper.h" #include "shared/source/helpers/hw_helper.h" @@ -646,10 +645,10 @@ Device *Device::create(DriverHandle *driverHandle, NEO::Device *neoDevice, uint3 if (neoDevice->getCompilerInterface()) { auto hwInfo = neoDevice->getHardwareInfo(); if (neoDevice->getPreemptionMode() == NEO::PreemptionMode::MidThread || neoDevice->getDebugger()) { - auto sipType = NEO::SipKernel::getSipKernelType(hwInfo.platform.eRenderCoreFamily, neoDevice->getDebugger()); - NEO::initSipKernel(sipType, *neoDevice); + bool ret = NEO::SipKernel::initSipKernel(NEO::SipKernel::getSipKernelType(*neoDevice), *neoDevice); + UNRECOVERABLE_IF(!ret); - auto stateSaveAreaHeader = NEO::SipKernel::getSipStateSaveAreaHeader(*neoDevice); + auto &stateSaveAreaHeader = NEO::SipKernel::getSipKernel(*neoDevice).getStateSaveAreaHeader(); if (debugSurface && stateSaveAreaHeader.size() > 0) { auto &hwHelper = NEO::HwHelper::get(hwInfo.platform.eRenderCoreFamily); NEO::MemoryTransferHelper::transferMemoryToAllocation(hwHelper.isBlitCopyRequiredForLocalMemory(hwInfo, *debugSurface), diff --git a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_enqueuecommandlist.cpp b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_enqueuecommandlist.cpp index 118c806bd5..66a6282016 100644 --- a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_enqueuecommandlist.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_enqueuecommandlist.cpp @@ -306,7 +306,7 @@ HWTEST_F(CommandQueueExecuteCommandLists, givenMidThreadPreemptionWhenCommandsAr if (preemptionMode == NEO::PreemptionMode::MidThread) { EXPECT_NE(cmdList.end(), itorSip); - auto sipAllocation = SipKernel::getSipKernelAllocation(*neoDevice); + auto sipAllocation = SipKernel::getSipKernel(*neoDevice).getSipAllocation(); STATE_SIP *stateSipCmd = reinterpret_cast(*itorSip); EXPECT_EQ(sipAllocation->getGpuAddressToPatch(), stateSipCmd->getSystemInstructionPointer()); } else { @@ -361,7 +361,7 @@ HWTEST2_F(CommandQueueExecuteCommandLists, givenMidThreadPreemptionWhenCommandsA if (preemptionMode == NEO::PreemptionMode::MidThread) { EXPECT_NE(cmdList.end(), itorSip); - auto sipAllocation = SipKernel::getSipKernelAllocation(*neoDevice); + auto sipAllocation = SipKernel::getSipKernel(*neoDevice).getSipAllocation(); STATE_SIP *stateSipCmd = reinterpret_cast(*itorSip); EXPECT_EQ(sipAllocation->getGpuAddressToPatch(), stateSipCmd->getSystemInstructionPointer()); } else { diff --git a/level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger.cpp b/level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger.cpp index 1e401557d0..34365cae44 100644 --- a/level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger.cpp +++ b/level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger.cpp @@ -39,20 +39,21 @@ TEST_F(L0DebuggerTest, givenL0DebuggerWhenGettingL0DebuggerThenValidDebuggerInst } TEST_F(L0DebuggerTest, givenL0DebuggerWhenGettingSipAllocationThenValidSipTypeIsReturned) { - auto systemRoutine = SipKernel::getSipKernelAllocation(*neoDevice); + neoDevice->setDebuggerActive(true); + auto systemRoutine = SipKernel::getSipKernel(*neoDevice).getSipAllocation(); ASSERT_NE(nullptr, systemRoutine); - auto sipType = SipKernel::getSipKernelType(neoDevice->getHardwareInfo().platform.eRenderCoreFamily, true); + auto sipType = SipKernel::getSipKernelType(*neoDevice); auto expectedSipAllocation = neoDevice->getBuiltIns()->getSipKernel(sipType, *neoDevice).getSipAllocation(); EXPECT_EQ(expectedSipAllocation, systemRoutine); } TEST_F(L0DebuggerTest, givenL0DebuggerWhenGettingStateSaveAreaHeaderThenValidSipTypeIsReturned) { - auto stateSaveAreaHeader = SipKernel::getSipStateSaveAreaHeader(*neoDevice); + auto &stateSaveAreaHeader = SipKernel::getSipKernel(*neoDevice).getStateSaveAreaHeader(); - auto sipType = SipKernel::getSipKernelType(neoDevice->getHardwareInfo().platform.eRenderCoreFamily, true); - auto expectedStateSaveAreaHeader = neoDevice->getBuiltIns()->getSipKernel(sipType, *neoDevice).getStateSaveAreaHeader(); + auto sipType = SipKernel::getSipKernelType(*neoDevice); + auto &expectedStateSaveAreaHeader = neoDevice->getBuiltIns()->getSipKernel(sipType, *neoDevice).getStateSaveAreaHeader(); EXPECT_EQ(expectedStateSaveAreaHeader, stateSaveAreaHeader); } @@ -75,10 +76,10 @@ TEST(Debugger, givenL0DebuggerOFFWhenGettingStateSaveAreaHeaderThenValidSipTypeI driverHandle->initialize(std::move(devices)); - auto stateSaveAreaHeader = SipKernel::getSipStateSaveAreaHeader(*neoDevice); + auto &stateSaveAreaHeader = SipKernel::getSipKernel(*neoDevice).getStateSaveAreaHeader(); - auto sipType = SipKernel::getSipKernelType(neoDevice->getHardwareInfo().platform.eRenderCoreFamily, false); - auto expectedStateSaveAreaHeader = neoDevice->getBuiltIns()->getSipKernel(sipType, *neoDevice).getStateSaveAreaHeader(); + auto sipType = SipKernel::getSipKernelType(*neoDevice); + auto &expectedStateSaveAreaHeader = neoDevice->getBuiltIns()->getSipKernel(sipType, *neoDevice).getStateSaveAreaHeader(); EXPECT_EQ(expectedStateSaveAreaHeader, stateSaveAreaHeader); } @@ -181,7 +182,7 @@ HWTEST_F(L0DebuggerTest, givenDebuggingEnabledWhenCommandListIsExecutedThenValid STATE_SIP *stateSip = genCmdCast(*stateSipCmds[0]); - auto systemRoutine = SipKernel::getSipKernelAllocation(*neoDevice); + auto systemRoutine = SipKernel::getSipKernel(*neoDevice).getSipAllocation(); ASSERT_NE(nullptr, systemRoutine); EXPECT_EQ(systemRoutine->getGpuAddress(), stateSip->getSystemInstructionPointer()); } @@ -512,7 +513,7 @@ HWTEST2_F(L0DebuggerInternalUsageTest, givenDebuggingEnabledWhenInternalCmdQIsUs EXPECT_EQ(ZE_RESULT_SUCCESS, result); auto sbaBuffer = device->getL0Debugger()->getSbaTrackingBuffer(neoDevice->getDefaultEngine().commandStreamReceiver->getOsContext().getContextId()); - auto sipIsa = NEO::SipKernel::getSipKernelAllocation(*neoDevice); + auto sipIsa = NEO::SipKernel::getSipKernel(*neoDevice).getSipAllocation(); auto debugSurface = device->getDebugSurface(); bool sbaFound = false; bool sipFound = false; diff --git a/level_zero/core/test/unit_tests/sources/debugger/test_source_level_debugger.cpp b/level_zero/core/test/unit_tests/sources/debugger/test_source_level_debugger.cpp index 12fdf4a3ee..c89a420b1d 100644 --- a/level_zero/core/test/unit_tests/sources/debugger/test_source_level_debugger.cpp +++ b/level_zero/core/test/unit_tests/sources/debugger/test_source_level_debugger.cpp @@ -219,7 +219,7 @@ HWTEST2_F(SLDebuggerInternalUsageTest, givenDebuggingEnabledWhenInternalCmdQIsUs EXPECT_EQ(0u, stateSip.size()); } - auto sipIsa = NEO::SipKernel::getSipKernelAllocation(*device); + auto sipIsa = NEO::SipKernel::getSipKernel(*device).getSipAllocation(); auto debugSurface = deviceL0->getDebugSurface(); bool sipFound = false; bool debugSurfaceFound = false; diff --git a/level_zero/core/test/unit_tests/sources/device/test_device.cpp b/level_zero/core/test/unit_tests/sources/device/test_device.cpp index ec70009d76..6cabda45eb 100644 --- a/level_zero/core/test/unit_tests/sources/device/test_device.cpp +++ b/level_zero/core/test/unit_tests/sources/device/test_device.cpp @@ -11,6 +11,7 @@ #include "shared/source/os_interface/os_time.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/mocks/mock_device.h" +#include "shared/test/common/mocks/mock_sip.h" #include "shared/test/common/mocks/ult_device_factory.h" #include "opencl/source/os_interface/os_inc_base.h" @@ -31,13 +32,6 @@ using ::testing::Return; -namespace NEO { -namespace MockSipData { -extern SipKernelType calledType; -extern bool called; -} // namespace MockSipData -} // namespace NEO - namespace L0 { namespace ult { @@ -66,6 +60,7 @@ TEST(L0DeviceTest, givenMidThreadPreemptionWhenCreatingDeviceThenSipKernelIsInit ze_result_t returnValue = ZE_RESULT_SUCCESS; VariableBackup mockSipCalled(&NEO::MockSipData::called, false); VariableBackup mockSipCalledType(&NEO::MockSipData::calledType, NEO::SipKernelType::COUNT); + VariableBackup backupSipInitType(&MockSipData::useMockSip, true); std::unique_ptr driverHandle(new DriverHandleImp); auto hwInfo = *NEO::defaultHwInfo; @@ -103,7 +98,8 @@ TEST(L0DeviceTest, givenDebuggerEnabledButIGCNotReturnsSSAHThenSSAHIsNotCopied) driverHandle->enableProgramDebugging = true; driverHandle->initialize(std::move(devices)); - auto stateSaveAreaHeader = NEO::SipKernel::getSipStateSaveAreaHeader(*neoDevice); + auto sipType = SipKernel::getSipKernelType(*neoDevice); + auto &stateSaveAreaHeader = neoDevice->getBuiltIns()->getSipKernel(sipType, *neoDevice).getStateSaveAreaHeader(); EXPECT_EQ(static_cast(0), stateSaveAreaHeader.size()); } @@ -111,6 +107,7 @@ TEST(L0DeviceTest, givenDisabledPreemptionWhenCreatingDeviceThenSipKernelIsNotIn ze_result_t returnValue = ZE_RESULT_SUCCESS; VariableBackup mockSipCalled(&NEO::MockSipData::called, false); VariableBackup mockSipCalledType(&NEO::MockSipData::calledType, NEO::SipKernelType::COUNT); + VariableBackup backupSipInitType(&MockSipData::useMockSip, true); std::unique_ptr driverHandle(new DriverHandleImp); auto hwInfo = *NEO::defaultHwInfo; diff --git a/opencl/source/built_ins/builtins_dispatch_builder.cpp b/opencl/source/built_ins/builtins_dispatch_builder.cpp index 03c69fd474..6adf64a7e8 100644 --- a/opencl/source/built_ins/builtins_dispatch_builder.cpp +++ b/opencl/source/built_ins/builtins_dispatch_builder.cpp @@ -11,7 +11,6 @@ #include "shared/source/built_ins/sip.h" #include "shared/source/compiler_interface/compiler_interface.h" #include "shared/source/helpers/basic_math.h" -#include "shared/source/helpers/built_ins_helper.h" #include "shared/source/helpers/debug_helpers.h" #include "opencl/source/built_ins/aux_translation_builtin.h" diff --git a/opencl/source/dll/CMakeLists.txt b/opencl/source/dll/CMakeLists.txt index a7a79667a0..22293baf2e 100644 --- a/opencl/source/dll/CMakeLists.txt +++ b/opencl/source/dll/CMakeLists.txt @@ -18,12 +18,12 @@ set(RUNTIME_SRCS_DLL_BASE ${CMAKE_CURRENT_SOURCE_DIR}/debug_manager.cpp ${CMAKE_CURRENT_SOURCE_DIR}/source_level_debugger_dll.cpp ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/get_devices.cpp + ${NEO_SHARED_DIRECTORY}/built_ins/sip_init.cpp ${NEO_SHARED_DIRECTORY}/dll/options_dll.cpp ${NEO_SHARED_DIRECTORY}/gmm_helper/resource_info.cpp ${NEO_SHARED_DIRECTORY}/gmm_helper/page_table_mngr.cpp ${NEO_SHARED_DIRECTORY}/helpers/abort.cpp ${NEO_SHARED_DIRECTORY}/helpers/allow_deferred_deleter.cpp - ${NEO_SHARED_DIRECTORY}/helpers/built_ins_helper.cpp ${NEO_SHARED_DIRECTORY}/helpers/debug_helpers.cpp ${NEO_SHARED_DIRECTORY}/utilities/cpuintrinsics.cpp ${NEO_SHARED_DIRECTORY}/utilities/debug_settings_reader_creator.cpp diff --git a/opencl/source/platform/platform.cpp b/opencl/source/platform/platform.cpp index f2252d5e25..2be498df15 100644 --- a/opencl/source/platform/platform.cpp +++ b/opencl/source/platform/platform.cpp @@ -7,6 +7,7 @@ #include "platform.h" +#include "shared/source/built_ins/sip.h" #include "shared/source/command_stream/command_stream_receiver.h" #include "shared/source/compiler_interface/compiler_interface.h" #include "shared/source/debug_settings/debug_settings_manager.h" @@ -14,7 +15,6 @@ #include "shared/source/execution_environment/execution_environment.h" #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/gmm_helper/gmm_helper.h" -#include "shared/source/helpers/built_ins_helper.h" #include "shared/source/helpers/debug_helpers.h" #include "shared/source/helpers/get_info.h" #include "shared/source/helpers/hw_helper.h" @@ -139,10 +139,9 @@ bool Platform::initialize(std::vector> devices) { pClDevice = new ClDevice{*pDevice, this}; this->clDevices.push_back(pClDevice); - auto hwInfo = pClDevice->getHardwareInfo(); if (pClDevice->getPreemptionMode() == PreemptionMode::MidThread || pClDevice->isDebuggerActive()) { - auto sipType = SipKernel::getSipKernelType(hwInfo.platform.eRenderCoreFamily, pClDevice->isDebuggerActive()); - initSipKernel(sipType, *pDevice); + bool ret = SipKernel::initSipKernel(SipKernel::getSipKernelType(*pDevice), *pDevice); + UNRECOVERABLE_IF(!ret); } } diff --git a/opencl/test/unit_test/built_ins/built_in_tests.cpp b/opencl/test/unit_test/built_ins/built_in_tests.cpp index 65401b63d0..fe7c72a4b7 100644 --- a/opencl/test/unit_test/built_ins/built_in_tests.cpp +++ b/opencl/test/unit_test/built_ins/built_in_tests.cpp @@ -2141,15 +2141,6 @@ TEST_F(BuiltInTests, givenSipKernelWhenAllocationFailsThenItHasNullptrGraphicsAl EXPECT_EQ(nullptr, sipAllocation); } -TEST_F(BuiltInTests, givenSameDeviceIsUsedWhenUsingStaticGetterThenExpectRetrieveSameAllocation) { - const SipKernel &sipKern = pDevice->getBuiltIns()->getSipKernel(SipKernelType::Csr, pContext->getDevice(0)->getDevice()); - auto sipAllocation = sipKern.getSipAllocation(); - EXPECT_NE(nullptr, sipAllocation); - auto staticSipAllocation = SipKernel::getSipKernelAllocation(*pDevice); - EXPECT_NE(nullptr, staticSipAllocation); - EXPECT_EQ(sipAllocation, staticSipAllocation); -} - TEST_F(BuiltInTests, givenDebugFlagForceUseSourceWhenArgIsBinaryThenReturnBuiltinCodeBinary) { DebugManager.flags.RebuildPrecompiledKernels.set(true); auto builtinsLib = std::unique_ptr(new BuiltinsLib()); diff --git a/opencl/test/unit_test/built_ins/sip_tests.cpp b/opencl/test/unit_test/built_ins/sip_tests.cpp index 258f289076..30bd40602c 100644 --- a/opencl/test/unit_test/built_ins/sip_tests.cpp +++ b/opencl/test/unit_test/built_ins/sip_tests.cpp @@ -40,12 +40,19 @@ TEST(Sip, givenSipKernelClassWhenAskedForMaxDebugSurfaceSizeThenCorrectValueIsRe } TEST(Sip, givenDebuggingInactiveWhenSipTypeIsQueriedThenCsrSipTypeIsReturned) { - auto sipType = SipKernel::getSipKernelType(renderCoreFamily, false); + auto mockDevice = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); + EXPECT_NE(nullptr, mockDevice); + + auto sipType = SipKernel::getSipKernelType(*mockDevice); EXPECT_EQ(SipKernelType::Csr, sipType); } TEST(DebugSip, givenDebuggingActiveWhenSipTypeIsQueriedThenDbgCsrSipTypeIsReturned) { - auto sipType = SipKernel::getSipKernelType(renderCoreFamily, true); + auto mockDevice = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); + EXPECT_NE(nullptr, mockDevice); + mockDevice->setDebuggerActive(true); + + auto sipType = SipKernel::getSipKernelType(*mockDevice); EXPECT_LE(SipKernelType::DbgCsr, sipType); } diff --git a/opencl/test/unit_test/command_stream/command_stream_receiver_flush_task_1_tests.cpp b/opencl/test/unit_test/command_stream/command_stream_receiver_flush_task_1_tests.cpp index 50a0839902..d9e513f5fe 100644 --- a/opencl/test/unit_test/command_stream/command_stream_receiver_flush_task_1_tests.cpp +++ b/opencl/test/unit_test/command_stream/command_stream_receiver_flush_task_1_tests.cpp @@ -199,7 +199,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndMidThread *pDevice); auto cmdBuffer = mockedSubmissionsAggregator->peekCommandBuffers().peekHead(); - auto sipAllocation = pDevice->getBuiltIns()->getSipKernel(SipKernelType::Csr, *pDevice).getSipAllocation(); + auto sipAllocation = SipKernel::getSipKernel(*pDevice).getSipAllocation(); bool found = false; for (auto allocation : cmdBuffer->surfaces) { if (allocation == sipAllocation) { @@ -229,7 +229,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInDefaultModeAndMidThreadP dispatchFlags, *pDevice); - auto sipAllocation = pDevice->getBuiltIns()->getSipKernel(SipKernelType::Csr, *pDevice).getSipAllocation(); + auto sipAllocation = SipKernel::getSipKernel(*pDevice).getSipAllocation(); bool found = false; for (auto allocation : mockCsr->copyOfAllocations) { if (allocation == sipAllocation) { diff --git a/opencl/test/unit_test/device/device_caps_tests.cpp b/opencl/test/unit_test/device/device_caps_tests.cpp index 05af89d1a0..1cd33576b3 100644 --- a/opencl/test/unit_test/device/device_caps_tests.cpp +++ b/opencl/test/unit_test/device/device_caps_tests.cpp @@ -13,6 +13,7 @@ #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/helpers/variable_backup.h" #include "shared/test/common/mocks/mock_device.h" +#include "shared/test/common/mocks/mock_sip.h" #include "opencl/source/platform/extensions.h" #include "opencl/test/unit_test/fixtures/device_info_fixture.h" @@ -30,22 +31,17 @@ namespace NEO { extern const char *familyName[]; -namespace MockSipData { -extern SipKernelType calledType; -extern bool called; -} // namespace MockSipData } // namespace NEO using namespace NEO; struct DeviceGetCapsTest : public ::testing::Test { void SetUp() override { - MockSipData::calledType = SipKernelType::COUNT; - MockSipData::called = false; + MockSipData::clearUseFlags(); + backupSipInitType = std::make_unique>(&MockSipData::useMockSip, true); } void TearDown() override { - MockSipData::calledType = SipKernelType::COUNT; - MockSipData::called = false; + MockSipData::clearUseFlags(); } void verifyOpenclCAllVersions(MockClDevice &clDevice) { @@ -110,6 +106,8 @@ struct DeviceGetCapsTest : public ::testing::Test { EXPECT_EQ(clDevice.getDeviceInfo().openclCFeatures.end(), ++openclCFeatureIterator); } + + std::unique_ptr> backupSipInitType; }; TEST_F(DeviceGetCapsTest, WhenCreatingDeviceThenCapsArePopulatedCorrectly) { diff --git a/opencl/test/unit_test/fixtures/cl_device_fixture.cpp b/opencl/test/unit_test/fixtures/cl_device_fixture.cpp index 7e947e58a7..4b5b81de6a 100644 --- a/opencl/test/unit_test/fixtures/cl_device_fixture.cpp +++ b/opencl/test/unit_test/fixtures/cl_device_fixture.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,6 +7,8 @@ #include "opencl/test/unit_test/fixtures/cl_device_fixture.h" +#include "shared/source/built_ins/sip.h" + #include "gtest/gtest.h" namespace NEO { diff --git a/opencl/test/unit_test/gen9/sip_tests_gen9.cpp b/opencl/test/unit_test/gen9/sip_tests_gen9.cpp index 9eec8234c5..dc0767581d 100644 --- a/opencl/test/unit_test/gen9/sip_tests_gen9.cpp +++ b/opencl/test/unit_test/gen9/sip_tests_gen9.cpp @@ -32,7 +32,12 @@ GEN9TEST_F(gen9SipTests, givenDebugCsrSipKernelWithLocalMemoryWhenAskedForDebugS } GEN9TEST_F(gen9SipTests, givenDebuggingActiveWhenSipTypeIsQueriedThenDbgCsrLocalIsReturned) { - auto sipType = SipKernel::getSipKernelType(renderCoreFamily, true); + auto mockDevice = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); + EXPECT_NE(nullptr, mockDevice); + mockDevice->isDebuggerActiveParentCall = false; + mockDevice->isDebuggerActiveReturn = true; + + auto sipType = SipKernel::getSipKernelType(*mockDevice); EXPECT_EQ(SipKernelType::DbgCsrLocal, sipType); } } // namespace SipKernelTests diff --git a/opencl/test/unit_test/libult/CMakeLists.txt b/opencl/test/unit_test/libult/CMakeLists.txt index c2b67a943c..dbcb8fa1ba 100644 --- a/opencl/test/unit_test/libult/CMakeLists.txt +++ b/opencl/test/unit_test/libult/CMakeLists.txt @@ -66,11 +66,11 @@ set(IGDRCL_SRCS_LIB_ULT ${NEO_SOURCE_DIR}/opencl/test/unit_test/utilities/debug_settings_reader_creator.cpp ${NEO_SHARED_TEST_DIRECTORY}/unit_test/base_ult_config_listener.cpp ${NEO_SHARED_TEST_DIRECTORY}/unit_test/base_ult_config_listener.cpp - ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/built_ins_helper.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/memory_leak_listener.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/memory_leak_listener.h ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/memory_management.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/memory_management.h + ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/sip_init.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/test_files.cpp ${NEO_SHARED_TEST_DIRECTORY}/common/helpers/test_files.h ) diff --git a/opencl/test/unit_test/libult/io_functions.cpp b/opencl/test/unit_test/libult/io_functions.cpp index dfece60416..dd2947d794 100644 --- a/opencl/test/unit_test/libult/io_functions.cpp +++ b/opencl/test/unit_test/libult/io_functions.cpp @@ -19,6 +19,7 @@ rewindFuncPtr rewindPtr = &mockRewind; freadFuncPtr freadPtr = &mockFread; uint32_t mockFopenCalled = 0; +FILE *mockFopenReturned = reinterpret_cast(0x40); uint32_t mockVfptrinfCalled = 0; uint32_t mockFcloseCalled = 0; uint32_t mockGetenvCalled = 0; diff --git a/opencl/test/unit_test/main.cpp b/opencl/test/unit_test/main.cpp index a9f2ac299d..ae5fef7a14 100644 --- a/opencl/test/unit_test/main.cpp +++ b/opencl/test/unit_test/main.cpp @@ -54,10 +54,6 @@ extern const char *executionDirectorySuffix; std::thread::id tempThreadID; -namespace MockSipData { -extern std::unique_ptr mockSipKernel; -} - namespace PagaFaultManagerTestConfig { bool disabled = false; } @@ -160,8 +156,11 @@ void handle_SIGABRT(int sig_no) { } #endif -void initializeTestHelpers() { +void initializeTestHelpers(TestMode currentTestmode) { MockSipData::mockSipKernel.reset(new MockSipKernel()); + if (currentTestmode == TestMode::AubTests || currentTestmode == TestMode::AubTestsWithTbx) { + MockSipData::useMockSip = false; + } } void cleanTestHelpers() { @@ -465,7 +464,7 @@ int main(int argc, char **argv) { } else { GmmInterface::initialize(nullptr, nullptr); } - initializeTestHelpers(); + initializeTestHelpers(testMode); retVal = RUN_ALL_TESTS(); diff --git a/opencl/test/unit_test/mocks/mock_io_functions.h b/opencl/test/unit_test/mocks/mock_io_functions.h index ae8f529cca..eeb0d0a157 100644 --- a/opencl/test/unit_test/mocks/mock_io_functions.h +++ b/opencl/test/unit_test/mocks/mock_io_functions.h @@ -15,6 +15,7 @@ namespace NEO { namespace IoFunctions { extern uint32_t mockFopenCalled; +extern FILE *mockFopenReturned; extern uint32_t mockVfptrinfCalled; extern uint32_t mockFcloseCalled; extern uint32_t mockGetenvCalled; @@ -29,7 +30,7 @@ extern std::unordered_map *mockableEnvValues; inline FILE *mockFopen(const char *filename, const char *mode) { mockFopenCalled++; - return reinterpret_cast(0x40); + return mockFopenReturned; } inline int mockVfptrinf(FILE *stream, const char *format, va_list arg) { diff --git a/opencl/test/unit_test/platform/platform_tests.cpp b/opencl/test/unit_test/platform/platform_tests.cpp index af7e12feed..a4551fb27e 100644 --- a/opencl/test/unit_test/platform/platform_tests.cpp +++ b/opencl/test/unit_test/platform/platform_tests.cpp @@ -13,6 +13,7 @@ #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/mocks/mock_sip.h" #include "opencl/source/cl_device/cl_device.h" #include "opencl/source/platform/extensions.h" @@ -33,25 +34,20 @@ using namespace NEO; -namespace NEO { -namespace MockSipData { -extern SipKernelType calledType; -extern bool called; -} // namespace MockSipData -} // namespace NEO - struct PlatformTest : public ::testing::Test { void SetUp() override { - MockSipData::calledType = SipKernelType::COUNT; - MockSipData::called = false; + MockSipData::clearUseFlags(); + backupSipInitType = std::make_unique>(&MockSipData::useMockSip, true); + pPlatform.reset(new MockPlatform()); } void TearDown() override { - MockSipData::calledType = SipKernelType::COUNT; - MockSipData::called = false; + MockSipData::clearUseFlags(); } - cl_int retVal = CL_SUCCESS; std::unique_ptr pPlatform; + std::unique_ptr> backupSipInitType; + + cl_int retVal = CL_SUCCESS; }; struct MockPlatformWithMockExecutionEnvironment : public MockPlatform { diff --git a/opencl/test/unit_test/source_level_debugger/source_level_debugger_csr_tests.cpp b/opencl/test/unit_test/source_level_debugger/source_level_debugger_csr_tests.cpp index 2793b3caec..944f527768 100644 --- a/opencl/test/unit_test/source_level_debugger/source_level_debugger_csr_tests.cpp +++ b/opencl/test/unit_test/source_level_debugger/source_level_debugger_csr_tests.cpp @@ -44,8 +44,7 @@ HWTEST_F(CommandStreamReceiverWithActiveDebuggerTest, givenCsrWithActiveDebugger dispatchFlags, baseDevice); - auto sipType = SipKernel::getSipKernelType(baseDevice.getHardwareInfo().platform.eRenderCoreFamily, true); - auto sipAllocation = baseDevice.getBuiltIns()->getSipKernel(sipType, baseDevice).getSipAllocation(); + auto sipAllocation = SipKernel::getSipKernel(baseDevice).getSipAllocation(); bool found = false; for (auto allocation : mockCsr->copyOfAllocations) { if (allocation == sipAllocation) { @@ -75,6 +74,8 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverWithActiveDebuggerTest, givenCs std::unique_ptr allocation(new MockGraphicsAllocation(buffer, MemoryConstants::pageSize)); std::unique_ptr heap(new IndirectHeap(allocation.get())); + auto &baseDevice = device->getDevice(); + mockCsr->flushTask(commandStream, 0, *heap.get(), @@ -82,10 +83,9 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverWithActiveDebuggerTest, givenCs *heap.get(), 0, dispatchFlags, - device->getDevice()); + baseDevice); - auto sipType = SipKernel::getSipKernelType(device->getHardwareInfo().platform.eRenderCoreFamily, true); - auto sipAllocation = device->getBuiltIns()->getSipKernel(sipType, device->getDevice()).getSipAllocation(); + auto sipAllocation = SipKernel::getSipKernel(baseDevice).getSipAllocation(); HardwareParse hwParser; hwParser.parseCommands(preambleStream); @@ -126,6 +126,8 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverWithActiveDebuggerTest, givenCs std::unique_ptr allocation(new MockGraphicsAllocation(buffer, MemoryConstants::pageSize)); std::unique_ptr heap(new IndirectHeap(allocation.get())); + auto &baseDevice = device->getDevice(); + mockCsr->flushTask(commandStream, 0, *heap.get(), @@ -133,7 +135,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverWithActiveDebuggerTest, givenCs *heap.get(), 0, dispatchFlags, - device->getDevice()); + baseDevice); mockCsr->flushBatchedSubmissions(); @@ -144,10 +146,9 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverWithActiveDebuggerTest, givenCs *heap.get(), 0, dispatchFlags, - device->getDevice()); + baseDevice); - auto sipType = SipKernel::getSipKernelType(device->getHardwareInfo().platform.eRenderCoreFamily, true); - auto sipAllocation = device->getBuiltIns()->getSipKernel(sipType, device->getDevice()).getSipAllocation(); + auto sipAllocation = SipKernel::getSipKernel(baseDevice).getSipAllocation(); HardwareParse hwParser; hwParser.parseCommands(preambleStream); diff --git a/opencl/test/unit_test/source_level_debugger/source_level_debugger_csr_tests.h b/opencl/test/unit_test/source_level_debugger/source_level_debugger_csr_tests.h index aee55dc9ed..8d7bf2060f 100644 --- a/opencl/test/unit_test/source_level_debugger/source_level_debugger_csr_tests.h +++ b/opencl/test/unit_test/source_level_debugger/source_level_debugger_csr_tests.h @@ -6,6 +6,7 @@ */ #include "shared/test/common/mocks/mock_os_library.h" +#include "shared/test/common/mocks/mock_sip.h" #include "opencl/test/unit_test/helpers/execution_environment_helper.h" #include "opencl/test/unit_test/mocks/mock_builtins.h" diff --git a/opencl/test/unit_test/test_files/igdrcl.config b/opencl/test/unit_test/test_files/igdrcl.config index 46e2e6d838..7c3c04e087 100644 --- a/opencl/test/unit_test/test_files/igdrcl.config +++ b/opencl/test/unit_test/test_files/igdrcl.config @@ -30,6 +30,7 @@ AUBDumpForceAllToLocalMemory = 0 EnableSWTags = 0 DumpSWTagsBXML = 0 ForceDeviceId = unk +LoadBinarySipFromFile = unk OverrideCsrAllocationSize = -1 ForceL1Caching = -1 UseKmdMigration = 0 diff --git a/shared/source/built_ins/CMakeLists.txt b/shared/source/built_ins/CMakeLists.txt index fa22c8dcea..274ba621fd 100644 --- a/shared/source/built_ins/CMakeLists.txt +++ b/shared/source/built_ins/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2017-2020 Intel Corporation +# Copyright (C) 2017-2021 Intel Corporation # # SPDX-License-Identifier: MIT # diff --git a/shared/source/built_ins/built_ins.cpp b/shared/source/built_ins/built_ins.cpp index b6a5f93c56..c31740ed01 100644 --- a/shared/source/built_ins/built_ins.cpp +++ b/shared/source/built_ins/built_ins.cpp @@ -11,7 +11,6 @@ #include "shared/source/compiler_interface/compiler_interface.h" #include "shared/source/device_binary_format/device_binary_formats.h" #include "shared/source/helpers/basic_math.h" -#include "shared/source/helpers/built_ins_helper.h" #include "shared/source/helpers/debug_helpers.h" #include "shared/source/memory_manager/memory_manager.h" @@ -38,11 +37,11 @@ const SipKernel &BuiltIns::getSipKernel(SipKernelType type, Device &device) { auto initializer = [&] { std::vector sipBinary; - std::vector stateSaveAareHeader; + std::vector stateSaveAreaHeader; auto compilerInteface = device.getCompilerInterface(); UNRECOVERABLE_IF(compilerInteface == nullptr); - auto ret = compilerInteface->getSipKernelBinary(device, type, sipBinary, stateSaveAareHeader); + auto ret = compilerInteface->getSipKernelBinary(device, type, sipBinary, stateSaveAreaHeader); UNRECOVERABLE_IF(ret != TranslationOutput::ErrorCode::Success); UNRECOVERABLE_IF(sipBinary.size() == 0); @@ -62,7 +61,7 @@ const SipKernel &BuiltIns::getSipKernel(SipKernelType type, Device &device) { device, sipAllocation, 0, sipBinary.data(), sipBinary.size()); } - sipBuiltIn.first.reset(new SipKernel(type, sipAllocation, std::move(stateSaveAareHeader))); + sipBuiltIn.first.reset(new SipKernel(type, sipAllocation, std::move(stateSaveAreaHeader))); }; std::call_once(sipBuiltIn.second, initializer); UNRECOVERABLE_IF(sipBuiltIn.first == nullptr); diff --git a/shared/source/built_ins/sip.cpp b/shared/source/built_ins/sip.cpp index e0877441d8..56fb757b00 100644 --- a/shared/source/built_ins/sip.cpp +++ b/shared/source/built_ins/sip.cpp @@ -8,8 +8,10 @@ #include "shared/source/built_ins/sip.h" #include "shared/source/built_ins/built_ins.h" +#include "shared/source/debug_settings/debug_settings_manager.h" #include "shared/source/device/device.h" #include "shared/source/execution_environment/execution_environment.h" +#include "shared/source/helpers/aligned_memory.h" #include "shared/source/helpers/debug_helpers.h" #include "shared/source/helpers/hw_helper.h" #include "shared/source/helpers/ptr_math.h" @@ -17,14 +19,17 @@ #include "shared/source/memory_manager/allocation_properties.h" #include "shared/source/memory_manager/graphics_allocation.h" #include "shared/source/memory_manager/memory_manager.h" +#include "shared/source/utilities/io_functions.h" namespace NEO { const size_t SipKernel::maxDbgSurfaceSize = 0x1800000; // proper value should be taken from compiler when it's ready +SipClassType SipKernel::classType = SipClassType::Init; + SipKernel::~SipKernel() = default; -SipKernel::SipKernel(SipKernelType type, GraphicsAllocation *sipAlloc, std::vector ssah) : type(type), sipAllocation(sipAlloc), stateSaveAreaHeader(ssah) { +SipKernel::SipKernel(SipKernelType type, GraphicsAllocation *sipAlloc, std::vector ssah) : stateSaveAreaHeader(ssah), sipAllocation(sipAlloc), type(type) { } GraphicsAllocation *SipKernel::getSipAllocation() const { @@ -35,20 +40,102 @@ const std::vector &SipKernel::getStateSaveAreaHeader() const { return stateSaveAreaHeader; } -SipKernelType SipKernel::getSipKernelType(GFXCORE_FAMILY family, bool debuggingActive) { - auto &hwHelper = HwHelper::get(family); - return hwHelper.getSipKernelType(debuggingActive); -} - -GraphicsAllocation *SipKernel::getSipKernelAllocation(Device &device) { +SipKernelType SipKernel::getSipKernelType(Device &device) { bool debuggingEnabled = device.getDebugger() != nullptr || device.isDebuggerActive(); - auto sipType = SipKernel::getSipKernelType(device.getHardwareInfo().platform.eRenderCoreFamily, debuggingEnabled); - return device.getBuiltIns()->getSipKernel(sipType, device).getSipAllocation(); + auto &hwHelper = HwHelper::get(device.getHardwareInfo().platform.eRenderCoreFamily); + return hwHelper.getSipKernelType(debuggingEnabled); } -const std::vector &SipKernel::getSipStateSaveAreaHeader(Device &device) { - bool debuggingEnabled = device.getDebugger() != nullptr; - auto sipType = SipKernel::getSipKernelType(device.getHardwareInfo().platform.eRenderCoreFamily, debuggingEnabled); - return device.getBuiltIns()->getSipKernel(sipType, device).getStateSaveAreaHeader(); +bool SipKernel::initBuiltinsSipKernel(SipKernelType type, Device &device) { + device.getBuiltIns()->getSipKernel(type, device); + return true; } + +bool SipKernel::initRawBinaryFromFileKernel(SipKernelType type, Device &device, std::string &fileName) { + FILE *fileDescriptor = nullptr; + long int size = 0; + size_t bytesRead = 0u; + + fileDescriptor = IoFunctions::fopenPtr(fileName.c_str(), "rb"); + if (fileDescriptor == NULL) { + return false; + } + + IoFunctions::fseekPtr(fileDescriptor, 0, SEEK_END); + size = IoFunctions::ftellPtr(fileDescriptor); + IoFunctions::rewindPtr(fileDescriptor); + + void *alignedBuffer = alignedMalloc(size, MemoryConstants::pageSize); + + bytesRead = IoFunctions::freadPtr(alignedBuffer, 1, size, fileDescriptor); + IoFunctions::fclosePtr(fileDescriptor); + if (static_cast(bytesRead) != size || bytesRead == 0u) { + alignedFree(alignedBuffer); + return false; + } + + const auto allocType = GraphicsAllocation::AllocationType::KERNEL_ISA_INTERNAL; + + AllocationProperties properties = {device.getRootDeviceIndex(), bytesRead, allocType, device.getDeviceBitfield()}; + properties.flags.use32BitFrontWindow = false; + + auto sipAllocation = device.getMemoryManager()->allocateGraphicsMemoryWithProperties(properties); + if (sipAllocation == nullptr) { + alignedFree(alignedBuffer); + return false; + } + + auto &hwInfo = device.getHardwareInfo(); + auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily); + + MemoryTransferHelper::transferMemoryToAllocation(hwHelper.isBlitCopyRequiredForLocalMemory(hwInfo, *sipAllocation), + device, sipAllocation, 0, alignedBuffer, + bytesRead); + + alignedFree(alignedBuffer); + + std::vector emptyStateSaveAreaHeader; + uint32_t sipIndex = static_cast(type); + device.getExecutionEnvironment()->rootDeviceEnvironments[device.getRootDeviceIndex()]->sipKernels[sipIndex] = + std::make_unique(type, sipAllocation, std::move(emptyStateSaveAreaHeader)); + + return true; +} + +void SipKernel::freeSipKernels(RootDeviceEnvironment *rootDeviceEnvironment, MemoryManager *memoryManager) { + for (auto &sipKernel : rootDeviceEnvironment->sipKernels) { + if (sipKernel.get()) { + memoryManager->freeGraphicsMemory(sipKernel->getSipAllocation()); + } + } +} + +void SipKernel::selectSipClassType(std::string &fileName) { + const std::string unknown("unk"); + if (fileName.compare(unknown) == 0) { + SipKernel::classType = SipClassType::Builtins; + } else { + SipKernel::classType = SipClassType::RawBinaryFromFile; + } +} + +bool SipKernel::initSipKernelImpl(SipKernelType type, Device &device) { + std::string fileName = DebugManager.flags.LoadBinarySipFromFile.get(); + SipKernel::selectSipClassType(fileName); + + if (SipKernel::classType == SipClassType::RawBinaryFromFile) { + return SipKernel::initRawBinaryFromFileKernel(type, device, fileName); + } + return SipKernel::initBuiltinsSipKernel(type, device); +} + +const SipKernel &SipKernel::getSipKernelImpl(Device &device) { + auto sipType = SipKernel::getSipKernelType(device); + + if (SipKernel::classType == SipClassType::RawBinaryFromFile) { + return *device.getRootDeviceEnvironment().sipKernels[static_cast(sipType)].get(); + } + return device.getBuiltIns()->getSipKernel(sipType, device); +} + } // namespace NEO diff --git a/shared/source/built_ins/sip.h b/shared/source/built_ins/sip.h index 8e106dc175..a608518bc9 100644 --- a/shared/source/built_ins/sip.h +++ b/shared/source/built_ins/sip.h @@ -16,6 +16,8 @@ namespace NEO { class Device; class GraphicsAllocation; +class MemoryManager; +struct RootDeviceEnvironment; class SipKernel { public: @@ -30,17 +32,29 @@ class SipKernel { return type; } - static const size_t maxDbgSurfaceSize; - MOCKABLE_VIRTUAL GraphicsAllocation *getSipAllocation() const; MOCKABLE_VIRTUAL const std::vector &getStateSaveAreaHeader() const; - static SipKernelType getSipKernelType(GFXCORE_FAMILY family, bool debuggingActive); - static GraphicsAllocation *getSipKernelAllocation(Device &device); - static const std::vector &getSipStateSaveAreaHeader(Device &device); + + static bool initSipKernel(SipKernelType type, Device &device); + static void freeSipKernels(RootDeviceEnvironment *rootDeviceEnvironment, MemoryManager *memoryManager); + + static const SipKernel &getSipKernel(Device &device); + static SipKernelType getSipKernelType(Device &device); + + static const size_t maxDbgSurfaceSize; + static SipClassType classType; protected: - SipKernelType type = SipKernelType::COUNT; - GraphicsAllocation *sipAllocation = nullptr; + static bool initSipKernelImpl(SipKernelType type, Device &device); + static const SipKernel &getSipKernelImpl(Device &device); + + static bool initBuiltinsSipKernel(SipKernelType type, Device &device); + static bool initRawBinaryFromFileKernel(SipKernelType type, Device &device, std::string &fileName); + + static void selectSipClassType(std::string &fileName); + const std::vector stateSaveAreaHeader; + GraphicsAllocation *sipAllocation = nullptr; + SipKernelType type = SipKernelType::COUNT; }; } // namespace NEO diff --git a/shared/source/built_ins/sip_init.cpp b/shared/source/built_ins/sip_init.cpp new file mode 100644 index 0000000000..81fd420691 --- /dev/null +++ b/shared/source/built_ins/sip_init.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/built_ins/sip.h" + +namespace NEO { + +bool SipKernel::initSipKernel(SipKernelType type, Device &device) { + return SipKernel::initSipKernelImpl(type, device); +} + +const SipKernel &SipKernel::getSipKernel(Device &device) { + return SipKernel::getSipKernelImpl(device); +} + +} // namespace NEO diff --git a/shared/source/built_ins/sip_kernel_type.h b/shared/source/built_ins/sip_kernel_type.h index c9acdfe97f..ce55204eef 100644 --- a/shared/source/built_ins/sip_kernel_type.h +++ b/shared/source/built_ins/sip_kernel_type.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -18,4 +18,11 @@ enum class SipKernelType : std::uint32_t { COUNT }; +enum class SipClassType : std::uint32_t { + Init = 0, + Builtins, + RawBinaryFromFile, + HexadecimalHeaderFile +}; + } // namespace NEO diff --git a/shared/source/command_stream/command_stream_receiver_hw_base.inl b/shared/source/command_stream/command_stream_receiver_hw_base.inl index 35419c6398..7a95a16541 100644 --- a/shared/source/command_stream/command_stream_receiver_hw_base.inl +++ b/shared/source/command_stream/command_stream_receiver_hw_base.inl @@ -510,7 +510,7 @@ CompletionStamp CommandStreamReceiverHw::flushTask( } if (dispatchFlags.preemptionMode == PreemptionMode::MidThread || sourceLevelDebuggerActive) { - makeResident(*SipKernel::getSipKernelAllocation(device)); + makeResident(*SipKernel::getSipKernel(device).getSipAllocation()); if (debugSurface) { makeResident(*debugSurface); } diff --git a/shared/source/command_stream/preemption.inl b/shared/source/command_stream/preemption.inl index ec64697afb..c4f3f2ef09 100644 --- a/shared/source/command_stream/preemption.inl +++ b/shared/source/command_stream/preemption.inl @@ -36,7 +36,7 @@ void PreemptionHelper::programStateSip(LinearStream &preambleCmdStream, Device & bool isMidThreadPreemption = device.getPreemptionMode() == PreemptionMode::MidThread; if (isMidThreadPreemption || debuggingEnabled) { - auto sipAllocation = SipKernel::getSipKernelAllocation(device); + auto sipAllocation = SipKernel::getSipKernel(device).getSipAllocation(); auto sip = reinterpret_cast(preambleCmdStream.getSpace(sizeof(STATE_SIP))); STATE_SIP cmd = GfxFamily::cmdInitStateSip; diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index 0dff63736b..518bc0a0be 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -58,6 +58,7 @@ DECLARE_DEBUG_VARIABLE(bool, ZebinIgnoreIcbeVersion, false, "Ignore IGC\'s ICBE DECLARE_DEBUG_VARIABLE(bool, UseExternalAllocatorForSshAndDsh, false, "Use 32 bit external Allocator for ssh and dsh in Level Zero") DECLARE_DEBUG_VARIABLE(bool, UseBindlessDebugSip, false, "Use bindless debug system routine") DECLARE_DEBUG_VARIABLE(std::string, ForceDeviceId, std::string("unk"), "DeviceId selected for testing") +DECLARE_DEBUG_VARIABLE(std::string, LoadBinarySipFromFile, std::string("unk"), "Select binary file to load SIP kernel raw binary") DECLARE_DEBUG_VARIABLE(int32_t, ForceL1Caching, -1, "-1: default, 0: disable, 1: enable, When set to true driver will program L1 cache policy for surface state and stateless accessess") DECLARE_DEBUG_VARIABLE(int32_t, ForceAuxTranslationEnabled, -1, "-1: default, 0: disabled, 1: enabled") DECLARE_DEBUG_VARIABLE(int32_t, SchedulerSimulationReturnInstance, 0, "prints execution model related debug information") diff --git a/shared/source/debugger/debugger.cpp b/shared/source/debugger/debugger.cpp index a5bec21ee8..14821d9abc 100644 --- a/shared/source/debugger/debugger.cpp +++ b/shared/source/debugger/debugger.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,11 +7,12 @@ #include "shared/source/debugger/debugger.h" -#include "shared/source/built_ins/sip.h" #include "shared/source/built_ins/sip_kernel_type.h" +#include "shared/source/helpers/hw_helper.h" #include "shared/source/helpers/hw_info.h" #include "shared/source/indirect_heap/indirect_heap.h" #include "shared/source/source_level_debugger/source_level_debugger.h" + namespace NEO { std::unique_ptr Debugger::create(HardwareInfo *hwInfo) { std::unique_ptr sourceLevelDebugger; @@ -19,7 +20,8 @@ std::unique_ptr Debugger::create(HardwareInfo *hwInfo) { sourceLevelDebugger.reset(SourceLevelDebugger::create()); } if (sourceLevelDebugger) { - bool localMemorySipAvailable = (SipKernelType::DbgCsrLocal == SipKernel::getSipKernelType(hwInfo->platform.eRenderCoreFamily, true)); + auto &hwHelper = HwHelper::get(hwInfo->platform.eRenderCoreFamily); + bool localMemorySipAvailable = (SipKernelType::DbgCsrLocal == hwHelper.getSipKernelType(true)); sourceLevelDebugger->initialize(localMemorySipAvailable); } return sourceLevelDebugger; diff --git a/shared/source/execution_environment/execution_environment.cpp b/shared/source/execution_environment/execution_environment.cpp index f1d31b0c35..4f530b882a 100644 --- a/shared/source/execution_environment/execution_environment.cpp +++ b/shared/source/execution_environment/execution_environment.cpp @@ -8,6 +8,7 @@ #include "shared/source/execution_environment/execution_environment.h" #include "shared/source/built_ins/built_ins.h" +#include "shared/source/built_ins/sip.h" #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/helpers/hw_helper.h" #include "shared/source/memory_manager/memory_manager.h" @@ -24,6 +25,7 @@ ExecutionEnvironment::~ExecutionEnvironment() { if (memoryManager) { memoryManager->commonCleanup(); for (const auto &rootDeviceEnvironment : this->rootDeviceEnvironments) { + SipKernel::freeSipKernels(rootDeviceEnvironment.get(), memoryManager.get()); if (rootDeviceEnvironment->builtins.get()) { rootDeviceEnvironment->builtins.get()->freeSipKernels(memoryManager.get()); } diff --git a/shared/source/execution_environment/root_device_environment.h b/shared/source/execution_environment/root_device_environment.h index e7ea8589ed..6cbdb1631f 100644 --- a/shared/source/execution_environment/root_device_environment.h +++ b/shared/source/execution_environment/root_device_environment.h @@ -6,6 +6,7 @@ */ #pragma once +#include "shared/source/built_ins/sip_kernel_type.h" #include "shared/source/helpers/options.h" #include @@ -28,6 +29,7 @@ class HwDeviceId; class MemoryManager; class MemoryOperationsHandler; class OSInterface; +class SipKernel; class SWTagsManager; struct HardwareInfo; @@ -58,6 +60,7 @@ struct RootDeviceEnvironment { BindlessHeapsHelper *getBindlessHeapsHelper() const; void createBindlessHeapsHelper(MemoryManager *memoryManager, bool availableDevices, uint32_t rootDeviceIndex); + std::unique_ptr sipKernels[static_cast(SipKernelType::COUNT)]; std::unique_ptr gmmHelper; std::unique_ptr osInterface; std::unique_ptr pageTableManager; diff --git a/shared/source/helpers/CMakeLists.txt b/shared/source/helpers/CMakeLists.txt index 72bcaa3168..34e3d871be 100644 --- a/shared/source/helpers/CMakeLists.txt +++ b/shared/source/helpers/CMakeLists.txt @@ -21,7 +21,6 @@ set(NEO_CORE_HELPERS ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/blit_commands_helper_extra.cpp ${CMAKE_CURRENT_SOURCE_DIR}/blit_commands_helper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/blit_commands_helper.h - ${CMAKE_CURRENT_SOURCE_DIR}/built_ins_helper.h ${CMAKE_CURRENT_SOURCE_DIR}/cache_policy.cpp ${CMAKE_CURRENT_SOURCE_DIR}/cache_policy.h ${CMAKE_CURRENT_SOURCE_DIR}/common_types.h diff --git a/shared/source/helpers/built_ins_helper.cpp b/shared/source/helpers/built_ins_helper.cpp deleted file mode 100644 index 0a4b05e8f4..0000000000 --- a/shared/source/helpers/built_ins_helper.cpp +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (C) 2018-2021 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "shared/source/helpers/built_ins_helper.h" - -#include "shared/source/device/device.h" -#include "shared/source/device_binary_format/device_binary_formats.h" - -namespace NEO { -void initSipKernel(SipKernelType type, Device &device) { - device.getBuiltIns()->getSipKernel(type, device); -} -} // namespace NEO diff --git a/shared/source/helpers/built_ins_helper.h b/shared/source/helpers/built_ins_helper.h deleted file mode 100644 index a8e4d2ebff..0000000000 --- a/shared/source/helpers/built_ins_helper.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (C) 2018-2021 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#pragma once -#include "shared/source/built_ins/built_ins.h" - -namespace NEO { -class Device; - -void initSipKernel(SipKernelType type, Device &device); - -} // namespace NEO diff --git a/shared/source/memory_manager/os_agnostic_memory_manager.h b/shared/source/memory_manager/os_agnostic_memory_manager.h index 57c5553278..0fc15579ee 100644 --- a/shared/source/memory_manager/os_agnostic_memory_manager.h +++ b/shared/source/memory_manager/os_agnostic_memory_manager.h @@ -50,6 +50,14 @@ class MemoryAllocation : public GraphicsAllocation { } void overrideMemoryPool(MemoryPool::Type pool); + + void clearUsageInfo() { + for (auto &info : usageInfos) { + info.inspectionId = 0u; + info.residencyTaskCount = objectNotResident; + info.taskCount = objectNotUsed; + } + } }; class OsAgnosticMemoryManager : public MemoryManager { diff --git a/shared/test/common/fixtures/device_fixture.cpp b/shared/test/common/fixtures/device_fixture.cpp index b332cbbac0..83aecf6db7 100644 --- a/shared/test/common/fixtures/device_fixture.cpp +++ b/shared/test/common/fixtures/device_fixture.cpp @@ -7,6 +7,8 @@ #include "shared/test/common/fixtures/device_fixture.h" +#include "shared/source/built_ins/sip.h" + #include "gtest/gtest.h" namespace NEO { diff --git a/shared/test/common/gen11/test_preemption_gen11.cpp b/shared/test/common/gen11/test_preemption_gen11.cpp index d5a9daa7f8..93ce249ef8 100644 --- a/shared/test/common/gen11/test_preemption_gen11.cpp +++ b/shared/test/common/gen11/test_preemption_gen11.cpp @@ -59,7 +59,7 @@ GEN11TEST_F(Gen11PreemptionTests, whenMidThreadPreemptionIsAvailableThenStateSip auto stateSipCmd = hwParsePreamble.getCommand(); ASSERT_NE(nullptr, stateSipCmd); - EXPECT_EQ(device->getBuiltIns()->getSipKernel(SipKernelType::Csr, *device).getSipAllocation()->getGpuAddressToPatch(), stateSipCmd->getSystemInstructionPointer()); + EXPECT_EQ(SipKernel::getSipKernel(*device).getSipAllocation()->getGpuAddressToPatch(), stateSipCmd->getSystemInstructionPointer()); } GEN11TEST_F(Gen11PreemptionTests, WhenGettingPreemptionWaCsSizeThenZeroIsReturned) { diff --git a/shared/test/common/gen9/test_preemption_gen9.cpp b/shared/test/common/gen9/test_preemption_gen9.cpp index 3ff7067e2c..12a4cd5e5c 100644 --- a/shared/test/common/gen9/test_preemption_gen9.cpp +++ b/shared/test/common/gen9/test_preemption_gen9.cpp @@ -65,7 +65,7 @@ GEN9TEST_F(Gen9PreemptionTests, whenMidThreadPreemptionIsAvailableThenStateSipIs auto stateSipCmd = hwParsePreamble.getCommand(); ASSERT_NE(nullptr, stateSipCmd); - EXPECT_EQ(device->getBuiltIns()->getSipKernel(SipKernelType::Csr, *device).getSipAllocation()->getGpuAddressToPatch(), stateSipCmd->getSystemInstructionPointer()); + EXPECT_EQ(SipKernel::getSipKernel(*device).getSipAllocation()->getGpuAddressToPatch(), stateSipCmd->getSystemInstructionPointer()); } GEN9TEST_F(Gen9PreemptionTests, givenMidBatchPreemptionWhenProgrammingWaCmdsBeginThenExpectNoCmds) { @@ -154,6 +154,5 @@ GEN9TEST_F(Gen9PreemptionTests, givenMidThreadPreemptionModeWhenStateSipIsProgra auto cmd = hwParserOnlyPreemption.getCommand(); EXPECT_NE(nullptr, cmd); - auto sipType = SipKernel::getSipKernelType(mockDevice->getHardwareInfo().platform.eRenderCoreFamily, mockDevice->isDebuggerActive()); - EXPECT_EQ(mockDevice->getBuiltIns()->getSipKernel(sipType, *mockDevice).getSipAllocation()->getGpuAddressToPatch(), cmd->getSystemInstructionPointer()); + EXPECT_EQ(SipKernel::getSipKernel(*mockDevice).getSipAllocation()->getGpuAddressToPatch(), cmd->getSystemInstructionPointer()); } diff --git a/shared/test/common/helpers/CMakeLists.txt b/shared/test/common/helpers/CMakeLists.txt index 21252ecc1e..9de549fbf5 100644 --- a/shared/test/common/helpers/CMakeLists.txt +++ b/shared/test/common/helpers/CMakeLists.txt @@ -10,7 +10,6 @@ set(NEO_CORE_HELPERS_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/blit_commands_helper_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/blit_commands_helper_tests.inl ${CMAKE_CURRENT_SOURCE_DIR}/blit_commands_helper_tests_gen12lp.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/built_ins_helper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/debug_manager_state_restore.h ${CMAKE_CURRENT_SOURCE_DIR}/default_hw_info.h @@ -23,6 +22,7 @@ set(NEO_CORE_HELPERS_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/memory_leak_listener.h ${CMAKE_CURRENT_SOURCE_DIR}/memory_management.h ${CMAKE_CURRENT_SOURCE_DIR}/simd_helper_tests.inl + ${CMAKE_CURRENT_SOURCE_DIR}/sip_init.cpp ${CMAKE_CURRENT_SOURCE_DIR}/string_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/string_to_hash_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_traits.h diff --git a/shared/test/common/helpers/built_ins_helper.cpp b/shared/test/common/helpers/built_ins_helper.cpp deleted file mode 100644 index cefcc455b0..0000000000 --- a/shared/test/common/helpers/built_ins_helper.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2018-2021 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "shared/source/helpers/built_ins_helper.h" - -#include "shared/source/device/device.h" -#include "shared/test/common/mocks/mock_sip.h" - -namespace NEO { - -namespace MockSipData { -std::unique_ptr mockSipKernel; -SipKernelType calledType = SipKernelType::COUNT; -bool called = false; -} // namespace MockSipData - -void initSipKernel(SipKernelType type, Device &device) { - MockSipData::calledType = type; - MockSipData::called = true; -} - -} // namespace NEO diff --git a/shared/test/common/helpers/sip_init.cpp b/shared/test/common/helpers/sip_init.cpp new file mode 100644 index 0000000000..be83b0ce98 --- /dev/null +++ b/shared/test/common/helpers/sip_init.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/device/device.h" +#include "shared/source/memory_manager/os_agnostic_memory_manager.h" +#include "shared/test/common/mocks/mock_sip.h" + +#include + +namespace NEO { + +namespace MockSipData { +std::unique_ptr mockSipKernel; +SipKernelType calledType = SipKernelType::COUNT; +bool called = false; +bool returned = true; +bool useMockSip = false; + +void clearUseFlags() { + calledType = SipKernelType::COUNT; + called = false; +} +} // namespace MockSipData + +bool SipKernel::initSipKernel(SipKernelType type, Device &device) { + if (MockSipData::useMockSip) { + SipKernel::classType = SipClassType::Builtins; + MockSipData::calledType = type; + MockSipData::called = true; + + MockSipData::mockSipKernel->mockSipMemoryAllocation->clearUsageInfo(); + return MockSipData::returned; + } else { + return SipKernel::initSipKernelImpl(type, device); + } +} + +const SipKernel &SipKernel::getSipKernel(Device &device) { + if (MockSipData::useMockSip) { + return *MockSipData::mockSipKernel.get(); + } else { + return SipKernel::getSipKernelImpl(device); + } +} + +} // namespace NEO diff --git a/shared/test/common/mocks/mock_device.h b/shared/test/common/mocks/mock_device.h index 1c168e3ddb..effc1ca072 100644 --- a/shared/test/common/mocks/mock_device.h +++ b/shared/test/common/mocks/mock_device.h @@ -49,6 +49,7 @@ class MockDevice : public RootDevice { using Device::executionEnvironment; using Device::getGlobalMemorySize; using Device::initializeCaps; + using Device::isDebuggerActive; using RootDevice::createEngines; using RootDevice::defaultEngineIndex; using RootDevice::getDeviceBitfield; @@ -127,7 +128,17 @@ class MockDevice : public RootDevice { return std::unique_ptr(createCommandStreamReceiverFunc(*executionEnvironment, getRootDeviceIndex(), getDeviceBitfield())); } + bool isDebuggerActive() const override { + if (isDebuggerActiveParentCall) { + return Device::isDebuggerActive(); + } + return isDebuggerActiveReturn; + } + static decltype(&createCommandStream) createCommandStreamReceiverFunc; + + bool isDebuggerActiveParentCall = true; + bool isDebuggerActiveReturn = false; }; template <> diff --git a/shared/test/common/mocks/mock_sip.cpp b/shared/test/common/mocks/mock_sip.cpp index ebf6c2cfdc..916e74e4bf 100644 --- a/shared/test/common/mocks/mock_sip.cpp +++ b/shared/test/common/mocks/mock_sip.cpp @@ -7,38 +7,19 @@ #include "shared/test/common/mocks/mock_sip.h" -#include "shared/source/helpers/file_io.h" -#include "shared/source/helpers/hw_info.h" #include "shared/source/memory_manager/os_agnostic_memory_manager.h" #include "shared/test/common/helpers/test_files.h" -#include "cif/macros/enable.h" -#include "ocl_igc_interface/igc_ocl_device_ctx.h" - #include #include namespace NEO { MockSipKernel::MockSipKernel(SipKernelType type, GraphicsAllocation *sipAlloc) : SipKernel(type, sipAlloc, {'s', 's', 'a', 'h'}) { - this->mockSipMemoryAllocation = - std::make_unique(0u, - GraphicsAllocation::AllocationType::KERNEL_ISA_INTERNAL, - nullptr, - MemoryConstants::pageSize * 10u, - 0u, - MemoryConstants::pageSize, - MemoryPool::System4KBPages, 3u); + createMockSipAllocation(); } MockSipKernel::MockSipKernel() : SipKernel(SipKernelType::Csr, nullptr, {'s', 's', 'a', 'h'}) { - this->mockSipMemoryAllocation = - std::make_unique(0u, - GraphicsAllocation::AllocationType::KERNEL_ISA_INTERNAL, - nullptr, - MemoryConstants::pageSize * 10u, - 0u, - MemoryConstants::pageSize, - MemoryPool::System4KBPages, 3u); + createMockSipAllocation(); } MockSipKernel::~MockSipKernel() = default; @@ -56,4 +37,16 @@ GraphicsAllocation *MockSipKernel::getSipAllocation() const { const std::vector &MockSipKernel::getStateSaveAreaHeader() const { return mockStateSaveAreaHeader; } + +void MockSipKernel::createMockSipAllocation() { + this->mockSipMemoryAllocation = + std::make_unique(0u, + GraphicsAllocation::AllocationType::KERNEL_ISA_INTERNAL, + nullptr, + MemoryConstants::pageSize * 10u, + 0u, + MemoryConstants::pageSize, + MemoryPool::System4KBPages, 3u); +} + } // namespace NEO diff --git a/shared/test/common/mocks/mock_sip.h b/shared/test/common/mocks/mock_sip.h index 2ccda4d00a..afc0d5dd0b 100644 --- a/shared/test/common/mocks/mock_sip.h +++ b/shared/test/common/mocks/mock_sip.h @@ -31,6 +31,8 @@ class MockSipKernel : public SipKernel { GraphicsAllocation *getSipAllocation() const override; const std::vector &getStateSaveAreaHeader() const override; + void createMockSipAllocation(); + std::unique_ptr mockSipMemoryAllocation; const std::vector mockStateSaveAreaHeader = {'s', 's', 'a', 'h'}; MockExecutionEnvironment executionEnvironment; @@ -40,5 +42,9 @@ namespace MockSipData { extern std::unique_ptr mockSipKernel; extern SipKernelType calledType; extern bool called; +extern bool returned; +extern bool useMockSip; + +void clearUseFlags(); } // namespace MockSipData } // namespace NEO diff --git a/shared/test/unit_test/built_ins/CMakeLists.txt b/shared/test/unit_test/built_ins/CMakeLists.txt index ac69bc1a92..165aceb167 100644 --- a/shared/test/unit_test/built_ins/CMakeLists.txt +++ b/shared/test/unit_test/built_ins/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2020 Intel Corporation +# Copyright (C) 2020-2021 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -7,4 +7,5 @@ target_sources(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/built_in_tests_shared.inl + ${CMAKE_CURRENT_SOURCE_DIR}/sip_tests.cpp ) diff --git a/shared/test/unit_test/built_ins/sip_tests.cpp b/shared/test/unit_test/built_ins/sip_tests.cpp new file mode 100644 index 0000000000..8af4606eef --- /dev/null +++ b/shared/test/unit_test/built_ins/sip_tests.cpp @@ -0,0 +1,183 @@ +/* + * Copyright (C) 2018-2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/test/common/fixtures/device_fixture.h" +#include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/helpers/variable_backup.h" +#include "shared/test/common/mocks/mock_device.h" +#include "shared/test/common/mocks/mock_sip.h" + +#include "opencl/test/unit_test/mocks/mock_io_functions.h" +#include "opencl/test/unit_test/mocks/mock_memory_manager.h" +#include "test.h" + +using namespace NEO; + +struct RawBinarySipFixture : public DeviceFixture { + void SetUp() { + DebugManager.flags.LoadBinarySipFromFile.set("dummy_file.bin"); + + backupSipInitType = std::make_unique>(&MockSipData::useMockSip, false); + backupSipClassType = std::make_unique>(&SipKernel::classType); + + backupFopenReturned = std::make_unique>(&IoFunctions::mockFopenReturned); + backupFtellReturned = std::make_unique>(&IoFunctions::mockFtellReturn, 128); + backupFreadReturned = std::make_unique>(&IoFunctions::mockFreadReturn, 128u); + + backupFopenCalled = std::make_unique>(&IoFunctions::mockFopenCalled, 0u); + backupFseekCalled = std::make_unique>(&IoFunctions::mockFseekCalled, 0u); + backupFtellCalled = std::make_unique>(&IoFunctions::mockFtellCalled, 0u); + backupRewindCalled = std::make_unique>(&IoFunctions::mockRewindCalled, 0u); + backupFreadCalled = std::make_unique>(&IoFunctions::mockFreadCalled, 0u); + backupFcloseCalled = std::make_unique>(&IoFunctions::mockFcloseCalled, 0u); + + DeviceFixture::SetUp(); + } + + void TearDown() { + DeviceFixture::TearDown(); + } + + DebugManagerStateRestore dbgRestorer; + + std::unique_ptr> backupSipInitType; + std::unique_ptr> backupSipClassType; + + std::unique_ptr> backupFopenReturned; + std::unique_ptr> backupFtellReturned; + std::unique_ptr> backupFreadReturned; + + std::unique_ptr> backupFopenCalled; + std::unique_ptr> backupFseekCalled; + std::unique_ptr> backupFtellCalled; + std::unique_ptr> backupRewindCalled; + std::unique_ptr> backupFreadCalled; + std::unique_ptr> backupFcloseCalled; +}; + +using RawBinarySipTest = Test; + +TEST_F(RawBinarySipTest, givenRawBinaryFileWhenInitSipKernelThenSipIsLoadedFromFile) { + bool ret = SipKernel::initSipKernel(SipKernelType::Csr, *pDevice); + EXPECT_TRUE(ret); + + EXPECT_EQ(1u, IoFunctions::mockFopenCalled); + EXPECT_EQ(1u, IoFunctions::mockFseekCalled); + EXPECT_EQ(1u, IoFunctions::mockFtellCalled); + EXPECT_EQ(1u, IoFunctions::mockRewindCalled); + EXPECT_EQ(1u, IoFunctions::mockFreadCalled); + EXPECT_EQ(1u, IoFunctions::mockFcloseCalled); + + EXPECT_EQ(SipKernelType::Csr, SipKernel::getSipKernelType(*pDevice)); + + uint32_t sipIndex = static_cast(SipKernelType::Csr); + auto sipKernel = pDevice->getRootDeviceEnvironment().sipKernels[sipIndex].get(); + ASSERT_NE(nullptr, sipKernel); + auto storedAllocation = sipKernel->getSipAllocation(); + + auto sipAllocation = SipKernel::getSipKernel(*pDevice).getSipAllocation(); + EXPECT_NE(nullptr, storedAllocation); + EXPECT_EQ(storedAllocation, sipAllocation); +} + +TEST_F(RawBinarySipTest, givenRawBinaryFileWhenInitSipKernelAndDebuggerActiveThenDbgSipIsLoadedFromFile) { + pDevice->setDebuggerActive(true); + auto currentSipKernelType = SipKernel::getSipKernelType(*pDevice); + bool ret = SipKernel::initSipKernel(currentSipKernelType, *pDevice); + EXPECT_TRUE(ret); + + EXPECT_EQ(1u, IoFunctions::mockFopenCalled); + EXPECT_EQ(1u, IoFunctions::mockFseekCalled); + EXPECT_EQ(1u, IoFunctions::mockFtellCalled); + EXPECT_EQ(1u, IoFunctions::mockRewindCalled); + EXPECT_EQ(1u, IoFunctions::mockFreadCalled); + EXPECT_EQ(1u, IoFunctions::mockFcloseCalled); + + EXPECT_LE(SipKernelType::DbgCsr, currentSipKernelType); + + uint32_t sipIndex = static_cast(currentSipKernelType); + auto sipKernel = pDevice->getRootDeviceEnvironment().sipKernels[sipIndex].get(); + ASSERT_NE(nullptr, sipKernel); + auto storedAllocation = sipKernel->getSipAllocation(); + + auto sipAllocation = SipKernel::getSipKernel(*pDevice).getSipAllocation(); + EXPECT_NE(nullptr, storedAllocation); + EXPECT_EQ(storedAllocation, sipAllocation); +} + +TEST_F(RawBinarySipTest, givenRawBinaryFileWhenOpenFileFailsThenSipIsNotLoadedFromFile) { + IoFunctions::mockFopenReturned = nullptr; + bool ret = SipKernel::initSipKernel(SipKernelType::Csr, *pDevice); + EXPECT_FALSE(ret); + + EXPECT_EQ(1u, IoFunctions::mockFopenCalled); + EXPECT_EQ(0u, IoFunctions::mockFseekCalled); + EXPECT_EQ(0u, IoFunctions::mockFtellCalled); + EXPECT_EQ(0u, IoFunctions::mockRewindCalled); + EXPECT_EQ(0u, IoFunctions::mockFreadCalled); + EXPECT_EQ(0u, IoFunctions::mockFcloseCalled); + + EXPECT_EQ(SipKernelType::Csr, SipKernel::getSipKernelType(*pDevice)); + uint32_t sipIndex = static_cast(SipKernelType::Csr); + auto sipKernel = pDevice->getRootDeviceEnvironment().sipKernels[sipIndex].get(); + EXPECT_EQ(nullptr, sipKernel); +} + +TEST_F(RawBinarySipTest, givenRawBinaryFileWhenTellSizeDiffrentThanBytesReadThenSipIsNotCreated) { + IoFunctions::mockFtellReturn = 28; + bool ret = SipKernel::initSipKernel(SipKernelType::Csr, *pDevice); + EXPECT_FALSE(ret); + + EXPECT_EQ(1u, IoFunctions::mockFopenCalled); + EXPECT_EQ(1u, IoFunctions::mockFseekCalled); + EXPECT_EQ(1u, IoFunctions::mockFtellCalled); + EXPECT_EQ(1u, IoFunctions::mockRewindCalled); + EXPECT_EQ(1u, IoFunctions::mockFreadCalled); + EXPECT_EQ(1u, IoFunctions::mockFcloseCalled); + + EXPECT_EQ(SipKernelType::Csr, SipKernel::getSipKernelType(*pDevice)); + uint32_t sipIndex = static_cast(SipKernelType::Csr); + auto sipKernel = pDevice->getRootDeviceEnvironment().sipKernels[sipIndex].get(); + EXPECT_EQ(nullptr, sipKernel); +} + +TEST_F(RawBinarySipTest, givenRawBinaryFileWhenBytesReadIsZeroThenSipIsNotCreated) { + IoFunctions::mockFreadReturn = 0u; + IoFunctions::mockFtellReturn = 0; + bool ret = SipKernel::initSipKernel(SipKernelType::Csr, *pDevice); + EXPECT_FALSE(ret); + + EXPECT_EQ(1u, IoFunctions::mockFopenCalled); + EXPECT_EQ(1u, IoFunctions::mockFseekCalled); + EXPECT_EQ(1u, IoFunctions::mockFtellCalled); + EXPECT_EQ(1u, IoFunctions::mockRewindCalled); + EXPECT_EQ(1u, IoFunctions::mockFreadCalled); + EXPECT_EQ(1u, IoFunctions::mockFcloseCalled); + + EXPECT_EQ(SipKernelType::Csr, SipKernel::getSipKernelType(*pDevice)); + uint32_t sipIndex = static_cast(SipKernelType::Csr); + auto sipKernel = pDevice->getRootDeviceEnvironment().sipKernels[sipIndex].get(); + EXPECT_EQ(nullptr, sipKernel); +} + +TEST_F(RawBinarySipTest, givenRawBinaryFileWhenAllocationCreationFailsThenSipIsNotCreated) { + pDevice->executionEnvironment->memoryManager.reset(new FailMemoryManager(0, *pDevice->executionEnvironment)); + bool ret = SipKernel::initSipKernel(SipKernelType::Csr, *pDevice); + EXPECT_FALSE(ret); + + EXPECT_EQ(1u, IoFunctions::mockFopenCalled); + EXPECT_EQ(1u, IoFunctions::mockFseekCalled); + EXPECT_EQ(1u, IoFunctions::mockFtellCalled); + EXPECT_EQ(1u, IoFunctions::mockRewindCalled); + EXPECT_EQ(1u, IoFunctions::mockFreadCalled); + EXPECT_EQ(1u, IoFunctions::mockFcloseCalled); + + EXPECT_EQ(SipKernelType::Csr, SipKernel::getSipKernelType(*pDevice)); + uint32_t sipIndex = static_cast(SipKernelType::Csr); + auto sipKernel = pDevice->getRootDeviceEnvironment().sipKernels[sipIndex].get(); + EXPECT_EQ(nullptr, sipKernel); +} diff --git a/shared/test/unit_test/source_level_debugger/source_level_debugger_preamble_test.inl b/shared/test/unit_test/source_level_debugger/source_level_debugger_preamble_test.inl index b6da8fd828..c75223d215 100644 --- a/shared/test/unit_test/source_level_debugger/source_level_debugger_preamble_test.inl +++ b/shared/test/unit_test/source_level_debugger/source_level_debugger_preamble_test.inl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Intel Corporation + * Copyright (C) 2018-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -29,8 +29,7 @@ void SourceLevelDebuggerPreambleTest::givenMidThreadPreemptionAndDebu STATE_SIP *stateSipCmd = (STATE_SIP *)*itorStateSip; auto sipAddress = stateSipCmd->getSystemInstructionPointer(); - auto sipType = SipKernel::getSipKernelType(mockDevice->getHardwareInfo().platform.eRenderCoreFamily, mockDevice->isDebuggerActive()); - EXPECT_EQ(mockDevice->getBuiltIns()->getSipKernel(sipType, *mockDevice).getSipAllocation()->getGpuAddressToPatch(), sipAddress); + EXPECT_EQ(SipKernel::getSipKernel(*mockDevice).getSipAllocation()->getGpuAddressToPatch(), sipAddress); } template @@ -55,8 +54,7 @@ void SourceLevelDebuggerPreambleTest::givenMidThreadPreemptionAndDisa STATE_SIP *stateSipCmd = (STATE_SIP *)*itorStateSip; auto sipAddress = stateSipCmd->getSystemInstructionPointer(); - auto sipType = SipKernel::getSipKernelType(mockDevice->getHardwareInfo().platform.eRenderCoreFamily, mockDevice->isDebuggerActive()); - EXPECT_EQ(mockDevice->getBuiltIns()->getSipKernel(sipType, *mockDevice).getSipAllocation()->getGpuAddressToPatch(), sipAddress); + EXPECT_EQ(SipKernel::getSipKernel(*mockDevice).getSipAllocation()->getGpuAddressToPatch(), sipAddress); } template @@ -81,8 +79,7 @@ void SourceLevelDebuggerPreambleTest::givenPreemptionDisabledAndDebug STATE_SIP *stateSipCmd = (STATE_SIP *)*itorStateSip; auto sipAddress = stateSipCmd->getSystemInstructionPointer(); - auto sipType = SipKernel::getSipKernelType(mockDevice->getHardwareInfo().platform.eRenderCoreFamily, mockDevice->isDebuggerActive()); - EXPECT_EQ(mockDevice->getBuiltIns()->getSipKernel(sipType, *mockDevice).getSipAllocation()->getGpuAddressToPatch(), sipAddress); + EXPECT_EQ(SipKernel::getSipKernel(*mockDevice).getSipAllocation()->getGpuAddressToPatch(), sipAddress); } template