Add new functionality to load SIP from file

Related-To: NEO-5718

Signed-off-by: Zbigniew Zdanowicz <zbigniew.zdanowicz@intel.com>
This commit is contained in:
Zbigniew Zdanowicz
2021-04-16 12:52:30 +00:00
committed by Compute-Runtime-Automation
parent f83b51e628
commit 902cce597a
53 changed files with 534 additions and 211 deletions

View File

@@ -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
)

View File

@@ -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

View File

@@ -286,7 +286,7 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::executeCommandLists(
}
if (sipKernelUsed) {
auto sipIsa = NEO::SipKernel::getSipKernelAllocation(*neoDevice);
auto sipIsa = NEO::SipKernel::getSipKernel(*neoDevice).getSipAllocation();
residencyContainer.push_back(sipIsa);
}

View File

@@ -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),

View File

@@ -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<STATE_SIP *>(*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<STATE_SIP *>(*itorSip);
EXPECT_EQ(sipAllocation->getGpuAddressToPatch(), stateSipCmd->getSystemInstructionPointer());
} else {

View File

@@ -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<STATE_SIP *>(*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;

View File

@@ -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;

View File

@@ -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<bool> mockSipCalled(&NEO::MockSipData::called, false);
VariableBackup<NEO::SipKernelType> mockSipCalledType(&NEO::MockSipData::calledType, NEO::SipKernelType::COUNT);
VariableBackup<bool> backupSipInitType(&MockSipData::useMockSip, true);
std::unique_ptr<DriverHandleImp> 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<size_t>(0), stateSaveAreaHeader.size());
}
@@ -111,6 +107,7 @@ TEST(L0DeviceTest, givenDisabledPreemptionWhenCreatingDeviceThenSipKernelIsNotIn
ze_result_t returnValue = ZE_RESULT_SUCCESS;
VariableBackup<bool> mockSipCalled(&NEO::MockSipData::called, false);
VariableBackup<NEO::SipKernelType> mockSipCalledType(&NEO::MockSipData::calledType, NEO::SipKernelType::COUNT);
VariableBackup<bool> backupSipInitType(&MockSipData::useMockSip, true);
std::unique_ptr<DriverHandleImp> driverHandle(new DriverHandleImp);
auto hwInfo = *NEO::defaultHwInfo;

View File

@@ -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"

View File

@@ -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

View File

@@ -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<std::unique_ptr<Device>> 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);
}
}

View File

@@ -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<BuiltinsLib>(new BuiltinsLib());

View File

