@@ -347,6 +347,54 @@ RT::PiProgram ProgramManager::createPIProgram(const RTDeviceBinaryImage &Img,
347
347
348
348
return Res;
349
349
}
350
+ static void applyOptionsFromImage (std::string &CompileOpts,
351
+ std::string &LinkOpts,
352
+ const RTDeviceBinaryImage &Img) {
353
+ // Build options are overridden if environment variables are present.
354
+ // Environment variables are not changed during program lifecycle so it
355
+ // is reasonable to use static here to read them only once.
356
+ static const char *CompileOptsEnv =
357
+ SYCLConfig<SYCL_PROGRAM_COMPILE_OPTIONS>::get ();
358
+ static const char *LinkOptsEnv = SYCLConfig<SYCL_PROGRAM_LINK_OPTIONS>::get ();
359
+ // Update only if compile options are not overwritten by environment
360
+ // variable
361
+ if (!CompileOptsEnv) {
362
+ if (!CompileOpts.empty ())
363
+ CompileOpts += " " ;
364
+ CompileOpts += Img.getCompileOptions ();
365
+ }
366
+
367
+ // The -vc-codegen option is always preserved for ESIMD kernels, regardless
368
+ // of the contents SYCL_PROGRAM_COMPILE_OPTIONS environment variable.
369
+ pi_device_binary_property isEsimdImage = Img.getProperty (" isEsimdImage" );
370
+ if (isEsimdImage && pi::DeviceBinaryProperty (isEsimdImage).asUint32 ()) {
371
+ if (!CompileOpts.empty ())
372
+ CompileOpts += " " ;
373
+ CompileOpts += " -vc-codegen" ;
374
+ }
375
+
376
+ // Update only if link options are not overwritten by environment variable
377
+ if (!LinkOptsEnv)
378
+ if (!LinkOpts.empty ())
379
+ LinkOpts += " " ;
380
+ LinkOpts += Img.getLinkOptions ();
381
+ }
382
+
383
+ static void applyOptionsFromEnvironment (std::string &CompileOpts,
384
+ std::string &LinkOpts) {
385
+ // Build options are overridden if environment variables are present.
386
+ // Environment variables are not changed during program lifecycle so it
387
+ // is reasonable to use static here to read them only once.
388
+ static const char *CompileOptsEnv =
389
+ SYCLConfig<SYCL_PROGRAM_COMPILE_OPTIONS>::get ();
390
+ if (CompileOptsEnv) {
391
+ CompileOpts = CompileOptsEnv;
392
+ }
393
+ static const char *LinkOptsEnv = SYCLConfig<SYCL_PROGRAM_LINK_OPTIONS>::get ();
394
+ if (LinkOptsEnv) {
395
+ LinkOpts = LinkOptsEnv;
396
+ }
397
+ }
350
398
351
399
RT::PiProgram ProgramManager::getBuiltPIProgram (OSModuleHandle M,
352
400
const context &Context,
@@ -374,26 +422,12 @@ RT::PiProgram ProgramManager::getBuiltPIProgram(OSModuleHandle M,
374
422
375
423
std::string CompileOpts;
376
424
std::string LinkOpts;
377
- // Build options are overridden if environment variables are present.
378
- // Environment variables are not changed during program lifecycle so it
379
- // is reasonable to use static here to read them only once.
380
- static const char *CompileOptsEnv =
381
- SYCLConfig<SYCL_PROGRAM_COMPILE_OPTIONS>::get ();
382
- if (CompileOptsEnv) {
383
- CompileOpts = CompileOptsEnv;
384
- } else { // Use build options only when the environment variable is missed
385
- if (Prg) {
386
- std::string BuildOptions = Prg->get_build_options ();
387
- if (!BuildOptions.empty ()) {
388
- CompileOpts += " " ;
389
- CompileOpts += BuildOptions;
390
- }
391
- }
392
- }
393
- static const char *LinkOptsEnv = SYCLConfig<SYCL_PROGRAM_LINK_OPTIONS>::get ();
394
- if (LinkOptsEnv) {
395
- LinkOpts = LinkOptsEnv;
425
+ if (Prg) {
426
+ CompileOpts = Prg->get_build_options ();
396
427
}
428
+
429
+ applyOptionsFromEnvironment (CompileOpts, LinkOpts);
430
+
397
431
SerializedObj SpecConsts;
398
432
if (Prg)
399
433
Prg->stableSerializeSpecConstRegistry (SpecConsts);
@@ -402,24 +436,8 @@ RT::PiProgram ProgramManager::getBuiltPIProgram(OSModuleHandle M,
402
436
&LinkOpts, &JITCompilationIsRequired, SpecConsts] {
403
437
const RTDeviceBinaryImage &Img =
404
438
getDeviceImage (M, KSId, Context, Device, JITCompilationIsRequired);
405
- // Update only if compile options are not overwritten by environment
406
- // variable
407
- if (!CompileOptsEnv) {
408
- CompileOpts += Img.getCompileOptions ();
409
- }
410
-
411
- // The -vc-codegen option is always preserved for ESIMD kernels, regardless
412
- // of the contents SYCL_PROGRAM_COMPILE_OPTIONS environment variable.
413
- pi_device_binary_property isEsimdImage = Img.getProperty (" isEsimdImage" );
414
- if (isEsimdImage && pi::DeviceBinaryProperty (isEsimdImage).asUint32 ()) {
415
- if (!CompileOpts.empty ())
416
- CompileOpts += " " ;
417
- CompileOpts += " -vc-codegen" ;
418
- }
419
439
420
- // Update only if link options are not overwritten by environment variable
421
- if (!LinkOptsEnv)
422
- LinkOpts += Img.getLinkOptions ();
440
+ applyOptionsFromImage (CompileOpts, LinkOpts, Img);
423
441
ContextImplPtr ContextImpl = getSyclObjImpl (Context);
424
442
const detail::plugin &Plugin = ContextImpl->getPlugin ();
425
443
RT::PiProgram NativePrg;
@@ -1518,41 +1536,15 @@ device_image_plain ProgramManager::build(const device_image_plain &DeviceImage,
1518
1536
1519
1537
std::string CompileOpts;
1520
1538
std::string LinkOpts;
1521
- // Build options are overridden if environment variables are present.
1522
- // Environment variables are not changed during program lifecycle so it
1523
- // is reasonable to use static here to read them only once.
1524
- static const char *CompileOptsEnv =
1525
- SYCLConfig<SYCL_PROGRAM_COMPILE_OPTIONS>::get ();
1526
- if (CompileOptsEnv)
1527
- CompileOpts = CompileOptsEnv;
1528
-
1529
- static const char *LinkOptsEnv = SYCLConfig<SYCL_PROGRAM_LINK_OPTIONS>::get ();
1530
- if (LinkOptsEnv) {
1531
- LinkOpts = LinkOptsEnv;
1532
- }
1539
+ applyOptionsFromEnvironment (CompileOpts, LinkOpts);
1533
1540
1534
1541
const RTDeviceBinaryImage *ImgPtr = InputImpl->get_bin_image_ref ();
1535
1542
const RTDeviceBinaryImage &Img = *ImgPtr;
1536
1543
1537
1544
// TODO: Unify this code with getBuiltPIProgram
1538
1545
auto BuildF = [this , &Context, Img, &Devs, &CompileOpts, &LinkOpts,
1539
1546
&InputImpl] {
1540
- // Update only if compile options are not overwritten by environment
1541
- // variable
1542
- if (!CompileOptsEnv) {
1543
- CompileOpts += Img.getCompileOptions ();
1544
- pi_device_binary_property isEsimdImage = Img.getProperty (" isEsimdImage" );
1545
-
1546
- if (isEsimdImage && pi::DeviceBinaryProperty (isEsimdImage).asUint32 ()) {
1547
- if (!CompileOpts.empty ())
1548
- CompileOpts += " " ;
1549
- CompileOpts += " -vc-codegen" ;
1550
- }
1551
- }
1552
-
1553
- // Update only if link options are not overwritten by environment variable
1554
- if (!LinkOptsEnv)
1555
- LinkOpts += Img.getLinkOptions ();
1547
+ applyOptionsFromImage (CompileOpts, LinkOpts, Img);
1556
1548
ContextImplPtr ContextImpl = getSyclObjImpl (Context);
1557
1549
const detail::plugin &Plugin = ContextImpl->getPlugin ();
1558
1550
0 commit comments