@@ -365,37 +365,52 @@ RT::PiProgram ProgramManager::createPIProgram(const RTDeviceBinaryImage &Img,
365
365
366
366
return Res;
367
367
}
368
- static void applyOptionsFromImage (std::string &CompileOpts,
369
- std::string &LinkOpts,
370
- const RTDeviceBinaryImage &Img) {
368
+
369
+ static void appendLinkOptionsFromImage (std::string &LinkOpts,
370
+ const RTDeviceBinaryImage &Img) {
371
+ static const char *LinkOptsEnv = SYCLConfig<SYCL_PROGRAM_LINK_OPTIONS>::get ();
372
+ // Update only if link options are not overwritten by environment variable
373
+ if (!LinkOptsEnv) {
374
+ const char *TemporaryStr = Img.getLinkOptions ();
375
+ if (TemporaryStr != nullptr ) {
376
+ if (!LinkOpts.empty ())
377
+ LinkOpts += " " ;
378
+ LinkOpts += std::string (TemporaryStr);
379
+ }
380
+ }
381
+ }
382
+
383
+ static void appendCompileOptionsFromImage (std::string &CompileOpts,
384
+ const RTDeviceBinaryImage &Img) {
371
385
// Build options are overridden if environment variables are present.
372
386
// Environment variables are not changed during program lifecycle so it
373
387
// is reasonable to use static here to read them only once.
374
388
static const char *CompileOptsEnv =
375
389
SYCLConfig<SYCL_PROGRAM_COMPILE_OPTIONS>::get ();
376
- static const char *LinkOptsEnv = SYCLConfig<SYCL_PROGRAM_LINK_OPTIONS>:: get ( );
390
+ pi_device_binary_property isEsimdImage = Img. getProperty ( " isEsimdImage " );
377
391
// Update only if compile options are not overwritten by environment
378
392
// variable
379
393
if (!CompileOptsEnv) {
380
394
if (!CompileOpts.empty ())
381
395
CompileOpts += " " ;
382
- CompileOpts += Img.getCompileOptions ();
396
+ const char *TemporaryStr = Img.getCompileOptions ();
397
+ if (TemporaryStr != nullptr )
398
+ CompileOpts += std::string (TemporaryStr);
383
399
}
384
-
385
400
// The -vc-codegen option is always preserved for ESIMD kernels, regardless
386
401
// of the contents SYCL_PROGRAM_COMPILE_OPTIONS environment variable.
387
- pi_device_binary_property isEsimdImage = Img.getProperty (" isEsimdImage" );
388
402
if (isEsimdImage && pi::DeviceBinaryProperty (isEsimdImage).asUint32 ()) {
389
403
if (!CompileOpts.empty ())
390
404
CompileOpts += " " ;
391
405
CompileOpts += " -vc-codegen" ;
392
406
}
407
+ }
393
408
394
- // Update only if link options are not overwritten by environment variable
395
- if (!LinkOptsEnv)
396
- if (!LinkOpts. empty ())
397
- LinkOpts += " " ;
398
- LinkOpts += Img. getLinkOptions ( );
409
+ static void applyOptionsFromImage (std::string &CompileOpts,
410
+ std::string &LinkOpts,
411
+ const RTDeviceBinaryImage &Img) {
412
+ appendCompileOptionsFromImage (CompileOpts, Img) ;
413
+ appendLinkOptionsFromImage ( LinkOpts, Img);
399
414
}
400
415
401
416
static void applyOptionsFromEnvironment (std::string &CompileOpts,
@@ -1000,9 +1015,12 @@ ProgramManager::ProgramPtr ProgramManager::build(
1000
1015
1001
1016
const detail::plugin &Plugin = Context->getPlugin ();
1002
1017
if (LinkPrograms.empty () && !ForceLink) {
1018
+ const std::string &Options = LinkOptions.empty ()
1019
+ ? CompileOptions
1020
+ : (CompileOptions + " " + LinkOptions);
1003
1021
RT::PiResult Error = Plugin.call_nocheck <PiApiKind::piProgramBuild>(
1004
- Program.get (), /* num devices =*/ 1 , &Device, CompileOptions .c_str (),
1005
- nullptr , nullptr );
1022
+ Program.get (), /* num devices =*/ 1 , &Device, Options .c_str (), nullptr ,
1023
+ nullptr );
1006
1024
if (Error != PI_SUCCESS)
1007
1025
throw compile_program_error (getProgramBuildLog (Program.get (), Context),
1008
1026
Error);
@@ -1674,10 +1692,12 @@ ProgramManager::compile(const device_image_plain &DeviceImage,
1674
1692
// TODO: Set spec constatns here.
1675
1693
1676
1694
// TODO: Handle zero sized Device list.
1695
+ std::string CompileOptions;
1696
+ appendCompileOptionsFromImage (CompileOptions,
1697
+ *(InputImpl->get_bin_image_ref ()));
1677
1698
RT::PiResult Error = Plugin.call_nocheck <PiApiKind::piProgramCompile>(
1678
1699
ObjectImpl->get_program_ref (), /* num devices=*/ Devs.size (),
1679
- PIDevices.data (),
1680
- /* options=*/ nullptr ,
1700
+ PIDevices.data (), CompileOptions.c_str (),
1681
1701
/* num_input_headers=*/ 0 , /* input_headers=*/ nullptr ,
1682
1702
/* header_include_names=*/ nullptr ,
1683
1703
/* pfn_notify=*/ nullptr , /* user_data*/ nullptr );
@@ -1706,15 +1726,21 @@ ProgramManager::link(const std::vector<device_image_plain> &DeviceImages,
1706
1726
for (const device &Dev : Devs)
1707
1727
PIDevices.push_back (getSyclObjImpl (Dev)->getHandleRef ());
1708
1728
1729
+ std::string LinkOptionsStr;
1730
+ for (const device_image_plain &DeviceImage : DeviceImages) {
1731
+ const std::shared_ptr<device_image_impl> &InputImpl =
1732
+ getSyclObjImpl (DeviceImage);
1733
+ appendLinkOptionsFromImage (LinkOptionsStr,
1734
+ *(InputImpl->get_bin_image_ref ()));
1735
+ }
1709
1736
const context &Context = getSyclObjImpl (DeviceImages[0 ])->get_context ();
1710
1737
const ContextImplPtr ContextImpl = getSyclObjImpl (Context);
1711
-
1712
1738
const detail::plugin &Plugin = ContextImpl->getPlugin ();
1713
1739
1714
1740
RT::PiProgram LinkedProg = nullptr ;
1715
1741
RT::PiResult Error = Plugin.call_nocheck <PiApiKind::piProgramLink>(
1716
1742
ContextImpl->getHandleRef (), PIDevices.size (), PIDevices.data (),
1717
- /* options=*/ nullptr , PIPrograms.size (), PIPrograms.data (),
1743
+ /* options=*/ LinkOptionsStr. c_str () , PIPrograms.size (), PIPrograms.data (),
1718
1744
/* pfn_notify=*/ nullptr ,
1719
1745
/* user_data=*/ nullptr , &LinkedProg);
1720
1746
0 commit comments