Skip to content

Commit 10f7f1d

Browse files
committed
apply suggested changes
1 parent 0d50a89 commit 10f7f1d

File tree

2 files changed

+42
-107
lines changed

2 files changed

+42
-107
lines changed

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 39 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -366,59 +366,50 @@ RT::PiProgram ProgramManager::createPIProgram(const RTDeviceBinaryImage &Img,
366366
return Res;
367367
}
368368

369-
static void addEsimdImageCompileOptions(std::string &CompileOpts) {
370-
if (!CompileOpts.empty())
371-
CompileOpts += " ";
372-
CompileOpts += "-vc-codegen";
373-
}
374-
375-
static void applyLinkOptionsFromImage(std::string &LinkOpts,
376-
const RTDeviceBinaryImage &Img) {
377-
if (!LinkOpts.empty())
378-
LinkOpts += " ";
379-
const char *TemporaryStr = Img.getLinkOptions();
380-
if (TemporaryStr != nullptr)
381-
LinkOpts += std::string(TemporaryStr);
382-
}
383-
384-
static void applyCompileOptionsFromImage(
385-
std::string &CompileOpts, const RTDeviceBinaryImage &Img,
386-
const pi_device_binary_property &isEsimdImage = nullptr) {
387-
if (!CompileOpts.empty())
388-
CompileOpts += " ";
389-
const char *TemporaryStr = Img.getCompileOptions();
390-
if (TemporaryStr != nullptr)
391-
CompileOpts += TemporaryStr;
392-
if (isEsimdImage) {
393-
addEsimdImageCompileOptions(CompileOpts);
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+
if (!LinkOpts.empty())
375+
LinkOpts += " ";
376+
const char *TemporaryStr = Img.getLinkOptions();
377+
if (TemporaryStr != nullptr)
378+
LinkOpts += std::string(TemporaryStr);
394379
}
395380
}
396381

