mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-20 00:24:58 +08:00
- 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
154 lines
6.4 KiB
C++
154 lines
6.4 KiB
C++
/*
|
|
* Copyright (c) 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"),
|
|
* to deal in the Software without restriction, including without limitation
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included
|
|
* in all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
|
|
#include "runtime/compiler_interface/compiler_options.h"
|
|
#include "unit_tests/fixtures/program_fixture.h"
|
|
#include "unit_tests/global_environment.h"
|
|
#include "unit_tests/helpers/kernel_binary_helper.h"
|
|
#include "unit_tests/helpers/kernel_filename_helper.h"
|
|
#include "unit_tests/mocks/mock_program.h"
|
|
#include "unit_tests/program/program_tests.h"
|
|
#include "unit_tests/program/program_from_binary.h"
|
|
#include "test.h"
|
|
#include "gmock/gmock-matchers.h"
|
|
#include <algorithm>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
using namespace OCLRT;
|
|
|
|
TEST_F(ProgramTests, givenDeafultProgramObjectWhenKernelDebugEnabledIsQueriedThenFalseIsReturned) {
|
|
MockProgram program(pContext, false);
|
|
EXPECT_FALSE(program.isKernelDebugEnabled());
|
|
}
|
|
|
|
TEST_F(ProgramTests, givenProgramObjectWhenEnableKernelDebugIsCalledThenProgramHasKernelDebugEnabled) {
|
|
MockProgram program(pContext, false);
|
|
program.enableKernelDebug();
|
|
EXPECT_TRUE(program.isKernelDebugEnabled());
|
|
}
|
|
|
|
class ProgramWithKernelDebuggingTest : public ProgramSimpleFixture,
|
|
public ::testing::Test {
|
|
public:
|
|
void SetUp() override {
|
|
ProgramSimpleFixture::SetUp();
|
|
device = pDevice;
|
|
|
|
std::string filename;
|
|
std::string kernelOption(CompilerOptions::debugKernelEnable);
|
|
KernelFilenameHelper::getKernelFilenameFromInternalOption(kernelOption, filename);
|
|
|
|
kbHelper = new KernelBinaryHelper(filename, false);
|
|
CreateProgramWithSource<MockProgram>(
|
|
pContext,
|
|
&device,
|
|
"copybuffer.cl");
|
|
mockProgram = reinterpret_cast<MockProgram *>(pProgram);
|
|
pProgram->enableKernelDebug();
|
|
}
|
|
|
|
void TearDown() override {
|
|
delete kbHelper;
|
|
ProgramSimpleFixture::TearDown();
|
|
}
|
|
cl_device_id device;
|
|
KernelBinaryHelper *kbHelper = nullptr;
|
|
MockProgram *mockProgram = nullptr;
|
|
};
|
|
|
|
TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsCompiledThenInternalOptionsIncludeDebugFlag) {
|
|
if (pDevice->getHardwareInfo().pPlatform->eRenderCoreFamily >= IGFX_GEN9_CORE) {
|
|
std::string receivedInternalOptions;
|
|
|
|
auto debugVars = OCLRT::getFclDebugVars();
|
|
debugVars.receivedInternalOptionsOutput = &receivedInternalOptions;
|
|
gEnvironment->fclPushDebugVars(debugVars);
|
|
|
|
cl_int retVal = pProgram->compile(1, &device, nullptr,
|
|
0, nullptr, nullptr,
|
|
nullptr,
|
|
nullptr);
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_THAT(receivedInternalOptions, ::testing::HasSubstr(CompilerOptions::debugKernelEnable));
|
|
gEnvironment->fclPopDebugVars();
|
|
}
|
|
}
|
|
|
|
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;
|
|
|
|
auto debugVars = OCLRT::getFclDebugVars();
|
|
debugVars.receivedInternalOptionsOutput = &receivedInternalOptions;
|
|
gEnvironment->fclPushDebugVars(debugVars);
|
|
|
|
cl_int retVal = pProgram->build(1, &device, nullptr, nullptr, nullptr, false);
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_THAT(receivedInternalOptions, ::testing::HasSubstr(CompilerOptions::debugKernelEnable));
|
|
gEnvironment->fclPopDebugVars();
|
|
}
|
|
}
|
|
|
|
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);
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
auto kernelInfo = pProgram->getKernelInfo("CopyBuffer");
|
|
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);
|
|
}
|
|
}
|