Move appending compiler extensions to compiler parser

Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2021-10-19 19:21:38 +00:00
committed by Compute-Runtime-Automation
parent dceea6bc18
commit 664b33787d
6 changed files with 117 additions and 54 deletions

View File

@@ -6,6 +6,7 @@
set(IGDRCL_SRCS_tests_compiler_interface
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/cl_compiler_interface_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/default_cl_cache_config_tests.cpp
)

View File

@@ -0,0 +1,83 @@
/*
* Copyright (C) 2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/file_io.h"
#include "shared/test/common/helpers/test_files.h"
#include "shared/test/common/libult/global_environment.h"
#include "shared/test/common/mocks/mock_compiler_interface.h"
#include "opencl/test/unit_test/fixtures/cl_device_fixture.h"
#include "test.h"
using namespace NEO;
class ClCompilerInterfaceTest : public ClDeviceFixture,
public ::testing::Test {
public:
void SetUp() override {
ClDeviceFixture::SetUp();
// create the compiler interface
this->pCompilerInterface = new MockCompilerInterface();
bool initRet = pCompilerInterface->initialize(std::make_unique<CompilerCache>(CompilerCacheConfig{}), true);
ASSERT_TRUE(initRet);
pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->compilerInterface.reset(pCompilerInterface);
std::string testFile;
testFile.append(clFiles);
testFile.append("CopyBuffer_simd16.cl");
pSource = loadDataFromFile(
testFile.c_str(),
sourceSize);
ASSERT_NE(0u, sourceSize);
ASSERT_NE(nullptr, pSource);
inputArgs.src = ArrayRef<char>(pSource.get(), sourceSize);
inputArgs.internalOptions = ArrayRef<const char>(pClDevice->peekCompilerExtensions().c_str(), pClDevice->peekCompilerExtensions().size());
}
void TearDown() override {
pSource.reset();
ClDeviceFixture::TearDown();
}
MockCompilerInterface *pCompilerInterface;
TranslationInput inputArgs = {IGC::CodeType::oclC, IGC::CodeType::oclGenBin};
std::unique_ptr<char[]> pSource = nullptr;
size_t sourceSize = 0;
};
TEST_F(ClCompilerInterfaceTest, WhenBuildIsInvokedThenFclReceivesListOfExtensionsInInternalOptions) {
std::string receivedInternalOptions;
auto debugVars = NEO::getFclDebugVars();
debugVars.receivedInternalOptionsOutput = &receivedInternalOptions;
gEnvironment->fclPushDebugVars(debugVars);
TranslationOutput translationOutput = {};
auto err = pCompilerInterface->build(*pDevice, inputArgs, translationOutput);
EXPECT_EQ(TranslationOutput::ErrorCode::Success, err);
EXPECT_THAT(receivedInternalOptions, testing::HasSubstr(pClDevice->peekCompilerExtensions()));
gEnvironment->fclPopDebugVars();
}
TEST_F(ClCompilerInterfaceTest, WhenCompileIsInvokedThenFclReceivesListOfExtensionsInInternalOptions) {
std::string receivedInternalOptions;
MockCompilerDebugVars fclDebugVars;
retrieveBinaryKernelFilename(fclDebugVars.fileName, "CopyBuffer_simd16_", ".bc");
fclDebugVars.receivedInternalOptionsOutput = &receivedInternalOptions;
gEnvironment->fclPushDebugVars(fclDebugVars);
TranslationOutput translationOutput = {};
auto err = pCompilerInterface->compile(*pDevice, inputArgs, translationOutput);
EXPECT_EQ(TranslationOutput::ErrorCode::Success, err);
EXPECT_THAT(receivedInternalOptions, testing::HasSubstr(pClDevice->peekCompilerExtensions()));
gEnvironment->fclPopDebugVars();
}

View File

@@ -25,8 +25,6 @@
#include "shared/source/os_interface/os_inc_base.h"
#include "shared/source/os_interface/os_library.h"
#include "opencl/source/platform/extensions.h"
#include "cif/common/cif_main.h"
#include "cif/helpers/error.h"
#include "cif/import/library_api.h"
@@ -172,7 +170,7 @@ int OfflineCompiler::buildIrBinary() {
if (true == NEO::areNotNullptr(err->GetMemory<char>())) {
updateBuildLog(err->GetMemory<char>(), err->GetSizeRaw());
retVal = CL_BUILD_PROGRAM_FAILURE;
retVal = BUILD_PROGRAM_FAILURE;
return retVal;
}
@@ -451,22 +449,7 @@ int OfflineCompiler::initialize(size_t numArgs, const std::vector<std::string> &
internalOptions = CompilerOptions::concatenate("-ocl-version=300 -cl-ext=-all,+cl_khr_3d_image_writes", internalOptions);
CompilerOptions::concatenateAppend(internalOptions, CompilerOptions::enableImageSupport);
} else {
std::string extensionsList = getExtensionsList(hwInfo);
if (requiresAdditionalExtensions(options)) {
extensionsList += "cl_khr_3d_image_writes ";
}
OpenClCFeaturesContainer openclCFeatures;
if (requiresOpenClCFeatures(options)) {
getOpenclCFeaturesList(hwInfo, openclCFeatures);
}
auto compilerExtensions = convertEnabledExtensionsToCompilerInternalOptions(extensionsList.c_str(), openclCFeatures);
auto oclVersion = getOclVersionCompilerInternalOption(hwInfo.capabilityTable.clVersionSupport);
internalOptions = CompilerOptions::concatenate(oclVersion, compilerExtensions, internalOptions);
if (hwInfo.capabilityTable.supportsImages) {
CompilerOptions::concatenateAppend(internalOptions, CompilerOptions::enableImageSupport);
}
appendExtensionsToInternalOptions(hwInfo, options, internalOptions);
}
parseDebugSettings();
@@ -967,7 +950,7 @@ void OfflineCompiler::storeBinary(
delete[] pDst;
pDst = new char[srcSize];
dstSize = (cl_uint)srcSize;
dstSize = static_cast<uint32_t>(srcSize);
memcpy_s(pDst, dstSize, pSrc, srcSize);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Intel Corporation
* Copyright (C) 2020-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -7,6 +7,10 @@
#include "shared/source/helpers/compiler_options_parser.h"
#include "shared/source/compiler_interface/compiler_options/compiler_options_base.h"
#include "opencl/source/platform/extensions.h"
#include <cstdint>
#include <sstream>
@@ -32,5 +36,22 @@ bool requiresOpenClCFeatures(const std::string &compileOptions) {
bool requiresAdditionalExtensions(const std::string &compileOptions) {
return (getMajorVersion(compileOptions) == 2);
}
void appendExtensionsToInternalOptions(const HardwareInfo &hwInfo, const std::string &options, std::string &internalOptions) {
std::string extensionsList = getExtensionsList(hwInfo);
if (requiresAdditionalExtensions(options)) {
extensionsList += "cl_khr_3d_image_writes ";
}
OpenClCFeaturesContainer openclCFeatures;
if (requiresOpenClCFeatures(options)) {
getOpenclCFeaturesList(hwInfo, openclCFeatures);
}
auto compilerExtensions = convertEnabledExtensionsToCompilerInternalOptions(extensionsList.c_str(), openclCFeatures);
auto oclVersion = getOclVersionCompilerInternalOption(hwInfo.capabilityTable.clVersionSupport);
internalOptions = CompilerOptions::concatenate(oclVersion, compilerExtensions, internalOptions);
if (hwInfo.capabilityTable.supportsImages) {
CompilerOptions::concatenateAppend(internalOptions, CompilerOptions::enableImageSupport);
}
}
} // namespace NEO

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Intel Corporation
* Copyright (C) 2020-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -12,8 +12,11 @@
namespace NEO {
extern const std::string clStdOptionName;
struct HardwareInfo;
bool requiresOpenClCFeatures(const std::string &compileOptions);
bool requiresAdditionalExtensions(const std::string &compileOptions);
void appendExtensionsToInternalOptions(const HardwareInfo &hwInfo, const std::string &options, std::string &internalOptions);
} // namespace NEO

View File

@@ -9,6 +9,7 @@
#include "shared/source/compiler_interface/compiler_interface.inl"
#include "shared/source/helpers/file_io.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/test/common/fixtures/device_fixture.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/test_files.h"
#include "shared/test/common/helpers/unit_test_helper.h"
@@ -17,7 +18,6 @@
#include "shared/test/common/mocks/mock_compiler_interface.h"
#include "shared/test/common/mocks/mock_compilers.h"
#include "opencl/test/unit_test/fixtures/cl_device_fixture.h"
#include "test.h"
#include "gmock/gmock.h"
@@ -35,11 +35,11 @@ const char *gCBadDompilerDllName = "libbad_compiler.so";
#error "Unknown OS!"
#endif
class CompilerInterfaceTest : public ClDeviceFixture,
class CompilerInterfaceTest : public DeviceFixture,
public ::testing::Test {
public:
void SetUp() override {
ClDeviceFixture::SetUp();
DeviceFixture::SetUp();
// create the compiler interface
this->pCompilerInterface = new MockCompilerInterface();
@@ -60,13 +60,12 @@ class CompilerInterfaceTest : public ClDeviceFixture,
ASSERT_NE(nullptr, pSource);
inputArgs.src = ArrayRef<char>(pSource.get(), sourceSize);
inputArgs.internalOptions = ArrayRef<const char>(pClDevice->peekCompilerExtensions().c_str(), pClDevice->peekCompilerExtensions().size());
}
void TearDown() override {
pSource.reset();
ClDeviceFixture::TearDown();
DeviceFixture::TearDown();
}
MockCompilerInterface *pCompilerInterface;
@@ -161,19 +160,6 @@ TEST_F(CompilerInterfaceTest, WhenPreferredIntermediateRepresentationSpecifiedTh
EXPECT_EQ(TranslationOutput::ErrorCode::Success, err);
}
TEST_F(CompilerInterfaceTest, WhenBuildIsInvokedThenFclReceivesListOfExtensionsInInternalOptions) {
std::string receivedInternalOptions;
auto debugVars = NEO::getFclDebugVars();
debugVars.receivedInternalOptionsOutput = &receivedInternalOptions;
gEnvironment->fclPushDebugVars(debugVars);
TranslationOutput translationOutput = {};
auto err = pCompilerInterface->build(*pDevice, inputArgs, translationOutput);
EXPECT_EQ(TranslationOutput::ErrorCode::Success, err);
EXPECT_THAT(receivedInternalOptions, testing::HasSubstr(pClDevice->peekCompilerExtensions()));
gEnvironment->fclPopDebugVars();
}
TEST_F(CompilerInterfaceTest, whenCompilerIsNotAvailableThenBuildFailsGracefully) {
pCompilerInterface->igcMain.reset(nullptr);
TranslationOutput translationOutput = {};
@@ -250,20 +236,6 @@ TEST_F(CompilerInterfaceTest, GivenProgramCreatedFromIrWhenCompileIsCalledThenDo
EXPECT_EQ(TranslationOutput::ErrorCode::AlreadyCompiled, err);
}
TEST_F(CompilerInterfaceTest, WhenCompileIsInvokedThenFclReceivesListOfExtensionsInInternalOptions) {
std::string receivedInternalOptions;
MockCompilerDebugVars fclDebugVars;
retrieveBinaryKernelFilename(fclDebugVars.fileName, "CopyBuffer_simd16_", ".bc");
fclDebugVars.receivedInternalOptionsOutput = &receivedInternalOptions;
gEnvironment->fclPushDebugVars(fclDebugVars);
TranslationOutput translationOutput = {};
auto err = pCompilerInterface->compile(*pDevice, inputArgs, translationOutput);
EXPECT_EQ(TranslationOutput::ErrorCode::Success, err);
EXPECT_THAT(receivedInternalOptions, testing::HasSubstr(pClDevice->peekCompilerExtensions()));
gEnvironment->fclPopDebugVars();
}
TEST_F(CompilerInterfaceTest, whenCompilerIsNotAvailableThenCompileFailsGracefully) {
MockCompilerDebugVars fclDebugVars;
fclDebugVars.fileName = clFiles + "copybuffer.elf";