diff --git a/opencl/test/unit_test/offline_compiler/gen8/CMakeLists.txt b/opencl/test/unit_test/offline_compiler/gen8/CMakeLists.txt new file mode 100644 index 0000000000..c6b637f3ec --- /dev/null +++ b/opencl/test/unit_test/offline_compiler/gen8/CMakeLists.txt @@ -0,0 +1,14 @@ +# +# Copyright (C) 2021 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +if(TESTS_GEN8) + set(IGDRCL_SRCS_offline_compiler_tests_gen8 + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/offline_compiler_tests_gen8.cpp + ) + target_sources(ocloc_tests PRIVATE ${IGDRCL_SRCS_offline_compiler_tests_gen8}) + add_subdirectories() +endif() diff --git a/opencl/test/unit_test/offline_compiler/gen8/offline_compiler_tests_gen8.cpp b/opencl/test/unit_test/offline_compiler/gen8/offline_compiler_tests_gen8.cpp new file mode 100644 index 0000000000..6ae9f6d02e --- /dev/null +++ b/opencl/test/unit_test/offline_compiler/gen8/offline_compiler_tests_gen8.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "opencl/test/unit_test/offline_compiler/mock/mock_offline_compiler.h" +#include "opencl/test/unit_test/offline_compiler/offline_compiler_tests.h" + +#include "gmock/gmock.h" + +namespace NEO { + +TEST_F(OfflineCompilerTests, givenDebugOptionWhenPlatformIsBelowGen9ThenInternalOptionShouldNotContainKernelDebugEnable) { + std::vector argv = { + "ocloc", + "-options", + "-g", + "-file", + "test_files/copybuffer.cl", + "-device", + "bdw"}; + + auto mockOfflineCompiler = std::unique_ptr(new MockOfflineCompiler()); + ASSERT_NE(nullptr, mockOfflineCompiler); + mockOfflineCompiler->initialize(argv.size(), argv); + + std::string internalOptions = mockOfflineCompiler->internalOptions; + + EXPECT_THAT(internalOptions, Not(::testing::HasSubstr("-cl-kernel-debug-enable"))); +} +} // namespace NEO \ No newline at end of file diff --git a/opencl/test/unit_test/offline_compiler/offline_compiler_tests.cpp b/opencl/test/unit_test/offline_compiler/offline_compiler_tests.cpp index 39d7f64882..30a4c637c3 100644 --- a/opencl/test/unit_test/offline_compiler/offline_compiler_tests.cpp +++ b/opencl/test/unit_test/offline_compiler/offline_compiler_tests.cpp @@ -31,6 +31,29 @@ extern Environment *gEnvironment; namespace NEO { +void MultiCommandTests::createFileWithArgs(const std::vector &singleArgs, int numOfBuild) { + std::ofstream myfile(nameOfFileWithArgs); + if (myfile.is_open()) { + for (int i = 0; i < numOfBuild; i++) { + for (auto singleArg : singleArgs) + myfile << singleArg + " "; + myfile << std::endl; + } + myfile.close(); + } else + printf("Unable to open file\n"); +} + +void MultiCommandTests::deleteFileWithArgs() { + if (remove(nameOfFileWithArgs.c_str()) != 0) + perror("Error deleting file"); +} + +void MultiCommandTests::deleteOutFileList() { + if (remove(outFileList.c_str()) != 0) + perror("Error deleting file"); +} + std::string getCompilerOutputFileName(const std::string &fileName, const std::string &type) { std::string fName(fileName); fName.append("_"); @@ -295,6 +318,28 @@ TEST_F(OfflineCompilerTests, givenIncorrectDeviceIdWithIncorrectHexPatternThenIn EXPECT_EQ(CL_INVALID_DEVICE, retVal); } +TEST_F(OfflineCompilerTests, givenDebugOptionThenInternalOptionShouldContainKernelDebugEnable) { + if (gEnvironment->devicePrefix == "bdw") { + GTEST_SKIP(); + } + + std::vector argv = { + "ocloc", + "-options", + "-g", + "-file", + "test_files/copybuffer.cl", + "-device", + gEnvironment->devicePrefix.c_str()}; + + auto mockOfflineCompiler = std::unique_ptr(new MockOfflineCompiler()); + ASSERT_NE(nullptr, mockOfflineCompiler); + mockOfflineCompiler->initialize(argv.size(), argv); + + std::string internalOptions = mockOfflineCompiler->internalOptions; + EXPECT_THAT(internalOptions, ::testing::HasSubstr("-cl-kernel-debug-enable")); +} + TEST_F(OfflineCompilerTests, givenVariousClStdValuesWhenCompilingSourceThenCorrectExtensionsArePassed) { std::string clStdOptionValues[] = {"", "-cl-std=CL1.2", "-cl-std=CL2.0", "-cl-std=CL3.0"}; diff --git a/opencl/test/unit_test/offline_compiler/offline_compiler_tests.h b/opencl/test/unit_test/offline_compiler/offline_compiler_tests.h index 28add9e15b..3e74da4244 100644 --- a/opencl/test/unit_test/offline_compiler/offline_compiler_tests.h +++ b/opencl/test/unit_test/offline_compiler/offline_compiler_tests.h @@ -34,28 +34,4 @@ class MultiCommandTests : public ::testing::Test { int retVal = OfflineCompiler::ErrorCode::SUCCESS; std::unique_ptr oclocArgHelperWithoutInput = std::make_unique(); }; - -void MultiCommandTests::createFileWithArgs(const std::vector &singleArgs, int numOfBuild) { - std::ofstream myfile(nameOfFileWithArgs); - if (myfile.is_open()) { - for (int i = 0; i < numOfBuild; i++) { - for (auto singleArg : singleArgs) - myfile << singleArg + " "; - myfile << std::endl; - } - myfile.close(); - } else - printf("Unable to open file\n"); -} - -void MultiCommandTests::deleteFileWithArgs() { - if (remove(nameOfFileWithArgs.c_str()) != 0) - perror("Error deleting file"); -} - -void MultiCommandTests::deleteOutFileList() { - if (remove(outFileList.c_str()) != 0) - perror("Error deleting file"); -} - } // namespace NEO diff --git a/shared/offline_compiler/source/offline_compiler.cpp b/shared/offline_compiler/source/offline_compiler.cpp index 4a22d3b713..d5841ffe89 100644 --- a/shared/offline_compiler/source/offline_compiler.cpp +++ b/shared/offline_compiler/source/offline_compiler.cpp @@ -405,6 +405,13 @@ int OfflineCompiler::initialize(size_t numArgs, const std::vector & argHelper->printf("Error: Cannot get HW Info for device %s.\n", deviceName.c_str()); return retVal; } + + if (options.find(CompilerOptions::generateDebugInfo.str()) != std::string::npos) { + if (hwInfo.platform.eRenderCoreFamily >= IGFX_GEN9_CORE) { + internalOptions = CompilerOptions::concatenate(internalOptions, CompilerOptions::debugKernelEnable); + } + } + if (deviceName.empty()) { internalOptions = CompilerOptions::concatenate("-ocl-version=300 -cl-ext=-all,+cl_khr_3d_image_writes", internalOptions); CompilerOptions::concatenateAppend(internalOptions, CompilerOptions::enableImageSupport);