397-
static void applyOptionsFromImage(std::string &CompileOpts,
398-
std::string &LinkOpts,
399-
const RTDeviceBinaryImage &Img) {
382+
static void appendCompileOptionsFromImage(std::string &CompileOpts,
383+
const RTDeviceBinaryImage &Img) {
400384
// Build options are overridden if environment variables are present.
401385
// Environment variables are not changed during program lifecycle so it
402386
// is reasonable to use static here to read them only once.
403387
static const char *CompileOptsEnv =
404388
SYCLConfig<SYCL_PROGRAM_COMPILE_OPTIONS>::get();
405-
static const char *LinkOptsEnv = SYCLConfig<SYCL_PROGRAM_LINK_OPTIONS>::get();
389+
pi_device_binary_property isEsimdImage = Img.getProperty("isEsimdImage");
406390
// Update only if compile options are not overwritten by environment
407391
// variable
392+
if (!CompileOptsEnv) {
393+
if (!CompileOpts.empty())
394+
CompileOpts += " ";
395+
const char *TemporaryStr = Img.getCompileOptions();
396+
if (TemporaryStr != nullptr)
397+
CompileOpts += std::string(TemporaryStr);
398+
}
408399
// The -vc-codegen option is always preserved for ESIMD kernels, regardless
409400
// of the contents SYCL_PROGRAM_COMPILE_OPTIONS environment variable.
410-
pi_device_binary_property isEsimdImage = Img.getProperty("isEsimdImage");
411-
if (!CompileOptsEnv) {
412-
applyCompileOptionsFromImage(CompileOpts, Img, isEsimdImage);
413-
} else if (isEsimdImage &&
414-
pi::DeviceBinaryProperty(isEsimdImage).asUint32()) {
415-
addEsimdImageCompileOptions(CompileOpts);
401+
if (isEsimdImage && pi::DeviceBinaryProperty(isEsimdImage).asUint32()) {
402+
if (!CompileOpts.empty())
403+
CompileOpts += " ";
404+
CompileOpts += "-vc-codegen";
416405
}
406+
}
417407

418-
// Update only if link options are not overwritten by environment variable
419-
if (!LinkOptsEnv) {
420-
applyLinkOptionsFromImage(LinkOpts, Img);
421-
}
408+
static void applyOptionsFromImage(std::string &CompileOpts,
409+
std::string &LinkOpts,
410+
const RTDeviceBinaryImage &Img) {
411+
appendCompileOptionsFromImage(CompileOpts, Img);
412+
appendLinkOptionsFromImage(LinkOpts, Img);
422413
}
423414

424415
static void applyOptionsFromEnvironment(std::string &CompileOpts,
@@ -1004,10 +995,9 @@ ProgramManager::ProgramPtr ProgramManager::build(
1004995

1005996
const detail::plugin &Plugin = Context->getPlugin();
1006997
if (LinkPrograms.empty() && !ForceLink) {
1007-
std::string Options = CompileOptions;
1008-
if (!LinkOptions.empty()) {
1009-
Options += " " + LinkOptions;
1010-
}
998+
std::string Options = LinkOptions.empty()
999+
? CompileOptions
1000+
: (CompileOptions + " " + LinkOptions);
10111001
RT::PiResult Error = Plugin.call_nocheck<PiApiKind::piProgramBuild>(
10121002
Program.get(), /*num devices =*/1, &Device, Options.c_str(), nullptr,
10131003
nullptr);
@@ -1693,12 +1683,12 @@ ProgramManager::compile(const device_image_plain &DeviceImage,
16931683
// TODO: Set spec constatns here.
16941684

16951685
// TODO: Handle zero sized Device list.
1696-
1697-
const char *compileOptions =
1698-
InputImpl->get_bin_image_ref()->getCompileOptions();
1686+
std::string CompileOptions;
1687+
appendCompileOptionsFromImage(CompileOptions,
1688+
*(InputImpl->get_bin_image_ref()));
16991689
RT::PiResult Error = Plugin.call_nocheck<PiApiKind::piProgramCompile>(
17001690
ObjectImpl->get_program_ref(), /*num devices=*/Devs.size(),
1701-
PIDevices.data(), compileOptions,
1691+
PIDevices.data(), CompileOptions.c_str(),
17021692
/*num_input_headers=*/0, /*input_headers=*/nullptr,
17031693
/*header_include_names=*/nullptr,
17041694
/*pfn_notify=*/nullptr, /*user_data*/ nullptr);
@@ -1731,8 +1721,8 @@ ProgramManager::link(const std::vector<device_image_plain> &DeviceImages,
17311721
for (const device_image_plain &DeviceImage : DeviceImages) {
17321722
const std::shared_ptr<device_image_impl> &InputImpl =
17331723
getSyclObjImpl(DeviceImage);
1734-
applyLinkOptionsFromImage(LinkOptionsStr,
1735-
*(InputImpl->get_bin_image_ref()));
1724+
appendLinkOptionsFromImage(LinkOptionsStr,
1725+
*(InputImpl->get_bin_image_ref()));
17361726
}
17371727
const context &Context = getSyclObjImpl(DeviceImages[0])->get_context();
17381728
const ContextImplPtr ContextImpl = getSyclObjImpl(Context);

sycl/unittests/program_manager/passing_link_and_compile_options.cpp

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -231,64 +231,9 @@ TEST(Link_Compile_Options, compile_link_Options_Test_filled_options) {
231231
EXPECT_EQ(expected_compile_options_1, current_compile_options);
232232
}
233233

234-
TEST(Link_Compile_Options,
235-
compile_link_Options_Test_two_devices_filled_options) {
236-
sycl::platform Plt{sycl::default_selector()};
237-
if (Plt.is_host()) {
238-
std::cerr << "Test is not supported on host, skipping\n";
239-
GTEST_SKIP(); // test is not supported on host.
240-
}
241-
242-
if (Plt.get_backend() == sycl::backend::ext_oneapi_cuda) {
243-
std::cerr << "Test is not supported on CUDA platform, skipping\n";
244-
GTEST_SKIP();
245-
}
246-
247-
if (Plt.get_backend() == sycl::backend::ext_oneapi_hip) {
248-
std::cerr << "Test is not supported on HIP platform, skipping\n";
249-
GTEST_SKIP();
250-
}
251-
sycl::unittest::PiMock Mock{Plt};
252-
setupDefaultMockAPIs(Mock);
253-
Mock.redefine<sycl::detail::PiApiKind::piProgramCompile>(
254-
redefinedProgramCompile);
255-
Mock.redefine<sycl::detail::PiApiKind::piProgramLink>(redefinedProgramLink);
256-
const sycl::device Dev_1 = Plt.get_devices()[0];
257-
current_link_options.clear();
258-
current_compile_options.clear();
259-
std::string expected_compile_options_1 = "-cl-opt-disable",
260-
expected_compile_options_2 =
261-
"-cl-fp32-correctly-rounded-divide-sqrt",
262-
expected_link_options_1 = "-cl-denorms-are-zero",
263-
expected_link_options_2 = "-cl-no-signed-zeros";
264-
static sycl::unittest::PiImage DevImage_1 =
265-
generateEAMTestKernel1Image<EAMTestKernel1>(expected_compile_options_1,
266-
expected_link_options_1);
267-
static sycl::unittest::PiImage DevImage_2 =
268-
generateEAMTestKernel2Image<EAMTestKernel2>(expected_compile_options_2,
269-
expected_link_options_2);
270-
static sycl::unittest::PiImage Images[] = {DevImage_1, DevImage_2};
271-
static sycl::unittest::PiImageArray<2> DevImageArray{Images};
272-
273-
auto KernelID_1 = sycl::get_kernel_id<EAMTestKernel1>();
274-
auto KernelID_2 = sycl::get_kernel_id<EAMTestKernel2>();
275-
sycl::queue Queue{Dev_1};
276-
const sycl::context Ctx = Queue.get_context();
277-
sycl::kernel_bundle KernelBundle1 =
278-
sycl::get_kernel_bundle<sycl::bundle_state::input>(Ctx, {Dev_1},
279-
{KernelID_1});
280-
sycl::kernel_bundle KernelBundle2 =
281-
sycl::get_kernel_bundle<sycl::bundle_state::input>(Ctx, {Dev_1},
282-
{KernelID_2});
283-
auto BundleObj1 = sycl::compile(KernelBundle1);
284-
auto BundleObj2 = sycl::compile(KernelBundle2);
285-
sycl::link(BundleObj1);
286-
sycl::link(BundleObj2);
287-
EXPECT_EQ(expected_link_options_1 + " " + expected_link_options_2,
288-
current_link_options);
289-
EXPECT_EQ(expected_compile_options_1 + " " + expected_compile_options_2,
290-
current_compile_options);
291-
}
234+
// According to kernel_bundle_impl.hpp:205 sycl::link now is not linking
235+
// any two device images together
236+
// TODO : Add check for linking 2 device images together when implemented.
292237

293238
TEST(Link_Compile_Options, check_sycl_build) {
294239
sycl::platform Plt{sycl::default_selector()};

0 commit comments

Comments
 (0)