Skip to content

[New offload model] Cleanup the way sycl-post-link options are generated #14177

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 6 commits into from
Jun 18, 2024

Conversation

asudarsa
Copy link
Contributor

In an earlier PR (#14101), we added support to generate sycl-post-link options (that partly depend on target triple) in clang Driver and then update the options using target triple information in the clang-linker-wrapper.
This PR cleans up that implementation by fully generating these options inside the clang-linker-wrapper. This requires some more user-specified options to be passed into the clang-linker-wrapper.

Thanks

@asudarsa asudarsa requested review from a team as code owners June 14, 2024 05:07
@asudarsa
Copy link
Contributor Author

asudarsa commented Jun 14, 2024

@sarnex

I have made changes based on PR 14101 review comments, Can you please take a look?

Thanks

bool NewOffloadDriver = TC.getDriver().getUseNewOffloadingDriver();
// Note: Do not use Triple when NewOffloadDriver is 'true'.
if (!NewOffloadDriver && (OutputType == types::TY_LLVM_BC)) {
// Add any sycl-post-link options that rely on a specific Triple in addition
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Main changes in this function are removal of NewOffloadDriver boolean and some comment updates.

if ((!EmitOnlyKernelsAsEntryPointsArg.empty()) && !Triple.isNVPTX() &&
!Triple.isAMDGPU())
addArg("-emit-only-kernels-as-entry-points");
// Add any sycl-post-link options that rely on a specific Triple in addition
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed all string parsing logic.

// Handle -Xdevice-post-link
TC.TranslateTargetOpt(T, TCArgs, CmdArgs, options::OPT_Xdevice_post_link,
options::OPT_Xdevice_post_link_EQ,
JA.getOffloadingArch());
Copy link
Contributor

@mdtoguchi mdtoguchi Jun 14, 2024

Choose a reason for hiding this comment

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

The options passed by the user should override any options we set in the driver, so this should be moved to after getTripleBasedSYCLPostLinkOpts

... I just noticed that this used to be later in the function - why the move?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah....Ok....I just moved it to match the order in new-offloading model. I will move this down in both places. Thanks. Good catch.

[=](sycl::id<1> idx) {});
});
return 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

These two tests don't look particularly different. At a high level, these don't need to be scrutinized with the REQUIRES: restriction and should work as a single test with just different --target values to exercise the given target.

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 test failed under windows. So, I split it into two.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have two tests. But I have removed the need to compile them (replaced with dry runs)

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.

Thank you! Some comments below:

if (!TCArgs.hasArg(options::OPT_fsycl_device_code_split_EQ) &&
(NewOffloadDriver || !(Triple.getArchName() == "spir64_fpga")))
(!(Triple.getArchName() == "spir64_fpga")))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make this

Suggested change
(!(Triple.getArchName() == "spir64_fpga")))
Triple.getArchName() != "spir64_fpga"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would like to keep one pair of surrounding parenthesis...

