Skip to content

[SYCL][Driver] Improve -save-temps for SYCL mode #4931

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 7 commits into from
Dec 1, 2021

Conversation

jchlanda
Copy link
Contributor

Make sure that header and footer files as well as the output of llvm-foreach (such as asm and fatbin for CUDA) stay in the output directory.

As discussed here: #4752

I'm unsure if that is a canonical way of getting the directory, as it relies on the output file's directory (not absolute) or the current dir.

@jchlanda jchlanda force-pushed the jakub/save_temps_llvm_foreach branch 2 times, most recently from dc12fa6 to f1d2f4d Compare November 10, 2021 19:12
llvm::sys::path::remove_filename(OutFileDir);
// `remove_filename` will return an empty string if in CWD, patch it.
if (OutFileDir.empty())
llvm::sys::path::native(OutFileDir = "./");
Copy link
Contributor

Choose a reason for hiding this comment

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

It is my understanding that we should use the -o information for the saved temporary files when -save-temps=obj is used. Otherwise, the CWD is used.

Also, since OutFileDir is only used with IsSaveTemps, we can move this logic there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed.
I kept the declaration of OutFileDir above the loop, so it doesn't need to be re-calculated.

@jchlanda jchlanda requested a review from mdtoguchi November 15, 2021 09:13
@jchlanda jchlanda force-pushed the jakub/save_temps_llvm_foreach branch 2 times, most recently from bf7a42b to 698272a Compare November 15, 2021 09:39
/// ###########################################################################
/// Verify that -save-temps puts header/footer in a correct place
// RUN: %clang -fsycl -fno-sycl-device-lib=all -fsycl-targets=spir64-unknown-unknown -target x86_64-unknown-linux-gnu -save-temps %s -### 2>&1 | FileCheck %s -check-prefixes=CHECK-SAVE-TEMPS-DIR
// CHECK-SAVE-TEMPS-DIR: clang{{.*}} "-fsycl-int-header=./sycl-offload-header-{{[a-z0-9]*}}.h"{{.*}}"-fsycl-int-footer=./sycl-offload-footer-{{[a-z0-9]*}}.h"
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 also check behaviors with -save-temps=obj and -o?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interestingly enough, -save-temps=obj with -o containing a relative path breaks the compilation. It fails to correctly construct the output file names for sycl-post-link job. As that is also present in main branch, I'd like to address it in a separate PR.

@jchlanda jchlanda force-pushed the jakub/save_temps_llvm_foreach branch from ca2f3ca to 9a19200 Compare November 16, 2021 11:54
@jchlanda jchlanda requested a review from mdtoguchi November 16, 2021 11:59
// If in `SaveTempsCwd` mode, or `remove_filename` returned an empty
// string use CWD, otherwise append separator.
if (OutFileDir.empty())
llvm::sys::path::native(OutFileDir = "./");
Copy link
Contributor

Choose a reason for hiding this comment

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

I looked through how other temporaries for save-temps are formulated in regards to $CWD, and there is no qualifier like ./. The output is just the filename. Perhaps we should do the same here.

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 think you are right, removed. Looks like the other use of ./ https://github.com/jchlanda/llvm/blob/jakub/save_temps_llvm_foreach/clang/lib/Driver/ToolChains/SYCL.cpp#L138 will have to stay, because of the way llvm-foreach handles the OutDirectory option.

@jchlanda jchlanda force-pushed the jakub/save_temps_llvm_foreach branch from 7734610 to e91f9d4 Compare November 17, 2021 10:52
@jchlanda jchlanda requested a review from mdtoguchi November 24, 2021 09:36
@jchlanda
Copy link
Contributor Author

Is there anything else that should be done for this PR?

@bader bader changed the title save-temps improvements [SYCL][Driver] Improve -save-temps for SYCL mode Nov 24, 2021
@jchlanda jchlanda force-pushed the jakub/save_temps_llvm_foreach branch from e91f9d4 to a9d40c8 Compare November 26, 2021 08:29
mdtoguchi
mdtoguchi previously approved these changes Nov 29, 2021
Copy link
Contributor

@mdtoguchi mdtoguchi 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!

@bader
Copy link
Contributor

bader commented Nov 30, 2021

@jchlanda, please, take a look at test failures on Windows platform.

@jchlanda jchlanda force-pushed the jakub/save_temps_llvm_foreach branch from 41ae583 to 1f3e9da Compare November 30, 2021 16:03
@jchlanda
Copy link
Contributor Author

@jchlanda, please, take a look at test failures on Windows platform.

Thank you @bader, should be fixed in: 1f3e9da

@bader bader self-requested a review November 30, 2021 16:07
@bader bader merged commit 96012a4 into intel:sycl Dec 1, 2021
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