Skip to content

[SYCL] Pass driver options to JIT compiler and linker #5476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
cfe7313
Implement passing <opts> to sycl::link() and sycl::compile()
HabKaffee Feb 1, 2022
99faffa
commit changes before pull new updates
HabKaffee Feb 2, 2022
a5597b5
Merge branch 'sycl' into Realisation_of_sycl_link_build_compile
HabKaffee Feb 2, 2022
a7d1ca7
passing link options to function done without tests
HabKaffee Feb 2, 2022
49310b8
Tests added
HabKaffee Feb 2, 2022
7a4e84a
commit before merging
HabKaffee Feb 3, 2022
534d15a
Merge branch 'sycl' into Realisation_of_sycl_link_build_compile
HabKaffee Feb 3, 2022
4143cb5
fix changes before merging
HabKaffee Feb 4, 2022
9bcca3a
Merge branch 'sycl' into Realisation_of_sycl_link_build_compile
HabKaffee Feb 4, 2022
1ee85ba
Passing link and compile options done
HabKaffee Feb 4, 2022
c695dfc
Clang format hotfix
HabKaffee Feb 4, 2022
9079626
Remove debug info from test file
HabKaffee Feb 4, 2022
f8da779
Added skips for host, CUDA and HIP
HabKaffee Feb 4, 2022
60b3e9a
Some changes in licence and description
HabKaffee Feb 4, 2022
cd8e1d5
Applied suggested changes
HabKaffee Feb 5, 2022
11d3f6e
Merge branch 'sycl' into Realisation_of_sycl_link_build_compile
HabKaffee Feb 7, 2022
70a7de1
Merge branch 'sycl' into Realisation_of_sycl_link_build_compile
HabKaffee Feb 7, 2022
d17b0bd
Merge branch 'intel:sycl' into Realisation_of_sycl_link_build_compile
HabKaffee Feb 8, 2022
b934f01
Merge branch 'Realisation_of_sycl_link_build_compile' of https://gith…
HabKaffee Feb 8, 2022
344e899
Merge branch 'intel:sycl' into Realisation_of_sycl_link_build_compile
HabKaffee Feb 8, 2022
e0189f1
Merge branch 'Realisation_of_sycl_link_build_compile' of https://gith…
HabKaffee Feb 8, 2022
13081cc
Merge branch 'sycl' into Realisation_of_sycl_link_build_compile
HabKaffee Feb 8, 2022
3c80c89
Merge branch 'sycl' into Realisation_of_sycl_link_build_compile
HabKaffee Feb 9, 2022
5c50b94
store changes before merge last ver. of sycl
HabKaffee Feb 9, 2022
58641df
Merge branch 'sycl' into Realisation_of_sycl_link_build_compile
HabKaffee Feb 9, 2022
dc19071
Apply suggested changes
HabKaffee Feb 9, 2022
dd99cd2
clang-format fix
HabKaffee Feb 9, 2022
dbbf36f
Merge branch 'intel:sycl' into Realisation_of_sycl_link_build_compile
HabKaffee Feb 9, 2022
72a2082
Applied suggested fixes
HabKaffee Feb 9, 2022
36f62dc
Clang format fix
HabKaffee Feb 9, 2022
667283c
change std::optional<std::string> to std::string
HabKaffee Feb 9, 2022
08b78ec
Merge branch 'intel:sycl' into Realisation_of_sycl_link_build_compile
HabKaffee Feb 10, 2022
1e3281d
Merge branch 'intel:sycl' into Realisation_of_sycl_link_build_compile
HabKaffee Feb 11, 2022
504c400
Merge branch 'intel:sycl' into Realisation_of_sycl_link_build_compile
HabKaffee Feb 14, 2022
5fe124c
Implemented all suggested changes and fixed affected test
HabKaffee Feb 14, 2022
66efc56
clang format hotfix
HabKaffee Feb 14, 2022
0d50a89
restore LinkDeviceLibs to false
HabKaffee Feb 14, 2022
10f7f1d
apply suggested changes
HabKaffee Feb 14, 2022
7b047a8
apply suggested change
HabKaffee Feb 15, 2022
23fe607
Clang format fix
HabKaffee Feb 15, 2022
79ee7c1
Merge branch 'sycl' into Realisation_of_sycl_link_build_compile
HabKaffee Feb 16, 2022
c70286a
Update sycl/source/detail/program_manager/program_manager.cpp
HabKaffee Feb 16, 2022
9f7e2ea
Merge branch 'sycl' into Realisation_of_sycl_link_build_compile
HabKaffee Feb 21, 2022
a37e17a
Merge branch 'intel:sycl' into Realisation_of_sycl_link_build_compile
HabKaffee Feb 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 44 additions & 18 deletions sycl/source/detail/program_manager/program_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,37 +365,52 @@ RT::PiProgram ProgramManager::createPIProgram(const RTDeviceBinaryImage &Img,

return Res;
}
static void applyOptionsFromImage(std::string &CompileOpts,
std::string &LinkOpts,
const RTDeviceBinaryImage &Img) {

static void appendLinkOptionsFromImage(std::string &LinkOpts,
const RTDeviceBinaryImage &Img) {
static const char *LinkOptsEnv = SYCLConfig<SYCL_PROGRAM_LINK_OPTIONS>::get();
// Update only if link options are not overwritten by environment variable
if (!LinkOptsEnv) {
const char *TemporaryStr = Img.getLinkOptions();
if (TemporaryStr != nullptr) {
if (!LinkOpts.empty())
LinkOpts += " ";
LinkOpts += std::string(TemporaryStr);
}
}
}

static void appendCompileOptionsFromImage(std::string &CompileOpts,
const RTDeviceBinaryImage &Img) {
// Build options are overridden if environment variables are present.
// Environment variables are not changed during program lifecycle so it
// is reasonable to use static here to read them only once.
static const char *CompileOptsEnv =
SYCLConfig<SYCL_PROGRAM_COMPILE_OPTIONS>::get();
static const char *LinkOptsEnv = SYCLConfig<SYCL_PROGRAM_LINK_OPTIONS>::get();
pi_device_binary_property isEsimdImage = Img.getProperty("isEsimdImage");
// Update only if compile options are not overwritten by environment
// variable
if (!CompileOptsEnv) {
if (!CompileOpts.empty())
CompileOpts += " ";
CompileOpts += Img.getCompileOptions();
const char *TemporaryStr = Img.getCompileOptions();
if (TemporaryStr != nullptr)
CompileOpts += std::string(TemporaryStr);
}

// The -vc-codegen option is always preserved for ESIMD kernels, regardless
// of the contents SYCL_PROGRAM_COMPILE_OPTIONS environment variable.
pi_device_binary_property isEsimdImage = Img.getProperty("isEsimdImage");
if (isEsimdImage && pi::DeviceBinaryProperty(isEsimdImage).asUint32()) {
if (!CompileOpts.empty())
CompileOpts += " ";
CompileOpts += "-vc-codegen";
}
}

// Update only if link options are not overwritten by environment variable
if (!LinkOptsEnv)
if (!LinkOpts.empty())
LinkOpts += " ";
LinkOpts += Img.getLinkOptions();
static void applyOptionsFromImage(std::string &CompileOpts,
std::string &LinkOpts,
const RTDeviceBinaryImage &Img) {
appendCompileOptionsFromImage(CompileOpts, Img);
appendLinkOptionsFromImage(LinkOpts, Img);
}

static void applyOptionsFromEnvironment(std::string &CompileOpts,
Expand Down Expand Up @@ -1000,9 +1015,12 @@ ProgramManager::ProgramPtr ProgramManager::build(

const detail::plugin &Plugin = Context->getPlugin();
if (LinkPrograms.empty() && !ForceLink) {
const std::string &Options = LinkOptions.empty()
? CompileOptions
: (CompileOptions + " " + LinkOptions);
RT::PiResult Error = Plugin.call_nocheck<PiApiKind::piProgramBuild>(
Program.get(), /*num devices =*/1, &Device, CompileOptions.c_str(),
nullptr, nullptr);
Program.get(), /*num devices =*/1, &Device, Options.c_str(), nullptr,
nullptr);
if (Error != PI_SUCCESS)
throw compile_program_error(getProgramBuildLog(Program.get(), Context),
Error);
Expand Down Expand Up @@ -1674,10 +1692,12 @@ ProgramManager::compile(const device_image_plain &DeviceImage,
// TODO: Set spec constatns here.

// TODO: Handle zero sized Device list.
std::string CompileOptions;
appendCompileOptionsFromImage(CompileOptions,
*(InputImpl->get_bin_image_ref()));
RT::PiResult Error = Plugin.call_nocheck<PiApiKind::piProgramCompile>(
ObjectImpl->get_program_ref(), /*num devices=*/Devs.size(),
PIDevices.data(),
/*options=*/nullptr,
PIDevices.data(), CompileOptions.c_str(),
/*num_input_headers=*/0, /*input_headers=*/nullptr,
/*header_include_names=*/nullptr,
/*pfn_notify=*/nullptr, /*user_data*/ nullptr);
Expand Down Expand Up @@ -1706,15 +1726,21 @@ ProgramManager::link(const std::vector<device_image_plain> &DeviceImages,
for (const device &Dev : Devs)
PIDevices.push_back(getSyclObjImpl(Dev)->getHandleRef());

std::string LinkOptionsStr;
for (const device_image_plain &DeviceImage : DeviceImages) {
const std::shared_ptr<device_image_impl> &InputImpl =
getSyclObjImpl(DeviceImage);
appendLinkOptionsFromImage(LinkOptionsStr,
*(InputImpl->get_bin_image_ref()));
}
const context &Context = getSyclObjImpl(DeviceImages[0])->get_context();
const ContextImplPtr ContextImpl = getSyclObjImpl(Context);

const detail::plugin &Plugin = ContextImpl->getPlugin();

RT::PiProgram LinkedProg = nullptr;
RT::PiResult Error = Plugin.call_nocheck<PiApiKind::piProgramLink>(
ContextImpl->getHandleRef(), PIDevices.size(), PIDevices.data(),
/*options=*/nullptr, PIPrograms.size(), PIPrograms.data(),
/*options=*/LinkOptionsStr.c_str(), PIPrograms.size(), PIPrograms.data(),
/*pfn_notify=*/nullptr,
/*user_data=*/nullptr, &LinkedProg);

Expand Down
2 changes: 1 addition & 1 deletion sycl/unittests/misc/KernelBuildOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ TEST(KernelBuildOptions, KernelBundleBasic) {
sycl::kernel_bundle KernelBundle =
sycl::get_kernel_bundle<sycl::bundle_state::input>(Ctx, {Dev});
auto ExecBundle = sycl::build(KernelBundle);
EXPECT_EQ(BuildOpts, "-compile-img -vc-codegen");
EXPECT_EQ(BuildOpts, "-compile-img -vc-codegen -link-img");

auto ObjBundle = sycl::compile(KernelBundle, KernelBundle.get_devices());
// TODO: uncomment when image options are passed to BE
Expand Down
1 change: 1 addition & 0 deletions sycl/unittests/program_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ add_sycl_unittest(ProgramManagerTests OBJECT
EliminatedArgMask.cpp
itt_annotations.cpp
SubDevices.cpp
passing_link_and_compile_options.cpp
)

Loading