Skip to content

Commit

Permalink
Allow building rustc's LLVM with Offload support
Browse files Browse the repository at this point in the history
  • Loading branch information
ZuseZ4 committed Oct 11, 2024
1 parent 52fd998 commit 36c458d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
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

# 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 @@ -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());
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 @@ -930,6 +931,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 @@ -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;
Expand Down Expand Up @@ -1873,6 +1876,7 @@ impl Config {
use_libcxx,
use_linker,
allow_old_toolchain,
offload,
polly,
clang,
enable_warnings,
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down

0 comments on commit 36c458d

Please sign in to comment.