-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Offload: Build offload as a single Step #150108
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
base: main
Are you sure you want to change the base?
Conversation
|
This PR modifies If appropriate, please update This PR changes how LLVM is built. Consider updating src/bootstrap/download-ci-llvm-stamp. This PR modifies If appropriate, please update |
|
|
93bc6ea to
4b2d2b9
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
4b2d2b9 to
dbe2964
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments, otherwise it looks reasonable.
| # Whether to build LLVM with support for it's gpu offload runtime. | ||
| #llvm.offload = false | ||
|
|
||
| # absolute path to ClangConfig.cmake |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit weird that it is called dir, but the comment states that it should be a path to a file. Should it be a path to a directory that contains this file?
| let in_tree_gcc_info = git_info(&exec_ctx, false, &src.join("src/gcc")); | ||
| let in_tree_llvm_info = git_info(&exec_ctx, false, &src.join("src/llvm-project")); | ||
| let enzyme_info = git_info(&exec_ctx, omit_git_hash, &src.join("src/tools/enzyme")); | ||
| let offload_info = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed, the commit will be always the same as the LLVM commit. See #148671 (comment).
| ldflags: Option<String> = "ldflags", | ||
| use_libcxx: Option<bool> = "use-libcxx", | ||
| use_linker: Option<String> = "use-linker", | ||
| clang_dir: Option<String> = "offload-clang-dir", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| clang_dir: Option<String> = "offload-clang-dir", | |
| offload_clang_dir: Option<String> = "offload-clang-dir", |
| .join(" ") | ||
| .into(); | ||
|
|
||
| // If we use an external clang as opposed to building our own llvm_clang, than that clang will |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that mean that even if we don't enable offload, the host Clang will somehow use its own include directories when building LLVM? That sounds suspicious.
| } | ||
|
|
||
| impl Step for OmpOffload { | ||
| type Output = PathBuf; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please modify this to be more similar to #150071? So that it returns some named struct that contains the final path to the libXXX dylibs. So that code that then uses the output (e.g. in the Assemble step) does not need to guess how are the files named, and the corresponding logic to find the files is localized within this step.
| // automatically manages our artifacts in the subfolder. | ||
| let out_dir = builder.llvm_out(target).join("offload-outdir"); | ||
| if std::fs::exists(&out_dir).is_ok_and(|x| !x) { | ||
| std::fs::DirBuilder::new().create(&out_dir).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lol, I never saw this in the stdlib, TIL. Isn't it enough to do std::fs::create_dir_all though?
| // binaries. We therefore write our offload artifacts into it's own subfolder. We use a | ||
| // subfolder, so that all the logic that processes our build artifacts (hopefully) also | ||
| // automatically manages our artifacts in the subfolder. | ||
| let out_dir = builder.llvm_out(target).join("offload-outdir"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think that we should use a different build directory, and handle the copying manually in the Assemble step. We should not rely on other code copying the offload stuff for us. Partly also because we will want to have it as a separate component, and not put the offload things into e.g. the rustc or llvm-tools component by accident.
| .define("OFFLOAD_INCLUDE_TESTS", "OFF") | ||
| .define("OPENMP_STANDALONE_BUILD", "ON") | ||
| .define("LLVM_ROOT", builder.llvm_out(target).join("build")) | ||
| .define("LLVM_DIR", builder.llvm_out(target).join("lib").join("cmake").join("llvm")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a field in LlvmResult with a path to this directory.
| builder.sysroot_target_libdir(target_compiler, target_compiler.host); | ||
| let lib_ext = std::env::consts::DLL_EXTENSION; | ||
|
|
||
| let libenzyme = "libLLVMOffload"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted in another comment, the logic for locating these components should ideally be localized within the offload step itself. It should then contain the paths to the dylibs (either just as a Vec<PathBuf>, or as three fields, depending on whether it is useful to distinguish them), and the code here in Assembly should just copy them to the correct directories.
| builder.sysroot_target_libdir(target_compiler, target_compiler.host); | ||
| let lib_ext = std::env::consts::DLL_EXTENSION; | ||
|
|
||
| let libenzyme = "libLLVMOffload"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| let libenzyme = "libLLVMOffload"; | |
| let liboffload = "libLLVMOffload"; |
|
@rustbot author |
r? @Kobzol
Since it looks like we'll postpone enabling offload in CI for a bit, I factored out these improvements which we want independently. I locally tested both build options successfully, the in-tree-clang build, as well as the build where we provide a path to an external clang.