mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-20 08:53:55 +08:00
fix: Better IR file format ext handling
This fix makes ocloc honor IR file format when picking extension for the output file. Additionally, this commit removes reduntant IR output when compiling from IR. Related-To: NEO-15876 Signed-off-by: Chodor, Jaroslaw <jaroslaw.chodor@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
84f7b538df
commit
d8ef0aa99d
@@ -5840,6 +5840,7 @@ TEST_F(OfflineCompilerTests, GivenDebugFlagWhenBuildingFromSourceThenTemporarySo
|
|||||||
std::string expectedSOption = "-s \"" + expectedTempFilePath.string() + "\"";
|
std::string expectedSOption = "-s \"" + expectedTempFilePath.string() + "\"";
|
||||||
EXPECT_TRUE(CompilerOptions::contains(mockOfflineCompiler.options, expectedSOption));
|
EXPECT_TRUE(CompilerOptions::contains(mockOfflineCompiler.options, expectedSOption));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(OfflineCompilerTests, GivenSpirvInputAndSpecConstFileWhenFileExistsThenSpecializationConstantsAreLoaded) {
|
TEST_F(OfflineCompilerTests, GivenSpirvInputAndSpecConstFileWhenFileExistsThenSpecializationConstantsAreLoaded) {
|
||||||
MockOfflineCompiler mockOfflineCompiler;
|
MockOfflineCompiler mockOfflineCompiler;
|
||||||
mockOfflineCompiler.uniqueHelper->filesMap = filesMap;
|
mockOfflineCompiler.uniqueHelper->filesMap = filesMap;
|
||||||
@@ -6391,4 +6392,34 @@ TEST_F(OfflineCompilerTests, givenMixedValidFormatsInDeviceOptionsWhenParsingThe
|
|||||||
EXPECT_NE(mockOfflineCompiler->perDeviceOptions.end(),
|
EXPECT_NE(mockOfflineCompiler->perDeviceOptions.end(),
|
||||||
mockOfflineCompiler->perDeviceOptions.find(ipVersion));
|
mockOfflineCompiler->perDeviceOptions.find(ipVersion));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(OclocOutputFileExtensions, GivenKnownFileFormatTheChooseProperExtension) {
|
||||||
|
using namespace IGC::CodeType;
|
||||||
|
std::pair<IGC::CodeType::CodeType_t, const char *> expectedExts[] = {
|
||||||
|
{llvmLl, ".ll"},
|
||||||
|
{llvmBc, ".bc"},
|
||||||
|
{spirV, ".spv"},
|
||||||
|
{oclC, ".cl"},
|
||||||
|
{oclCpp, ".cl"},
|
||||||
|
{oclGenBin, ".bin"},
|
||||||
|
{elf, ".bin"},
|
||||||
|
{undefined, ".bin"},
|
||||||
|
{invalid, ".bin"}};
|
||||||
|
|
||||||
|
for (const auto &[codeType, expectedExt] : expectedExts) {
|
||||||
|
auto ext = NEO::getFileExtension(codeType);
|
||||||
|
EXPECT_STREQ(expectedExt, ext.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(OclocOutputFileExtensions, GivenCustomFileFormatThenUseItAsExtension) {
|
||||||
|
auto customCodeType = IGC::CodeType::CodeTypeCoder::Enc("TXT");
|
||||||
|
auto ext = NEO::getFileExtension(customCodeType);
|
||||||
|
EXPECT_STREQ(".txt", ext.c_str());
|
||||||
|
|
||||||
|
customCodeType = IGC::CodeType::CodeTypeCoder::Enc("MD");
|
||||||
|
ext = NEO::getFileExtension(customCodeType);
|
||||||
|
EXPECT_STREQ(".md", ext.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace NEO
|
} // namespace NEO
|
||||||
|
|||||||
@@ -1769,7 +1769,7 @@ void OfflineCompiler::writeOutAllFiles() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (irBinary && (this->inputCodeType != IGC::CodeType::spirV)) {
|
if (irBinary && (this->inputCodeType == IGC::CodeType::oclC)) {
|
||||||
std::string irOutputFileName = generateFilePathForIr(fileBase) + generateOptsSuffix();
|
std::string irOutputFileName = generateFilePathForIr(fileBase) + generateOptsSuffix();
|
||||||
|
|
||||||
argHelper->saveOutput(irOutputFileName, irBinary, irBinarySize);
|
argHelper->saveOutput(irOutputFileName, irBinary, irBinarySize);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "shared/source/compiler_interface/compiler_options.h"
|
#include "shared/source/compiler_interface/compiler_options.h"
|
||||||
#include "shared/source/helpers/hw_info.h"
|
#include "shared/source/helpers/hw_info.h"
|
||||||
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
||||||
|
#include "shared/source/helpers/string_helpers.h"
|
||||||
#include "shared/source/utilities/arrayref.h"
|
#include "shared/source/utilities/arrayref.h"
|
||||||
#include "shared/source/utilities/const_stringref.h"
|
#include "shared/source/utilities/const_stringref.h"
|
||||||
|
|
||||||
@@ -51,9 +52,14 @@ constexpr bool isIntermediateRepresentation(IGC::CodeType::CodeType_t codeType)
|
|||||||
return false == ((IGC::CodeType::oclC == codeType) || (IGC::CodeType::oclCpp == codeType) || (IGC::CodeType::oclGenBin == codeType));
|
return false == ((IGC::CodeType::oclC == codeType) || (IGC::CodeType::oclCpp == codeType) || (IGC::CodeType::oclGenBin == codeType));
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr const char *getFileExtension(IGC::CodeType::CodeType_t codeType) {
|
inline std::string getFileExtension(IGC::CodeType::CodeType_t codeType) {
|
||||||
switch (codeType) {
|
switch (codeType) {
|
||||||
default:
|
default:
|
||||||
|
return "." + StringHelpers::toLower(IGC::CodeType::CodeTypeCoder::Dec(codeType));
|
||||||
|
case IGC::CodeType::oclGenBin:
|
||||||
|
case IGC::CodeType::elf:
|
||||||
|
case IGC::CodeType::undefined:
|
||||||
|
case IGC::CodeType::invalid:
|
||||||
return ".bin";
|
return ".bin";
|
||||||
case IGC::CodeType::llvmBc:
|
case IGC::CodeType::llvmBc:
|
||||||
return ".bc";
|
return ".bc";
|
||||||
@@ -61,6 +67,10 @@ constexpr const char *getFileExtension(IGC::CodeType::CodeType_t codeType) {
|
|||||||
return ".ll";
|
return ".ll";
|
||||||
case IGC::CodeType::spirV:
|
case IGC::CodeType::spirV:
|
||||||
return ".spv";
|
return ".spv";
|
||||||
|
case IGC::CodeType::oclC:
|
||||||
|
return ".cl";
|
||||||
|
case IGC::CodeType::oclCpp:
|
||||||
|
return ".cl";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,8 +197,8 @@ All supported acronyms: %s.
|
|||||||
void updateBuildLog(const char *pErrorString, const size_t errorStringSize);
|
void updateBuildLog(const char *pErrorString, const size_t errorStringSize);
|
||||||
MOCKABLE_VIRTUAL bool generateElfBinary();
|
MOCKABLE_VIRTUAL bool generateElfBinary();
|
||||||
std::string generateFilePathForIr(const std::string &fileNameBase) {
|
std::string generateFilePathForIr(const std::string &fileNameBase) {
|
||||||
const char *ext = getFileExtension(intermediateRepresentation);
|
auto ext = getFileExtension(intermediateRepresentation);
|
||||||
return generateFilePath(outputDirectory, fileNameBase, ext);
|
return generateFilePath(outputDirectory, fileNameBase, ext.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string generateOptsSuffix() {
|
std::string generateOptsSuffix() {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include "CL/cl.h"
|
#include "CL/cl.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -83,4 +84,14 @@ inline std::vector<std::string> split(const std::string &input, const char *deli
|
|||||||
inline uint32_t toUint32t(const std::string &input) {
|
inline uint32_t toUint32t(const std::string &input) {
|
||||||
return static_cast<uint32_t>(std::stoul(input, nullptr, 0));
|
return static_cast<uint32_t>(std::stoul(input, nullptr, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void toLowerInPlace(std::string &src) {
|
||||||
|
std::transform(src.begin(), src.end(), src.begin(), [](unsigned char c) { return std::tolower(c); });
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string toLower(const std::string &src) {
|
||||||
|
std::string ret = src;
|
||||||
|
toLowerInPlace(ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
} // namespace StringHelpers
|
} // namespace StringHelpers
|
||||||
|
|||||||
@@ -12,6 +12,11 @@
|
|||||||
|
|
||||||
using NEO::Hash;
|
using NEO::Hash;
|
||||||
|
|
||||||
|
TEST(ToLower, GiventStringThenChangeItToLowerCase) {
|
||||||
|
std::string ls = StringHelpers::toLower("SomeTEXT");
|
||||||
|
EXPECT_STREQ("sometext", ls.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
TEST(CreateCombinedStrings, GivenSingleStringWhenCreatingCombinedStringThenDstStringMatchesSrcString) {
|
TEST(CreateCombinedStrings, GivenSingleStringWhenCreatingCombinedStringThenDstStringMatchesSrcString) {
|
||||||
std::string dstString;
|
std::string dstString;
|
||||||
size_t dstStringSizeInBytes = 0;
|
size_t dstStringSizeInBytes = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user