Experimental support for OCL debugging with L0

- initial changes

Related-To: NEO-7075

Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe
2022-07-12 08:22:46 +00:00
committed by Compute-Runtime-Automation
parent b3a0f835df
commit 5a3a39a281
6 changed files with 115 additions and 3 deletions

View File

@ -17,6 +17,7 @@
#include "shared/source/helpers/hw_info.h"
#include "shared/source/helpers/kernel_helpers.h"
#include "shared/source/memory_manager/unified_memory_manager.h"
#include "shared/source/os_interface/debug_env_reader.h"
#include "shared/source/os_interface/device_factory.h"
#include "shared/source/os_interface/os_context.h"
#include "shared/source/utilities/api_intercept.h"
@ -88,6 +89,14 @@ cl_int CL_API_CALL clGetPlatformIDs(cl_uint numEntries,
if (platformsImpl->empty()) {
auto executionEnvironment = new ClExecutionEnvironment();
executionEnvironment->incRefInternal();
if (NEO::DebugManager.flags.ExperimentalEnableL0DebuggerForOpenCL.get()) {
NEO::EnvironmentVariableReader envReader;
auto programDebugging = envReader.getSetting("ZET_ENABLE_PROGRAM_DEBUGGING", false);
if (programDebugging) {
executionEnvironment->setDebuggingEnabled();
}
}
auto allDevices = DeviceFactory::createDevices(*executionEnvironment);
executionEnvironment->decRefInternal();
if (allDevices.empty()) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -45,6 +45,7 @@ Platform::Platform(ExecutionEnvironment &executionEnvironmentIn) : executionEnvi
Platform::~Platform() {
for (auto clDevice : this->clDevices) {
clDevice->getDevice().getRootDeviceEnvironmentRef().debugger.reset(nullptr);
clDevice->decRefInternal();
}
@ -138,6 +139,12 @@ bool Platform::initialize(std::vector<std::unique_ptr<Device>> devices) {
pClDevice = new ClDevice{*pDevice, this};
this->clDevices.push_back(pClDevice);
if (pClDevice->getDevice().getExecutionEnvironment()->isDebuggingEnabled()) {
const auto rootDeviceIndex = pClDevice->getDevice().getRootDeviceIndex();
auto rootDeviceEnvironment = pClDevice->getDevice().getExecutionEnvironment()->rootDeviceEnvironments[rootDeviceIndex].get();
rootDeviceEnvironment->initDebuggerL0(&pClDevice->getDevice());
}
if (pClDevice->getPreemptionMode() == PreemptionMode::MidThread || pClDevice->isDebuggerActive()) {
bool ret = SipKernel::initSipKernel(SipKernel::getSipKernelType(*pDevice), *pDevice);
UNRECOVERABLE_IF(!ret);

View File

@ -1,16 +1,19 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/os_interface/device_factory.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/ult_hw_config.h"
#include "shared/test/common/helpers/variable_backup.h"
#include "shared/test/common/mocks/mock_io_functions.h"
#include "opencl/source/context/context.h"
#include "opencl/source/platform/platform.h"
#include "opencl/test/unit_test/mocks/mock_platform.h"
#include "cl_api_tests.h"
@ -131,4 +134,85 @@ TEST(clGetPlatformIDsNegativeTests, whenFailToInitializePlatformThenClGetPlatfom
platformsImpl->clear();
}
TEST(clGetPlatformIDsTest, givenEnabledExperimentalSupportAndEnabledProgramDebuggingWhenGettingPlatformIdsThenDebuggingEnabledIsSetInExecutionEnvironment) {
DebugManagerStateRestore stateRestore;
NEO::DebugManager.flags.ExperimentalEnableL0DebuggerForOpenCL.set(1);
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
hwInfo.capabilityTable.levelZeroSupported = true;
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
std::unordered_map<std::string, std::string> mockableEnvs = {{"ZET_ENABLE_PROGRAM_DEBUGGING", "1"}};
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
cl_int retVal = CL_SUCCESS;
cl_platform_id platformRet = nullptr;
cl_uint numPlatforms = 0;
platformsImpl->clear();
retVal = clGetPlatformIDs(1, &platformRet, &numPlatforms);
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, platformsImpl);
auto executionEnvironment = platform()->peekExecutionEnvironment();
EXPECT_TRUE(executionEnvironment->isDebuggingEnabled());
platformsImpl->clear();
}
TEST(clGetPlatformIDsTest, givenNoExperimentalSupportAndEnabledProgramDebuggingWhenGettingPlatformIdsThenDebuggingEnabledIsNotSetInExecutionEnvironment) {
DebugManagerStateRestore stateRestore;
NEO::DebugManager.flags.ExperimentalEnableL0DebuggerForOpenCL.set(0);
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
hwInfo.capabilityTable.levelZeroSupported = true;
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
std::unordered_map<std::string, std::string> mockableEnvs = {{"ZET_ENABLE_PROGRAM_DEBUGGING", "1"}};
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
cl_int retVal = CL_SUCCESS;
cl_platform_id platformRet = nullptr;
cl_uint numPlatforms = 0;
platformsImpl->clear();
retVal = clGetPlatformIDs(1, &platformRet, &numPlatforms);
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, platformsImpl);
auto executionEnvironment = platform()->peekExecutionEnvironment();
EXPECT_FALSE(executionEnvironment->isDebuggingEnabled());
platformsImpl->clear();
}
TEST(clGetPlatformIDsTest, givenEnabledExperimentalSupportAndZeroProgramDebuggingWhenGettingPlatformIdsThenDebuggingEnabledIsNotSetInExecutionEnvironment) {
DebugManagerStateRestore stateRestore;
NEO::DebugManager.flags.ExperimentalEnableL0DebuggerForOpenCL.set(1);
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
hwInfo.capabilityTable.levelZeroSupported = true;
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
std::unordered_map<std::string, std::string> mockableEnvs = {{"ZET_ENABLE_PROGRAM_DEBUGGING", "0"}};
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
cl_int retVal = CL_SUCCESS;
cl_platform_id platformRet = nullptr;
cl_uint numPlatforms = 0;
platformsImpl->clear();
retVal = clGetPlatformIDs(1, &platformRet, &numPlatforms);
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, platformsImpl);
auto executionEnvironment = platform()->peekExecutionEnvironment();
EXPECT_FALSE(executionEnvironment->isDebuggingEnabled());
platformsImpl->clear();
}
} // namespace ULT

View File

@ -440,6 +440,16 @@ TEST(PlatformInitTest, givenSingleDeviceWithNonZeroRootDeviceIndexInPassedDevice
EXPECT_EQ(2u, platform()->getClDevice(0)->getRootDeviceIndex());
}
TEST(PlatformInitTest, GivenDebuggingEnabledWhenPlatformIsInitializedThenL0DebuggerIsCreated) {
std::vector<std::unique_ptr<Device>> devices;
auto executionEnvironment = new MockExecutionEnvironment(defaultHwInfo.get(), false, 1);
executionEnvironment->setDebuggingEnabled();
devices.push_back(std::make_unique<MockDevice>(executionEnvironment, 0));
auto status = platform()->initialize(std::move(devices));
EXPECT_TRUE(status);
EXPECT_NE(nullptr, platform()->getClDevice(0)->getDevice().getL0Debugger());
}
TEST(PlatformGroupDevicesTest, whenMultipleDevicesAreCreatedThenGroupDevicesCreatesVectorPerEachProductFamily) {
DebugManagerStateRestore restorer;
const size_t numRootDevices = 5u;

View File

@ -406,6 +406,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, ExperimentalSetWalkerPartitionCount, 0, "Experim
DECLARE_DEBUG_VARIABLE(int32_t, ExperimentalSetWalkerPartitionType, -1, "Experimental implementation: Set COMPUTE_WALKER Partition Type. Valid values for types from 1 to 3")
DECLARE_DEBUG_VARIABLE(int32_t, ExperimentalEnableCustomLocalMemoryAlignment, 0, "Align local memory allocations to a given value. Works only with allocations at least as big as the value. 0: no effect, 2097152: 2 megabytes, 1073741824: 1 gigabyte")
DECLARE_DEBUG_VARIABLE(bool, ExperimentalEnableSourceLevelDebugger, false, "Experimentally enable source level debugger.")
DECLARE_DEBUG_VARIABLE(bool, ExperimentalEnableL0DebuggerForOpenCL, false, "Experimentally enable debugging OCL with L0 Debug API.")
DECLARE_DEBUG_VARIABLE(bool, ExperimentalEnableDeviceAllocationCache, false, "Experimentally enable allocation cache.")
/*DRIVER TOGGLES*/

View File

@ -433,4 +433,5 @@ OverrideDeviceName = unk
EnablePrivateBO = 0
ExperimentalEnableDeviceAllocationCache = 0
OverrideL1CachePolicyInSurfaceStateAndStateless = -1
EnableBcsSwControlWa = -1
EnableBcsSwControlWa = -1
ExperimentalEnableL0DebuggerForOpenCL = 0