From b1f21b84530dcfd14bb29cbb3152a3d40108806c Mon Sep 17 00:00:00 2001 From: Manuel Drehwald Date: Sat, 12 Oct 2024 00:16:39 +0200 Subject: [PATCH] Allow building rustc's LLVM with Offload support --- config.example.toml | 3 +++ src/bootstrap/configure.py | 1 + src/bootstrap/src/core/build_steps/llvm.rs | 15 +++++++++++++++ src/bootstrap/src/core/config/config.rs | 9 +++++++++ src/bootstrap/src/utils/change_tracker.rs | 5 +++++ 5 files changed, 33 insertions(+) diff --git a/config.example.toml b/config.example.toml index 4b591b949b36d..707c9378e5a6f 100644 --- a/config.example.toml +++ b/config.example.toml @@ -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 + # 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 diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index a555a26367d51..070c6d6cda367 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -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") diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 3021358415790..86903409dbed1 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -459,6 +459,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()); diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 3f025a198cb97..94ab2abdaec01 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -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, @@ -930,6 +931,7 @@ define_config! { use_libcxx: Option = "use-libcxx", use_linker: Option = "use-linker", allow_old_toolchain: Option = "allow-old-toolchain", + offload: Option = "offload", polly: Option = "polly", clang: Option = "clang", enable_warnings: Option = "enable-warnings", @@ -1636,6 +1638,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; @@ -1873,6 +1876,7 @@ impl Config { use_libcxx, use_linker, allow_old_toolchain, + offload, polly, clang, enable_warnings, @@ -1889,6 +1893,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); @@ -1910,6 +1915,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); @@ -2086,6 +2092,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)); @@ -2970,6 +2977,7 @@ pub(crate) fn check_incompatible_options_for_ci_llvm( use_libcxx, use_linker, allow_old_toolchain, + offload, polly, clang, enable_warnings, @@ -2992,6 +3000,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); diff --git a/src/bootstrap/src/utils/change_tracker.rs b/src/bootstrap/src/utils/change_tracker.rs index b37786496cb56..8eab4939861aa 100644 --- a/src/bootstrap/src/utils/change_tracker.rs +++ b/src/bootstrap/src/utils/change_tracker.rs @@ -275,4 +275,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[ severity: ChangeSeverity::Info, summary: "New option `./x setup editor` added, replacing `./x setup vscode` and adding support for vim, emacs and helix.", }, + 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.", + }, ];