@@ -72,8 +72,6 @@ cl_int CompilerInterface::build(
7272 highLevelCodeType = IGC::CodeType::oclC;
7373 if (useLlvmText == true ) {
7474 intermediateCodeType = IGC::CodeType::llvmLl;
75- } else {
76- intermediateCodeType = IGC::CodeType::llvmBc;
7775 }
7876 }
7977
@@ -90,7 +88,10 @@ cl_int CompilerInterface::build(
9088 uint32_t numDevices = static_cast <uint32_t >(program.getNumDevices ());
9189 for (uint32_t i = 0 ; i < numDevices; i++) {
9290 const auto &device = program.getDevice (i);
93- UNRECOVERABLE_IF (intermediateCodeType == IGC::CodeType::undefined);
91+ if (intermediateCodeType == IGC::CodeType::undefined) {
92+ UNRECOVERABLE_IF (highLevelCodeType != IGC::CodeType::oclC);
93+ intermediateCodeType = getPreferredIntermediateRepresentation (device);
94+ }
9495
9596 bool binaryLoaded = false ;
9697 std::string kernelFileHash;
@@ -124,7 +125,7 @@ cl_int CompilerInterface::build(
124125 return CL_BUILD_PROGRAM_FAILURE;
125126 }
126127
127- program.storeLlvmBinary (fclOutput->GetOutput ()->GetMemory <char >(), fclOutput->GetOutput ()->GetSizeRaw ());
128+ program.storeIrBinary (fclOutput->GetOutput ()->GetMemory <char >(), fclOutput->GetOutput ()->GetSizeRaw (), intermediateCodeType == IGC::CodeType::spirV );
128129 program.updateBuildLog (&device, fclOutput->GetBuildLog ()->GetMemory <char >(), fclOutput->GetBuildLog ()->GetSizeRaw ());
129130
130131 fclOutput->GetOutput ()->Retain (); // will be used as input to compiler
@@ -186,14 +187,15 @@ cl_int CompilerInterface::compile(
186187 inType = IGC::CodeType::elf;
187188 if (useLlvmText == true ) {
188189 outType = IGC::CodeType::llvmLl;
189- } else {
190- outType = IGC::CodeType::llvmBc;
191190 }
192191 }
193192
194193 uint32_t numDevices = static_cast <uint32_t >(program.getNumDevices ());
195194 for (uint32_t i = 0 ; i < numDevices; i++) {
196195 const auto &device = program.getDevice (i);
196+ if (outType == IGC::CodeType::undefined) {
197+ outType = getPreferredIntermediateRepresentation (device);
198+ }
197199
198200 if (fromIntermediate == false ) {
199201 auto fclSrc = CIF::Builtins::CreateConstBuffer (fclMain.get (), inputArgs.pInput , inputArgs.InputSize );
@@ -214,13 +216,13 @@ cl_int CompilerInterface::compile(
214216 return CL_COMPILE_PROGRAM_FAILURE;
215217 }
216218
217- program.storeLlvmBinary (fclOutput->GetOutput ()->GetMemory <char >(), fclOutput->GetOutput ()->GetSizeRaw ());
219+ program.storeIrBinary (fclOutput->GetOutput ()->GetMemory <char >(), fclOutput->GetOutput ()->GetSizeRaw (), outType == IGC::CodeType::spirV );
218220 program.updateBuildLog (&device, fclOutput->GetBuildLog ()->GetMemory <char >(), fclOutput->GetBuildLog ()->GetSizeRaw ());
219221 } else {
220222 char *pOutput;
221223 uint32_t OutputSize;
222224 program.getSource (pOutput, OutputSize);
223- program.storeLlvmBinary (pOutput, OutputSize);
225+ program.storeIrBinary (pOutput, OutputSize, outType == IGC::CodeType::spirV );
224226 }
225227 }
226228
@@ -249,8 +251,8 @@ cl_int CompilerInterface::link(
249251 CIF::RAII::UPtr_t<IGC::OclTranslationOutputTagOCL> currOut;
250252 inSrc->Retain (); // shared with currSrc
251253 CIF::RAII::UPtr_t<CIF::Builtins::BufferSimple> currSrc (inSrc.get ());
252-
253- IGC::CodeType::CodeType_t translationChain[] = {IGC::CodeType::elf, IGC::CodeType::llvmBc , IGC::CodeType::oclGenBin};
254+ auto intermediateRepresentation = getPreferredIntermediateRepresentation (device);
255+ IGC::CodeType::CodeType_t translationChain[] = {IGC::CodeType::elf, intermediateRepresentation , IGC::CodeType::oclGenBin};
254256 constexpr size_t numTranslations = sizeof (translationChain) / sizeof (translationChain[0 ]);
255257 for (size_t ti = 1 ; ti < numTranslations; ti++) {
256258 IGC::CodeType::CodeType_t inType = translationChain[ti - 1 ];
@@ -295,7 +297,8 @@ cl_int CompilerInterface::createLibrary(
295297 auto igcOptions = CIF::Builtins::CreateConstBuffer (igcMain.get (), inputArgs.pOptions , inputArgs.OptionsSize );
296298 auto igcInternalOptions = CIF::Builtins::CreateConstBuffer (igcMain.get (), inputArgs.pInternalOptions , inputArgs.InternalOptionsSize );
297299
298- auto igcTranslationCtx = createIgcTranslationCtx (device, IGC::CodeType::elf, IGC::CodeType::llvmBc);
300+ auto intermediateRepresentation = getPreferredIntermediateRepresentation (device);
301+ auto igcTranslationCtx = createIgcTranslationCtx (device, IGC::CodeType::elf, intermediateRepresentation);
299302
300303 auto igcOutput = translate (igcTranslationCtx.get (), igcSrc.get (),
301304 igcOptions.get (), igcInternalOptions.get ());
@@ -309,7 +312,7 @@ cl_int CompilerInterface::createLibrary(
309312 return CL_BUILD_PROGRAM_FAILURE;
310313 }
311314
312- program.storeLlvmBinary (igcOutput->GetOutput ()->GetMemory <char >(), igcOutput->GetOutput ()->GetSizeRaw ());
315+ program.storeIrBinary (igcOutput->GetOutput ()->GetMemory <char >(), igcOutput->GetOutput ()->GetSizeRaw (), intermediateRepresentation == IGC::CodeType::spirV );
313316 program.updateBuildLog (&device, igcOutput->GetBuildLog ()->GetMemory <char >(), igcOutput->GetBuildLog ()->GetSizeRaw ());
314317 }
315318
@@ -362,17 +365,17 @@ BinaryCache *CompilerInterface::replaceBinaryCache(BinaryCache *newCache) {
362365 return res;
363366}
364367
365- CIF::RAII::UPtr_t< IGC::FclOclTranslationCtxTagOCL> CompilerInterface::createFclTranslationCtx (const Device &device, IGC::CodeType::CodeType_t inType, IGC::CodeType::CodeType_t outType ) {
368+ IGC::FclOclDeviceCtxTagOCL * CompilerInterface::getFclDeviceCtx (const Device &device) {
366369 auto it = fclDeviceContexts.find (&device);
367370 if (it != fclDeviceContexts.end ()) {
368- return it->second -> CreateTranslationCtx (inType, outType );
371+ return it->second . get ( );
369372 }
370373
371374 {
372375 auto ulock = this ->lock ();
373376 it = fclDeviceContexts.find (&device);
374377 if (it != fclDeviceContexts.end ()) {
375- return it->second -> CreateTranslationCtx (inType, outType );
378+ return it->second . get ( );
376379 }
377380
378381 if (fclMain == nullptr ) {
@@ -388,12 +391,27 @@ CIF::RAII::UPtr_t<IGC::FclOclTranslationCtxTagOCL> CompilerInterface::createFclT
388391 newDeviceCtx->SetOclApiVersion (device.getHardwareInfo ().capabilityTable .clVersionSupport * 10 );
389392 fclDeviceContexts[&device] = std::move (newDeviceCtx);
390393
391- if (fclBaseTranslationCtx == nullptr ) {
392- fclBaseTranslationCtx = fclDeviceContexts[&device]-> CreateTranslationCtx (inType, outType);
393- }
394+ return fclDeviceContexts[&device]. get ();
395+ }
396+ }
394397
395- return fclDeviceContexts[&device]->CreateTranslationCtx (inType, outType);
398+ IGC::CodeType::CodeType_t CompilerInterface::getPreferredIntermediateRepresentation (const Device &device) {
399+ return IGC::CodeType::llvmBc;
400+ }
401+
402+ CIF::RAII::UPtr_t<IGC::FclOclTranslationCtxTagOCL> CompilerInterface::createFclTranslationCtx (const Device &device, IGC::CodeType::CodeType_t inType, IGC::CodeType::CodeType_t outType) {
403+
404+ auto deviceCtx = getFclDeviceCtx (device);
405+ if (deviceCtx == nullptr ) {
406+ DEBUG_BREAK_IF (true ); // could not create device context
407+ return nullptr ;
408+ }
409+
410+ if (fclBaseTranslationCtx == nullptr ) {
411+ fclBaseTranslationCtx = fclDeviceContexts[&device]->CreateTranslationCtx (inType, outType);
396412 }
413+
414+ return deviceCtx->CreateTranslationCtx (inType, outType);
397415}
398416
399417CIF::RAII::UPtr_t<IGC::IgcOclTranslationCtxTagOCL> CompilerInterface::createIgcTranslationCtx (const Device &device, IGC::CodeType::CodeType_t inType, IGC::CodeType::CodeType_t outType) {
0 commit comments