Add support for exclusion of IR from binary generated by ocloc

Itroduces new parameter "-exclude_ir" to ocloc CLI.
This parameter can be used to reduce output binary size
when IR is not needed.

Related-To: NEO-6477

Signed-off-by: Patryk Wrobel <patryk.wrobel@intel.com>
This commit is contained in:
Patryk Wrobel
2021-12-08 13:40:26 +00:00
committed by Compute-Runtime-Automation
parent 2fd536104d
commit c324279bf5
3 changed files with 68 additions and 1 deletions

View File

@ -10,6 +10,8 @@
#include "shared/source/compiler_interface/intermediate_representations.h"
#include "shared/source/compiler_interface/oclc_extensions.h"
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/device_binary_format/elf/elf_decoder.h"
#include "shared/source/device_binary_format/elf/ocl_elf.h"
#include "shared/source/helpers/file_io.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
@ -71,6 +73,15 @@ void compilerOutputRemove(const std::string &fileName, const std::string &type)
std::remove(getCompilerOutputFileName(fileName, type).c_str());
}
template <typename SectionHeaders>
bool isAnyIrSectionDefined(const SectionHeaders &sectionHeaders) {
const auto isIrSection = [](const auto &section) {
return section.header && (section.header->type == Elf::SHT_OPENCL_SPIRV || section.header->type == Elf::SHT_OPENCL_LLVM_BINARY);
};
return std::any_of(sectionHeaders.begin(), sectionHeaders.end(), isIrSection);
}
TEST_F(MultiCommandTests, WhenBuildingMultiCommandThenSuccessIsReturned) {
nameOfFileWithArgs = "test_files/ImAMulitiComandMinimalGoodFile.txt";
std::vector<std::string> argv = {
@ -389,6 +400,57 @@ TEST_F(OfflineCompilerTests, givenDashGInBiggerOptionStringWhenInitializingThenI
EXPECT_THAT(internalOptions, ::testing::Not(::testing::HasSubstr("-cl-kernel-debug-enable")));
}
TEST_F(OfflineCompilerTests, givenExcludeIrArgumentWhenCompilingKernelThenIrShouldBeExcluded) {
std::vector<std::string> argv = {
"ocloc",
"-file",
"test_files/copybuffer.cl",
"-exclude_ir",
"-device",
gEnvironment->devicePrefix.c_str()};
MockOfflineCompiler mockOfflineCompiler{};
mockOfflineCompiler.initialize(argv.size(), argv);
const auto buildResult{mockOfflineCompiler.build()};
EXPECT_EQ(OfflineCompiler::SUCCESS, buildResult);
std::string errorReason{};
std::string warning{};
const auto elf{Elf::decodeElf(mockOfflineCompiler.elfBinary, errorReason, warning)};
ASSERT_TRUE(errorReason.empty());
ASSERT_TRUE(warning.empty());
EXPECT_FALSE(isAnyIrSectionDefined(elf.sectionHeaders));
}
TEST_F(OfflineCompilerTests, givenLackOfExcludeIrArgumentWhenCompilingKernelThenIrShouldBeIncluded) {
std::vector<std::string> argv = {
"ocloc",
"-file",
"test_files/copybuffer.cl",
"-device",
gEnvironment->devicePrefix.c_str()};
MockOfflineCompiler mockOfflineCompiler{};
mockOfflineCompiler.initialize(argv.size(), argv);
const auto buildResult{mockOfflineCompiler.build()};
EXPECT_EQ(OfflineCompiler::SUCCESS, buildResult);
std::string errorReason{};
std::string warning{};
const auto elf{Elf::decodeElf(mockOfflineCompiler.elfBinary, errorReason, warning)};
ASSERT_TRUE(errorReason.empty());
ASSERT_TRUE(warning.empty());
EXPECT_TRUE(isAnyIrSectionDefined(elf.sectionHeaders));
}
TEST_F(OfflineCompilerTests, givenVariousClStdValuesWhenCompilingSourceThenCorrectExtensionsArePassed) {
std::string clStdOptionValues[] = {"", "-cl-std=CL1.2", "-cl-std=CL2.0", "-cl-std=CL3.0"};