@@ -417,22 +417,32 @@ static void applyOptionsFromImage(std::string &CompileOpts,
417
417
appendLinkOptionsFromImage (LinkOpts, Img);
418
418
}
419
419
420
- static void applyOptionsFromEnvironment (std::string &CompileOpts,
421
- std::string &LinkOpts) {
422
- // Build options are overridden if environment variables are present.
420
+ static void applyCompileOptionsFromEnvironment (std::string &CompileOpts) {
423
421
// Environment variables are not changed during program lifecycle so it
424
422
// is reasonable to use static here to read them only once.
425
423
static const char *CompileOptsEnv =
426
424
SYCLConfig<SYCL_PROGRAM_COMPILE_OPTIONS>::get ();
427
425
if (CompileOptsEnv) {
428
426
CompileOpts = CompileOptsEnv;
429
427
}
428
+ }
429
+
430
+ static void applyLinkOptionsFromEnvironment (std::string &LinkOpts) {
431
+ // Environment variables are not changed during program lifecycle so it
432
+ // is reasonable to use static here to read them only once.
430
433
static const char *LinkOptsEnv = SYCLConfig<SYCL_PROGRAM_LINK_OPTIONS>::get ();
431
434
if (LinkOptsEnv) {
432
435
LinkOpts = LinkOptsEnv;
433
436
}
434
437
}
435
438
439
+ static void applyOptionsFromEnvironment (std::string &CompileOpts,
440
+ std::string &LinkOpts) {
441
+ // Build options are overridden if environment variables are present.
442
+ applyCompileOptionsFromEnvironment (CompileOpts);
443
+ applyLinkOptionsFromEnvironment (LinkOpts);
444
+ }
445
+
436
446
std::pair<RT::PiProgram, bool > ProgramManager::getOrCreatePIProgram (
437
447
const RTDeviceBinaryImage &Img, const context &Context,
438
448
const device &Device, const std::string &CompileAndLinkOptions,
@@ -1695,6 +1705,7 @@ ProgramManager::compile(const device_image_plain &DeviceImage,
1695
1705
1696
1706
// TODO: Handle zero sized Device list.
1697
1707
std::string CompileOptions;
1708
+ applyCompileOptionsFromEnvironment (CompileOptions);
1698
1709
appendCompileOptionsFromImage (CompileOptions,
1699
1710
*(InputImpl->get_bin_image_ref ()));
1700
1711
RT::PiResult Error = Plugin.call_nocheck <PiApiKind::piProgramCompile>(
@@ -1729,11 +1740,14 @@ ProgramManager::link(const std::vector<device_image_plain> &DeviceImages,
1729
1740
PIDevices.push_back (getSyclObjImpl (Dev)->getHandleRef ());
1730
1741
1731
1742
std::string LinkOptionsStr;
1732
- for (const device_image_plain &DeviceImage : DeviceImages) {
1733
- const std::shared_ptr<device_image_impl> &InputImpl =
1734
- getSyclObjImpl (DeviceImage);
1735
- appendLinkOptionsFromImage (LinkOptionsStr,
1736
- *(InputImpl->get_bin_image_ref ()));
1743
+ applyLinkOptionsFromEnvironment (LinkOptionsStr);
1744
+ if (LinkOptionsStr.empty ()) {
1745
+ for (const device_image_plain &DeviceImage : DeviceImages) {
1746
+ const std::shared_ptr<device_image_impl> &InputImpl =
1747
+ getSyclObjImpl (DeviceImage);
1748
+ appendLinkOptionsFromImage (LinkOptionsStr,
1749
+ *(InputImpl->get_bin_image_ref ()));
1750
+ }
1737
1751
}
1738
1752
const context &Context = getSyclObjImpl (DeviceImages[0 ])->get_context ();
1739
1753
const ContextImplPtr ContextImpl = getSyclObjImpl (Context);
0 commit comments