Kernel Source Level debugger support 2/n

- adding kernel debug option to build program
- program tests refactor
- pregenerated debug kernel for ULTs

Change-Id: I00152639148fd48c4f709dc7cd9c46392df567c8
This commit is contained in:
Hoppe, Mateusz
2018-03-15 18:13:52 +01:00
committed by sys_ocldev
parent 507544a999
commit 18eb0b5e64
9 changed files with 205 additions and 70 deletions

View File

@@ -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"),
@@ -22,6 +22,7 @@
#include "config.h"
#include "runtime/compiler_interface/compiler_interface.h"
#include "runtime/compiler_interface/compiler_options.h"
#include "runtime/os_interface/debug_settings_manager.h"
#include "runtime/platform/platform.h"
#include "runtime/helpers/validators.h"
@@ -91,6 +92,10 @@ cl_int Program::build(
break;
}
if (isKernelDebugEnabled()) {
internalOptions.append(CompilerOptions::debugKernelEnable);
}
internalOptions.append(platform()->peekCompilerExtensions());
inputArgs.pInput = (char *)(sourceCode.c_str());
inputArgs.InputSize = (uint32_t)sourceCode.size();

View File

@@ -230,6 +230,37 @@ 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)
get_filename_component(filename ${filepath} NAME)
get_filename_component(basename ${filepath} NAME_WE)
set(outputdir "${TargetDir}/${product}/test_files/${NEO_ARCH}/")
set(workdir "${CMAKE_CURRENT_SOURCE_DIR}/test_files/")
set(results)
foreach(arg ${ARGN})
string(REPLACE " " "_" argwospaces ${arg})
set(outputpath_base "${outputdir}/${argwospaces}_${product}")
set(output_files
${outputpath_base}.bc
${outputpath_base}.bin
${outputpath_base}.gen
)
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
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()
function(neo_gen_kernel_from_ll target product filepath output_name compile_options)
get_filename_component(filename ${filepath} NAME)
get_filename_component(basename ${filepath} NAME_WE)
@@ -267,6 +298,10 @@ 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"
)
@@ -346,9 +381,11 @@ foreach(GEN_NUM RANGE ${MAX_GEN})
if(MSVC OR CMAKE_SIZEOF_VOID_P EQUAL 8)
neo_gen_kernels(test_kernels_${PLATFORM_IT_LOWER} ${PLATFORM_IT_LOWER} ${TEST_KERNELS})
neo_gen_kernel_with_options(test_kernel_${PLATFORM_IT_LOWER} ${PLATFORM_IT_LOWER} ${TEST_KERNEL} ${TEST_KERNEL_options})
neo_gen_kernel_with_internal_options(test_kernel_internal_options_${PLATFORM_IT_LOWER} ${PLATFORM_IT_LOWER} ${TEST_KERNEL} ${TEST_KERNEL_internal_options})
add_dependencies(unit_tests test_kernels_${PLATFORM_IT_LOWER})
add_dependencies(unit_tests test_kernel_${PLATFORM_IT_LOWER})
add_dependencies(unit_tests test_kernel_internal_options_${PLATFORM_IT_LOWER})
set(sip_kernel_file_name)
set(sip_kernel_output_file)

View File

@@ -286,15 +286,15 @@ INSTANTIATE_TEST_CASE_P(KernelTests,
::testing::ValuesIn(BinaryFileNames),
::testing::ValuesIn(KernelNames)));
class KernelFromBinaryTest : public ProgramFromBinarySimpleTest,
class KernelFromBinaryTest : public ProgramSimpleFixture,
public MemoryManagementFixture {
public:
void SetUp() override {
MemoryManagementFixture::SetUp();
ProgramFromBinarySimpleTest::SetUp();
ProgramSimpleFixture::SetUp();
}
void TearDown() override {
ProgramFromBinarySimpleTest::TearDown();
ProgramSimpleFixture::TearDown();
MemoryManagementFixture::TearDown();
}
};

View File

@@ -35,6 +35,7 @@ set(IGDRCL_SRCS_tests_program
${CMAKE_CURRENT_SOURCE_DIR}/program_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/program_tests.h
${CMAKE_CURRENT_SOURCE_DIR}/program_with_block_kernels_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/program_with_kernel_debug_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/program_with_source.h
)
target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_program})

View File