const llvm::Triple Triple) {
const llvm::Triple HostTriple(Args.getLastArgValue(OPT_host_triple_EQ));
bool SYCLNativeCPU = (HostTriple == Triple);
bool SpecConsts = !(Triple.isNVPTX() || Triple.isAMDGCN() ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I find it easier to read if we distrubute the '!', so !Triple.isNVPTS() && !Triple.isAMDGCN() ...

const llvm::Triple Triple) {
const llvm::Triple HostTriple(Args.getLastArgValue(OPT_host_triple_EQ));
bool SYCLNativeCPU = (HostTriple == Triple);
bool SpecConsts = !(Triple.isNVPTX() || Triple.isAMDGCN() ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we rename this to be more descriptive? If this is what it is really for, maybe this

Suggested change
bool SpecConsts = !(Triple.isNVPTX() || Triple.isAMDGCN() ||
bool SpecConstsSupported = !(Triple.isNVPTX() || Triple.isAMDGCN() ||

Also we should do the same in the Clang.cpp function

// added based on the user setting of -fsycl-device-code-split.
bool NoSplit = true;
for (auto Arg : PostLinkArgs)
if (Arg.contains("-split=")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if instead we can rely on the user settings and use Args.hasArg or something rather than a string check based on what the other function did.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is one scenario where I felt the current approach is simpler than passing -fsycl-device-code-split option along to the clang-linker-wrapper. It opens up additional issues like passing -fsycl-device-code-split as well as -split=? etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

the tradeoff is then we have multiple places changing for the tool option name itself and not the clang-linker-wrapper arg, so if we want to change the tool option or something then we have multiple places to update, but i don't think that's a huge deal

PostLinkArgs.push_back("-split-esimd");
PostLinkArgs.push_back("-lower-esimd");

bool IsAOT = Triple.isNVPTX() || Triple.isAMDGCN() ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use isSPIRAOT to get rid of some of these checks?

 bool isSPIRAOT() const {
    return isSPIR() && (getSubArch() == Triple::SPIRSubArch_fpga ||
                        getSubArch() == Triple::SPIRSubArch_gen ||
                        getSubArch() == Triple::SPIRSubArch_x86_64);
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good one. Will do

// Note: Do not use Triple when NewOffloadDriver is 'true'.
if (!NewOffloadDriver && (OutputType == types::TY_LLVM_BC)) {
// Add any sycl-post-link options that rely on a specific Triple in addition
// to user supplied options. This function is invoked only for old offloading
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// to user supplied options. This function is invoked only for old offloading
// to user supplied options. This function is invoked only for the old offloading

if (!NewOffloadDriver && (OutputType == types::TY_LLVM_BC)) {
// Add any sycl-post-link options that rely on a specific Triple in addition
// to user supplied options. This function is invoked only for old offloading
// model. For new offloading model, a slightly modified version of this
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// model. For new offloading model, a slightly modified version of this
// model. For the new offloading model, a slightly modified version of this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I remember my first thesis report where my professor marked out atleast a 100 extraneous 'the's. Since then I have been stringent with them. Sorry.

Copy link
Contributor

Choose a reason for hiding this comment

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

haha dont worry it's super minor, i just have an eye for typos

// model. For new offloading model, a slightly modified version of this
// function is called inside clang-linker-wrapper.
// NOTE: Any changes made here should be reflected in the similarly named
// function in clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have any plans to make this a single function that both can call somehow? Having two functions that need to be kept in sync is not ideal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1 on this. I will work with Mike Toguchi to identify a common location for this.

@@ -170,3 +170,18 @@ def sycl_post_link_options_EQ : Joined<["--", "-"], "sycl-post-link-options=">,
def llvm_spirv_options_EQ : Joined<["--", "-"], "llvm-spirv-options=">,
Flags<[WrapperOnlyOption]>,
HelpText<"Options that will control llvm-spirv step">;

// Extra SYCL options to help generate sycl-post-link options that also depend
// on target triple.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// on target triple.
// on the target triple.

// NOTE: Any changes made here should be reflected in the similarly named
// function in clang/lib/Driver/ToolChains/Clang.cpp.
static void
getTripleBasedSYCLPostLinkOpts(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.

Sorry I might have missed something, but can you remind me why we need two functions, one that cares about the triple and one that doesn't? It seem like it would be simpler if we had a single function because then we won't need to rely on things the previous one did.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's due to how clang-linker-wrapper processes images. clang-linker-wrapper receives a set of images each with its own target triple. So, we do not have a singular target triple at the call site of clang-linker-wrapper. The options which do not depend on the target triple can be computed once and passed into the linker wrapper. The options that depend on the target triple will need to be computed for each device image group ( group corresponds to a target triple) inside the clang-linker-wrapper. There are few other ways to implement this. one option will be to pass all required information to the clang-linker-wrapper and compute all of them in one place. Passing in all the required information seemed overkill. Current approach is agreeable, I Hope.

Thanks

Copy link
Contributor

Choose a reason for hiding this comment

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

assuming it doesnt get too much more complex i think it's okay

asudarsa added 6 commits June 17, 2024 07:38
Signed-off-by: Arvind Sudarsanam <[email protected]>
…-post-link command line

Signed-off-by: Arvind Sudarsanam <[email protected]>
Signed-off-by: Arvind Sudarsanam <[email protected]>
Signed-off-by: Arvind Sudarsanam <[email protected]>
@asudarsa asudarsa force-pushed the cleanup_sycl_post_link_options branch from 7ff9292 to 164b5d5 Compare June 17, 2024 15:03
@asudarsa asudarsa merged commit 3e474e0 into intel:sycl Jun 18, 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.

3 participants