Skip to content
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

[SYCL][ClangLinkerWrapper] Add SYCL Module split library usage in clang-linker-wrapper #13806

Merged
merged 3 commits into from
Jul 15, 2024

Conversation

maksimsab
Copy link
Contributor

This patch introduces -sycl-module-split-mode command line option in clang-linker-wrapper tool and makes the tool invoke either library or sycl-post-link tool depending on the presense of -sycl-module-split-mode option.

Also the patch removes funcionality of reading/writing of Table files in clang-linker-wrapper. Instead of them the tool starts using in-memory structures.

@maksimsab maksimsab force-pushed the sycl_split_functionality_part3 branch 2 times, most recently from 30ce597 to e463a8f Compare May 21, 2024 13:25
@maksimsab
Copy link
Contributor Author

Note for reviewers.
This patch functionally depends on #13282. It is supposed that the current patch will be merged strictly after #13282. However, in order to make it work the corresponding functionality was copy-pasted from #13282. If you have any issues about splitting part then, please, address them directly to #13282.

@maksimsab maksimsab marked this pull request as ready for review May 21, 2024 16:32
@maksimsab maksimsab requested review from a team as code owners May 21, 2024 16:32
@maksimsab maksimsab requested a review from asudarsa May 21, 2024 16:32
@maksimsab maksimsab force-pushed the sycl_split_functionality_part3 branch from e463a8f to 8789bf1 Compare May 22, 2024 12:17
@@ -163,6 +163,15 @@ def sycl_post_link_options_EQ : Joined<["--", "-"], "sycl-post-link-options=">,
Flags<[WrapperOnlyOption]>,
HelpText<"Options that will control sycl-post-link step">;

def sycl_module_split_mode_EQ :
Copy link
Contributor

@asudarsa asudarsa Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we will need to add tests to make sure that the existing tests which use the sycl-post-link will run the same way when we use the split library. I think this might be a good place to start adding E2E tests using new offloading model.

Thanks