@@ -40,12 +40,19 @@ TEST(Sip, givenSipKernelClassWhenAskedForMaxDebugSurfaceSizeThenCorrectValueIsRe
}
TEST(Sip, givenDebuggingInactiveWhenSipTypeIsQueriedThenCsrSipTypeIsReturned) {
auto sipType = SipKernel::getSipKernelType(renderCoreFamily, false);
auto mockDevice = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(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>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
EXPECT_NE(nullptr, mockDevice);
mockDevice->setDebuggerActive(true);
auto sipType = SipKernel::getSipKernelType(*mockDevice);
EXPECT_LE(SipKernelType::DbgCsr, sipType);
}

View File

@@ -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) {

View File

@@ -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<VariableBackup<bool>>(&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<VariableBackup<bool>> backupSipInitType;
};
TEST_F(DeviceGetCapsTest, WhenCreatingDeviceThenCapsArePopulatedCorrectly) {

View File

@@ -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 {

View File

@@ -32,7 +32,12 @@ GEN9TEST_F(gen9SipTests, givenDebugCsrSipKernelWithLocalMemoryWhenAskedForDebugS
}
GEN9TEST_F(gen9SipTests, givenDebuggingActiveWhenSipTypeIsQueriedThenDbgCsrLocalIsReturned) {
auto sipType = SipKernel::getSipKernelType(renderCoreFamily, true);
auto mockDevice = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
EXPECT_NE(nullptr, mockDevice);
mockDevice->isDebuggerActiveParentCall = false;
mockDevice->isDebuggerActiveReturn = true;
auto sipType = SipKernel::getSipKernelType(*mockDevice);
EXPECT_EQ(SipKernelType::DbgCsrLocal, sipType);
}
} // namespace SipKernelTests

View File

@@ -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
)

View File

@@ -19,6 +19,7 @@ rewindFuncPtr rewindPtr = &mockRewind;
freadFuncPtr freadPtr = &mockFread;
uint32_t mockFopenCalled = 0;
FILE *mockFopenReturned = reinterpret_cast<FILE *>(0x40);
uint32_t mockVfptrinfCalled = 0;
uint32_t mockFcloseCalled = 0;
uint32_t mockGetenvCalled = 0;

View File

@@ -54,10 +54,6 @@ extern const char *executionDirectorySuffix;
std::thread::id tempThreadID;
namespace MockSipData {
extern std::unique_ptr<MockSipKernel> 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();

View File

@@ -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<std::string, std::string> *mockableEnvValues;
inline FILE *mockFopen(const char *filename, const char *mode) {
mockFopenCalled++;
return reinterpret_cast<FILE *>(0x40);
return mockFopenReturned;
}
inline int mockVfptrinf(FILE *stream, const char *format, va_list arg) {

View File

@@ -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<VariableBackup<bool>>(&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<MockPlatform> pPlatform;
std::unique_ptr<VariableBackup<bool>> backupSipInitType;
cl_int retVal = CL_SUCCESS;
};
struct MockPlatformWithMockExecutionEnvironment : public MockPlatform {

View File

@@ -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<MockGraphicsAllocation> allocation(new MockGraphicsAllocation(buffer, MemoryConstants::pageSize));
std::unique_ptr<IndirectHeap> 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<FamilyType>(preambleStream);
@@ -126,6 +126,8 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverWithActiveDebuggerTest, givenCs
std::unique_ptr<MockGraphicsAllocation> allocation(new MockGraphicsAllocation(buffer, MemoryConstants::pageSize));
std::unique_ptr<IndirectHeap> 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<FamilyType>(preambleStream);

View File

@@ -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"

View File

@@ -30,6 +30,7 @@ AUBDumpForceAllToLocalMemory = 0
EnableSWTags = 0
DumpSWTagsBXML = 0
ForceDeviceId = unk
LoadBinarySipFromFile = unk
OverrideCsrAllocationSize = -1
ForceL1Caching = -1
UseKmdMigration = 0

View File

@@ -1,5 +1,5 @@
#
# Copyright (C) 2017-2020 Intel Corporation
# Copyright (C) 2017-2021 Intel Corporation
#
# SPDX-License-Identifier: MIT
#

View File

@@ -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<char> sipBinary;
std::vector<char> stateSaveAareHeader;
std::vector<char> 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);

View File

@@ -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<char> ssah) : type(type), sipAllocation(sipAlloc), stateSaveAreaHeader(ssah) {
SipKernel::SipKernel(SipKernelType type, GraphicsAllocation *sipAlloc, std::vector<char> ssah) : stateSaveAreaHeader(ssah), sipAllocation(sipAlloc), type(type) {
}
GraphicsAllocation *SipKernel::getSipAllocation() const {
@@ -35,20 +40,102 @@ const std::vector<char> &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<char> &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<long int>(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<char> emptyStateSaveAreaHeader;
uint32_t sipIndex = static_cast<uint32_t>(type);
device.getExecutionEnvironment()->rootDeviceEnvironments[device.getRootDeviceIndex()]->sipKernels[sipIndex] =
std::make_unique<SipKernel>(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<uint32_t>(sipType)].get();
}
return device.getBuiltIns()->getSipKernel(sipType, device);
}
} // namespace NEO

View File

@@ -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<char> &getStateSaveAreaHeader() const;
static SipKernelType getSipKernelType(GFXCORE_FAMILY family, bool debuggingActive);
static GraphicsAllocation *getSipKernelAllocation(Device &device);
static const std::vector<char> &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<char> stateSaveAreaHeader;
GraphicsAllocation *sipAllocation = nullptr;
SipKernelType type = SipKernelType::COUNT;
};
} // namespace NEO

View File

@@ -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

View File

@@ -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

View File

@@ -510,7 +510,7 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask(
}
if (dispatchFlags.preemptionMode == PreemptionMode::MidThread || sourceLevelDebuggerActive) {
makeResident(*SipKernel::getSipKernelAllocation(device));
makeResident(*SipKernel::getSipKernel(device).getSipAllocation());
if (debugSurface) {
makeResident(*debugSurface);
}

View File

@@ -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<STATE_SIP *>(preambleCmdStream.getSpace(sizeof(STATE_SIP)));
STATE_SIP cmd = GfxFamily::cmdInitStateSip;

View File

@@ -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")

View File

@@ -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> Debugger::create(HardwareInfo *hwInfo) {
std::unique_ptr<SourceLevelDebugger> sourceLevelDebugger;
@@ -19,7 +20,8 @@ std::unique_ptr<Debugger> 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;

View File

@@ -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());
}

View File

@@ -6,6 +6,7 @@
*/
#pragma once
#include "shared/source/built_ins/sip_kernel_type.h"
#include "shared/source/helpers/options.h"
#include <cstdint>
@@ -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<SipKernel> sipKernels[static_cast<uint32_t>(SipKernelType::COUNT)];
std::unique_ptr<GmmHelper> gmmHelper;
std::unique_ptr<OSInterface> osInterface;
std::unique_ptr<GmmPageTableMngr> pageTableManager;

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -59,7 +59,7 @@ GEN11TEST_F(Gen11PreemptionTests, whenMidThreadPreemptionIsAvailableThenStateSip
auto stateSipCmd = hwParsePreamble.getCommand<STATE_SIP>();
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) {

View File

@@ -65,7 +65,7 @@ GEN9TEST_F(Gen9PreemptionTests, whenMidThreadPreemptionIsAvailableThenStateSipIs
auto stateSipCmd = hwParsePreamble.getCommand<STATE_SIP>();
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<STATE_SIP>();
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());
}

View File

@@ -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

View File

@@ -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> mockSipKernel;
SipKernelType calledType = SipKernelType::COUNT;
bool called = false;
} // namespace MockSipData
void initSipKernel(SipKernelType type, Device &device) {
MockSipData::calledType = type;
MockSipData::called = true;
}
} // namespace NEO

View File

