From cc6fa3d1e11fa8e424af298337eeb86099e1d8fe Mon Sep 17 00:00:00 2001 From: "Hoppe, Mateusz" Date: Fri, 9 Mar 2018 14:40:31 +0100 Subject: [PATCH] Kernel source debugging support 1/n - new patch token - program debug compilation flag - sip kernel new methods for querying bti and debug surface size Change-Id: Icaddd15f269c4b76efdf926f2e346aa61cbaae02 --- offline_compiler/offline_compiler.cpp | 4 +- runtime/built_ins/sip.cpp | 6 ++ runtime/built_ins/sip.h | 12 ++++ runtime/compiler_interface/CMakeLists.txt | 2 + .../compiler_interface/compiler_options.cpp | 29 ++++++++ runtime/compiler_interface/compiler_options.h | 30 ++++++++ runtime/program/compile.cpp | 6 ++ runtime/program/kernel_info.cpp | 5 ++ runtime/program/kernel_info.h | 1 + runtime/program/patch_info.h | 2 + runtime/program/process_gen_binary.cpp | 11 +++ runtime/program/program.h | 10 ++- unit_tests/CMakeLists.txt | 71 +++++++++++++++++++ unit_tests/built_ins/sip_tests.cpp | 47 +++++++++++- unit_tests/gen9/CMakeLists.txt | 1 + unit_tests/gen9/sip_tests.cpp | 61 ++++++++++++++++ unit_tests/mocks/mock_program.h | 2 + .../offline_compiler_tests.cpp | 4 ++ unit_tests/program/kernel_data.cpp | 19 +++++ unit_tests/program/program_tests.cpp | 32 +++++++++ unit_tests/test_files/sip_dummy_kernel_32.ll | 1 + unit_tests/test_files/sip_dummy_kernel_64.ll | 5 +- 22 files changed, 356 insertions(+), 5 deletions(-) create mode 100644 runtime/compiler_interface/compiler_options.cpp create mode 100644 runtime/compiler_interface/compiler_options.h create mode 100644 unit_tests/gen9/sip_tests.cpp diff --git a/offline_compiler/offline_compiler.cpp b/offline_compiler/offline_compiler.cpp index 6ce94365b2..ccca0a7c40 100644 --- a/offline_compiler/offline_compiler.cpp +++ b/offline_compiler/offline_compiler.cpp @@ -265,7 +265,9 @@ std::string OfflineCompiler::getStringWithinDelimiters(const std::string &src) { start += strlen("R\"===("); size_t size = stop - start; - std::string dst(src, start, size); + std::string dst(src, start, size + 1); + dst[size] = '\0'; // put null char at the end + return dst; } diff --git a/runtime/built_ins/sip.cpp b/runtime/built_ins/sip.cpp index 23925089a9..67432cb319 100644 --- a/runtime/built_ins/sip.cpp +++ b/runtime/built_ins/sip.cpp @@ -30,6 +30,8 @@ namespace OCLRT { +const size_t SipKernel::maxDbgSurfaceSize = 0x49c000; // proper value should be taken from compiler when it's ready + const char *getSipKernelCompilerInternalOptions(SipKernelType kernel) { switch (kernel) { default: @@ -78,6 +80,10 @@ const char *getSipLlSrc(const Device &device) { SipKernel::SipKernel(SipKernelType type, Program *sipProgram) : type(type) { program.reset(sipProgram); + if (type == SipKernelType::DbgCsr || type == SipKernelType::DbgCsrLocal) { + debugSurfaceBti = 0; + debugSurfaceSize = SipKernel::maxDbgSurfaceSize; + } } GraphicsAllocation *SipKernel::getSipAllocation() const { diff --git a/runtime/built_ins/sip.h b/runtime/built_ins/sip.h index 8b127dc07f..38d95cdc2a 100644 --- a/runtime/built_ins/sip.h +++ b/runtime/built_ins/sip.h @@ -58,10 +58,22 @@ class SipKernel { return type; } + int32_t getDebugSurfaceBti() const { + return debugSurfaceBti; + } + + size_t getDebugSurfaceSize() const { + return debugSurfaceSize; + } + + static const size_t maxDbgSurfaceSize; + GraphicsAllocation *getSipAllocation() const; protected: SipKernelType type = SipKernelType::COUNT; std::unique_ptr program; + int32_t debugSurfaceBti = -1; + size_t debugSurfaceSize = 0; }; } diff --git a/runtime/compiler_interface/CMakeLists.txt b/runtime/compiler_interface/CMakeLists.txt index b56aee164e..9f4800abd1 100644 --- a/runtime/compiler_interface/CMakeLists.txt +++ b/runtime/compiler_interface/CMakeLists.txt @@ -24,6 +24,8 @@ set(RUNTIME_SRCS_COMPILER_INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/binary_cache.h ${CMAKE_CURRENT_SOURCE_DIR}/compiler_interface.cpp ${CMAKE_CURRENT_SOURCE_DIR}/compiler_interface.h + ${CMAKE_CURRENT_SOURCE_DIR}/compiler_options.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/compiler_options.h ${CMAKE_CURRENT_SOURCE_DIR}/compiler_interface.inl ${CMAKE_CURRENT_SOURCE_DIR}/create_main.cpp ) diff --git a/runtime/compiler_interface/compiler_options.cpp b/runtime/compiler_interface/compiler_options.cpp new file mode 100644 index 0000000000..90dbc730a3 --- /dev/null +++ b/runtime/compiler_interface/compiler_options.cpp @@ -0,0 +1,29 @@ +/* + * 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" + +namespace OCLRT { + +const char *CompilerOptions::debugKernelEnable = " -cl-kernel-debug-enable"; + +} // namespace OCLRT diff --git a/runtime/compiler_interface/compiler_options.h b/runtime/compiler_interface/compiler_options.h new file mode 100644 index 0000000000..6611bcf31f --- /dev/null +++ b/runtime/compiler_interface/compiler_options.h @@ -0,0 +1,30 @@ +/* + * 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. + */ + +#pragma once +#include + +namespace OCLRT { +struct CompilerOptions { + static const char *debugKernelEnable; +}; +} // namespace OCLRT diff --git a/runtime/program/compile.cpp b/runtime/program/compile.cpp index e68981296b..2da7ce2068 100644 --- a/runtime/program/compile.cpp +++ b/runtime/program/compile.cpp @@ -23,6 +23,7 @@ #include "config.h" #include "elf/writer.h" #include "runtime/compiler_interface/compiler_interface.h" +#include "runtime/compiler_interface/compiler_options.h" #include "runtime/platform/platform.h" #include "runtime/helpers/validators.h" #include "program.h" @@ -151,6 +152,11 @@ cl_int Program::compile( // set parameters for compilation internalOptions.append(platform()->peekCompilerExtensions()); + + if (isKernelDebugEnabled()) { + internalOptions.append(CompilerOptions::debugKernelEnable); + } + inputArgs.pInput = pCompileData; inputArgs.InputSize = (uint32_t)compileDataSize; inputArgs.pOptions = options.c_str(); diff --git a/runtime/program/kernel_info.cpp b/runtime/program/kernel_info.cpp index 61f874caa2..bc88278519 100644 --- a/runtime/program/kernel_info.cpp +++ b/runtime/program/kernel_info.cpp @@ -413,6 +413,11 @@ void KernelInfo::storePatchToken(const SPatchKernelAttributesInfo *pKernelAttrib } } +void KernelInfo::storePatchToken(const SPatchAllocateSystemThreadSurface *pSystemThreadSurface) { + usesSsh |= true; + patchInfo.pAllocateSystemThreadSurface = pSystemThreadSurface; +} + const char *KernelInfo::queryPrintfString(uint32_t index) const { auto printfInfo = patchInfo.stringDataMap.find(index); return printfInfo == patchInfo.stringDataMap.end() ? nullptr : printfInfo->second.pStringData; diff --git a/runtime/program/kernel_info.h b/runtime/program/kernel_info.h index df4c7fa151..4674f74b09 100644 --- a/runtime/program/kernel_info.h +++ b/runtime/program/kernel_info.h @@ -153,6 +153,7 @@ struct KernelInfo { void storePatchToken(const SPatchAllocateStatelessDefaultDeviceQueueSurface *pStatelessDefaultDeviceQueueSurfaceArg); void storePatchToken(const SPatchString *pStringArg); void storePatchToken(const SPatchKernelAttributesInfo *pKernelAttributesInfo); + void storePatchToken(const SPatchAllocateSystemThreadSurface *pSystemThreadSurface); GraphicsAllocation *getGraphicsAllocation() const { return this->kernelAllocation; } cl_int resolveKernelInfo(); void resizeKernelArgInfoAndRegisterParameter(uint32_t argCount) { diff --git a/runtime/program/patch_info.h b/runtime/program/patch_info.h index 170559b50c..df20d3b0ba 100644 --- a/runtime/program/patch_info.h +++ b/runtime/program/patch_info.h @@ -56,6 +56,7 @@ using iOpenCL::SPatchAllocateStatelessDefaultDeviceQueueSurface; using iOpenCL::SPatchString; using iOpenCL::SPatchGtpinFreeGRFInfo; using iOpenCL::SPatchStateSIP; +using iOpenCL::SPatchAllocateSystemThreadSurface; typedef struct TagPrintfStringInfo { size_t SizeInBytes; @@ -86,6 +87,7 @@ struct PatchInfo { const SPatchAllocateStatelessPrintfSurface *pAllocateStatelessPrintfSurface = nullptr; const SPatchAllocateStatelessEventPoolSurface *pAllocateStatelessEventPoolSurface = nullptr; const SPatchAllocateStatelessDefaultDeviceQueueSurface *pAllocateStatelessDefaultDeviceQueueSurface = nullptr; + const SPatchAllocateSystemThreadSurface *pAllocateSystemThreadSurface = nullptr; ::std::map stringDataMap; ::std::vector kernelArgumentInfo; diff --git a/runtime/program/process_gen_binary.cpp b/runtime/program/process_gen_binary.cpp index 06e5a59758..6cebf142b5 100644 --- a/runtime/program/process_gen_binary.cpp +++ b/runtime/program/process_gen_binary.cpp @@ -755,6 +755,17 @@ cl_int Program::parsePatchList(KernelInfo &kernelInfo) { "\n .SystemKernelOffset", pPatchToken->SystemKernelOffset); } break; + case PATCH_TOKEN_ALLOCATE_SIP_SURFACE: { + auto *pPatchToken = reinterpret_cast(pPatch); + kernelInfo.storePatchToken(pPatchToken); + DBG_LOG(LogPatchTokens, + "\n.PATCH_TOKEN_ALLOCATE_SIP_SURFACE", pPatch->Token, + "\n .Size", pPatch->Size, + "\n .BTI", pPatchToken->BTI, + "\n .Offset", pPatchToken->Offset, + "\n .PerThreadSystemThreadSurfaceSize", pPatchToken->PerThreadSystemThreadSurfaceSize); + } break; + default: printDebugString(DebugManager.flags.PrintDebugMessages.get(), stderr, " Program::parsePatchList. Unknown Patch Token: %d\n", pPatch->Token); if (false == isSafeToSkipUnhandledToken(pPatch->Token)) { diff --git a/runtime/program/program.h b/runtime/program/program.h index fbc86e1e56..e4709bf315 100644 --- a/runtime/program/program.h +++ b/runtime/program/program.h @@ -235,6 +235,10 @@ class Program : public BaseObject<_cl_program> { return programOptionVersion; } + void enableKernelDebug() { + kernelDebugEnabled = true; + } + static bool isValidLlvmBinary(const void *pBinary, size_t binarySize); static bool isValidSpirvBinary(const void *pBinary, size_t binarySize); @@ -276,6 +280,10 @@ class Program : public BaseObject<_cl_program> { void updateNonUniformFlag(); void updateNonUniformFlag(const Program **inputProgram, size_t numInputPrograms); + bool isKernelDebugEnabled() { + return kernelDebugEnabled; + } + static const std::string clOptNameClVer; static const std::string clOptNameUniformWgs; // clang-format off @@ -326,7 +334,7 @@ class Program : public BaseObject<_cl_program> { cl_uint numDevices; bool isBuiltIn; - + bool kernelDebugEnabled = false; friend class OfflineCompiler; // clang-format on }; diff --git a/unit_tests/CMakeLists.txt b/unit_tests/CMakeLists.txt index e116a86f62..10a420cd30 100644 --- a/unit_tests/CMakeLists.txt +++ b/unit_tests/CMakeLists.txt @@ -384,6 +384,45 @@ function(neo_gen_kernel_with_options target gen filepath) set_target_properties(${target} PROPERTIES FOLDER "kernels/${gen}") endfunction() +function(neo_gen_kernel_from_ll target gen filepath output_name compile_options) + get_filename_component(filename ${filepath} NAME) + get_filename_component(basename ${filepath} NAME_WE) + + set(outputdir "${TargetDir}/${gen}/test_files/${NEO_ARCH}") + set(workdir "${CMAKE_CURRENT_SOURCE_DIR}/test_files/") + + set(results) + set(outputpath_base "${outputdir}/${output_name}_${gen}") + set(output_files + ${outputpath_base}.bin + ${outputpath_base}.gen + ) + + string(CONCAT compile_options \" ${compile_options} \" ) + set(cmd "LD_LIBRARY_PATH=$ $ -q -file ${filename} -output ${output_name} -device ${gen} -${NEO_BITS} -out_dir ${outputdir} -internal_options ${compile_options} -llvm_input") + + if(MSVC) + add_custom_command( + OUTPUT ${output_files} + COMMAND cloc -q -file ${filename} -output ${output_name} -device ${gen} -${NEO_BITS} -out_dir ${outputdir} -internal_options ${compile_options} -llvm_input + WORKING_DIRECTORY ${workdir} + DEPENDS ${filepath} cloc + ) + else() + add_custom_command( + OUTPUT ${output_files} + COMMAND LD_LIBRARY_PATH=$ $ -q -file ${filename} -output ${output_name} -device ${gen} -${NEO_BITS} -out_dir ${outputdir} -internal_options ${compile_options} -llvm_input + WORKING_DIRECTORY ${workdir} + DEPENDS ${filepath} cloc + ) + endif() + + list(APPEND results ${output_files}) + + add_custom_target(${target} DEPENDS ${results} copy_compiler_files) + set_target_properties(${target} PROPERTIES FOLDER "kernels/${gen}") +endfunction() + set(TEST_KERNEL test_files/CopyBuffer_simd8.cl) set(TEST_KERNEL_options @@ -401,6 +440,14 @@ set(TEST_KERNEL_2_0 test_files/simple_block_kernel.cl ) +set(TEST_KERNEL_SIP_DEBUG_options + "-cl-include-sip-kernel-debug -cl-include-sip-csr -cl-set-bti:0" +) + +set(TEST_KERNEL_SIP_DEBUG_LOCAL_options + "-cl-include-sip-kernel-local-debug -cl-include-sip-csr -cl-set-bti:0" +) + set(TEST_KERNELS test_files/15895692906525787409.cl test_files/copybuffer.cl @@ -464,8 +511,32 @@ foreach(GEN_NUM RANGE 0 ${MAX_GEN} 1) 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}) + add_dependencies(unit_tests test_kernels_${PLATFORM_IT_LOWER}) add_dependencies(unit_tests test_kernel_${PLATFORM_IT_LOWER}) + + set(sip_kernel_file_name) + set(sip_kernel_output_file) + set(sip_debug_kernel_output_file) + set(sip_debug_local_kernel_output_file) + if(${NEO_BITS} EQUAL "32") + list(APPEND sip_kernel_file_name "test_files/sip_dummy_kernel_32.ll") + list(APPEND sip_debug_kernel_output_file "sip_dummy_kernel_debug_32") + list(APPEND sip_debug_local_kernel_output_file "sip_dummy_kernel_debug_local_32") + else() + list(APPEND sip_kernel_file_name "test_files/sip_dummy_kernel_64.ll") + list(APPEND sip_debug_kernel_output_file "sip_dummy_kernel_debug_64") + list(APPEND sip_debug_local_kernel_output_file "sip_dummy_kernel_debug_local_64") + endif() + + if("gen${GEN_NUM}" STREQUAL "gen9" ) + neo_gen_kernel_from_ll(test_kernel_sip_debug_local_${PLATFORM_IT_LOWER} ${PLATFORM_IT_LOWER} ${sip_kernel_file_name} ${sip_debug_local_kernel_output_file} ${TEST_KERNEL_SIP_DEBUG_LOCAL_options}) + add_dependencies(unit_tests test_kernel_sip_debug_local_${PLATFORM_IT_LOWER}) + endif() + + neo_gen_kernel_from_ll(test_kernel_sip_debug_${PLATFORM_IT_LOWER} ${PLATFORM_IT_LOWER} ${sip_kernel_file_name} ${sip_debug_kernel_output_file} ${TEST_KERNEL_SIP_DEBUG_options}) + add_dependencies(unit_tests test_kernel_sip_debug_${PLATFORM_IT_LOWER}) + if(${PLATFORM_SUPPORTS_2_0}) neo_gen_kernel_with_options(test_kernel_2_0_${PLATFORM_IT_LOWER} ${PLATFORM_IT_LOWER} ${TEST_KERNEL_2_0} ${TEST_KERNEL_2_0_options}) add_dependencies(unit_tests test_kernel_2_0_${PLATFORM_IT_LOWER}) diff --git a/unit_tests/built_ins/sip_tests.cpp b/unit_tests/built_ins/sip_tests.cpp index fb98bc21bb..31e353e1c5 100644 --- a/unit_tests/built_ins/sip_tests.cpp +++ b/unit_tests/built_ins/sip_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * 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"), @@ -23,13 +23,30 @@ #include "gtest/gtest.h" #include "test.h" +#include "runtime/built_ins/built_ins.h" #include "runtime/built_ins/sip.h" +#include "unit_tests/global_environment.h" +#include "unit_tests/helpers/test_files.h" #include "unit_tests/mocks/mock_device.h" #include "unit_tests/mocks/mock_device_factory.h" #include "unit_tests/mocks/mock_program.h" using namespace OCLRT; +namespace SipKernelTests { +std::string getDebugSipKernelNameWithBitnessAndProductSuffix(std::string &base, const char *product) { + std::string fullName = base + std::string("_"); + + if (sizeof(uintptr_t) == 8) { + fullName.append("64_"); + } else { + fullName.append("32_"); + } + + fullName.append(product); + return fullName; +} + TEST(Sip, WhenSipKernelIsInvalidThenEmptyCompilerInternalOptionsAreReturned) { const char *opt = getSipKernelCompilerInternalOptions(SipKernelType::COUNT); ASSERT_NE(nullptr, opt); @@ -93,6 +110,10 @@ TEST(Sip, getType) { EXPECT_EQ(SipKernelType::COUNT, undefined.getType()); } +TEST(Sip, givenSipKernelClassWhenAskedForMaxDebugSurfaceSizeThenCorrectValueIsReturned) { + EXPECT_EQ(0x49c000u, SipKernel::maxDbgSurfaceSize); +} + TEST(DebugSip, WhenRequestingDbgCsrSipKernelThenProperCompilerInternalOptionsAreReturned) { const char *opt = getSipKernelCompilerInternalOptions(SipKernelType::DbgCsr); ASSERT_NE(nullptr, opt); @@ -104,3 +125,27 @@ TEST(DebugSip, WhenRequestingDbgCsrWithLocalMemorySipKernelThenProperCompilerInt ASSERT_NE(nullptr, opt); EXPECT_STREQ("-cl-include-sip-kernel-local-debug -cl-include-sip-csr -cl-set-bti:0", opt); } + +TEST(DebugSip, givenDebugCsrSipKernelWhenAskedForDebugSurfaceBtiAndSizeThenBtiIsZeroAndSizeGreaterThanZero) { + auto mockDevice = std::unique_ptr(Device::create(nullptr)); + EXPECT_NE(nullptr, mockDevice); + MockCompilerDebugVars igcDebugVars; + + auto product = mockDevice->getProductAbbrev(); + std::string name = "sip_dummy_kernel_debug"; + std::string builtInFileRoot = testFiles + getDebugSipKernelNameWithBitnessAndProductSuffix(name, product); + std::string builtInGenFile = builtInFileRoot; + builtInGenFile.append(".gen"); + + igcDebugVars.fileName = builtInGenFile; + gEnvironment->igcPushDebugVars(igcDebugVars); + + auto &builtins = BuiltIns::getInstance(); + auto &sipKernel = builtins.getSipKernel(SipKernelType::DbgCsr, *mockDevice); + + EXPECT_EQ((int32_t)0, sipKernel.getDebugSurfaceBti()); + EXPECT_EQ(SipKernel::maxDbgSurfaceSize, sipKernel.getDebugSurfaceSize()); + + gEnvironment->igcPopDebugVars(); +} +} // namespace SipKernelTests \ No newline at end of file diff --git a/unit_tests/gen9/CMakeLists.txt b/unit_tests/gen9/CMakeLists.txt index bbc9f72603..a35f58ad79 100644 --- a/unit_tests/gen9/CMakeLists.txt +++ b/unit_tests/gen9/CMakeLists.txt @@ -28,6 +28,7 @@ set(IGDRCL_SRCS_tests_gen9 ${CMAKE_CURRENT_SOURCE_DIR}/hw_helper_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/image_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/sampler_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/sip_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_device_caps.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_device_queue_hw.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_platform_caps.cpp diff --git a/unit_tests/gen9/sip_tests.cpp b/unit_tests/gen9/sip_tests.cpp new file mode 100644 index 0000000000..4a88408ec9 --- /dev/null +++ b/unit_tests/gen9/sip_tests.cpp @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2017, 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 "gtest/gtest.h" +#include "test.h" + +#include "runtime/built_ins/built_ins.h" +#include "runtime/built_ins/sip.h" +#include "unit_tests/global_environment.h" +#include "unit_tests/helpers/test_files.h" +#include "unit_tests/mocks/mock_device.h" + +using namespace OCLRT; + +namespace SipKernelTests { +extern std::string getDebugSipKernelNameWithBitnessAndProductSuffix(std::string &base, const char *product); + +typedef ::testing::Test gen9SipTests; + +GEN9TEST_F(gen9SipTests, givenDebugCsrSipKernelWithLocalMemoryWhenAskedForDebugSurfaceBtiAndSizeThenBtiIsZeroAndSizeGreaterThanZero) { + auto mockDevice = std::unique_ptr(Device::create(nullptr)); + EXPECT_NE(nullptr, mockDevice); + MockCompilerDebugVars igcDebugVars; + + auto product = mockDevice->getProductAbbrev(); + std::string name = "sip_dummy_kernel_debug"; + std::string builtInFileRoot = testFiles + getDebugSipKernelNameWithBitnessAndProductSuffix(name, product); + std::string builtInGenFile = builtInFileRoot; + builtInGenFile.append(".gen"); + + igcDebugVars.fileName = builtInGenFile; + gEnvironment->igcPushDebugVars(igcDebugVars); + + auto &builtins = BuiltIns::getInstance(); + auto &sipKernel = builtins.getSipKernel(SipKernelType::DbgCsrLocal, *mockDevice); + + EXPECT_EQ((int32_t)0, sipKernel.getDebugSurfaceBti()); + EXPECT_EQ(SipKernel::maxDbgSurfaceSize, sipKernel.getDebugSurfaceSize()); + + gEnvironment->igcPopDebugVars(); +} +} // namespace SipKernelTests diff --git a/unit_tests/mocks/mock_program.h b/unit_tests/mocks/mock_program.h index f11caf08e2..04d651b5bb 100644 --- a/unit_tests/mocks/mock_program.h +++ b/unit_tests/mocks/mock_program.h @@ -35,6 +35,8 @@ class GraphicsAllocation; //////////////////////////////////////////////////////////////////////////////// class MockProgram : public Program { public: + using Program::isKernelDebugEnabled; + MockProgram() : Program() {} MockProgram(Context *context, bool isBuiltinKernel) : Program(context, isBuiltinKernel) {} ~MockProgram() { diff --git a/unit_tests/offline_compiler/offline_compiler_tests.cpp b/unit_tests/offline_compiler/offline_compiler_tests.cpp index d3c6727dc1..d2465e1218 100644 --- a/unit_tests/offline_compiler/offline_compiler_tests.cpp +++ b/unit_tests/offline_compiler/offline_compiler_tests.cpp @@ -395,6 +395,10 @@ TEST(OfflineCompilerTest, getStringWithinDelimiters) { auto dst = mockOfflineCompiler->getStringWithinDelimiters(src); + size_t size = dst.size(); + char nullChar = '\0'; + EXPECT_EQ(nullChar, dst[size - 1]); + // expect that pattern was not found EXPECT_EQ(std::string::npos, dst.find("R\"===(")); EXPECT_EQ(std::string::npos, dst.find(")===\"")); diff --git a/unit_tests/program/kernel_data.cpp b/unit_tests/program/kernel_data.cpp index 4585f8af07..c3442b7fbf 100644 --- a/unit_tests/program/kernel_data.cpp +++ b/unit_tests/program/kernel_data.cpp @@ -1233,3 +1233,22 @@ TEST_F(KernelDataTest, PATCH_TOKEN_STATE_SIP) { EXPECT_EQ_VAL(token.SystemKernelOffset, pKernelInfo->systemKernelOffset); } + +TEST_F(KernelDataTest, PATCH_TOKEN_ALLOCATE_SIP_SURFACE) { + SPatchAllocateSystemThreadSurface token; + token.Token = PATCH_TOKEN_ALLOCATE_SIP_SURFACE; + token.Size = static_cast(sizeof(SPatchAllocateSystemThreadSurface)); + token.Offset = 32; + token.BTI = 0; + token.PerThreadSystemThreadSurfaceSize = 0x10000; + + pPatchList = &token; + patchListSize = token.Size; + + buildAndDecode(); + + EXPECT_EQ(0u, pKernelInfo->patchInfo.pAllocateSystemThreadSurface->BTI); + EXPECT_EQ(token.Offset, pKernelInfo->patchInfo.pAllocateSystemThreadSurface->Offset); + EXPECT_EQ(token.Token, pKernelInfo->patchInfo.pAllocateSystemThreadSurface->Token); + EXPECT_EQ(token.PerThreadSystemThreadSurfaceSize, pKernelInfo->patchInfo.pAllocateSystemThreadSurface->PerThreadSystemThreadSurfaceSize); +} diff --git a/unit_tests/program/program_tests.cpp b/unit_tests/program/program_tests.cpp index 7c1b8966b6..bb51b4f0cf 100644 --- a/unit_tests/program/program_tests.cpp +++ b/unit_tests/program/program_tests.cpp @@ -21,6 +21,7 @@ */ #include "runtime/kernel/kernel.h" #include "runtime/command_stream/command_stream_receiver_hw.h" +#include "runtime/compiler_interface/compiler_options.h" #include "unit_tests/libult/ult_command_stream_receiver.h" #include "runtime/indirect_heap/indirect_heap.h" #include "runtime/helpers/aligned_memory.h" @@ -33,6 +34,7 @@ #include "runtime/program/create.inl" #include "program_tests.h" #include "unit_tests/fixtures/program_fixture.inl" +#include "unit_tests/global_environment.h" #include "unit_tests/helpers/kernel_binary_helper.h" #include "unit_tests/mocks/mock_kernel.h" #include "unit_tests/program/program_from_binary.h" @@ -2929,3 +2931,33 @@ 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(); +} diff --git a/unit_tests/test_files/sip_dummy_kernel_32.ll b/unit_tests/test_files/sip_dummy_kernel_32.ll index f054c27647..fd9aa45106 100644 --- a/unit_tests/test_files/sip_dummy_kernel_32.ll +++ b/unit_tests/test_files/sip_dummy_kernel_32.ll @@ -36,4 +36,5 @@ define void @f() { !5 = !{!"kernel_arg_type_qual"} !6 = !{!"kernel_arg_base_type"} !7 = !{!"kernel_arg_name"} + )===" \ No newline at end of file diff --git a/unit_tests/test_files/sip_dummy_kernel_64.ll b/unit_tests/test_files/sip_dummy_kernel_64.ll index 397e4c0cc8..520a621353 100644 --- a/unit_tests/test_files/sip_dummy_kernel_64.ll +++ b/unit_tests/test_files/sip_dummy_kernel_64.ll @@ -23,8 +23,8 @@ R"===( target datalayout = "e-p:64:64:64" target triple = "spir64" -define void @f() { - ret void +define void @f() { + ret void } !opencl.compiler.options = !{!0} !opencl.kernels = !{!1} @@ -36,4 +36,5 @@ define void @f() { !5 = !{!"kernel_arg_type_qual"} !6 = !{!"kernel_arg_base_type"} !7 = !{!"kernel_arg_name"} + )===" \ No newline at end of file