diff --git a/config.example.toml b/config.example.toml index a52968e9a414d..d5b904ebf3d59 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 15137fbb2b5c2..2e173c9e6df48 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 a2d40f6fbd891..ffb7d9a9e0e74 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -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()); diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 444c97a2048e3..087dde0d9c6b2 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, @@ -938,6 +939,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", @@ -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; @@ -1884,6 +1887,7 @@ impl Config { use_libcxx, use_linker, allow_old_toolchain, + offload, polly, clang, enable_warnings, @@ -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); @@ -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); @@ -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)); @@ -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, @@ -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); diff --git a/src/bootstrap/src/utils/change_tracker.rs b/src/bootstrap/src/utils/change_tracker.rs index fac24572a878c..b9cf8f0531698 100644 --- a/src/bootstrap/src/utils/change_tracker.rs +++ b/src/bootstrap/src/utils/change_tracker.rs @@ -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.", + }, ];