Skip to content

Enable the llvm offload build configuration #131527

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 1 commit into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
# Wheter to build Enzyme as AutoDiff backend.
#enzyme = false

# Whether to build LLVM with support for it's gpu offload runtime.
#offload = false
Copy link
Member

Choose a reason for hiding this comment

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

Maybe call it gpu-offload? Or does it also support offloading to other hardware like programmable network controllers and flash drives?

Copy link
Member Author

@ZuseZ4 ZuseZ4 Oct 12, 2024

Choose a reason for hiding this comment

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

only compute devices, so no controllers or flash drives, but also non-gpu hardware:
https://clang.llvm.org/docs/OffloadingDesign.html#openmp-offloading

supports [..] target offloading to several different architectures such as NVPTX, AMDGPU, X86_64, Arm, and PowerPC.

But then again GPUs are surely the most popular use-case (though afaik there is a hope to support other coprocessors too).
I don't care strongly for either and for some co-processors like TPUs support we probably want MLIR instead of offload anyway, which would be a follow-up project.


# Indicates whether ccache is used when building LLVM. Set to `true` to use the first `ccache` in
# PATH, or set an absolute path to use a specific version.
#ccache = false
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def v(*args):
o("optimize-llvm", "llvm.optimize", "build optimized LLVM")
o("llvm-assertions", "llvm.assertions", "build LLVM with assertions")
o("llvm-enzyme", "llvm.enzyme", "build LLVM with enzyme")
o("llvm-offload", "llvm.offload", "build LLVM with gpu offload support")
o("llvm-plugins", "llvm.plugins", "build LLVM with plugin interface")
o("debug-assertions", "rust.debug-assertions", "build with debugging assertions")
o("debug-assertions-std", "rust.debug-assertions-std", "build the standard library with debugging assertions")
Expand Down
15 changes: 15 additions & 0 deletions src/bootstrap/src/core/build_steps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,21 @@ impl Step for Llvm {
cfg.define("LLVM_ENABLE_PROJECTS", enabled_llvm_projects.join(";"));
}

let mut enabled_llvm_runtimes = Vec::new();

if builder.config.llvm_offload {
enabled_llvm_runtimes.push("offload");
//FIXME(ZuseZ4): LLVM intends to drop the offload dependency on openmp.
//Remove this line once they achieved it.
enabled_llvm_runtimes.push("openmp");
}

if !enabled_llvm_runtimes.is_empty() {
enabled_llvm_runtimes.sort();
enabled_llvm_runtimes.dedup();
cfg.define("LLVM_ENABLE_RUNTIMES", enabled_llvm_runtimes.join(";"));
}

if let Some(num_linkers) = builder.config.llvm_link_jobs {
if num_linkers > 0 {
cfg.define("LLVM_PARALLEL_LINK_JOBS", num_linkers.to_string());
Expand Down
9 changes: 9 additions & 0 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ pub struct Config {
pub llvm_assertions: bool,
pub llvm_tests: bool,
pub llvm_enzyme: bool,
pub llvm_offload: bool,
pub llvm_plugins: bool,
pub llvm_optimize: bool,
pub llvm_thin_lto: bool,
Expand Down Expand Up @@ -938,6 +939,7 @@ define_config! {
use_libcxx: Option<bool> = "use-libcxx",
use_linker: Option<String> = "use-linker",
allow_old_toolchain: Option<bool> = "allow-old-toolchain",
offload: Option<bool> = "offload",
polly: Option<bool> = "polly",
clang: Option<bool> = "clang",
enable_warnings: Option<bool> = "enable-warnings",
Expand Down Expand Up @@ -1647,6 +1649,7 @@ impl Config {
// we'll infer default values for them later
let mut llvm_tests = None;
let mut llvm_enzyme = None;
let mut llvm_offload = None;
let mut llvm_plugins = None;
let mut debug = None;
let mut debug_assertions = None;
Expand Down Expand Up @@ -1884,6 +1887,7 @@ impl Config {
use_libcxx,
use_linker,
allow_old_toolchain,
offload,
polly,
clang,
enable_warnings,
Expand All @@ -1900,6 +1904,7 @@ impl Config {
set(&mut config.ninja_in_file, ninja);
llvm_tests = tests;
llvm_enzyme = enzyme;
llvm_offload = offload;
llvm_plugins = plugins;
set(&mut config.llvm_optimize, optimize_toml);
set(&mut config.llvm_thin_lto, thin_lto);
Expand All @@ -1921,6 +1926,7 @@ impl Config {
set(&mut config.llvm_use_libcxx, use_libcxx);
config.llvm_use_linker.clone_from(&use_linker);
config.llvm_allow_old_toolchain = allow_old_toolchain.unwrap_or(false);
config.llvm_offload = offload.unwrap_or(false);
config.llvm_polly = polly.unwrap_or(false);
config.llvm_clang = clang.unwrap_or(false);
config.llvm_enable_warnings = enable_warnings.unwrap_or(false);
Expand Down Expand Up @@ -2097,6 +2103,7 @@ impl Config {

config.llvm_tests = llvm_tests.unwrap_or(false);
config.llvm_enzyme = llvm_enzyme.unwrap_or(false);
config.llvm_offload = llvm_offload.unwrap_or(false);
config.llvm_plugins = llvm_plugins.unwrap_or(false);
config.rust_optimize = optimize.unwrap_or(RustOptimize::Bool(true));

Expand Down Expand Up @@ -2963,6 +2970,7 @@ pub(crate) fn check_incompatible_options_for_ci_llvm(
use_libcxx,
use_linker,
allow_old_toolchain,
offload,
polly,
clang,
enable_warnings,
Expand All @@ -2985,6 +2993,7 @@ pub(crate) fn check_incompatible_options_for_ci_llvm(
err!(current_llvm_config.use_libcxx, use_libcxx);
err!(current_llvm_config.use_linker, use_linker);
err!(current_llvm_config.allow_old_toolchain, allow_old_toolchain);
err!(current_llvm_config.offload, offload);
err!(current_llvm_config.polly, polly);
err!(current_llvm_config.clang, clang);
err!(current_llvm_config.build_config, build_config);
Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/src/utils/change_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
severity: ChangeSeverity::Info,
summary: "New option `build.compiletest-diff-tool` that adds support for a custom differ for compiletest",
},
ChangeInfo {
change_id: 131513,
severity: ChangeSeverity::Info,
summary: "New option `llvm.offload` to control whether the llvm offload runtime for GPU support is built. Implicitly enables the openmp runtime as dependency.",
},
];
Loading