@@ -367,11 +367,36 @@ RT::PiProgram ProgramManager::getBuiltPIProgram(OSModuleHandle M,
367
367
auto GetF = [](const Locked<ProgramCacheT> &LockedCache) -> ProgramCacheT & {
368
368
return LockedCache.get ();
369
369
};
370
- auto BuildF = [this , &M, &KSId, &Context, &Device, Prg,
371
- &JITCompilationIsRequired] {
372
- const RTDeviceBinaryImage &Img =
373
- getDeviceImage (M, KSId, Context, Device, JITCompilationIsRequired);
370
+ std::string BuildOptions;
371
+ if (Prg)
372
+ BuildOptions = Prg->get_build_options ();
373
+ const RTDeviceBinaryImage &Img =
374
+ getDeviceImage (M, KSId, Context, Device, JITCompilationIsRequired);
375
+ std::string CompileOpts = Img.getCompileOptions ();
376
+ std::string LinkOpts = Img.getLinkOptions ();
377
+ pi_device_binary_property isEsimdImage = Img.getProperty (" isEsimdImage" );
378
+ if (!BuildOptions.empty ()) {
379
+ CompileOpts += " " ;
380
+ CompileOpts += BuildOptions;
381
+ }
382
+ if (isEsimdImage && pi::DeviceBinaryProperty (isEsimdImage).asUint32 ()) {
383
+ if (!CompileOpts.empty ())
384
+ CompileOpts += " " ;
385
+ CompileOpts += " -vc-codegen" ;
386
+ }
374
387
388
+ // Build options are overridden if environment variables are present
389
+ const char *CompileOptsEnv = SYCLConfig<SYCL_PROGRAM_COMPILE_OPTIONS>::get ();
390
+ if (CompileOptsEnv) {
391
+ CompileOpts = CompileOptsEnv;
392
+ }
393
+ const char *LinkOptsEnv = SYCLConfig<SYCL_PROGRAM_LINK_OPTIONS>::get ();
394
+ if (LinkOptsEnv) {
395
+ LinkOpts = LinkOptsEnv;
396
+ }
397
+
398
+ auto BuildF = [this , &M, &KSId, &Context, &Device, Prg, &Img,
399
+ &JITCompilationIsRequired, &CompileOpts, &LinkOpts] {
375
400
ContextImplPtr ContextImpl = getSyclObjImpl (Context);
376
401
const detail::plugin &Plugin = ContextImpl->getPlugin ();
377
402
RT::PiProgram NativePrg = createPIProgram (Img, Context, Device);
@@ -390,17 +415,9 @@ RT::PiProgram ProgramManager::getBuiltPIProgram(OSModuleHandle M,
390
415
!SYCLConfig<SYCL_DEVICELIB_NO_FALLBACK>::get ())
391
416
DeviceLibReqMask = getDeviceLibReqMask (Img);
392
417
393
- std::string CompileOpts = Img.getCompileOptions ();
394
- pi_device_binary_property isEsimdImage = Img.getProperty (" isEsimdImage" );
395
- if (isEsimdImage && pi::DeviceBinaryProperty (isEsimdImage).asUint32 ()) {
396
- if (!CompileOpts.empty ())
397
- CompileOpts += " " ;
398
- CompileOpts += " -vc-codegen" ;
399
- }
400
-
401
418
ProgramPtr BuiltProgram =
402
- build (std::move (ProgramManaged), ContextImpl, CompileOpts,
403
- Img. getLinkOptions (), getRawSyclObjImpl (Device)->getHandleRef (),
419
+ build (std::move (ProgramManaged), ContextImpl, CompileOpts, LinkOpts,
420
+ getRawSyclObjImpl (Device)->getHandleRef (),
404
421
ContextImpl->getCachedLibPrograms (), DeviceLibReqMask);
405
422
406
423
{
@@ -417,7 +434,8 @@ RT::PiProgram ProgramManager::getBuiltPIProgram(OSModuleHandle M,
417
434
const RT::PiDevice PiDevice = getRawSyclObjImpl (Device)->getHandleRef ();
418
435
auto BuildResult = getOrBuild<PiProgramT, compile_program_error>(
419
436
Cache,
420
- std::make_pair (std::make_pair (std::move (SpecConsts), KSId), PiDevice),
437
+ std::make_pair (std::make_pair (std::move (SpecConsts), KSId),
438
+ std::make_pair (PiDevice, CompileOpts + LinkOpts)),
421
439
AcquireF, GetF, BuildF);
422
440
return BuildResult->Ptr .load ();
423
441
}
@@ -465,9 +483,8 @@ std::pair<RT::PiKernel, std::mutex *> ProgramManager::getOrCreateKernel(
465
483
return Result;
466
484
};
467
485
468
- const RT::PiDevice PiDevice = getRawSyclObjImpl (Device)->getHandleRef ();
469
486
auto BuildResult = getOrBuild<PiKernelT, invalid_object_error>(
470
- Cache, std::make_pair ( KernelName, PiDevice) , AcquireF, GetF, BuildF);
487
+ Cache, KernelName, AcquireF, GetF, BuildF);
471
488
return std::make_pair (BuildResult->Ptr .load (),
472
489
&(BuildResult->MBuildResultMutex ));
473
490
}
0 commit comments