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-
237151bool 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 ();
0 commit comments