mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-30 01:35:20 +08:00
Revert "L0 support for SPIRv static module linking"
This reverts commit 479035c839.
Signed-off-by: Compute-Runtime-Validation <compute-runtime-validation@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
8939ca94f7
commit
e7a7a61b4e
@@ -11,9 +11,6 @@
|
||||
#include "shared/source/compiler_interface/linker.h"
|
||||
#include "shared/source/device/device.h"
|
||||
#include "shared/source/device_binary_format/device_binary_formats.h"
|
||||
#include "shared/source/device_binary_format/elf/elf.h"
|
||||
#include "shared/source/device_binary_format/elf/elf_encoder.h"
|
||||
#include "shared/source/device_binary_format/elf/ocl_elf.h"
|
||||
#include "shared/source/helpers/api_specific_config.h"
|
||||
#include "shared/source/helpers/constants.h"
|
||||
#include "shared/source/helpers/kernel_helpers.h"
|
||||
@@ -77,37 +74,12 @@ ModuleTranslationUnit::~ModuleTranslationUnit() {
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<uint8_t> ModuleTranslationUnit::generateElfFromSpirV(std::vector<const char *> inputSpirVs, std::vector<uint32_t> inputModuleSizes) {
|
||||
NEO::Elf::ElfEncoder<> elfEncoder(true, false, 1U);
|
||||
elfEncoder.getElfFileHeader().type = NEO::Elf::ET_OPENCL_OBJECTS;
|
||||
bool ModuleTranslationUnit::buildFromSpirV(const char *input, uint32_t inputSize, const char *buildOptions, const char *internalBuildOptions,
|
||||
const ze_module_constants_t *pConstants) {
|
||||
UNRECOVERABLE_IF((nullptr == device) || (nullptr == device->getNEODevice()));
|
||||
auto compilerInterface = device->getNEODevice()->getCompilerInterface();
|
||||
UNRECOVERABLE_IF(nullptr == compilerInterface);
|
||||
|
||||
StackVec<uint32_t, 64> specConstIds;
|
||||
StackVec<uint64_t, 64> specConstValues;
|
||||
for (uint32_t i = 0; i < static_cast<uint32_t>(inputSpirVs.size()); i++) {
|
||||
if (specConstantsValues.size() > 0) {
|
||||
specConstIds.clear();
|
||||
specConstValues.clear();
|
||||
specConstIds.reserve(specConstantsValues.size());
|
||||
specConstValues.reserve(specConstantsValues.size());
|
||||
for (const auto &specConst : specConstantsValues) {
|
||||
specConstIds.push_back(specConst.first);
|
||||
specConstValues.push_back(specConst.second);
|
||||
}
|
||||
elfEncoder.appendSection(NEO::Elf::SHT_OPENCL_SPIRV_SC_IDS, NEO::Elf::SectionNamesOpenCl::spirvSpecConstIds,
|
||||
ArrayRef<const uint8_t>::fromAny(specConstIds.begin(), specConstIds.size()));
|
||||
elfEncoder.appendSection(NEO::Elf::SHT_OPENCL_SPIRV_SC_VALUES, NEO::Elf::SectionNamesOpenCl::spirvSpecConstValues,
|
||||
ArrayRef<const uint8_t>::fromAny(specConstValues.begin(), specConstValues.size()));
|
||||
}
|
||||
|
||||
auto sectionType = NEO::Elf::SHT_OPENCL_SPIRV;
|
||||
NEO::ConstStringRef sectionName = NEO::Elf::SectionNamesOpenCl::spirvObject;
|
||||
elfEncoder.appendSection(sectionType, sectionName, ArrayRef<const uint8_t>(reinterpret_cast<const uint8_t *>(inputSpirVs[i]), inputModuleSizes[i]));
|
||||
}
|
||||
|
||||
return elfEncoder.encode();
|
||||
}
|
||||
|
||||
std::string ModuleTranslationUnit::generateCompilerOptions(const char *buildOptions, const char *internalBuildOptions) {
|
||||
if (nullptr != buildOptions) {
|
||||
options = buildOptions;
|
||||
}
|
||||
@@ -127,10 +99,8 @@ std::string ModuleTranslationUnit::generateCompilerOptions(const char *buildOpti
|
||||
internalOptions = NEO::CompilerOptions::concatenate(internalOptions, NEO::CompilerOptions::greaterThan4gbBuffersRequired);
|
||||
}
|
||||
|
||||
return internalOptions;
|
||||
}
|
||||
NEO::TranslationInput inputArgs = {IGC::CodeType::spirV, IGC::CodeType::oclGenBin};
|
||||
|
||||
bool ModuleTranslationUnit::processSpecConstantInfo(NEO::CompilerInterface *compilerInterface, const ze_module_constants_t *pConstants, const char *input, uint32_t inputSize) {
|
||||
if (pConstants) {
|
||||
NEO::SpecConstantInfo specConstInfo;
|
||||
auto retVal = compilerInterface->getSpecConstantsInfo(*device->getNEODevice(), ArrayRef<const char>(input, inputSize), specConstInfo);
|
||||
@@ -156,31 +126,18 @@ bool ModuleTranslationUnit::processSpecConstantInfo(NEO::CompilerInterface *comp
|
||||
specConstantsValues[specConstantId] = specConstantValue;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ModuleTranslationUnit::compileGenBinary(NEO::TranslationInput inputArgs, bool staticLink) {
|
||||
auto compilerInterface = device->getNEODevice()->getCompilerInterface();
|
||||
UNRECOVERABLE_IF(nullptr == compilerInterface);
|
||||
|
||||
inputArgs.src = ArrayRef<const char>(input, inputSize);
|
||||
inputArgs.apiOptions = ArrayRef<const char>(options.c_str(), options.length());
|
||||
inputArgs.internalOptions = ArrayRef<const char>(internalOptions.c_str(), internalOptions.length());
|
||||
inputArgs.specializedValues = this->specConstantsValues;
|
||||
|
||||
NEO::TranslationOutput compilerOuput = {};
|
||||
NEO::TranslationOutput::ErrorCode compilerErr;
|
||||
|
||||
if (staticLink) {
|
||||
compilerErr = compilerInterface->link(*device->getNEODevice(), inputArgs, compilerOuput);
|
||||
} else {
|
||||
compilerErr = compilerInterface->build(*device->getNEODevice(), inputArgs, compilerOuput);
|
||||
}
|
||||
|
||||
auto compilerErr = compilerInterface->build(*device->getNEODevice(), inputArgs, compilerOuput);
|
||||
this->updateBuildLog(compilerOuput.frontendCompilerLog);
|
||||
this->updateBuildLog(compilerOuput.backendCompilerLog);
|
||||
|
||||
if (NEO::TranslationOutput::ErrorCode::Success != compilerErr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this->irBinary = std::move(compilerOuput.intermediateRepresentation.mem);
|
||||
this->irBinarySize = compilerOuput.intermediateRepresentation.size;
|
||||
this->unpackedDeviceBinary = std::move(compilerOuput.deviceBinary.mem);
|
||||
@@ -191,49 +148,6 @@ bool ModuleTranslationUnit::compileGenBinary(NEO::TranslationInput inputArgs, bo
|
||||
return processUnpackedBinary();
|
||||
}
|
||||
|
||||
bool ModuleTranslationUnit::staticLinkSpirV(std::vector<const char *> inputSpirVs, std::vector<uint32_t> inputModuleSizes, const char *buildOptions, const char *internalBuildOptions,
|
||||
std::vector<const ze_module_constants_t *> specConstants) {
|
||||
auto compilerInterface = device->getNEODevice()->getCompilerInterface();
|
||||
UNRECOVERABLE_IF(nullptr == compilerInterface);
|
||||
|
||||
std::string internalOptions = this->generateCompilerOptions(buildOptions, internalBuildOptions);
|
||||
|
||||
for (uint32_t i = 0; i < static_cast<uint32_t>(specConstants.size()); i++) {
|
||||
auto specConstantResult = this->processSpecConstantInfo(compilerInterface, specConstants[i], inputSpirVs[i], inputModuleSizes[i]);
|
||||
if (!specConstantResult) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
NEO::TranslationInput linkInputArgs = {IGC::CodeType::elf, IGC::CodeType::oclGenBin};
|
||||
|
||||
auto spirvElfSource = generateElfFromSpirV(inputSpirVs, inputModuleSizes);
|
||||
|
||||
linkInputArgs.src = ArrayRef<const char>(reinterpret_cast<const char *>(spirvElfSource.data()), spirvElfSource.size());
|
||||
linkInputArgs.apiOptions = ArrayRef<const char>(options.c_str(), options.length());
|
||||
linkInputArgs.internalOptions = ArrayRef<const char>(internalOptions.c_str(), internalOptions.length());
|
||||
return this->compileGenBinary(linkInputArgs, true);
|
||||
}
|
||||
|
||||
bool ModuleTranslationUnit::buildFromSpirV(const char *input, uint32_t inputSize, const char *buildOptions, const char *internalBuildOptions,
|
||||
const ze_module_constants_t *pConstants) {
|
||||
auto compilerInterface = device->getNEODevice()->getCompilerInterface();
|
||||
UNRECOVERABLE_IF(nullptr == compilerInterface);
|
||||
|
||||
std::string internalOptions = this->generateCompilerOptions(buildOptions, internalBuildOptions);
|
||||
|
||||
auto specConstantResult = this->processSpecConstantInfo(compilerInterface, pConstants, input, inputSize);
|
||||
if (!specConstantResult)
|
||||
return false;
|
||||
|
||||
NEO::TranslationInput inputArgs = {IGC::CodeType::spirV, IGC::CodeType::oclGenBin};
|
||||
|
||||
inputArgs.src = ArrayRef<const char>(input, inputSize);
|
||||
inputArgs.apiOptions = ArrayRef<const char>(options.c_str(), options.length());
|
||||
inputArgs.internalOptions = ArrayRef<const char>(internalOptions.c_str(), internalOptions.length());
|
||||
return this->compileGenBinary(inputArgs, false);
|
||||
}
|
||||
|
||||
bool ModuleTranslationUnit::createFromNativeBinary(const char *input, size_t inputSize) {
|
||||
UNRECOVERABLE_IF((nullptr == device) || (nullptr == device->getNEODevice()));
|
||||
auto productAbbreviation = NEO::hardwarePrefix[device->getNEODevice()->getHardwareInfo().platform.eProductFamily];
|
||||
@@ -438,60 +352,19 @@ bool ModuleImp::initialize(const ze_module_desc_t *desc, NEO::Device *neoDevice)
|
||||
std::string buildOptions;
|
||||
std::string internalBuildOptions;
|
||||
|
||||
if (desc->pNext) {
|
||||
const ze_base_desc_t *expDesc = reinterpret_cast<const ze_base_desc_t *>(desc->pNext);
|
||||
if (expDesc->stype == ZE_STRUCTURE_TYPE_MODULE_PROGRAM_EXP_DESC) {
|
||||
if (desc->format != ZE_MODULE_FORMAT_IL_SPIRV) {
|
||||
return false;
|
||||
}
|
||||
const ze_module_program_exp_desc_t *programExpDesc =
|
||||
reinterpret_cast<const ze_module_program_exp_desc_t *>(expDesc);
|
||||
std::vector<const char *> inputSpirVs;
|
||||
std::vector<uint32_t> inputModuleSizes;
|
||||
std::vector<const ze_module_constants_t *> specConstants;
|
||||
this->createBuildOptions(desc->pBuildFlags, buildOptions, internalBuildOptions);
|
||||
|
||||
this->createBuildOptions(nullptr, buildOptions, internalBuildOptions);
|
||||
|
||||
for (uint32_t i = 0; i < static_cast<uint32_t>(programExpDesc->count); i++) {
|
||||
std::string tmpBuildOptions;
|
||||
std::string tmpInternalBuildOptions;
|
||||
inputSpirVs.push_back(reinterpret_cast<const char *>(programExpDesc->pInputModules[i]));
|
||||
auto inputSizesInfo = const_cast<size_t *>(programExpDesc->inputSizes);
|
||||
uint32_t inputSize = static_cast<uint32_t>(inputSizesInfo[i]);
|
||||
inputModuleSizes.push_back(inputSize);
|
||||
if (programExpDesc->pConstants) {
|
||||
specConstants.push_back(programExpDesc->pConstants[i]);
|
||||
}
|
||||
if (programExpDesc->pBuildFlags) {
|
||||
this->createBuildOptions(programExpDesc->pBuildFlags[i], tmpBuildOptions, tmpInternalBuildOptions);
|
||||
buildOptions = buildOptions + tmpBuildOptions;
|
||||
internalBuildOptions = internalBuildOptions + tmpInternalBuildOptions;
|
||||
}
|
||||
}
|
||||
|
||||
success = this->translationUnit->staticLinkSpirV(inputSpirVs,
|
||||
inputModuleSizes,
|
||||
buildOptions.c_str(),
|
||||
internalBuildOptions.c_str(),
|
||||
specConstants);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (desc->format == ZE_MODULE_FORMAT_NATIVE) {
|
||||
success = this->translationUnit->createFromNativeBinary(
|
||||
reinterpret_cast<const char *>(desc->pInputModule), desc->inputSize);
|
||||
} else if (desc->format == ZE_MODULE_FORMAT_IL_SPIRV) {
|
||||
success = this->translationUnit->buildFromSpirV(reinterpret_cast<const char *>(desc->pInputModule),
|
||||
static_cast<uint32_t>(desc->inputSize),
|
||||
buildOptions.c_str(),
|
||||
internalBuildOptions.c_str(),
|
||||
desc->pConstants);
|
||||
} else {
|
||||
this->createBuildOptions(desc->pBuildFlags, buildOptions, internalBuildOptions);
|
||||
|
||||
if (desc->format == ZE_MODULE_FORMAT_NATIVE) {
|
||||
success = this->translationUnit->createFromNativeBinary(
|
||||
reinterpret_cast<const char *>(desc->pInputModule), desc->inputSize);
|
||||
} else if (desc->format == ZE_MODULE_FORMAT_IL_SPIRV) {
|
||||
success = this->translationUnit->buildFromSpirV(reinterpret_cast<const char *>(desc->pInputModule),
|
||||
static_cast<uint32_t>(desc->inputSize),
|
||||
buildOptions.c_str(),
|
||||
internalBuildOptions.c_str(),
|
||||
desc->pConstants);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
verifyDebugCapabilities();
|
||||
|
||||
@@ -35,14 +35,8 @@ struct ModuleTranslationUnit {
|
||||
virtual ~ModuleTranslationUnit();
|
||||
MOCKABLE_VIRTUAL bool buildFromSpirV(const char *input, uint32_t inputSize, const char *buildOptions, const char *internalBuildOptions,
|
||||
const ze_module_constants_t *pConstants);
|
||||
MOCKABLE_VIRTUAL bool staticLinkSpirV(std::vector<const char *> inputSpirVs, std::vector<uint32_t> inputModuleSizes, const char *buildOptions, const char *internalBuildOptions,
|
||||
std::vector<const ze_module_constants_t *> specConstants);
|
||||
MOCKABLE_VIRTUAL bool createFromNativeBinary(const char *input, size_t inputSize);
|
||||
MOCKABLE_VIRTUAL bool processUnpackedBinary();
|
||||
std::vector<uint8_t> generateElfFromSpirV(std::vector<const char *> inputSpirVs, std::vector<uint32_t> inputModuleSizes);
|
||||
bool processSpecConstantInfo(NEO::CompilerInterface *compilerInterface, const ze_module_constants_t *pConstants, const char *input, uint32_t inputSize);
|
||||
std::string generateCompilerOptions(const char *buildOptions, const char *internalBuildOptions);
|
||||
bool compileGenBinary(NEO::TranslationInput inputArgs, bool staticLink);
|
||||
void updateBuildLog(const std::string &newLogEntry);
|
||||
void processDebugData();
|
||||
L0::Device *device = nullptr;
|
||||
|
||||
@@ -90,12 +90,6 @@ struct MockCompilerInterface : public NEO::CompilerInterface {
|
||||
|
||||
return NEO::TranslationOutput::ErrorCode::Success;
|
||||
}
|
||||
NEO::TranslationOutput::ErrorCode link(const NEO::Device &device,
|
||||
const NEO::TranslationInput &input,
|
||||
NEO::TranslationOutput &output) override {
|
||||
|
||||
return NEO::TranslationOutput::ErrorCode::Success;
|
||||
}
|
||||
};
|
||||
template <typename T1, typename T2>
|
||||
struct MockCompilerInterfaceWithSpecConstants : public NEO::CompilerInterface {
|
||||
@@ -109,14 +103,6 @@ struct MockCompilerInterfaceWithSpecConstants : public NEO::CompilerInterface {
|
||||
|
||||
return NEO::TranslationOutput::ErrorCode::Success;
|
||||
}
|
||||
NEO::TranslationOutput::ErrorCode link(const NEO::Device &device,
|
||||
const NEO::TranslationInput &input,
|
||||
NEO::TranslationOutput &output) override {
|
||||
|
||||
EXPECT_EQ(moduleNumSpecConstants, input.specializedValues.size());
|
||||
|
||||
return NEO::TranslationOutput::ErrorCode::Success;
|
||||
}
|
||||
|
||||
NEO::TranslationOutput::ErrorCode getSpecConstantsInfo(const NEO::Device &device,
|
||||
ArrayRef<const char> srcSpirV, NEO::SpecConstantInfo &output) override {
|
||||
@@ -136,14 +122,5 @@ struct MockCompilerInterfaceWithSpecConstants : public NEO::CompilerInterface {
|
||||
static_assert(sizeof(T1) < sizeof(T2));
|
||||
};
|
||||
|
||||
struct MockCompilerInterfaceLinkFailure : public NEO::CompilerInterface {
|
||||
NEO::TranslationOutput::ErrorCode link(const NEO::Device &device,
|
||||
const NEO::TranslationInput &input,
|
||||
NEO::TranslationOutput &output) override {
|
||||
|
||||
return NEO::TranslationOutput::ErrorCode::BuildFailure;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
|
||||
@@ -533,62 +533,6 @@ struct ModuleSpecConstantsTests : public DeviceFixture,
|
||||
module->destroy();
|
||||
}
|
||||
|
||||
void runTestStatic() {
|
||||
std::string testFile;
|
||||
retrieveBinaryKernelFilenameNoRevision(testFile, binaryFilename + "_", ".spv");
|
||||
|
||||
size_t sizeModule1, sizeModule2 = 0;
|
||||
auto srcModule1 = loadDataFromFile(testFile.c_str(), sizeModule1);
|
||||
auto srcModule2 = loadDataFromFile(testFile.c_str(), sizeModule2);
|
||||
|
||||
ASSERT_NE(0u, sizeModule1);
|
||||
ASSERT_NE(0u, sizeModule2);
|
||||
ASSERT_NE(nullptr, srcModule1);
|
||||
ASSERT_NE(nullptr, srcModule2);
|
||||
|
||||
ze_module_desc_t combinedModuleDesc = {ZE_STRUCTURE_TYPE_MODULE_DESC};
|
||||
ze_module_program_exp_desc_t staticLinkModuleDesc = {ZE_STRUCTURE_TYPE_MODULE_PROGRAM_EXP_DESC};
|
||||
std::vector<const uint8_t *> inputSpirVs;
|
||||
std::vector<size_t> inputSizes;
|
||||
std::vector<ze_module_constants_t *> specConstantsArray;
|
||||
combinedModuleDesc.format = ZE_MODULE_FORMAT_IL_SPIRV;
|
||||
combinedModuleDesc.pNext = &staticLinkModuleDesc;
|
||||
|
||||
specConstants.numConstants = mockCompiler->moduleNumSpecConstants;
|
||||
for (uint32_t i = mockCompiler->moduleNumSpecConstants / 2; i > 0; i--) {
|
||||
specConstantsPointerValues.push_back(&mockCompiler->moduleSpecConstantsValuesT1[i - 1]);
|
||||
specConstantsPointerValues.push_back(&mockCompiler->moduleSpecConstantsValuesT2[i - 1]);
|
||||
}
|
||||
for (uint32_t i = mockCompiler->moduleNumSpecConstants; i > 0; i--) {
|
||||
specConstantsPointerIds.push_back(mockCompiler->moduleSpecConstantsIds[i - 1]);
|
||||
}
|
||||
specConstants.pConstantIds = specConstantsPointerIds.data();
|
||||
specConstants.pConstantValues = specConstantsPointerValues.data();
|
||||
specConstantsArray.push_back(&specConstants);
|
||||
specConstantsArray.push_back(&specConstants);
|
||||
|
||||
inputSizes.push_back(sizeModule1);
|
||||
inputSpirVs.push_back(reinterpret_cast<const uint8_t *>(srcModule1.get()));
|
||||
inputSizes.push_back(sizeModule2);
|
||||
inputSpirVs.push_back(reinterpret_cast<const uint8_t *>(srcModule2.get()));
|
||||
|
||||
staticLinkModuleDesc.count = 2;
|
||||
staticLinkModuleDesc.inputSizes = inputSizes.data();
|
||||
staticLinkModuleDesc.pInputModules = inputSpirVs.data();
|
||||
staticLinkModuleDesc.pConstants = const_cast<const ze_module_constants_t **>(specConstantsArray.data());
|
||||
|
||||
auto module = new Module(device, nullptr, ModuleType::User);
|
||||
module->translationUnit.reset(mockTranslationUnit);
|
||||
|
||||
bool success = module->initialize(&combinedModuleDesc, neoDevice);
|
||||
for (uint32_t i = 0; i < mockCompiler->moduleNumSpecConstants / 2; i++) {
|
||||
EXPECT_EQ(static_cast<uint64_t>(module->translationUnit->specConstantsValues[mockCompiler->moduleSpecConstantsIds[2 * i]]), static_cast<uint64_t>(mockCompiler->moduleSpecConstantsValuesT2[i]));
|
||||
EXPECT_EQ(static_cast<uint64_t>(module->translationUnit->specConstantsValues[mockCompiler->moduleSpecConstantsIds[2 * i + 1]]), static_cast<uint64_t>(mockCompiler->moduleSpecConstantsValuesT1[i]));
|
||||
}
|
||||
EXPECT_TRUE(success);
|
||||
module->destroy();
|
||||
}
|
||||
|
||||
const uint32_t moduleNumSpecConstants = 3 * 2;
|
||||
ze_module_constants_t specConstants;
|
||||
std::vector<const void *> specConstantsPointerValues;
|
||||
@@ -691,223 +635,6 @@ TEST_F(ModuleSpecConstantsLongTests, givenSpecializationConstantsSetWhenUserPass
|
||||
module->destroy();
|
||||
}
|
||||
|
||||
using ModuleSpecConstantsLongTests = ModuleSpecConstantsTests<uint32_t, uint64_t>;
|
||||
TEST_F(ModuleSpecConstantsLongTests, givenSpecializationConstantsSetWithLongSizeInExpDescriptorThenStaticLinkedModuleCorrectlyPassesThemToTheCompiler) {
|
||||
runTestStatic();
|
||||
}
|
||||
using ModuleSpecConstantsCharTests = ModuleSpecConstantsTests<char, uint32_t>;
|
||||
TEST_F(ModuleSpecConstantsCharTests, givenSpecializationConstantsSetWithCharSizeInExpDescriptorThenStaticLinkedModuleCorrectlyPassesThemToTheCompiler) {
|
||||
runTestStatic();
|
||||
}
|
||||
|
||||
TEST_F(ModuleSpecConstantsLongTests, givenSpecializationConstantsSetWhenCompilerReturnsErrorFromStaticLinkThenModuleInitFails) {
|
||||
class FailingMockCompilerInterfaceWithSpecConstants : public MockCompilerInterfaceWithSpecConstants<uint32_t, uint64_t> {
|
||||
public:
|
||||
FailingMockCompilerInterfaceWithSpecConstants(uint32_t moduleNumSpecConstants) : MockCompilerInterfaceWithSpecConstants<uint32_t, uint64_t>(moduleNumSpecConstants) {}
|
||||
NEO::TranslationOutput::ErrorCode getSpecConstantsInfo(const NEO::Device &device,
|
||||
ArrayRef<const char> srcSpirV, NEO::SpecConstantInfo &output) override {
|
||||
return NEO::TranslationOutput::ErrorCode::CompilerNotAvailable;
|
||||
}
|
||||
};
|
||||
mockCompiler = new FailingMockCompilerInterfaceWithSpecConstants(moduleNumSpecConstants);
|
||||
auto rootDeviceEnvironment = neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0].get();
|
||||
rootDeviceEnvironment->compilerInterface.reset(mockCompiler);
|
||||
std::string testFile;
|
||||
retrieveBinaryKernelFilenameNoRevision(testFile, binaryFilename + "_", ".spv");
|
||||
|
||||
size_t sizeModule1, sizeModule2 = 0;
|
||||
auto srcModule1 = loadDataFromFile(testFile.c_str(), sizeModule1);
|
||||
auto srcModule2 = loadDataFromFile(testFile.c_str(), sizeModule2);
|
||||
|
||||
ASSERT_NE(0u, sizeModule1);
|
||||
ASSERT_NE(0u, sizeModule2);
|
||||
ASSERT_NE(nullptr, srcModule1);
|
||||
ASSERT_NE(nullptr, srcModule2);
|
||||
|
||||
ze_module_desc_t combinedModuleDesc = {ZE_STRUCTURE_TYPE_MODULE_DESC};
|
||||
ze_module_program_exp_desc_t staticLinkModuleDesc = {ZE_STRUCTURE_TYPE_MODULE_PROGRAM_EXP_DESC};
|
||||
std::vector<const uint8_t *> inputSpirVs;
|
||||
std::vector<size_t> inputSizes;
|
||||
std::vector<ze_module_constants_t *> specConstantsArray;
|
||||
combinedModuleDesc.format = ZE_MODULE_FORMAT_IL_SPIRV;
|
||||
combinedModuleDesc.pNext = &staticLinkModuleDesc;
|
||||
|
||||
specConstants.numConstants = mockCompiler->moduleNumSpecConstants;
|
||||
for (uint32_t i = mockCompiler->moduleNumSpecConstants / 2; i > 0; i--) {
|
||||
specConstantsPointerValues.push_back(&mockCompiler->moduleSpecConstantsValuesT1[i - 1]);
|
||||
specConstantsPointerValues.push_back(&mockCompiler->moduleSpecConstantsValuesT2[i - 1]);
|
||||
}
|
||||
for (uint32_t i = mockCompiler->moduleNumSpecConstants; i > 0; i--) {
|
||||
specConstantsPointerIds.push_back(mockCompiler->moduleSpecConstantsIds[i - 1]);
|
||||
}
|
||||
specConstants.pConstantIds = specConstantsPointerIds.data();
|
||||
specConstants.pConstantValues = specConstantsPointerValues.data();
|
||||
specConstantsArray.push_back(&specConstants);
|
||||
specConstantsArray.push_back(&specConstants);
|
||||
|
||||
inputSizes.push_back(sizeModule1);
|
||||
inputSpirVs.push_back(reinterpret_cast<const uint8_t *>(srcModule1.get()));
|
||||
inputSizes.push_back(sizeModule2);
|
||||
inputSpirVs.push_back(reinterpret_cast<const uint8_t *>(srcModule2.get()));
|
||||
|
||||
staticLinkModuleDesc.count = 2;
|
||||
staticLinkModuleDesc.inputSizes = inputSizes.data();
|
||||
staticLinkModuleDesc.pInputModules = inputSpirVs.data();
|
||||
staticLinkModuleDesc.pConstants = const_cast<const ze_module_constants_t **>(specConstantsArray.data());
|
||||
|
||||
auto module = new Module(device, nullptr, ModuleType::User);
|
||||
module->translationUnit.reset(mockTranslationUnit);
|
||||
|
||||
bool success = module->initialize(&combinedModuleDesc, neoDevice);
|
||||
EXPECT_FALSE(success);
|
||||
module->destroy();
|
||||
}
|
||||
|
||||
struct ModuleStaticLinkTests : public DeviceFixture,
|
||||
public ::testing::Test {
|
||||
void SetUp() override {
|
||||
DeviceFixture::SetUp();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
DeviceFixture::TearDown();
|
||||
}
|
||||
|
||||
void loadMultipleModules() {
|
||||
std::string testFile;
|
||||
retrieveBinaryKernelFilenameNoRevision(testFile, binaryFilename + "_", ".spv");
|
||||
|
||||
srcModule1 = loadDataFromFile(testFile.c_str(), sizeModule1);
|
||||
srcModule2 = loadDataFromFile(testFile.c_str(), sizeModule2);
|
||||
|
||||
ASSERT_NE(0u, sizeModule1);
|
||||
ASSERT_NE(0u, sizeModule2);
|
||||
ASSERT_NE(nullptr, srcModule1);
|
||||
ASSERT_NE(nullptr, srcModule2);
|
||||
}
|
||||
|
||||
void setupExpProgramDesc(ze_module_format_t format) {
|
||||
combinedModuleDesc.format = format;
|
||||
combinedModuleDesc.pNext = &staticLinkModuleDesc;
|
||||
|
||||
inputSizes.push_back(sizeModule1);
|
||||
inputSpirVs.push_back(reinterpret_cast<const uint8_t *>(srcModule1.get()));
|
||||
inputSizes.push_back(sizeModule2);
|
||||
inputSpirVs.push_back(reinterpret_cast<const uint8_t *>(srcModule2.get()));
|
||||
|
||||
staticLinkModuleDesc.count = 2;
|
||||
staticLinkModuleDesc.inputSizes = inputSizes.data();
|
||||
staticLinkModuleDesc.pInputModules = inputSpirVs.data();
|
||||
}
|
||||
|
||||
void runLinkFailureTest() {
|
||||
MockCompilerInterfaceLinkFailure *mockCompiler;
|
||||
mockCompiler = new MockCompilerInterfaceLinkFailure();
|
||||
auto rootDeviceEnvironment = neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0].get();
|
||||
rootDeviceEnvironment->compilerInterface.reset(mockCompiler);
|
||||
mockTranslationUnit = new MockModuleTranslationUnit(device);
|
||||
|
||||
loadMultipleModules();
|
||||
|
||||
setupExpProgramDesc(ZE_MODULE_FORMAT_IL_SPIRV);
|
||||
|
||||
auto module = new Module(device, nullptr, ModuleType::User);
|
||||
module->translationUnit.reset(mockTranslationUnit);
|
||||
|
||||
bool success = module->initialize(&combinedModuleDesc, neoDevice);
|
||||
EXPECT_FALSE(success);
|
||||
module->destroy();
|
||||
}
|
||||
void runSpirvFailureTest() {
|
||||
MockCompilerInterface *mockCompiler;
|
||||
mockCompiler = new MockCompilerInterface();
|
||||
auto rootDeviceEnvironment = neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0].get();
|
||||
rootDeviceEnvironment->compilerInterface.reset(mockCompiler);
|
||||
mockTranslationUnit = new MockModuleTranslationUnit(device);
|
||||
|
||||
loadMultipleModules();
|
||||
|
||||
setupExpProgramDesc(ZE_MODULE_FORMAT_NATIVE);
|
||||
|
||||
auto module = new Module(device, nullptr, ModuleType::User);
|
||||
module->translationUnit.reset(mockTranslationUnit);
|
||||
|
||||
bool success = module->initialize(&combinedModuleDesc, neoDevice);
|
||||
EXPECT_FALSE(success);
|
||||
module->destroy();
|
||||
}
|
||||
void runExpDescFailureTest() {
|
||||
MockCompilerInterface *mockCompiler;
|
||||
mockCompiler = new MockCompilerInterface();
|
||||
auto rootDeviceEnvironment = neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0].get();
|
||||
rootDeviceEnvironment->compilerInterface.reset(mockCompiler);
|
||||
mockTranslationUnit = new MockModuleTranslationUnit(device);
|
||||
|
||||
ze_module_desc_t invalidExpDesc = {ZE_STRUCTURE_TYPE_MODULE_DESC};
|
||||
combinedModuleDesc.format = ZE_MODULE_FORMAT_IL_SPIRV;
|
||||
combinedModuleDesc.pNext = &invalidExpDesc;
|
||||
|
||||
auto module = new Module(device, nullptr, ModuleType::User);
|
||||
module->translationUnit.reset(mockTranslationUnit);
|
||||
|
||||
bool success = module->initialize(&combinedModuleDesc, neoDevice);
|
||||
EXPECT_FALSE(success);
|
||||
module->destroy();
|
||||
}
|
||||
void runSprivLinkBuildFlags() {
|
||||
MockCompilerInterface *mockCompiler;
|
||||
mockCompiler = new MockCompilerInterface();
|
||||
auto rootDeviceEnvironment = neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0].get();
|
||||
rootDeviceEnvironment->compilerInterface.reset(mockCompiler);
|
||||
mockTranslationUnit = new MockModuleTranslationUnit(device);
|
||||
|
||||
loadMultipleModules();
|
||||
|
||||
setupExpProgramDesc(ZE_MODULE_FORMAT_IL_SPIRV);
|
||||
|
||||
std::vector<char *> buildFlags;
|
||||
std::string module1BuildFlags("-ze-opt-disable");
|
||||
std::string module2BuildFlags("-ze-opt-greater-than-4GB-buffer-required");
|
||||
buildFlags.push_back(const_cast<char *>(module1BuildFlags.c_str()));
|
||||
buildFlags.push_back(const_cast<char *>(module2BuildFlags.c_str()));
|
||||
|
||||
staticLinkModuleDesc.pBuildFlags = const_cast<const char **>(buildFlags.data());
|
||||
|
||||
auto module = new Module(device, nullptr, ModuleType::User);
|
||||
module->translationUnit.reset(mockTranslationUnit);
|
||||
|
||||
bool success = module->initialize(&combinedModuleDesc, neoDevice);
|
||||
EXPECT_TRUE(success);
|
||||
module->destroy();
|
||||
}
|
||||
const std::string binaryFilename = "test_kernel";
|
||||
const std::string kernelName = "test";
|
||||
MockModuleTranslationUnit *mockTranslationUnit;
|
||||
std::unique_ptr<char[]> srcModule1;
|
||||
std::unique_ptr<char[]> srcModule2;
|
||||
size_t sizeModule1, sizeModule2 = 0;
|
||||
std::vector<const uint8_t *> inputSpirVs;
|
||||
std::vector<size_t> inputSizes;
|
||||
ze_module_desc_t combinedModuleDesc = {ZE_STRUCTURE_TYPE_MODULE_DESC};
|
||||
ze_module_program_exp_desc_t staticLinkModuleDesc = {ZE_STRUCTURE_TYPE_MODULE_PROGRAM_EXP_DESC};
|
||||
};
|
||||
|
||||
TEST_F(ModuleStaticLinkTests, givenMultipleModulesProvidedForSpirVStaticLinkAndCompilerFailsThenFailureIsReturned) {
|
||||
runLinkFailureTest();
|
||||
}
|
||||
|
||||
TEST_F(ModuleStaticLinkTests, givenMultipleModulesProvidedForSpirVStaticLinkAndFormatIsNotSpirvThenFailureisReturned) {
|
||||
runSpirvFailureTest();
|
||||
}
|
||||
|
||||
TEST_F(ModuleStaticLinkTests, givenInvalidExpDescForModuleCreateThenFailureisReturned) {
|
||||
runExpDescFailureTest();
|
||||
}
|
||||
|
||||
TEST_F(ModuleStaticLinkTests, givenMultipleModulesProvidedForSpirVStaticLinkAndBuildFlagsRequestedThenSuccessisReturned) {
|
||||
runSprivLinkBuildFlags();
|
||||
}
|
||||
|
||||
using ModuleLinkingTest = Test<DeviceFixture>;
|
||||
|
||||
HWTEST_F(ModuleLinkingTest, whenExternFunctionsAllocationIsPresentThenItsBeingAddedToResidencyContainer) {
|
||||
|
||||
Reference in New Issue
Block a user