mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-21 09:14:47 +08:00
Adding spirv to cloc
cloc will now accept spirv as input when spirv_input command line argument is present Change-Id: Iaca88e1bd11ec2e4b2bfbac3e372ba97fa7efc8e
This commit is contained in:
committed by
sys_ocldev
parent
c10d0d79f5
commit
02216e198d
@@ -135,8 +135,8 @@ int OfflineCompiler::buildSourceCode() {
|
|||||||
UNRECOVERABLE_IF(igcDeviceCtx == nullptr);
|
UNRECOVERABLE_IF(igcDeviceCtx == nullptr);
|
||||||
|
|
||||||
CIF::RAII::UPtr_t<IGC::OclTranslationOutputTagOCL> igcOutput;
|
CIF::RAII::UPtr_t<IGC::OclTranslationOutputTagOCL> igcOutput;
|
||||||
|
bool inputIsIntermediateRepresentation = inputFileLlvm || inputFileSpirV;
|
||||||
if (!inputFileLlvm) {
|
if (false == inputIsIntermediateRepresentation) {
|
||||||
IGC::CodeType::CodeType_t intermediateRepresentation = useLlvmText ? IGC::CodeType::llvmLl : preferredIntermediateRepresentation;
|
IGC::CodeType::CodeType_t intermediateRepresentation = useLlvmText ? IGC::CodeType::llvmLl : preferredIntermediateRepresentation;
|
||||||
// sourceCode.size() returns the number of characters without null terminated char
|
// sourceCode.size() returns the number of characters without null terminated char
|
||||||
auto fclSrc = CIF::Builtins::CreateConstBuffer(fclMain.get(), sourceCode.c_str(), sourceCode.size() + 1);
|
auto fclSrc = CIF::Builtins::CreateConstBuffer(fclMain.get(), sourceCode.c_str(), sourceCode.size() + 1);
|
||||||
@@ -181,7 +181,7 @@ int OfflineCompiler::buildSourceCode() {
|
|||||||
auto igcSrc = CIF::Builtins::CreateConstBuffer(igcMain.get(), sourceCode.c_str(), sourceCode.size());
|
auto igcSrc = CIF::Builtins::CreateConstBuffer(igcMain.get(), sourceCode.c_str(), sourceCode.size());
|
||||||
auto igcOptions = CIF::Builtins::CreateConstBuffer(igcMain.get(), nullptr, 0);
|
auto igcOptions = CIF::Builtins::CreateConstBuffer(igcMain.get(), nullptr, 0);
|
||||||
auto igcInternalOptions = CIF::Builtins::CreateConstBuffer(igcMain.get(), internalOptions.c_str(), internalOptions.size());
|
auto igcInternalOptions = CIF::Builtins::CreateConstBuffer(igcMain.get(), internalOptions.c_str(), internalOptions.size());
|
||||||
auto igcTranslationCtx = igcDeviceCtx->CreateTranslationCtx(IGC::CodeType::llvmLl, IGC::CodeType::oclGenBin);
|
auto igcTranslationCtx = igcDeviceCtx->CreateTranslationCtx(inputFileSpirV ? IGC::CodeType::spirV : IGC::CodeType::llvmBc, IGC::CodeType::oclGenBin);
|
||||||
igcOutput = igcTranslationCtx->Translate(igcSrc.get(), igcOptions.get(), igcInternalOptions.get(), nullptr, 0);
|
igcOutput = igcTranslationCtx->Translate(igcSrc.get(), igcOptions.get(), igcInternalOptions.get(), nullptr, 0);
|
||||||
}
|
}
|
||||||
if (igcOutput == nullptr) {
|
if (igcOutput == nullptr) {
|
||||||
@@ -469,6 +469,8 @@ int OfflineCompiler::parseCommandLine(uint32_t numArgs, const char **argv) {
|
|||||||
useLlvmText = true;
|
useLlvmText = true;
|
||||||
} else if (stringsAreEqual(argv[argIndex], "-llvm_input")) {
|
} else if (stringsAreEqual(argv[argIndex], "-llvm_input")) {
|
||||||
inputFileLlvm = true;
|
inputFileLlvm = true;
|
||||||
|
} else if (stringsAreEqual(argv[argIndex], "-spirv_input")) {
|
||||||
|
inputFileSpirV = true;
|
||||||
} else if (stringsAreEqual(argv[argIndex], "-cpp_file")) {
|
} else if (stringsAreEqual(argv[argIndex], "-cpp_file")) {
|
||||||
useCppFile = true;
|
useCppFile = true;
|
||||||
} else if ((stringsAreEqual(argv[argIndex], "-options")) &&
|
} else if ((stringsAreEqual(argv[argIndex], "-options")) &&
|
||||||
@@ -642,6 +644,7 @@ void OfflineCompiler::printUsage() {
|
|||||||
printf(" -llvm_text Readable LLVM text will be output in a .ll file instead of\n");
|
printf(" -llvm_text Readable LLVM text will be output in a .ll file instead of\n");
|
||||||
printf(" through the default lllvm binary (.bc) file.\n");
|
printf(" through the default lllvm binary (.bc) file.\n");
|
||||||
printf(" -llvm_input Indicates input file is llvm source\n");
|
printf(" -llvm_input Indicates input file is llvm source\n");
|
||||||
|
printf(" -spirv_input Indicates input file is a SpirV binary\n");
|
||||||
printf(" -options <options> Compiler options.\n");
|
printf(" -options <options> Compiler options.\n");
|
||||||
printf(" -options_name Add suffix with compile options to filename\n");
|
printf(" -options_name Add suffix with compile options to filename\n");
|
||||||
printf(" -q Be more quiet. print only warnings and errors.\n");
|
printf(" -q Be more quiet. print only warnings and errors.\n");
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ class OfflineCompiler {
|
|||||||
bool useOptionsSuffix = false;
|
bool useOptionsSuffix = false;
|
||||||
bool quiet = false;
|
bool quiet = false;
|
||||||
bool inputFileLlvm = false;
|
bool inputFileLlvm = false;
|
||||||
|
bool inputFileSpirV = false;
|
||||||
|
|
||||||
char *elfBinary = nullptr;
|
char *elfBinary = nullptr;
|
||||||
size_t elfBinarySize = 0;
|
size_t elfBinarySize = 0;
|
||||||
|
|||||||
@@ -455,6 +455,7 @@ CIF::ICIF *MockIgcOclDeviceCtx::Create(CIF::InterfaceId_t intId, CIF::Version_t
|
|||||||
IGC::IgcOclTranslationCtxBase *MockIgcOclDeviceCtx::CreateTranslationCtxImpl(CIF::Version_t ver,
|
IGC::IgcOclTranslationCtxBase *MockIgcOclDeviceCtx::CreateTranslationCtxImpl(CIF::Version_t ver,
|
||||||
IGC::CodeType::CodeType_t inType,
|
IGC::CodeType::CodeType_t inType,
|
||||||
IGC::CodeType::CodeType_t outType) {
|
IGC::CodeType::CodeType_t outType) {
|
||||||
|
requestedTranslationCtxs.emplace_back(inType, outType);
|
||||||
return new MockIgcOclTranslationCtx;
|
return new MockIgcOclTranslationCtx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -206,6 +206,9 @@ struct MockIgcOclDeviceCtx : MockCIF<IGC::IgcOclDeviceCtxTagOCL> {
|
|||||||
MockGTSystemInfo *gtSystemInfo = nullptr;
|
MockGTSystemInfo *gtSystemInfo = nullptr;
|
||||||
MockIgcFeaturesAndWorkarounds *igcFeWa = nullptr;
|
MockIgcFeaturesAndWorkarounds *igcFeWa = nullptr;
|
||||||
MockCompilerDebugVars debugVars;
|
MockCompilerDebugVars debugVars;
|
||||||
|
|
||||||
|
using TranslationOpT = std::pair<IGC::CodeType::CodeType_t, IGC::CodeType::CodeType_t>;
|
||||||
|
std::vector<TranslationOpT> requestedTranslationCtxs;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MockFclOclTranslationCtx : MockCIF<IGC::FclOclTranslationCtxTagOCL> {
|
struct MockFclOclTranslationCtx : MockCIF<IGC::FclOclTranslationCtxTagOCL> {
|
||||||
|
|||||||
@@ -30,11 +30,14 @@ class MockOfflineCompiler : public OfflineCompiler {
|
|||||||
public:
|
public:
|
||||||
using OfflineCompiler::generateFilePathForIr;
|
using OfflineCompiler::generateFilePathForIr;
|
||||||
using OfflineCompiler::generateOptsSuffix;
|
using OfflineCompiler::generateOptsSuffix;
|
||||||
|
using OfflineCompiler::igcDeviceCtx;
|
||||||
using OfflineCompiler::inputFileLlvm;
|
using OfflineCompiler::inputFileLlvm;
|
||||||
|
using OfflineCompiler::inputFileSpirV;
|
||||||
using OfflineCompiler::isSpirV;
|
using OfflineCompiler::isSpirV;
|
||||||
using OfflineCompiler::options;
|
using OfflineCompiler::options;
|
||||||
using OfflineCompiler::outputDirectory;
|
using OfflineCompiler::outputDirectory;
|
||||||
using OfflineCompiler::outputFile;
|
using OfflineCompiler::outputFile;
|
||||||
|
using OfflineCompiler::sourceCode;
|
||||||
using OfflineCompiler::useLlvmText;
|
using OfflineCompiler::useLlvmText;
|
||||||
using OfflineCompiler::useOptionsSuffix;
|
using OfflineCompiler::useOptionsSuffix;
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include "runtime/helpers/options.h"
|
#include "runtime/helpers/options.h"
|
||||||
#include "runtime/os_interface/debug_settings_manager.h"
|
#include "runtime/os_interface/debug_settings_manager.h"
|
||||||
#include "unit_tests/helpers/debug_manager_state_restore.h"
|
#include "unit_tests/helpers/debug_manager_state_restore.h"
|
||||||
|
#include "unit_tests/mocks/mock_compilers.h"
|
||||||
#include "gmock/gmock.h"
|
#include "gmock/gmock.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@@ -561,40 +562,53 @@ TEST(OfflineCompilerTest, givenDefaultOfflineCompilerObjectWhenNoOptionsAreChang
|
|||||||
EXPECT_FALSE(llvmFileOption);
|
EXPECT_FALSE(llvmFileOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(OfflineCompilerTest, givenLlvmInputFileAndLlvmInputFlagWhenBuildSourceCodeIsCalledThenGenBinaryIsProduced) {
|
TEST(OfflineCompilerTest, givenSpirvInputOptionPassedWhenCmdLineParsedThenInputFileSpirvIsSetTrue) {
|
||||||
|
const char *argv[] = {"cloc", "-spirv_input"};
|
||||||
|
|
||||||
auto mockOfflineCompiler = std::unique_ptr<MockOfflineCompiler>(new MockOfflineCompiler());
|
auto mockOfflineCompiler = std::unique_ptr<MockOfflineCompiler>(new MockOfflineCompiler());
|
||||||
ASSERT_NE(nullptr, mockOfflineCompiler);
|
|
||||||
|
|
||||||
auto retVal = mockOfflineCompiler->buildSourceCode();
|
testing::internal::CaptureStdout();
|
||||||
EXPECT_EQ(CL_INVALID_PROGRAM, retVal);
|
mockOfflineCompiler->parseCommandLine(ARRAY_COUNT(argv), argv);
|
||||||
|
std::string output = testing::internal::GetCapturedStdout();
|
||||||
|
EXPECT_NE(0u, output.size());
|
||||||
|
|
||||||
std::string sipKernelFileName = "test_files/sip_dummy_kernel";
|
EXPECT_TRUE(mockOfflineCompiler->inputFileSpirV);
|
||||||
|
}
|
||||||
|
|
||||||
if (sizeof(uintptr_t) == 8) {
|
TEST(OfflineCompilerTest, givenDefaultOfflineCompilerObjectWhenNoOptionsAreChangedThenSpirvInputFileIsFalse) {
|
||||||
sipKernelFileName += "_64.ll";
|
auto mockOfflineCompiler = std::unique_ptr<MockOfflineCompiler>(new MockOfflineCompiler());
|
||||||
} else {
|
EXPECT_FALSE(mockOfflineCompiler->inputFileSpirV);
|
||||||
sipKernelFileName += "_32.ll";
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
TEST(OfflineCompilerTest, givenIntermediatedRepresentationInputWhenBuildSourceCodeIsCalledThenProperTranslationContextIsUed) {
|
||||||
|
MockOfflineCompiler mockOfflineCompiler;
|
||||||
const char *argv[] = {
|
const char *argv[] = {
|
||||||
"cloc",
|
"cloc",
|
||||||
"-file",
|
"-file",
|
||||||
sipKernelFileName.c_str(),
|
"test_files/emptykernel.cl",
|
||||||
"-llvm_input",
|
|
||||||
"-device",
|
"-device",
|
||||||
gEnvironment->devicePrefix.c_str()};
|
gEnvironment->devicePrefix.c_str()};
|
||||||
|
|
||||||
retVal = mockOfflineCompiler->initialize(ARRAY_COUNT(argv), argv);
|
auto retVal = mockOfflineCompiler.initialize(ARRAY_COUNT(argv), argv);
|
||||||
|
auto mockIgcOclDeviceCtx = new OCLRT::MockIgcOclDeviceCtx();
|
||||||
|
mockOfflineCompiler.igcDeviceCtx = CIF::RAII::Pack<IGC::IgcOclDeviceCtxLatest>(mockIgcOclDeviceCtx);
|
||||||
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
||||||
|
|
||||||
|
mockOfflineCompiler.inputFileSpirV = true;
|
||||||
|
retVal = mockOfflineCompiler.buildSourceCode();
|
||||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||||
|
ASSERT_EQ(1U, mockIgcOclDeviceCtx->requestedTranslationCtxs.size());
|
||||||
|
OCLRT::MockIgcOclDeviceCtx::TranslationOpT expectedTranslation = {IGC::CodeType::spirV, IGC::CodeType::oclGenBin};
|
||||||
|
ASSERT_EQ(expectedTranslation, mockIgcOclDeviceCtx->requestedTranslationCtxs[0]);
|
||||||
|
|
||||||
EXPECT_EQ(nullptr, mockOfflineCompiler->getGenBinary());
|
mockOfflineCompiler.inputFileSpirV = false;
|
||||||
EXPECT_EQ(0u, mockOfflineCompiler->getGenBinarySize());
|
mockOfflineCompiler.inputFileLlvm = true;
|
||||||
|
mockIgcOclDeviceCtx->requestedTranslationCtxs.clear();
|
||||||
retVal = mockOfflineCompiler->buildSourceCode();
|
retVal = mockOfflineCompiler.buildSourceCode();
|
||||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||||
|
ASSERT_EQ(1U, mockIgcOclDeviceCtx->requestedTranslationCtxs.size());
|
||||||
EXPECT_NE(nullptr, mockOfflineCompiler->getGenBinary());
|
expectedTranslation = {IGC::CodeType::llvmBc, IGC::CodeType::oclGenBin};
|
||||||
EXPECT_NE(0u, mockOfflineCompiler->getGenBinarySize());
|
ASSERT_EQ(expectedTranslation, mockIgcOclDeviceCtx->requestedTranslationCtxs[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(OfflineCompilerTest, givenOutputFileOptionWhenSourceIsCompiledThenOutputFileHasCorrectName) {
|
TEST(OfflineCompilerTest, givenOutputFileOptionWhenSourceIsCompiledThenOutputFileHasCorrectName) {
|
||||||
|
|||||||
Reference in New Issue
Block a user