ModuleDesc MD = std::move(M); // makeModuleDesc() ?
// FIXME: false arguments are temporary for now.
auto Splitter =
getDeviceCodeSplitter(std::move(MD), Settings.Mode, false, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can try and pass the entries from -sycl-post-link-options via the Settings variable. I am ok to do it in a subsequent PR. There will be other options like -emit-exported-symbols, -emit-imported-symbols if/when we want to add dynamic linking support here.

Thanks

std::vector<SplitModule> OutputImages;
while (Splitter->hasMoreSplits()) {
ModuleDesc MD2 = Splitter->nextSplit();
MD2.fixupLinkageOfDirectInvokeSimdTargets();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will not be upstreaming this. Do we want to add a TODO marker for tracking that?

Thanks

}

static Expected<std::vector<module_split::SplitModule>>
runSYCLSplitLibrary(ArrayRef<StringRef> InputFiles, const ArgList &Args,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will want to parse the -sycl-post-link-options here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please share your thoughts on this? Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue here is that the library is not complete. The plan is to fulfill missing functionality and add the corresponding splitting option parsing.

Copy link
Contributor

@asudarsa asudarsa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks great. Specifically, the move from using 'table' file to using SplitModules is a very good segway to start using the generic 'Image' data structure (extended for SYCL).
I have added a few comments to be addressed. No major concerns from me.

Thanks

@sarnex
Copy link
Contributor

sarnex commented Jun 7, 2024

This looks great and I should be able to easily react to getting rid of the table in my thinLTO prototype, I'll take an in-depth look once we rebase on top of HEAD to resolve conflicts.

…er-wrapper

This patch introduces -sycl-module-split-mode command line option in
clang-linker-wrapper tool and makes the tool invoke either library or
sycl-post-link tool depending on the presense of -sycl-module-split-mode
option.

Also the patch removes funcionality of reading/writing of Table files in
clang-linker-wrapper. Instead of them the tool starts using in-memory
structures.
@maksimsab
Copy link
Contributor Author

I will do final cleanup and reopen this PR for CR.

@asudarsa
Copy link
Contributor

asudarsa commented Jul 9, 2024

Hi @maksimsab
This PR looks good as an incremental change. It is a little difficult to understand the status of these changes though. In the PR description, can you please add the list of sycl-post-link features that are already available in the library (for e.g. code splitting) and also the list of sycl-post-link features that are not yet available (e.g. prop/sym handling and -sycl-post-link-options handling) and also a short plan on when/how they will be added.
In terms of testing, is my understanding correct that the library flow is not yet ready for E2E testing?

Thanks

clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td Outdated Show resolved Hide resolved
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp Outdated Show resolved Hide resolved
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp Outdated Show resolved Hide resolved
auto [PropertyFilePath, SymbolsFilePath] = Rem.split("|");
llvm::util::PropertySetRegistry Properties;
std::string Symbols;
if (!PropertyFilePath.empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is props/syms being empty valid? Should we error?

Copy link
Contributor

@sarnex sarnex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks! only minor comments

return *TempFileOrErr;
llvm::module_split::ModuleSplitterSettings Settings;
Settings.Mode = Mode;
Settings.OutputPrefix = "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question, are there any cases where we're going to set a prefix in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, it should be changed when -save-temps is used.

@@ -45,6 +46,10 @@ enum IRSplitMode {
SPLIT_NONE // no splitting
};

// \returns IRSplitMode value if \p S is recognized. Otherwise, std::nullopt is
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: mix between // comments here and /// for parseSplitModulesFromFile

@@ -90,7 +103,7 @@
//
// RUN: clang-linker-wrapper -sycl-device-libraries=%t3.devicelib.o -sycl-post-link-options="SYCL_POST_LINK_OPTIONS" -llvm-spirv-options="LLVM_SPIRV_OPTIONS" "--host-triple=x86_64-unknown-linux-gnu" "--linker-path=/usr/bin/ld" "--" HOST_LINKER_FLAGS "-dynamic-linker" HOST_DYN_LIB "-o" "a.out" HOST_LIB_PATH HOST_STAT_LIB %t3.o --dry-run 2>&1 | FileCheck -check-prefix=CHK-CMDS-AOT-NV %s
// CHK-CMDS-AOT-NV: "{{.*}}spirv-to-ir-wrapper" {{.*}} -o [[FIRSTLLVMLINKIN:.*]].bc --llvm-spirv-opts --spirv-preserve-auxdata --spirv-target-env=SPV-IR --spirv-builtin-format=global
// CHK-CMDS-AOT-NV-NEXT: "{{.*}}llvm-link" [[FIRSTLLVMLINKIN:.*]].bc -o [[FIRSTLLVMLINKOUT:.*]].bc --suppress-warnings
// CHK-CMDS-AOT-NV-NEXT: "{{.*}}llvm-link" [[FIRSTLLVMLINKIN]].bc -o [[FIRSTLLVMLINKOUT:.*]].bc --suppress-warnings
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eagle eyes to catch the re-setting of the FIRSTLLVMLINKIN var!

Copy link
Contributor

@asudarsa asudarsa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I have one outstanding question about how you plan to handle -sycl-post-link-options in the library version. I am ok with a plan to support it in a future PR. But I would like to see some path forward here.
Thanks again for this PR.

@sarnex
Copy link
Contributor

sarnex commented Jul 15, 2024

@asudarsa Is it okay if I merge this PR? It doesn't seem like your comment is blocking. I'm dependent on this for thinLTO work. Thanks.

@sarnex
Copy link
Contributor

sarnex commented Jul 15, 2024

Sorry Arvind is on vacation for a while.

@maksimsab Is it okay if I merge this now and you can address any feedabck from Arvind when he comes back? Thanks.

@maksimsab
Copy link
Contributor Author

@sarnex Sure! I have the upcoming patch that depends on this one.

@sarnex
Copy link
Contributor

sarnex commented Jul 15, 2024

Thanks!

@sarnex sarnex merged commit 8761d40 into intel:sycl Jul 15, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants