mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Source Level Debugger: add generating debug data in cloc
- generate debug data to .dbg file in cloc - generate debug kernel for ults with "-g" option in addition to "-cl-kernel-debug-enable" - append "-g" option for compilation and build of programs with kernel debugging enabled to make compiler generate debug data Change-Id: I09401f84be6e09da167194a44d1b9a7f2bfb622d
This commit is contained in:
@ -191,6 +191,10 @@ int OfflineCompiler::buildSourceCode() {
|
||||
UNRECOVERABLE_IF(igcOutput->GetOutput() == nullptr);
|
||||
storeBinary(genBinary, genBinarySize, igcOutput->GetOutput()->GetMemory<char>(), igcOutput->GetOutput()->GetSizeRaw());
|
||||
updateBuildLog(igcOutput->GetBuildLog()->GetMemory<char>(), igcOutput->GetBuildLog()->GetSizeRaw());
|
||||
|
||||
if (igcOutput->GetDebugData()->GetSizeRaw() != 0) {
|
||||
storeBinary(debugDataBinary, debugDataBinarySize, igcOutput->GetDebugData()->GetMemory<char>(), igcOutput->GetDebugData()->GetSizeRaw());
|
||||
}
|
||||
retVal = igcOutput->Successful() ? CL_SUCCESS : CL_BUILD_PROGRAM_FAILURE;
|
||||
} while (0);
|
||||
|
||||
@ -806,6 +810,22 @@ void OfflineCompiler::writeOutAllFiles() {
|
||||
elfBinary,
|
||||
elfBinarySize);
|
||||
}
|
||||
|
||||
if (debugDataBinary) {
|
||||
std::string debugOutputFile = (outputDirectory == "") ? "" : outputDirectory + "/";
|
||||
debugOutputFile.append(fileBase + ".dbg");
|
||||
|
||||
if (useOptionsSuffix) {
|
||||
std::string opts(options.c_str());
|
||||
std::replace(opts.begin(), opts.end(), ' ', '_');
|
||||
debugOutputFile.append(opts);
|
||||
}
|
||||
|
||||
writeDataToFile(
|
||||
debugOutputFile.c_str(),
|
||||
debugDataBinary,
|
||||
debugDataBinarySize);
|
||||
}
|
||||
}
|
||||
|
||||
bool OfflineCompiler::readOptionsFromFile(std::string &options, const std::string &file) {
|
||||
|
@ -96,6 +96,8 @@ class OfflineCompiler {
|
||||
size_t genBinarySize = 0;
|
||||
char *llvmBinary = nullptr;
|
||||
size_t llvmBinarySize = 0;
|
||||
char *debugDataBinary = nullptr;
|
||||
size_t debugDataBinarySize = 0;
|
||||
|
||||
std::unique_ptr<OsLibrary> igcLib = nullptr;
|
||||
CIF::RAII::UPtr_t<CIF::CIFMain> igcMain = nullptr;
|
||||
|
@ -92,11 +92,13 @@ cl_int Program::build(
|
||||
break;
|
||||
}
|
||||
|
||||
internalOptions.append(platform()->peekCompilerExtensions());
|
||||
|
||||
if (isKernelDebugEnabled()) {
|
||||
internalOptions.append(CompilerOptions::debugKernelEnable);
|
||||
options.append(" -g ");
|
||||
}
|
||||
|
||||
internalOptions.append(platform()->peekCompilerExtensions());
|
||||
inputArgs.pInput = (char *)(sourceCode.c_str());
|
||||
inputArgs.InputSize = (uint32_t)sourceCode.size();
|
||||
inputArgs.pOptions = options.c_str();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Intel Corporation
|
||||
* Copyright (c) 2017 - 2018, Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
@ -155,6 +155,7 @@ cl_int Program::compile(
|
||||
|
||||
if (isKernelDebugEnabled()) {
|
||||
internalOptions.append(CompilerOptions::debugKernelEnable);
|
||||
options.append(" -g ");
|
||||
}
|
||||
|
||||
inputArgs.pInput = pCompileData;
|
||||
|
@ -223,7 +223,11 @@ function(neo_gen_kernel_with_options target product filepath)
|
||||
set_target_properties(${target} PROPERTIES FOLDER "kernels/${product}")
|
||||
endfunction()
|
||||
|
||||
function(neo_gen_kernel_with_internal_options target product filepath)
|
||||
set(TEST_KERNEL_kernel_debug_enable
|
||||
"-cl-kernel-debug-enable"
|
||||
)
|
||||
|
||||
function(neo_gen_kernel_with_kernel_debug_options target product filepath)
|
||||
get_filename_component(filename ${filepath} NAME)
|
||||
get_filename_component(basename ${filepath} NAME_WE)
|
||||
|
||||
@ -231,25 +235,24 @@ function(neo_gen_kernel_with_internal_options target product filepath)
|
||||
set(workdir "${CMAKE_CURRENT_SOURCE_DIR}/test_files/")
|
||||
|
||||
set(results)
|
||||
foreach(arg ${ARGN})
|
||||
string(REPLACE " " "_" argwospaces ${arg})
|
||||
string(REPLACE " " "_" argwospaces ${TEST_KERNEL_kernel_debug_enable})
|
||||
|
||||
set(outputpath_base "${outputdir}/${argwospaces}_${product}")
|
||||
set(output_files
|
||||
${outputpath_base}.bc
|
||||
${outputpath_base}.bin
|
||||
${outputpath_base}.gen
|
||||
${outputpath_base}.dbg
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${output_files}
|
||||
COMMAND ${cloc_cmd_prefix} -q -file ${filename} -device ${product} -${NEO_BITS} -out_dir ${outputdir} -output ${argwospaces} -internal_options ${arg} -options_name
|
||||
COMMAND ${cloc_cmd_prefix} -q -file ${filename} -device ${product} -${NEO_BITS} -out_dir ${outputdir} -output ${argwospaces} -internal_options ${TEST_KERNEL_kernel_debug_enable} -options "-g"
|
||||
WORKING_DIRECTORY ${workdir}
|
||||
DEPENDS ${filepath} cloc
|
||||
)
|
||||
|
||||
list(APPEND results ${output_files})
|
||||
endforeach()
|
||||
add_custom_target(${target} DEPENDS ${results} copy_compiler_files)
|
||||
set_target_properties(${target} PROPERTIES FOLDER "kernels/${product}")
|
||||
endfunction()
|
||||
@ -291,10 +294,6 @@ set(TEST_KERNEL_options
|
||||
"-x spir -spir-std=1.2"
|
||||
)
|
||||
|
||||
set(TEST_KERNEL_internal_options
|
||||
"-cl-kernel-debug-enable"
|
||||
)
|
||||
|
||||
set(TEST_KERNEL_2_0_options
|
||||
"-cl-std=CL2.0"
|
||||
)
|
||||
@ -379,7 +378,7 @@ macro(macro_for_each_platform)
|
||||
|
||||
# Temporarily disabled debug kernel generation on gen8
|
||||
if(NOT ("${GEN_TYPE_LOWER}" STREQUAL "gen8"))
|
||||
neo_gen_kernel_with_internal_options(test_kernel_internal_options_${PLATFORM_IT_LOWER} ${PLATFORM_IT_LOWER} ${TEST_KERNEL} ${TEST_KERNEL_internal_options})
|
||||
neo_gen_kernel_with_kernel_debug_options(test_kernel_debug_enable_${PLATFORM_IT_LOWER} ${PLATFORM_IT_LOWER} ${TEST_KERNEL})
|
||||
endif()
|
||||
|
||||
add_dependencies(unit_tests test_kernels_${PLATFORM_IT_LOWER})
|
||||
@ -387,7 +386,7 @@ macro(macro_for_each_platform)
|
||||
|
||||
# Temporarily disabled debug kernel generation on gen8
|
||||
if(NOT ("${GEN_TYPE_LOWER}" STREQUAL "gen8"))
|
||||
add_dependencies(unit_tests test_kernel_internal_options_${PLATFORM_IT_LOWER})
|
||||
add_dependencies(unit_tests test_kernel_debug_enable_${PLATFORM_IT_LOWER})
|
||||
endif()
|
||||
|
||||
set(sip_kernel_file_name)
|
||||
|
@ -357,10 +357,6 @@ void translate(bool usingIgc, CIF::Builtins::BufferSimple *src, CIF::Builtins::B
|
||||
if ((debugVars.forceBuildFailure == false) &&
|
||||
(out && src && src->GetMemoryRaw() && src->GetSizeRaw())) {
|
||||
|
||||
if (debugVars.debugDataToReturn != nullptr) {
|
||||
out->setDebugData(debugVars.debugDataToReturn, debugVars.debugDataToReturnSize);
|
||||
}
|
||||
|
||||
if (debugVars.internalOptionsExpected) {
|
||||
if (internalOptions->GetSizeRaw() < 1 || internalOptions->GetMemoryRaw() == nullptr) {
|
||||
if (out) {
|
||||
@ -371,6 +367,12 @@ void translate(bool usingIgc, CIF::Builtins::BufferSimple *src, CIF::Builtins::B
|
||||
|
||||
std::string inputFile = "";
|
||||
inputFile.append(debugVars.fileName);
|
||||
|
||||
std::string debugFile;
|
||||
auto pos = inputFile.rfind(".");
|
||||
debugFile = inputFile.substr(0, pos);
|
||||
debugFile.append(".dbg");
|
||||
|
||||
if (debugVars.appendOptionsToFileName &&
|
||||
options->GetSizeRaw()) {
|
||||
std::string opts(options->GetMemory<char>(), options->GetMemory<char>() + options->GetSize<char>());
|
||||
@ -381,6 +383,10 @@ void translate(bool usingIgc, CIF::Builtins::BufferSimple *src, CIF::Builtins::B
|
||||
}
|
||||
std::replace(opts.begin(), opts.end(), ' ', '_');
|
||||
inputFile.append(opts);
|
||||
|
||||
if (debugVars.debugDataToReturn == nullptr) {
|
||||
debugFile.append(opts);
|
||||
}
|
||||
}
|
||||
|
||||
size_t fileSize = 0;
|
||||
@ -390,6 +396,14 @@ void translate(bool usingIgc, CIF::Builtins::BufferSimple *src, CIF::Builtins::B
|
||||
if (fileSize == 0) {
|
||||
out->setError("error: Mock compiler could not find cached input file: " + inputFile);
|
||||
}
|
||||
|
||||
if (debugVars.debugDataToReturn != nullptr) {
|
||||
out->setDebugData(debugVars.debugDataToReturn, debugVars.debugDataToReturnSize);
|
||||
} else {
|
||||
size_t fileSize = 0;
|
||||
auto fileData = loadBinaryFile(debugFile, fileSize);
|
||||
out->setDebugData(fileData.get(), fileSize);
|
||||
}
|
||||
} else {
|
||||
out->setError();
|
||||
}
|
||||
|
@ -108,6 +108,11 @@ class MockProgram : public Program {
|
||||
allowNonUniform = allow;
|
||||
}
|
||||
|
||||
char *getDebugDataBinary(size_t &debugDataBinarySize) const {
|
||||
debugDataBinarySize = this->debugDataSize;
|
||||
return this->debugData;
|
||||
}
|
||||
|
||||
Device *getDevicePtr() { return this->pDevice; }
|
||||
|
||||
bool contextSet = false;
|
||||
|
@ -633,6 +633,50 @@ TEST(OfflineCompilerTest, givenOutputFileOptionWhenSourceIsCompiledThenOutputFil
|
||||
compilerOutputRemove("myOutputFileName", "gen");
|
||||
}
|
||||
|
||||
TEST(OfflineCompilerTest, givenDebugDataAvailableWhenSourceIsBuiltThenDebugDataFileIsCreated) {
|
||||
const char *argv[] = {
|
||||
"cloc",
|
||||
"-file",
|
||||
"test_files/copybuffer.cl",
|
||||
"-output",
|
||||
"myOutputFileName",
|
||||
"-device",
|
||||
gEnvironment->devicePrefix.c_str()};
|
||||
|
||||
char debugData[10];
|
||||
MockCompilerDebugVars igcDebugVars(gEnvironment->igcDebugVars);
|
||||
igcDebugVars.debugDataToReturn = debugData;
|
||||
igcDebugVars.debugDataToReturnSize = sizeof(debugData);
|
||||
|
||||
OCLRT::setIgcDebugVars(igcDebugVars);
|
||||
|
||||
auto mockOfflineCompiler = std::unique_ptr<MockOfflineCompiler>(new MockOfflineCompiler());
|
||||
ASSERT_NE(nullptr, mockOfflineCompiler);
|
||||
|
||||
int retVal = mockOfflineCompiler->initialize(ARRAY_COUNT(argv), argv);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
EXPECT_FALSE(compilerOutputExists("myOutputFileName", "bc"));
|
||||
EXPECT_FALSE(compilerOutputExists("myOutputFileName", "bin"));
|
||||
EXPECT_FALSE(compilerOutputExists("myOutputFileName", "gen"));
|
||||
EXPECT_FALSE(compilerOutputExists("myOutputFileName", "dbg"));
|
||||
|
||||
retVal = mockOfflineCompiler->build();
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
EXPECT_TRUE(compilerOutputExists("myOutputFileName", "bc"));
|
||||
EXPECT_TRUE(compilerOutputExists("myOutputFileName", "bin"));
|
||||
EXPECT_TRUE(compilerOutputExists("myOutputFileName", "gen"));
|
||||
EXPECT_TRUE(compilerOutputExists("myOutputFileName", "dbg"));
|
||||
|
||||
compilerOutputRemove("myOutputFileName", "bc");
|
||||
compilerOutputRemove("myOutputFileName", "bin");
|
||||
compilerOutputRemove("myOutputFileName", "gen");
|
||||
compilerOutputRemove("myOutputFileName", "dbg");
|
||||
|
||||
OCLRT::setIgcDebugVars(gEnvironment->igcDebugVars);
|
||||
}
|
||||
|
||||
TEST(OfflineCompilerTest, givenInternalOptionsWhenCmdLineParsedThenOptionsAreAppendedToInternalOptionsString) {
|
||||
const char *argv[] = {
|
||||
"cloc",
|
||||
|
@ -59,10 +59,11 @@ class ProgramWithKernelDebuggingTest : public ProgramSimpleFixture,
|
||||
KernelFilenameHelper::getKernelFilenameFromInternalOption(kernelOption, filename);
|
||||
|
||||
kbHelper = new KernelBinaryHelper(filename, false);
|
||||
CreateProgramWithSource(
|
||||
CreateProgramWithSource<MockProgram>(
|
||||
pContext,
|
||||
&device,
|
||||
"copybuffer.cl");
|
||||
mockProgram = reinterpret_cast<MockProgram *>(pProgram);
|
||||
pProgram->enableKernelDebug();
|
||||
}
|
||||
|
||||
@ -72,6 +73,7 @@ class ProgramWithKernelDebuggingTest : public ProgramSimpleFixture,
|
||||
}
|
||||
cl_device_id device;
|
||||
KernelBinaryHelper *kbHelper = nullptr;
|
||||
MockProgram *mockProgram = nullptr;
|
||||
};
|
||||
|
||||
TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsCompiledThenInternalOptionsIncludeDebugFlag) {
|
||||
@ -93,6 +95,18 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsCompi
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsCompiledThenInternalOptionsIncludeDashGFlag) {
|
||||
if (pDevice->getHardwareInfo().pPlatform->eRenderCoreFamily >= IGFX_GEN9_CORE) {
|
||||
cl_int retVal = pProgram->compile(1, &device, nullptr,
|
||||
0, nullptr, nullptr,
|
||||
nullptr,
|
||||
nullptr);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
EXPECT_THAT(pProgram->getOptions(), ::testing::HasSubstr("-g"));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsBuiltThenInternalOptionsIncludeDebugFlag) {
|
||||
if (pDevice->getHardwareInfo().pPlatform->eRenderCoreFamily >= IGFX_GEN9_CORE) {
|
||||
std::string receivedInternalOptions;
|
||||
@ -109,6 +123,14 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsBuilt
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsBuiltThenOptionsIncludeDashGFlag) {
|
||||
if (pDevice->getHardwareInfo().pPlatform->eRenderCoreFamily >= IGFX_GEN9_CORE) {
|
||||
cl_int retVal = pProgram->build(1, &device, nullptr, nullptr, nullptr, false);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
EXPECT_THAT(pProgram->getOptions(), ::testing::HasSubstr("-g"));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(ProgramWithKernelDebuggingTest, givenProgramWithKernelDebugEnabledWhenBuiltThenPatchTokenAllocateSipSurfaceHasSizeGreaterThanZero) {
|
||||
if (pDevice->getHardwareInfo().pPlatform->eRenderCoreFamily >= IGFX_GEN9_CORE) {
|
||||
retVal = pProgram->build(1, &device, CompilerOptions::debugKernelEnable, nullptr, nullptr, false);
|
||||
@ -118,3 +140,14 @@ TEST_F(ProgramWithKernelDebuggingTest, givenProgramWithKernelDebugEnabledWhenBui
|
||||
EXPECT_NE(0u, kernelInfo->patchInfo.pAllocateSystemThreadSurface->PerThreadSystemThreadSurfaceSize);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(ProgramWithKernelDebuggingTest, givenKernelDebugEnabledWhenProgramIsBuiltThenDebugDataIsStored) {
|
||||
if (pDevice->getHardwareInfo().pPlatform->eRenderCoreFamily >= IGFX_GEN9_CORE) {
|
||||
retVal = pProgram->build(1, &device, nullptr, nullptr, nullptr, false);
|
||||
|
||||
size_t debugDataSize = 0;
|
||||
auto debugData = mockProgram->getDebugDataBinary(debugDataSize);
|
||||
EXPECT_NE(nullptr, debugData);
|
||||
EXPECT_NE(0u, debugDataSize);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user