Refactor per platform extra settings in ocloc

Signed-off-by: Kamil Kopryk <kamil.kopryk@intel.com>
Related-To: NEO-6382
This commit is contained in:
Kamil Kopryk
2021-10-26 15:25:20 +00:00
committed by Compute-Runtime-Automation
parent 515130dbe8
commit 03540d5301
35 changed files with 359 additions and 138 deletions

View File

@ -66,6 +66,7 @@ set(IGDRCL_SRCS_offline_compiler_tests
${NEO_SHARED_TEST_DIRECTORY}/common/mocks/mock_compilers.h
${NEO_SHARED_TEST_DIRECTORY}/unit_test/device_binary_format/zebin_tests.h
${NEO_SHARED_TEST_DIRECTORY}/common/helpers/test_files.cpp
${NEO_SHARED_TEST_DIRECTORY}/common/test_macros/test_excludes.cpp
${IGDRCL_SRCS_cloc}
${IGDRCL_SRCS_offline_compiler_mock}
${NEO_CORE_tests_compiler_mocks}
@ -90,9 +91,11 @@ link_directories(${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
add_executable(ocloc_tests ${IGDRCL_SRCS_offline_compiler_tests})
target_include_directories(ocloc_tests PRIVATE
${NEO_SHARED_TEST_DIRECTORY}/common/test_macros/header${BRANCH_DIR_SUFFIX}
${NEO_SHARED_TEST_DIRECTORY}/common/test_configuration/unit_tests
$<TARGET_PROPERTY:ocloc_lib,INCLUDE_DIRECTORIES>
)
target_compile_definitions(ocloc_tests PUBLIC MOCKABLE_VIRTUAL=virtual $<TARGET_PROPERTY:ocloc_lib,INTERFACE_COMPILE_DEFINITIONS>)
target_compile_definitions(ocloc_tests PUBLIC MOCKABLE_VIRTUAL=virtual $<TARGET_PROPERTY:ocloc_lib,INTERFACE_COMPILE_DEFINITIONS> ${TESTED_GEN_FLAGS_DEFINITONS})
target_link_libraries(ocloc_tests gmock-gtest)

View File

@ -0,0 +1,13 @@
#
# Copyright (C) 2021 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
if(TESTS_GEN12LP)
set(IGDRCL_SRCS_offline_compiler_tests_gen12lp
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
)
target_sources(ocloc_tests PRIVATE ${IGDRCL_SRCS_offline_compiler_tests_gen12lp})
add_subdirectories()
endif()

View File

@ -0,0 +1,13 @@
#
# Copyright (C) 2021 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
if(TESTS_RKL)
set(IGDRCL_SRCS_offline_compiler_tests_rkl
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/offline_compiler_tests_rkl.cpp
)
target_sources(ocloc_tests PRIVATE ${IGDRCL_SRCS_offline_compiler_tests_rkl})
endif()

View File

@ -0,0 +1,26 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/compiler_interface/compiler_options/compiler_options.h"
#include "opencl/test/unit_test/offline_compiler/mock/mock_offline_compiler.h"
#include "opencl/test/unit_test/offline_compiler/offline_compiler_tests.h"
#include "test.h"
using namespace NEO;
using MockOfflineCompilerRklTests = ::testing::Test;
RKLTEST_F(MockOfflineCompilerRklTests, givenRklWhenAppendExtraInternalOptionsThenForceEmuInt32DivRemSPIsApplied) {
MockOfflineCompiler mockOfflineCompiler;
mockOfflineCompiler.deviceName = " rkl";
mockOfflineCompiler.initHardwareInfo(mockOfflineCompiler.deviceName);
std::string internalOptions = mockOfflineCompiler.internalOptions;
mockOfflineCompiler.appendExtraInternalOptions(mockOfflineCompiler.hwInfo, internalOptions);
size_t found = internalOptions.find(NEO::CompilerOptions::forceEmuInt32DivRemSP.data());
EXPECT_NE(std::string::npos, found);
}

View File

@ -7,8 +7,9 @@
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()

View File

@ -0,0 +1,14 @@
#
# Copyright (C) 2021 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
if(TESTS_BDW)
set(IGDRCL_SRCS_offline_compiler_tests_bdw
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/offline_compiler_tests_bdw.cpp
)
target_sources(ocloc_tests PRIVATE ${IGDRCL_SRCS_offline_compiler_tests_bdw})
endif()

View File

@ -0,0 +1,50 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/compiler_interface/compiler_options/compiler_options.h"
#include "opencl/test/unit_test/offline_compiler/mock/mock_offline_compiler.h"
#include "opencl/test/unit_test/offline_compiler/offline_compiler_tests.h"
#include "test.h"
#include "gmock/gmock.h"
using namespace NEO;
using MockOfflineCompilerBdwTests = ::testing::Test;
BDWTEST_F(MockOfflineCompilerBdwTests, givenDebugOptionAndBdwThenInternalOptionShouldNotContainKernelDebugEnable) {
std::vector<std::string> argv = {
"ocloc",
"-q",
"-options",
"-g",
"-file",
"test_files/copybuffer.cl",
"-device",
"bdw"};
auto mockOfflineCompiler = std::unique_ptr<MockOfflineCompiler>(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")));
}
BDWTEST_F(MockOfflineCompilerBdwTests, GivenBdwWhenParseDebugSettingsThenContainsHasBufferOffsetArg) {
MockOfflineCompiler mockOfflineCompiler;
mockOfflineCompiler.deviceName = "bdw";
mockOfflineCompiler.initHardwareInfo(mockOfflineCompiler.deviceName);
mockOfflineCompiler.parseDebugSettings();
std::string internalOptions = mockOfflineCompiler.internalOptions;
size_t found = internalOptions.find(NEO::CompilerOptions::hasBufferOffsetArg.data());
EXPECT_EQ(std::string::npos, found);
}

View File

@ -1,33 +0,0 @@
/*
* 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<std::string> argv = {
"ocloc",
"-options",
"-g",
"-file",
"test_files/copybuffer.cl",
"-device",
"bdw"};
auto mockOfflineCompiler = std::unique_ptr<MockOfflineCompiler>(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

View File

@ -0,0 +1,14 @@
#
# Copyright (C) 2021 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
if(TESTS_GEN9)
set(IGDRCL_SRCS_offline_compiler_tests_gen9
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
)
target_sources(ocloc_tests PRIVATE ${IGDRCL_SRCS_offline_compiler_tests_gen9})
add_subdirectories()
endif()

View File

@ -0,0 +1,14 @@
#
# Copyright (C) 2021 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
if(TESTS_SKL)
set(IGDRCL_SRCS_offline_compiler_tests_skl
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/offline_compiler_tests_skl.cpp
)
target_sources(ocloc_tests PRIVATE ${IGDRCL_SRCS_offline_compiler_tests_skl})
endif()

View File

@ -0,0 +1,63 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/compiler_interface/compiler_options/compiler_options.h"
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "opencl/test/unit_test/offline_compiler/mock/mock_offline_compiler.h"
#include "opencl/test/unit_test/offline_compiler/offline_compiler_tests.h"
#include "test.h"
namespace NEO {
using MockOfflineCompilerSklTests = ::testing::Test;
SKLTEST_F(MockOfflineCompilerSklTests, GivenSklWhenParseDebugSettingsThenStatelessToStatefullOptimizationIsEnabled) {
MockOfflineCompiler mockOfflineCompiler;
mockOfflineCompiler.deviceName = "skl";
mockOfflineCompiler.initHardwareInfo(mockOfflineCompiler.deviceName);
mockOfflineCompiler.parseDebugSettings();
std::string internalOptions = mockOfflineCompiler.internalOptions;
size_t found = internalOptions.find(NEO::CompilerOptions::hasBufferOffsetArg.data());
EXPECT_NE(std::string::npos, found);
}
SKLTEST_F(MockOfflineCompilerSklTests, GivenSklAndDisabledViaDebugThenStatelessToStatefullOptimizationDisabled) {
DebugManagerStateRestore stateRestore;
MockOfflineCompiler mockOfflineCompiler;
mockOfflineCompiler.deviceName = "skl";
DebugManager.flags.EnableStatelessToStatefulBufferOffsetOpt.set(0);
mockOfflineCompiler.initHardwareInfo(mockOfflineCompiler.deviceName);
mockOfflineCompiler.setStatelessToStatefullBufferOffsetFlag();
std::string internalOptions = mockOfflineCompiler.internalOptions;
size_t found = internalOptions.find(NEO::CompilerOptions::hasBufferOffsetArg.data());
EXPECT_EQ(std::string::npos, found);
}
SKLTEST_F(MockOfflineCompilerSklTests, givenSklWhenAppendExtraInternalOptionsThenForceEmuInt32DivRemSPIsNotApplied) {
MockOfflineCompiler mockOfflineCompiler;
mockOfflineCompiler.deviceName = "skl";
mockOfflineCompiler.initHardwareInfo(mockOfflineCompiler.deviceName);
std::string internalOptions = mockOfflineCompiler.internalOptions;
mockOfflineCompiler.appendExtraInternalOptions(mockOfflineCompiler.hwInfo, internalOptions);
size_t found = internalOptions.find(NEO::CompilerOptions::forceEmuInt32DivRemSP.data());
EXPECT_EQ(std::string::npos, found);
}
SKLTEST_F(MockOfflineCompilerSklTests, givenSklWhenAppendExtraInternalOptionsThenGreaterThan4gbBuffersRequiredIsNotSet) {
MockOfflineCompiler mockOfflineCompiler;
mockOfflineCompiler.deviceName = "skl";
mockOfflineCompiler.initHardwareInfo(mockOfflineCompiler.deviceName);
std::string internalOptions = mockOfflineCompiler.internalOptions;
mockOfflineCompiler.forceStatelessToStatefulOptimization = false;
mockOfflineCompiler.appendExtraInternalOptions(mockOfflineCompiler.hwInfo, internalOptions);
size_t found = internalOptions.find(NEO::CompilerOptions::greaterThan4gbBuffersRequired.data());
EXPECT_EQ(std::string::npos, found);
}
} // namespace NEO

View File

@ -19,6 +19,7 @@ const char *fSeparator = "/";
#endif
Environment *gEnvironment;
extern GFXCORE_FAMILY renderCoreFamily;
std::string getRunPath() {
char *cwd;
@ -79,6 +80,15 @@ int main(int argc, char **argv) {
}
}
for (unsigned int productId = 0; productId < IGFX_MAX_PRODUCT; ++productId) {
if (NEO::hardwarePrefix[productId] && (0 == strcmp(devicePrefix.c_str(), NEO::hardwarePrefix[productId]))) {
if (NEO::hardwareInfoTable[productId]) {
renderCoreFamily = NEO::hardwareInfoTable[productId]->platform.eRenderCoreFamily;
break;
}
}
}
// we look for test files always relative to binary location
// this simplifies multi-process execution and using different
// working directories

View File

@ -14,18 +14,20 @@ namespace NEO {
class MockOfflineCompiler : public OfflineCompiler {
public:
using OfflineCompiler::appendExtraInternalOptions;
using OfflineCompiler::argHelper;
using OfflineCompiler::deviceName;
using OfflineCompiler::elfBinary;
using OfflineCompiler::fclDeviceCtx;
using OfflineCompiler::forceStatelessToStatefulOptimization;
using OfflineCompiler::genBinary;
using OfflineCompiler::genBinarySize;
using OfflineCompiler::generateFilePathForIr;
using OfflineCompiler::generateOptsSuffix;
using OfflineCompiler::getHardwareInfo;
using OfflineCompiler::getStringWithinDelimiters;
using OfflineCompiler::hwInfo;
using OfflineCompiler::igcDeviceCtx;
using OfflineCompiler::initHardwareInfo;
using OfflineCompiler::inputFileLlvm;
using OfflineCompiler::inputFileSpirV;
using OfflineCompiler::internalOptions;
@ -37,6 +39,7 @@ class MockOfflineCompiler : public OfflineCompiler {
using OfflineCompiler::outputFile;
using OfflineCompiler::parseCommandLine;
using OfflineCompiler::parseDebugSettings;
using OfflineCompiler::setStatelessToStatefullBufferOffsetFlag;
using OfflineCompiler::sourceCode;
using OfflineCompiler::storeBinary;
using OfflineCompiler::updateBuildLog;

View File

@ -765,43 +765,6 @@ TEST(OfflineCompilerTest, givenStatelessToStatefullOptimizationEnabledWhenDebugS
EXPECT_NE(std::string::npos, found);
}
TEST(OfflineCompilerTest, GivenBdwThenStatelessToStatefullOptimizationIsDisabled) {
DebugManagerStateRestore stateRestore;
MockOfflineCompiler mockOfflineCompiler;
mockOfflineCompiler.deviceName = "bdw";
mockOfflineCompiler.parseDebugSettings();
std::string internalOptions = mockOfflineCompiler.internalOptions;
size_t found = internalOptions.find(NEO::CompilerOptions::hasBufferOffsetArg.data());
EXPECT_EQ(std::string::npos, found);
}
TEST(OfflineCompilerTest, GivenSklThenStatelessToStatefullOptimizationIsEnabled) {
DebugManagerStateRestore stateRestore;
MockOfflineCompiler mockOfflineCompiler;
mockOfflineCompiler.deviceName = "skl";
mockOfflineCompiler.parseDebugSettings();
std::string internalOptions = mockOfflineCompiler.internalOptions;
size_t found = internalOptions.find(NEO::CompilerOptions::hasBufferOffsetArg.data());
EXPECT_NE(std::string::npos, found);
}
TEST(OfflineCompilerTest, GivenSklAndDisabledViaDebugThenStatelessToStatefullOptimizationDisabled) {
DebugManagerStateRestore stateRestore;
MockOfflineCompiler mockOfflineCompiler;
mockOfflineCompiler.deviceName = "skl";
DebugManager.flags.EnableStatelessToStatefulBufferOffsetOpt.set(0);
mockOfflineCompiler.parseDebugSettings();
std::string internalOptions = mockOfflineCompiler.internalOptions;
size_t found = internalOptions.find(NEO::CompilerOptions::hasBufferOffsetArg.data());
EXPECT_EQ(std::string::npos, found);
}
TEST(OfflineCompilerTest, GivenDelimitersWhenGettingStringThenParseIsCorrect) {
auto mockOfflineCompiler = std::unique_ptr<MockOfflineCompiler>(new MockOfflineCompiler());
ASSERT_NE(nullptr, mockOfflineCompiler);
@ -851,9 +814,9 @@ TEST(OfflineCompilerTest, GivenValidParamWhenGettingHardwareInfoThenSuccessIsRet
auto mockOfflineCompiler = std::unique_ptr<MockOfflineCompiler>(new MockOfflineCompiler());
ASSERT_NE(nullptr, mockOfflineCompiler);
EXPECT_EQ(CL_INVALID_DEVICE, mockOfflineCompiler->getHardwareInfo("invalid"));
EXPECT_EQ(CL_INVALID_DEVICE, mockOfflineCompiler->initHardwareInfo("invalid"));
EXPECT_EQ(PRODUCT_FAMILY::IGFX_UNKNOWN, mockOfflineCompiler->getHardwareInfo().platform.eProductFamily);
EXPECT_EQ(CL_SUCCESS, mockOfflineCompiler->getHardwareInfo(gEnvironment->devicePrefix.c_str()));
EXPECT_EQ(CL_SUCCESS, mockOfflineCompiler->initHardwareInfo(gEnvironment->devicePrefix.c_str()));
EXPECT_NE(PRODUCT_FAMILY::IGFX_UNKNOWN, mockOfflineCompiler->getHardwareInfo().platform.eProductFamily);
}
@ -1472,7 +1435,7 @@ TEST(OfflineCompilerTest, givenNoRevisionIdWhenCompilerIsInitializedThenHwInfoHa
"-device",
gEnvironment->devicePrefix.c_str()};
mockOfflineCompiler->getHardwareInfo(gEnvironment->devicePrefix.c_str());
mockOfflineCompiler->initHardwareInfo(gEnvironment->devicePrefix.c_str());
auto revId = mockOfflineCompiler->hwInfo.platform.usRevId;
int retVal = mockOfflineCompiler->initialize(argv.size(), argv);
EXPECT_EQ(OfflineCompiler::ErrorCode::SUCCESS, retVal);
@ -1512,36 +1475,6 @@ TEST(OfflineCompilerTest, whenDeviceIsSpecifiedThenDefaultConfigFromTheDeviceIsU
EXPECT_EQ(euPerSubSliceCount * subSlicePerSliceCount * sliceCount, hwInfo.gtSystemInfo.EUCount);
}
struct WorkaroundApplicableForDevice {
const char *deviceName;
bool applicable;
};
using OfflineCompilerTestWithParams = testing::TestWithParam<WorkaroundApplicableForDevice>;
TEST_P(OfflineCompilerTestWithParams, givenRklWhenExtraSettingsResolvedThenForceEmuInt32DivRemSPIsApplied) {
WorkaroundApplicableForDevice params = GetParam();
MockOfflineCompiler mockOfflineCompiler;
mockOfflineCompiler.deviceName = params.deviceName;
mockOfflineCompiler.parseDebugSettings();
std::string internalOptions = mockOfflineCompiler.internalOptions;
size_t found = internalOptions.find(NEO::CompilerOptions::forceEmuInt32DivRemSP.data());
if (params.applicable) {
EXPECT_NE(std::string::npos, found);
} else {
EXPECT_EQ(std::string::npos, found);
}
}
WorkaroundApplicableForDevice workaroundApplicableForDeviceArray[] = {{"rkl", true}, {"dg1", false}, {"tgllp", false}};
INSTANTIATE_TEST_CASE_P(
WorkaroundApplicable,
OfflineCompilerTestWithParams,
testing::ValuesIn(workaroundApplicableForDeviceArray));
TEST(OclocCompile, whenDetectedPotentialInputTypeMismatchThenEmitsWarning) {
std::string sourceOclC = "__kernel void k() { }";
std::string sourceLlvmBc = NEO::llvmBcMagic.str();
@ -1589,7 +1522,7 @@ TEST(OclocCompile, whenDetectedPotentialInputTypeMismatchThenEmitsWarning) {
"-device",
gEnvironment->devicePrefix.c_str()};
ocloc.getHardwareInfo(gEnvironment->devicePrefix.c_str());
ocloc.initHardwareInfo(gEnvironment->devicePrefix.c_str());
int retVal = ocloc.initialize(argv.size(), argv);
ASSERT_EQ(0, retVal);
@ -1713,4 +1646,26 @@ TEST(OclocCompile, givenSpirvInputThenDontGenerateSpirvFile) {
EXPECT_TRUE(compilerOutputExists("offline_compiler_test/binary_with_zeroes", "bin"));
EXPECT_FALSE(compilerOutputExists("offline_compiler_test/binary_with_zeroes", "spv"));
}
TEST(OfflineCompilerTest, GivenDebugFlagWhenSetStatelessToStatefullBufferOffsetFlagThenStatelessToStatefullOptimizationIsSetCorrectly) {
DebugManagerStateRestore stateRestore;
MockOfflineCompiler mockOfflineCompiler;
{
DebugManager.flags.EnableStatelessToStatefulBufferOffsetOpt.set(0);
mockOfflineCompiler.initHardwareInfo(mockOfflineCompiler.deviceName);
mockOfflineCompiler.setStatelessToStatefullBufferOffsetFlag();
std::string internalOptions = mockOfflineCompiler.internalOptions;
size_t found = internalOptions.find(NEO::CompilerOptions::hasBufferOffsetArg.data());
EXPECT_EQ(std::string::npos, found);
}
{
DebugManager.flags.EnableStatelessToStatefulBufferOffsetOpt.set(1);
mockOfflineCompiler.initHardwareInfo(mockOfflineCompiler.deviceName);
mockOfflineCompiler.setStatelessToStatefullBufferOffsetFlag();
std::string internalOptions = mockOfflineCompiler.internalOptions;
size_t found = internalOptions.find(NEO::CompilerOptions::hasBufferOffsetArg.data());
EXPECT_NE(std::string::npos, found);
}
}
} // namespace NEO