@@ -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"),
@@ -82,16 +82,16 @@ class ProgramFromBinaryTest : public DeviceFixture,
};
////////////////////////////////////////////////////////////////////////////////
// ProgramFromBinarySimpleTest Test Fixture
// ProgramSimpleFixture Test Fixture
// Used to test the Program class, but not using parameters
////////////////////////////////////////////////////////////////////////////////
class ProgramFromBinarySimpleTest : public DeviceFixture,
public ContextFixture,
public ProgramFixture {
class ProgramSimpleFixture : public DeviceFixture,
public ContextFixture,
public ProgramFixture {
using ContextFixture::SetUp;
protected:
ProgramFromBinarySimpleTest() : retVal(CL_SUCCESS) {
public:
ProgramSimpleFixture() : retVal(CL_SUCCESS) {
}
void SetUp() override {
@@ -109,6 +109,7 @@ class ProgramFromBinarySimpleTest : public DeviceFixture,
DeviceFixture::TearDown();
}
protected:
cl_int retVal;
};
} // namespace OCLRT

View File

@@ -49,14 +49,24 @@
#include "gmock/gmock.h"
#include "elf/reader.h"
using namespace OCLRT;
void ProgramTests::SetUp() {
DeviceFixture::SetUp();
cl_device_id device = pDevice;
ContextFixture::SetUp(1, &device);
}
void ProgramTests::TearDown() {
ContextFixture::TearDown();
DeviceFixture::TearDown();
}
void CL_CALLBACK notifyFunc(
cl_program program,
void *userData) {
*((char *)userData) = 'a';
}
using namespace OCLRT;
std::vector<const char *> BinaryFileNames{
"CopyBuffer_simd32",
};
@@ -1300,15 +1310,15 @@ TEST_P(ProgramFromSourceTest, CreateWithSource_CreateLibrary) {
////////////////////////////////////////////////////////////////////////////////
// Program:: (PatchToken)
////////////////////////////////////////////////////////////////////////////////
class PatchTokenFromBinaryTest : public ProgramFromBinarySimpleTest,
class PatchTokenFromBinaryTest : public ProgramSimpleFixture,
public MemoryManagementFixture {
public:
void SetUp() override {
MemoryManagementFixture::SetUp();
ProgramFromBinarySimpleTest::SetUp();
ProgramSimpleFixture::SetUp();
}
void TearDown() override {
ProgramFromBinarySimpleTest::TearDown();
ProgramSimpleFixture::TearDown();
MemoryManagementFixture::TearDown();
}
};
@@ -1538,15 +1548,15 @@ TEST_F(PatchTokenTests, VmeKernelArg) {
delete pKernel;
}
class ProgramPatchTokenFromBinaryTest : public ProgramFromBinarySimpleTest,
class ProgramPatchTokenFromBinaryTest : public ProgramSimpleFixture,
public MemoryManagementFixture {
public:
void SetUp() override {
MemoryManagementFixture::SetUp();
ProgramFromBinarySimpleTest::SetUp();
ProgramSimpleFixture::SetUp();
}
void TearDown() override {
ProgramFromBinarySimpleTest::TearDown();
ProgramSimpleFixture::TearDown();
MemoryManagementFixture::TearDown();
}
};
@@ -1697,24 +1707,6 @@ INSTANTIATE_TEST_CASE_P(ProgramFromSourceTests,
::testing::ValuesIn(BinaryForSourceFileNames),
::testing::ValuesIn(KernelNames)));
class ProgramTests : public DeviceFixture,
public ::testing::Test,
public ContextFixture {
using ContextFixture::SetUp;
public:
void SetUp() override {
DeviceFixture::SetUp();
cl_device_id device = pDevice;
ContextFixture::SetUp(1, &device);
}
void TearDown() override {
ContextFixture::TearDown();
DeviceFixture::TearDown();
}
};
TEST_F(ProgramTests, ProgramCtorSetsProperInternalOptions) {
cl_int retVal = CL_DEVICE_NOT_FOUND;
auto defaultSetting = DebugManager.flags.DisableStatelessToStatefulOptimization.get();
@@ -2952,33 +2944,3 @@ TEST(SimpleProgramTests, givenDefaultProgramWhenSetDeviceIsCalledThenDeviceIsSet
pProgram.SetDevice(nullptr);
EXPECT_EQ(nullptr, pProgram.getDevicePtr());
}
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());
}
TEST_P(ProgramFromSourceTest, givenEnabledKernelDebugWhenProgramIsCompiledThenInternalOptionsIncludeDebugFlag) {
pProgram->enableKernelDebug();
cl_device_id device = pPlatform->getDevice(0);
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();
}

View File

@@ -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"),
@@ -21,10 +21,23 @@
*/
#pragma once
#include "unit_tests/fixtures/context_fixture.h"
#include "unit_tests/fixtures/device_fixture.h"
#include "gtest/gtest.h"
#include <vector>
extern std::vector<const char *> BinaryFileNames;
extern std::vector<const char *> SourceFileNames;
extern std::vector<const char *> BinaryForSourceFileNames;
extern std::vector<const char *> KernelNames;
class ProgramTests : public DeviceFixture,
public ::testing::Test,
public OCLRT::ContextFixture {
using OCLRT::ContextFixture::SetUp;
public:
void SetUp() override;
void TearDown() override;
};

View File

@@ -0,0 +1,116 @@
/*
* 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/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 fullName(CompilerOptions::debugKernelEnable);
// remove leading spaces
size_t position = fullName.find_first_not_of(" ");
std::string filename(fullName, position);
// replace space with underscore
std::replace(filename.begin(), filename.end(), ' ', '_');
kbHelper = new KernelBinaryHelper(filename, false);
CreateProgramWithSource(
pContext,
&device,
"copybuffer.cl");
pProgram->enableKernelDebug();
}
void TearDown() override {
delete kbHelper;
ProgramSimpleFixture::TearDown();
}
cl_device_id device;
KernelBinaryHelper *kbHelper = nullptr;
};
TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsCompiledThenInternalOptionsIncludeDebugFlag) {
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, givenEnabledKernelDebugWhenProgramIsBuiltThenInternalOptionsIncludeDebugFlag) {
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, givenProgramWithKernelDebugEnabledWhenBuiltThenPatchTokenAllocateSipSurfaceHasSizeGreaterThanZero) {
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);
}

View File

@@ -79,4 +79,4 @@ class ProgramFromSourceTest : public ContextFixture,
const char *KernelName;
cl_int retVal;
};
}
} // namespace OCLRT