@@ -72,8 +72,6 @@ cl_int CompilerInterface::build(
72
72
highLevelCodeType = IGC::CodeType::oclC;
73
73
if (useLlvmText == true ) {
74
74
intermediateCodeType = IGC::CodeType::llvmLl;
75
- } else {
76
- intermediateCodeType = IGC::CodeType::llvmBc;
77
75
}
78
76
}
79
77
@@ -90,7 +88,10 @@ cl_int CompilerInterface::build(
90
88
uint32_t numDevices = static_cast <uint32_t >(program.getNumDevices ());
91
89
for (uint32_t i = 0 ; i < numDevices; i++) {
92
90
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
+ }
94
95
95
96
bool binaryLoaded = false ;
96
97
std::string kernelFileHash;
@@ -124,7 +125,7 @@ cl_int CompilerInterface::build(
124
125
return CL_BUILD_PROGRAM_FAILURE;
125
126
}
126
127
127
- program.storeLlvmBinary (fclOutput->GetOutput ()->GetMemory <char >(), fclOutput->GetOutput ()->GetSizeRaw ());
128
+ program.storeIrBinary (fclOutput->GetOutput ()->GetMemory <char >(), fclOutput->GetOutput ()->GetSizeRaw (), intermediateCodeType == IGC::CodeType::spirV );
128
129
program.updateBuildLog (&device, fclOutput->GetBuildLog ()->GetMemory <char >(), fclOutput->GetBuildLog ()->GetSizeRaw ());
129
130
130
131
fclOutput->GetOutput ()->Retain (); // will be used as input to compiler
@@ -186,14 +187,15 @@ cl_int CompilerInterface::compile(
186
187
inType = IGC::CodeType::elf;
187
188
if (useLlvmText == true ) {
188
189
outType = IGC::CodeType::llvmLl;
189
- } else {
190
- outType = IGC::CodeType::llvmBc;
191
190
}
192
191
}
193
192
194
193
uint32_t numDevices = static_cast <uint32_t >(program.getNumDevices ());
195
194
for (uint32_t i = 0 ; i < numDevices; i++) {
196
195
const auto &device = program.getDevice (i);
196
+ if (outType == IGC::CodeType::undefined) {
197
+ outType = getPreferredIntermediateRepresentation (device);
198
+ }
197
199
198
200
if (fromIntermediate == false ) {
199
201
auto fclSrc = CIF::Builtins::CreateConstBuffer (fclMain.get (), inputArgs.pInput , inputArgs.InputSize );
@@ -214,13 +216,13 @@ cl_int CompilerInterface::compile(
214
216
return CL_COMPILE_PROGRAM_FAILURE;
215
217
}
216
218
217
- program.storeLlvmBinary (fclOutput->GetOutput ()->GetMemory <char >(), fclOutput->GetOutput ()->GetSizeRaw ());
219
+ program.storeIrBinary (fclOutput->GetOutput ()->GetMemory <char >(), fclOutput->GetOutput ()->GetSizeRaw (), outType == IGC::CodeType::spirV );
218
220
program.updateBuildLog (&device, fclOutput->GetBuildLog ()->GetMemory <char >(), fclOutput->GetBuildLog ()->GetSizeRaw ());
219
221
} else {
220
222
char *pOutput;
221
223
uint32_t OutputSize;
222
224
program.getSource (pOutput, OutputSize);
223
- program.storeLlvmBinary (pOutput, OutputSize);
225
+ program.storeIrBinary (pOutput, OutputSize, outType == IGC::CodeType::spirV );
224
226
}
225
227
}
226
228
@@ -249,8 +251,8 @@ cl_int CompilerInterface::link(
249
251
CIF::RAII::UPtr_t<IGC::OclTranslationOutputTagOCL> currOut;
250
252
inSrc->Retain (); // shared with currSrc
251
253
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};
254
256
constexpr size_t numTranslations = sizeof (translationChain) / sizeof (translationChain[0 ]);
255
257
for (size_t ti = 1 ; ti < numTranslations; ti++) {
256
258
IGC::CodeType::CodeType_t inType = translationChain[ti - 1 ];
@@ -295,7 +297,8 @@ cl_int CompilerInterface::createLibrary(
295
297
auto igcOptions = CIF::Builtins::CreateConstBuffer (igcMain.get (), inputArgs.pOptions , inputArgs.OptionsSize );
296
298
auto igcInternalOptions = CIF::Builtins::CreateConstBuffer (igcMain.get (), inputArgs.pInternalOptions , inputArgs.InternalOptionsSize );
297
299
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);
299
302
300
303
auto igcOutput = translate (igcTranslationCtx.get (), igcSrc.get (),
301
304
igcOptions.get (), igcInternalOptions.get ());
@@ -309,7 +312,7 @@ cl_int CompilerInterface::createLibrary(
309
312
return CL_BUILD_PROGRAM_FAILURE;
310
313
}
311
314
312
- program.storeLlvmBinary (igcOutput->GetOutput ()->GetMemory <char >(), igcOutput->GetOutput ()->GetSizeRaw ());
315
+ program.storeIrBinary (igcOutput->GetOutput ()->GetMemory <char >(), igcOutput->GetOutput ()->GetSizeRaw (), intermediateRepresentation == IGC::CodeType::spirV );
313
316
program.updateBuildLog (&device, igcOutput->GetBuildLog ()->GetMemory <char >(), igcOutput->GetBuildLog ()->GetSizeRaw ());
314
317
}
315
318
@@ -362,17 +365,17 @@ BinaryCache *CompilerInterface::replaceBinaryCache(BinaryCache *newCache) {
362
365
return res;
363
366
}
364
367
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) {
366
369
auto it = fclDeviceContexts.find (&device);
367
370
if (it != fclDeviceContexts.end ()) {
368
- return it->second -> CreateTranslationCtx (inType, outType );
371
+ return it->second . get ( );
369
372
}
370
373
371
374
{
372
375
auto ulock = this ->lock ();
373
376
it = fclDeviceContexts.find (&device);
374
377
if (it != fclDeviceContexts.end ()) {
375
- return it->second -> CreateTranslationCtx (inType, outType );
378
+ return it->second . get ( );
376
379
}
377
380
378
381
if (fclMain == nullptr ) {
@@ -388,12 +391,27 @@ CIF::RAII::UPtr_t<IGC::FclOclTranslationCtxTagOCL> CompilerInterface::createFclT
388
391
newDeviceCtx->SetOclApiVersion (device.getHardwareInfo ().capabilityTable .clVersionSupport * 10 );
389
392
fclDeviceContexts[&device] = std::move (newDeviceCtx);
390
393
391
- if (fclBaseTranslationCtx == nullptr ) {
392
- fclBaseTranslationCtx = fclDeviceContexts[&device]-> CreateTranslationCtx (inType, outType);
393
- }
394
+ return fclDeviceContexts[&device]. get ();
395
+ }
396
+ }
394
397
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);
396
412
}
413
+
414
+ return deviceCtx->CreateTranslationCtx (inType, outType);
397
415
}
398
416
399
417
CIF::RAII::UPtr_t<IGC::IgcOclTranslationCtxTagOCL> CompilerInterface::createIgcTranslationCtx (const Device &device, IGC::CodeType::CodeType_t inType, IGC::CodeType::CodeType_t outType) {
0 commit comments