mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-25 13:33:02 +08:00
Add debug flag to print driver diagnostics to cout.
- New registry flags can be used for applications that wants to dump driver diagnostics without using any additional tools - When flag is on , context is being created with driver diagnostics and hint level is being set to debug variable - If application is already using driver diagnostics the hint level is overwritten Change-Id: I9912c0a7e8f23adb8372997144e5b75f9cc05b1d
This commit is contained in:
committed by
sys_ocldev
parent
e579578bc8
commit
bee295415f
@@ -36,6 +36,7 @@
|
||||
#include "runtime/memory_manager/svm_memory_manager.h"
|
||||
#include "runtime/memory_manager/deferred_deleter.h"
|
||||
#include "runtime/memory_manager/memory_manager.h"
|
||||
#include "runtime/os_interface/debug_settings_manager.h"
|
||||
#include "runtime/sharings/sharing_factory.h"
|
||||
#include "runtime/sharings/sharing.h"
|
||||
#include <algorithm>
|
||||
@@ -104,6 +105,7 @@ bool Context::createImpl(const cl_context_properties *properties,
|
||||
|
||||
auto propertiesCurrent = properties;
|
||||
bool interopUserSync = false;
|
||||
int32_t driverDiagnosticsUsed = -1;
|
||||
auto sharingBuilder = sharingFactory.build();
|
||||
|
||||
std::unique_ptr<DriverDiagnostics> driverDiagnostics;
|
||||
@@ -122,7 +124,7 @@ bool Context::createImpl(const cl_context_properties *properties,
|
||||
}
|
||||
} break;
|
||||
case CL_CONTEXT_SHOW_DIAGNOSTICS_INTEL:
|
||||
driverDiagnostics.reset(new DriverDiagnostics((cl_diagnostics_verbose_level)propertyValue));
|
||||
driverDiagnosticsUsed = static_cast<int32_t>(propertyValue);
|
||||
break;
|
||||
case CL_CONTEXT_INTEROP_USER_SYNC:
|
||||
interopUserSync = propertyValue > 0;
|
||||
@@ -149,6 +151,13 @@ bool Context::createImpl(const cl_context_properties *properties,
|
||||
numProperties++;
|
||||
}
|
||||
|
||||
if (DebugManager.flags.PrintDriverDiagnostics.get() != -1) {
|
||||
driverDiagnosticsUsed = DebugManager.flags.PrintDriverDiagnostics.get();
|
||||
}
|
||||
if (driverDiagnosticsUsed >= 0) {
|
||||
driverDiagnostics.reset(new DriverDiagnostics((cl_diagnostics_verbose_level)driverDiagnosticsUsed));
|
||||
}
|
||||
|
||||
this->numProperties = numProperties;
|
||||
this->properties = propertiesNew;
|
||||
this->devices = devices;
|
||||
|
||||
@@ -107,7 +107,12 @@ class Context : public BaseObject<_cl_context> {
|
||||
char hint[DriverDiagnostics::maxHintStringSize];
|
||||
snprintf(hint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[performanceHint], std::forward<Args>(args)..., 0);
|
||||
if (driverDiagnostics->validFlags(flags)) {
|
||||
contextCallback(hint, &flags, sizeof(flags), userData);
|
||||
if (contextCallback) {
|
||||
contextCallback(hint, &flags, sizeof(flags), userData);
|
||||
}
|
||||
if (DebugManager.flags.PrintDriverDiagnostics.get() != -1) {
|
||||
printf("\n%s\n", hint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ DriverDiagnostics::DriverDiagnostics(cl_diagnostics_verbose_level level) {
|
||||
this->verboseLevel = level;
|
||||
}
|
||||
|
||||
cl_bool DriverDiagnostics::validFlags(cl_diagnostics_verbose_level flags) const {
|
||||
return (verboseLevel & flags) != 0;
|
||||
bool DriverDiagnostics::validFlags(cl_diagnostics_verbose_level flags) const {
|
||||
return !!(verboseLevel & flags);
|
||||
}
|
||||
|
||||
const char *DriverDiagnostics::hintFormat[] = {
|
||||
|
||||
@@ -67,7 +67,7 @@ enum PerformanceHints {
|
||||
class DriverDiagnostics {
|
||||
public:
|
||||
DriverDiagnostics(cl_diagnostics_verbose_level level);
|
||||
cl_bool validFlags(cl_diagnostics_verbose_level flags) const;
|
||||
bool validFlags(cl_diagnostics_verbose_level flags) const;
|
||||
~DriverDiagnostics() = default;
|
||||
static const char *hintFormat[];
|
||||
static const cl_int maxHintStringSize = 1024;
|
||||
|
||||
@@ -43,6 +43,7 @@ DECLARE_DEBUG_VARIABLE(bool, ResidencyDebugEnable, 0, "enables debug messages an
|
||||
DECLARE_DEBUG_VARIABLE(bool, EventsDebugEnable, 0, "enables debug messages for events, virtual events, blocked enqueues, events trees etc.")
|
||||
DECLARE_DEBUG_VARIABLE(bool, PrintEMDebugInformation, false, "prints execution model related debug information")
|
||||
DECLARE_DEBUG_VARIABLE(bool, PrintLWSSizes, false, "prints driver choosen local workgroup sizes")
|
||||
DECLARE_DEBUG_VARIABLE(int32_t, PrintDriverDiagnostics, -1, "prints driver diagnostics messages to standard output, value corresponds to hint level")
|
||||
/*PERFORMANCE FLAGS*/
|
||||
DECLARE_DEBUG_VARIABLE(bool, EnableNullHardware, false, "works on Windows only, sets the Null Hardware flag that makes all Command buffers completed while GPU does nothing")
|
||||
DECLARE_DEBUG_VARIABLE(bool, ForceLinearImages, false, "Force linear images. Default is Y-tiled.")
|
||||
|
||||
@@ -345,6 +345,93 @@ TEST_F(PerformanceHintTest, GivenNonZeroCopyImageAndContextWhenCreateImageThenCo
|
||||
EXPECT_FALSE(containsHint(expectedHint, userData));
|
||||
}
|
||||
|
||||
TEST_F(PerformanceHintTest, givenPrintDriverDiagnosticValueWhenContextIsCreatedThenItHasHintLevelSetToThatValue) {
|
||||
DebugManagerStateRestore dbgRestore;
|
||||
auto hintLevel = 1;
|
||||
DebugManager.flags.PrintDriverDiagnostics.set(hintLevel);
|
||||
|
||||
auto pDevice = castToObject<Device>(devices[0]);
|
||||
cl_device_id clDevice = pDevice;
|
||||
|
||||
auto context = Context::create<MockContext>(nullptr, DeviceVector(&clDevice, 1), nullptr, nullptr, retVal);
|
||||
|
||||
EXPECT_TRUE(!!context->isProvidingPerformanceHints());
|
||||
auto driverDiagnostics = context->getDriverDiagnostics();
|
||||
ASSERT_NE(nullptr, driverDiagnostics);
|
||||
EXPECT_TRUE(driverDiagnostics->validFlags(hintLevel));
|
||||
context->release();
|
||||
}
|
||||
|
||||
TEST_F(PerformanceHintTest, givenPrintDriverDiagnosticsDebugModeEnabledWhenHintIsCalledThenDriverProvidedOutputOnCout) {
|
||||
DebugManagerStateRestore dbgRestore;
|
||||
auto hintLevel = 255;
|
||||
DebugManager.flags.PrintDriverDiagnostics.set(hintLevel);
|
||||
|
||||
auto pDevice = castToObject<Device>(devices[0]);
|
||||
cl_device_id clDevice = pDevice;
|
||||
|
||||
auto context = Context::create<MockContext>(nullptr, DeviceVector(&clDevice, 1), nullptr, nullptr, retVal);
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
auto buffer = Buffer::create(
|
||||
context,
|
||||
CL_MEM_READ_ONLY,
|
||||
4096,
|
||||
nullptr,
|
||||
retVal);
|
||||
|
||||
std::string output = testing::internal::GetCapturedStdout();
|
||||
EXPECT_NE(0u, output.size());
|
||||
EXPECT_EQ('\n', output[0]);
|
||||
|
||||
buffer->release();
|
||||
context->release();
|
||||
}
|
||||
|
||||
TEST_F(PerformanceHintTest, givenPrintDriverDiagnosticsAndBadHintLevelWhenActionForHintOccursThenNothingIsProvidedToCout) {
|
||||
DebugManagerStateRestore dbgRestore;
|
||||
auto hintLevel = 8;
|
||||
DebugManager.flags.PrintDriverDiagnostics.set(hintLevel);
|
||||
|
||||
auto pDevice = castToObject<Device>(devices[0]);
|
||||
cl_device_id clDevice = pDevice;
|
||||
|
||||
auto context = Context::create<MockContext>(nullptr, DeviceVector(&clDevice, 1), nullptr, nullptr, retVal);
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
auto buffer = Buffer::create(
|
||||
context,
|
||||
CL_MEM_READ_ONLY,
|
||||
4096,
|
||||
nullptr,
|
||||
retVal);
|
||||
|
||||
std::string output = testing::internal::GetCapturedStdout();
|
||||
EXPECT_EQ(0u, output.size());
|
||||
|
||||
buffer->release();
|
||||
context->release();
|
||||
}
|
||||
|
||||
TEST_F(PerformanceHintTest, givenPrintDriverDiagnosticsDebugModeEnabledWhenContextIsBeingCreatedThenPropertiesPassedToContextAreOverwritten) {
|
||||
DebugManagerStateRestore dbgRestore;
|
||||
auto hintLevel = 1;
|
||||
DebugManager.flags.PrintDriverDiagnostics.set(hintLevel);
|
||||
|
||||
auto pDevice = castToObject<Device>(devices[0]);
|
||||
cl_device_id clDevice = pDevice;
|
||||
cl_context_properties validProperties[3] = {CL_CONTEXT_SHOW_DIAGNOSTICS_INTEL, CL_CONTEXT_DIAGNOSTICS_LEVEL_ALL_INTEL, 0};
|
||||
auto retValue = CL_SUCCESS;
|
||||
auto context = Context::create<MockContext>(validProperties, DeviceVector(&clDevice, 1), callbackFunction, (void *)userData, retVal);
|
||||
EXPECT_EQ(CL_SUCCESS, retValue);
|
||||
auto driverDiagnostics = context->getDriverDiagnostics();
|
||||
ASSERT_NE(nullptr, driverDiagnostics);
|
||||
EXPECT_TRUE(driverDiagnostics->validFlags(hintLevel));
|
||||
EXPECT_FALSE(driverDiagnostics->validFlags(2));
|
||||
|
||||
context->release();
|
||||
}
|
||||
|
||||
TEST_P(PerformanceHintKernelTest, GivenSpillFillWhenKernelIsInitializedThenContextProvidesProperHint) {
|
||||
|
||||
auto pDevice = castToObject<Device>(devices[0]);
|
||||
@@ -409,3 +496,7 @@ INSTANTIATE_TEST_CASE_P(
|
||||
DriverDiagnosticsTests,
|
||||
PerformanceHintKernelTest,
|
||||
testing::Bool());
|
||||
|
||||
TEST(PerformanceHintsDebugVariables, givenDefaultDebugManagerWhenPrintDriverDiagnosticsIsCalledThenMinusOneIsReturned) {
|
||||
EXPECT_EQ(-1, DebugManager.flags.PrintDriverDiagnostics.get());
|
||||
}
|
||||
@@ -46,6 +46,7 @@ class MockContext : public Context {
|
||||
cl_bool peekPreferD3dSharedResources() { return preferD3dSharedResources; }
|
||||
|
||||
void forcePreferD3dSharedResources(cl_bool value) { preferD3dSharedResources = value; }
|
||||
DriverDiagnostics *getDriverDiagnostics() { return this->driverDiagnostics; }
|
||||
|
||||
private:
|
||||
std::unique_ptr<Device> device;
|
||||
|
||||
@@ -55,3 +55,4 @@ DisableAUBBufferDump = false
|
||||
DisableAUBImageDump = false
|
||||
UseNoRingFlushesKmdMode = false
|
||||
OverrideThreadArbitrationPolicy = -1
|
||||
PrintDriverDiagnostics = -1
|
||||
Reference in New Issue
Block a user