Allow building rustc's LLVM with Offload support

This commit is contained in:
Manuel Drehwald 2024-10-12 00:16:39 +02:00
parent b188577f14
commit e2d3f5aaec
5 changed files with 33 additions and 0 deletions

View File

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

View File

@ -72,6 +72,7 @@ v("llvm-libunwind", "rust.llvm-libunwind", "use LLVM libunwind")
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")

View File

@ -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());

View File

@ -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<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",
@ -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);

View File

@ -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.",
},
];