@@ -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 <cassert>
namespace NEO {
namespace MockSipData {
std::unique_ptr<MockSipKernel> 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

View File

@@ -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<CommandStreamReceiver>(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 <>

View File

@@ -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 <fstream>
#include <map>
namespace NEO {
MockSipKernel::MockSipKernel(SipKernelType type, GraphicsAllocation *sipAlloc) : SipKernel(type, sipAlloc, {'s', 's', 'a', 'h'}) {
this->mockSipMemoryAllocation =
std::make_unique<MemoryAllocation>(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<MemoryAllocation>(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<char> &MockSipKernel::getStateSaveAreaHeader() const {
return mockStateSaveAreaHeader;
}
void MockSipKernel::createMockSipAllocation() {
this->mockSipMemoryAllocation =
std::make_unique<MemoryAllocation>(0u,
GraphicsAllocation::AllocationType::KERNEL_ISA_INTERNAL,
nullptr,
MemoryConstants::pageSize * 10u,
0u,
MemoryConstants::pageSize,
MemoryPool::System4KBPages, 3u);
}
} // namespace NEO

View File

@@ -31,6 +31,8 @@ class MockSipKernel : public SipKernel {
GraphicsAllocation *getSipAllocation() const override;
const std::vector<char> &getStateSaveAreaHeader() const override;
void createMockSipAllocation();
std::unique_ptr<MemoryAllocation> mockSipMemoryAllocation;
const std::vector<char> mockStateSaveAreaHeader = {'s', 's', 'a', 'h'};
MockExecutionEnvironment executionEnvironment;
@@ -40,5 +42,9 @@ namespace MockSipData {
extern std::unique_ptr<MockSipKernel> mockSipKernel;
extern SipKernelType calledType;
extern bool called;
extern bool returned;
extern bool useMockSip;
void clearUseFlags();
} // namespace MockSipData
} // namespace NEO

View File

@@ -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
)

View File

@@ -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<VariableBackup<bool>>(&MockSipData::useMockSip, false);
backupSipClassType = std::make_unique<VariableBackup<SipClassType>>(&SipKernel::classType);
backupFopenReturned = std::make_unique<VariableBackup<FILE *>>(&IoFunctions::mockFopenReturned);
backupFtellReturned = std::make_unique<VariableBackup<long int>>(&IoFunctions::mockFtellReturn, 128);
backupFreadReturned = std::make_unique<VariableBackup<size_t>>(&IoFunctions::mockFreadReturn, 128u);
backupFopenCalled = std::make_unique<VariableBackup<uint32_t>>(&IoFunctions::mockFopenCalled, 0u);
backupFseekCalled = std::make_unique<VariableBackup<uint32_t>>(&IoFunctions::mockFseekCalled, 0u);
backupFtellCalled = std::make_unique<VariableBackup<uint32_t>>(&IoFunctions::mockFtellCalled, 0u);
backupRewindCalled = std::make_unique<VariableBackup<uint32_t>>(&IoFunctions::mockRewindCalled, 0u);
backupFreadCalled = std::make_unique<VariableBackup<uint32_t>>(&IoFunctions::mockFreadCalled, 0u);
backupFcloseCalled = std::make_unique<VariableBackup<uint32_t>>(&IoFunctions::mockFcloseCalled, 0u);
DeviceFixture::SetUp();
}
void TearDown() {
DeviceFixture::TearDown();
}
DebugManagerStateRestore dbgRestorer;
std::unique_ptr<VariableBackup<bool>> backupSipInitType;
std::unique_ptr<VariableBackup<SipClassType>> backupSipClassType;
std::unique_ptr<VariableBackup<FILE *>> backupFopenReturned;
std::unique_ptr<VariableBackup<long int>> backupFtellReturned;
std::unique_ptr<VariableBackup<size_t>> backupFreadReturned;
std::unique_ptr<VariableBackup<uint32_t>> backupFopenCalled;
std::unique_ptr<VariableBackup<uint32_t>> backupFseekCalled;
std::unique_ptr<VariableBackup<uint32_t>> backupFtellCalled;
std::unique_ptr<VariableBackup<uint32_t>> backupRewindCalled;
std::unique_ptr<VariableBackup<uint32_t>> backupFreadCalled;
std::unique_ptr<VariableBackup<uint32_t>> backupFcloseCalled;
};
using RawBinarySipTest = Test<RawBinarySipFixture>;
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<uint32_t>(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<uint32_t>(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<uint32_t>(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<uint32_t>(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<uint32_t>(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<uint32_t>(SipKernelType::Csr);
auto sipKernel = pDevice->getRootDeviceEnvironment().sipKernels[sipIndex].get();
EXPECT_EQ(nullptr, sipKernel);
}

View File

@@ -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<GfxFamily>::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 <typename GfxFamily>
@@ -55,8 +54,7 @@ void SourceLevelDebuggerPreambleTest<GfxFamily>::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 <typename GfxFamily>
@@ -81,8 +79,7 @@ void SourceLevelDebuggerPreambleTest<GfxFamily>::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 <typename GfxFamily>