Skip to content

Commit e7a7a61

Browse files
Revert "L0 support for SPIRv static module linking"
This reverts commit 479035c. Signed-off-by: Compute-Runtime-Validation <[email protected]>
1 parent 8939ca9 commit e7a7a61

File tree

4 files changed

+22
-451
lines changed

4 files changed

+22
-451
lines changed

level_zero/core/source/module/module_imp.cpp

Lines changed: 22 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
#include "shared/source/compiler_interface/linker.h"
1212
#include "shared/source/device/device.h"
1313
#include "shared/source/device_binary_format/device_binary_formats.h"
14-
#include "shared/source/device_binary_format/elf/elf.h"
15-
#include "shared/source/device_binary_format/elf/elf_encoder.h"
16-
#include "shared/source/device_binary_format/elf/ocl_elf.h"
1714
#include "shared/source/helpers/api_specific_config.h"
1815
#include "shared/source/helpers/constants.h"
1916
#include "shared/source/helpers/kernel_helpers.h"
@@ -77,37 +74,12 @@ ModuleTranslationUnit::~ModuleTranslationUnit() {
7774
}
7875
}
7976

80-
std::vector<uint8_t> ModuleTranslationUnit::generateElfFromSpirV(std::vector<const char *> inputSpirVs, std::vector<uint32_t> inputModuleSizes) {
81-
NEO::Elf::ElfEncoder<> elfEncoder(true, false, 1U);
82-
elfEncoder.getElfFileHeader().type = NEO::Elf::ET_OPENCL_OBJECTS;
83-
84-
StackVec<uint32_t, 64> specConstIds;
85-
StackVec<uint64_t, 64> specConstValues;
86-
for (uint32_t i = 0; i < static_cast<uint32_t>(inputSpirVs.size()); i++) {
87-
if (specConstantsValues.size() > 0) {
88-
specConstIds.clear();
89-
specConstValues.clear();
90-
specConstIds.reserve(specConstantsValues.size());
91-
specConstValues.reserve(specConstantsValues.size());
92-
for (const auto &specConst : specConstantsValues) {
93-
specConstIds.push_back(specConst.first);
94-
specConstValues.push_back(specConst.second);
95-
}
96-
elfEncoder.appendSection(NEO::Elf::SHT_OPENCL_SPIRV_SC_IDS, NEO::Elf::SectionNamesOpenCl::spirvSpecConstIds,
97-
ArrayRef<const uint8_t>::fromAny(specConstIds.begin(), specConstIds.size()));
98-
elfEncoder.appendSection(NEO::Elf::SHT_OPENCL_SPIRV_SC_VALUES, NEO::Elf::SectionNamesOpenCl::spirvSpecConstValues,
99-
ArrayRef<const uint8_t>::fromAny(specConstValues.begin(), specConstValues.size()));
100-
}
101-
102-
auto sectionType = NEO::Elf::SHT_OPENCL_SPIRV;
103-
NEO::ConstStringRef sectionName = NEO::Elf::SectionNamesOpenCl::spirvObject;
104-
elfEncoder.appendSection(sectionType, sectionName, ArrayRef<const uint8_t>(reinterpret_cast<const uint8_t *>(inputSpirVs[i]), inputModuleSizes[i]));
105-
}
106-
107-
return elfEncoder.encode();
108-
}
77+
bool ModuleTranslationUnit::buildFromSpirV(const char *input, uint32_t inputSize, const char *buildOptions, const char *internalBuildOptions,
78+
const ze_module_constants_t *pConstants) {
79+
UNRECOVERABLE_IF((nullptr == device) || (nullptr == device->getNEODevice()));
80+
auto compilerInterface = device->getNEODevice()->getCompilerInterface();
81+
UNRECOVERABLE_IF(nullptr == compilerInterface);
10982

110-
std::string ModuleTranslationUnit::generateCompilerOptions(const char *buildOptions, const char *internalBuildOptions) {
11183
if (nullptr != buildOptions) {
11284
options = buildOptions;
11385
}
@@ -127,10 +99,8 @@ std::string ModuleTranslationUnit::generateCompilerOptions(const char *buildOpti
12799
internalOptions = NEO::CompilerOptions::concatenate(internalOptions, NEO::CompilerOptions::greaterThan4gbBuffersRequired);
128100
}
129101

130-
return internalOptions;
131-
}
102+
NEO::TranslationInput inputArgs = {IGC::CodeType::spirV, IGC::CodeType::oclGenBin};
132103

133-
bool ModuleTranslationUnit::processSpecConstantInfo(NEO::CompilerInterface *compilerInterface, const ze_module_constants_t *pConstants, const char *input, uint32_t inputSize) {
134104
if (pConstants) {
135105
NEO::SpecConstantInfo specConstInfo;
136106
auto retVal = compilerInterface->getSpecConstantsInfo(*device->getNEODevice(), ArrayRef<const char>(input, inputSize), specConstInfo);
@@ -156,31 +126,18 @@ bool ModuleTranslationUnit::processSpecConstantInfo(NEO::CompilerInterface *comp
156126
specConstantsValues[specConstantId] = specConstantValue;
157127
}
158128
}
159-
return true;
160-
}
161-
162-
bool ModuleTranslationUnit::compileGenBinary(NEO::TranslationInput inputArgs, bool staticLink) {
163-
auto compilerInterface = device->getNEODevice()->getCompilerInterface();
164-
UNRECOVERABLE_IF(nullptr == compilerInterface);
165129

130+
inputArgs.src = ArrayRef<const char>(input, inputSize);
131+
inputArgs.apiOptions = ArrayRef<const char>(options.c_str(), options.length());
132+
inputArgs.internalOptions = ArrayRef<const char>(internalOptions.c_str(), internalOptions.length());
166133
inputArgs.specializedValues = this->specConstantsValues;
167-
168134
NEO::TranslationOutput compilerOuput = {};
169-
NEO::TranslationOutput::ErrorCode compilerErr;
170-
171-
if (staticLink) {
172-
compilerErr = compilerInterface->link(*device->getNEODevice(), inputArgs, compilerOuput);
173-
} else {
174-
compilerErr = compilerInterface->build(*device->getNEODevice(), inputArgs, compilerOuput);
175-
}
176-
135+
auto compilerErr = compilerInterface->build(*device->getNEODevice(), inputArgs, compilerOuput);
177136
this->updateBuildLog(compilerOuput.frontendCompilerLog);
178137
this->updateBuildLog(compilerOuput.backendCompilerLog);
179-
180138
if (NEO::TranslationOutput::ErrorCode::Success != compilerErr) {
181139
return false;
182140
}
183-
184141
this->irBinary = std::move(compilerOuput.intermediateRepresentation.mem);
185142
this->irBinarySize = compilerOuput.intermediateRepresentation.size;
186143
this->unpackedDeviceBinary = std::move(compilerOuput.deviceBinary.mem);
@@ -191,49 +148,6 @@ bool ModuleTranslationUnit::compileGenBinary(NEO::TranslationInput inputArgs, bo
191148
return processUnpackedBinary();
192149
}
193150

194-
bool ModuleTranslationUnit::staticLinkSpirV(std::vector<const char *> inputSpirVs, std::vector<uint32_t> inputModuleSizes, const char *buildOptions, const char *internalBuildOptions,
195-
std::vector<const ze_module_constants_t *> specConstants) {
196-
auto compilerInterface = device->getNEODevice()->getCompilerInterface();
197-
UNRECOVERABLE_IF(nullptr == compilerInterface);
198-
199-
std::string internalOptions = this->generateCompilerOptions(buildOptions, internalBuildOptions);
200-
201-
for (uint32_t i = 0; i < static_cast<uint32_t>(specConstants.size()); i++) {
202-
auto specConstantResult = this->processSpecConstantInfo(compilerInterface, specConstants[i], inputSpirVs[i], inputModuleSizes[i]);
203-
if (!specConstantResult) {
204-
return false;
205-
}
206-
}
207-
208-
NEO::TranslationInput linkInputArgs = {IGC::CodeType::elf, IGC::CodeType::oclGenBin};
209-
210-
auto spirvElfSource = generateElfFromSpirV(inputSpirVs, inputModuleSizes);
211-
212-
linkInputArgs.src = ArrayRef<const char>(reinterpret_cast<const char *>(spirvElfSource.data()), spirvElfSource.size());
213-
linkInputArgs.apiOptions = ArrayRef<const char>(options.c_str(), options.length());
214-
linkInputArgs.internalOptions = ArrayRef<const char>(internalOptions.c_str(), internalOptions.length());
215-
return this->compileGenBinary(linkInputArgs, true);
216-
}
217-
218-
bool ModuleTranslationUnit::buildFromSpirV(const char *input, uint32_t inputSize, const char *buildOptions, const char *internalBuildOptions,
219-
const ze_module_constants_t *pConstants) {
220-
auto compilerInterface = device->getNEODevice()->getCompilerInterface();
221-
UNRECOVERABLE_IF(nullptr == compilerInterface);
222-
223-
std::string internalOptions = this->generateCompilerOptions(buildOptions, internalBuildOptions);
224-
225-
auto specConstantResult = this->processSpecConstantInfo(compilerInterface, pConstants, input, inputSize);
226-
if (!specConstantResult)
227-
return false;
228-
229-
NEO::TranslationInput inputArgs = {IGC::CodeType::spirV, IGC::CodeType::oclGenBin};
230-
231-
inputArgs.src = ArrayRef<const char>(input, inputSize);
232-
inputArgs.apiOptions = ArrayRef<const char>(options.c_str(), options.length());
233-
inputArgs.internalOptions = ArrayRef<const char>(internalOptions.c_str(), internalOptions.length());
234-
return this->compileGenBinary(inputArgs, false);
235-
}
236-
237151
bool ModuleTranslationUnit::createFromNativeBinary(const char *input, size_t inputSize) {
238152
UNRECOVERABLE_IF((nullptr == device) || (nullptr == device->getNEODevice()));
239153
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)
438352
std::string buildOptions;
439353
std::string internalBuildOptions;
440354

441-
if (desc->pNext) {
442-
const ze_base_desc_t *expDesc = reinterpret_cast<const ze_base_desc_t *>(desc->pNext);
443-
if (expDesc->stype == ZE_STRUCTURE_TYPE_MODULE_PROGRAM_EXP_DESC) {
444-
if (desc->format != ZE_MODULE_FORMAT_IL_SPIRV) {
445-
return false;
446-
}
447-
const ze_module_program_exp_desc_t *programExpDesc =
448-
reinterpret_cast<const ze_module_program_exp_desc_t *>(expDesc);
449-
std::vector<const char *> inputSpirVs;
450-
std::vector<uint32_t> inputModuleSizes;
451-
std::vector<const ze_module_constants_t *> specConstants;
452-
453-
this->createBuildOptions(nullptr, buildOptions, internalBuildOptions);
454-
455-
for (uint32_t i = 0; i < static_cast<uint32_t>(programExpDesc->count); i++) {
456-
std::string tmpBuildOptions;
457-
std::string tmpInternalBuildOptions;
458-
inputSpirVs.push_back(reinterpret_cast<const char *>(programExpDesc->pInputModules[i]));
459-
auto inputSizesInfo = const_cast<size_t *>(programExpDesc->inputSizes);
460-
uint32_t inputSize = static_cast<uint32_t>(inputSizesInfo[i]);
461-
inputModuleSizes.push_back(inputSize);
462-
if (programExpDesc->pConstants) {
463-
specConstants.push_back(programExpDesc->pConstants[i]);
464-
}
465-
if (programExpDesc->pBuildFlags) {
466-
this->createBuildOptions(programExpDesc->pBuildFlags[i], tmpBuildOptions, tmpInternalBuildOptions);
467-
buildOptions = buildOptions + tmpBuildOptions;
468-
internalBuildOptions = internalBuildOptions + tmpInternalBuildOptions;
469-
}
470-
}
471-
472-
success = this->translationUnit->staticLinkSpirV(inputSpirVs,
473-
inputModuleSizes,
474-
buildOptions.c_str(),
475-
internalBuildOptions.c_str(),
476-
specConstants);
477-
} else {
478-
return false;
479-
}
355+
this->createBuildOptions(desc->pBuildFlags, buildOptions, internalBuildOptions);
356+
357+
if (desc->format == ZE_MODULE_FORMAT_NATIVE) {
358+
success = this->translationUnit->createFromNativeBinary(
359+
reinterpret_cast<const char *>(desc->pInputModule), desc->inputSize);
360+
} else if (desc->format == ZE_MODULE_FORMAT_IL_SPIRV) {
361+
success = this->translationUnit->buildFromSpirV(reinterpret_cast<const char *>(desc->pInputModule),
362+
static_cast<uint32_t>(desc->inputSize),
363+
buildOptions.c_str(),
364+
internalBuildOptions.c_str(),
365+
desc->pConstants);
480366
} else {
481-
this->createBuildOptions(desc->pBuildFlags, buildOptions, internalBuildOptions);
482-
483-
if (desc->format == ZE_MODULE_FORMAT_NATIVE) {
484-
success = this->translationUnit->createFromNativeBinary(
485-
reinterpret_cast<const char *>(desc->pInputModule), desc->inputSize);
486-
} else if (desc->format == ZE_MODULE_FORMAT_IL_SPIRV) {
487-
success = this->translationUnit->buildFromSpirV(reinterpret_cast<const char *>(desc->pInputModule),
488-
static_cast<uint32_t>(desc->inputSize),
489-
buildOptions.c_str(),
490-
internalBuildOptions.c_str(),
491-
desc->pConstants);
492-
} else {
493-
return false;
494-
}
367+
return false;
495368
}
496369

497370
verifyDebugCapabilities();

level_zero/core/source/module/module_imp.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,8 @@ struct ModuleTranslationUnit {
3535
virtual ~ModuleTranslationUnit();
3636
MOCKABLE_VIRTUAL bool buildFromSpirV(const char *input, uint32_t inputSize, const char *buildOptions, const char *internalBuildOptions,
3737
const ze_module_constants_t *pConstants);
38-
MOCKABLE_VIRTUAL bool staticLinkSpirV(std::vector<const char *> inputSpirVs, std::vector<uint32_t> inputModuleSizes, const char *buildOptions, const char *internalBuildOptions,
39-
std::vector<const ze_module_constants_t *> specConstants);
4038
MOCKABLE_VIRTUAL bool createFromNativeBinary(const char *input, size_t inputSize);
4139
MOCKABLE_VIRTUAL bool processUnpackedBinary();
42-
std::vector<uint8_t> generateElfFromSpirV(std::vector<const char *> inputSpirVs, std::vector<uint32_t> inputModuleSizes);
43-
bool processSpecConstantInfo(NEO::CompilerInterface *compilerInterface, const ze_module_constants_t *pConstants, const char *input, uint32_t inputSize);
44-
std::string generateCompilerOptions(const char *buildOptions, const char *internalBuildOptions);
45-
bool compileGenBinary(NEO::TranslationInput inputArgs, bool staticLink);
4640
void updateBuildLog(const std::string &newLogEntry);
4741
void processDebugData();
4842
L0::Device *device = nullptr;

level_zero/core/test/unit_tests/mocks/mock_module.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,6 @@ struct MockCompilerInterface : public NEO::CompilerInterface {
9090

9191
return NEO::TranslationOutput::ErrorCode::Success;
9292
}
93-
NEO::TranslationOutput::ErrorCode link(const NEO::Device &device,
94-
const NEO::TranslationInput &input,
95-
NEO::TranslationOutput &output) override {
96-
97-
return NEO::TranslationOutput::ErrorCode::Success;
98-
}
9993
};
10094
template <typename T1, typename T2>
10195
struct MockCompilerInterfaceWithSpecConstants : public NEO::CompilerInterface {
@@ -109,14 +103,6 @@ struct MockCompilerInterfaceWithSpecConstants : public NEO::CompilerInterface {
109103

110104
return NEO::TranslationOutput::ErrorCode::Success;
111105
}
112-
NEO::TranslationOutput::ErrorCode link(const NEO::Device &device,
113-
const NEO::TranslationInput &input,
114-
NEO::TranslationOutput &output) override {
115-
116-
EXPECT_EQ(moduleNumSpecConstants, input.specializedValues.size());
117-
118-
return NEO::TranslationOutput::ErrorCode::Success;
119-
}
120106

121107
NEO::TranslationOutput::ErrorCode getSpecConstantsInfo(const NEO::Device &device,
122108
ArrayRef<const char> srcSpirV, NEO::SpecConstantInfo &output) override {
@@ -136,14 +122,5 @@ struct MockCompilerInterfaceWithSpecConstants : public NEO::CompilerInterface {
136122
static_assert(sizeof(T1) < sizeof(T2));
137123
};
138124

139-
struct MockCompilerInterfaceLinkFailure : public NEO::CompilerInterface {
140-
NEO::TranslationOutput::ErrorCode link(const NEO::Device &device,
141-
const NEO::TranslationInput &input,
142-
NEO::TranslationOutput &output) override {
143-
144-
return NEO::TranslationOutput::ErrorCode::BuildFailure;
145-
}
146-
};
147-
148125
} // namespace ult
149126
} // namespace L0

0 commit comments

Comments
 (0)