Skip to content

Commit 17f8215

Browse files
committed
Auto merge of rust-lang#131527 - ZuseZ4:enable-llvm-offload-runtime, r=Kobzol
Enable the llvm offload build configuration Tracking: - rust-lang#131513
2 parents 80d0d92 + e2d3f5a commit 17f8215

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

config.example.toml

+3
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@
8484
# Wheter to build Enzyme as AutoDiff backend.
8585
#enzyme = false
8686

87+
# Whether to build LLVM with support for it's gpu offload runtime.
88+
#offload = false
89+
8790
# Indicates whether ccache is used when building LLVM. Set to `true` to use the first `ccache` in
8891
# PATH, or set an absolute path to use a specific version.
8992
#ccache = false

src/bootstrap/configure.py

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def v(*args):
7272
o("optimize-llvm", "llvm.optimize", "build optimized LLVM")
7373
o("llvm-assertions", "llvm.assertions", "build LLVM with assertions")
7474
o("llvm-enzyme", "llvm.enzyme", "build LLVM with enzyme")
75+
o("llvm-offload", "llvm.offload", "build LLVM with gpu offload support")
7576
o("llvm-plugins", "llvm.plugins", "build LLVM with plugin interface")
7677
o("debug-assertions", "rust.debug-assertions", "build with debugging assertions")
7778
o("debug-assertions-std", "rust.debug-assertions-std", "build the standard library with debugging assertions")

src/bootstrap/src/core/build_steps/llvm.rs

+15
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,21 @@ impl Step for Llvm {
472472
cfg.define("LLVM_ENABLE_PROJECTS", enabled_llvm_projects.join(";"));
473473
}
474474

475+
let mut enabled_llvm_runtimes = Vec::new();
476+
477+
if builder.config.llvm_offload {
478+
enabled_llvm_runtimes.push("offload");
479+
//FIXME(ZuseZ4): LLVM intends to drop the offload dependency on openmp.
480+
//Remove this line once they achieved it.
481+
enabled_llvm_runtimes.push("openmp");
482+
}
483+
484+
if !enabled_llvm_runtimes.is_empty() {
485+
enabled_llvm_runtimes.sort();
486+
enabled_llvm_runtimes.dedup();
487+
cfg.define("LLVM_ENABLE_RUNTIMES", enabled_llvm_runtimes.join(";"));
488+
}
489+
475490
if let Some(num_linkers) = builder.config.llvm_link_jobs {
476491
if num_linkers > 0 {
477492
cfg.define("LLVM_PARALLEL_LINK_JOBS", num_linkers.to_string());

src/bootstrap/src/core/config/config.rs

+9
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ pub struct Config {
224224
pub llvm_assertions: bool,
225225
pub llvm_tests: bool,
226226
pub llvm_enzyme: bool,
227+
pub llvm_offload: bool,
227228
pub llvm_plugins: bool,
228229
pub llvm_optimize: bool,
229230
pub llvm_thin_lto: bool,
@@ -938,6 +939,7 @@ define_config! {
938939
use_libcxx: Option<bool> = "use-libcxx",
939940
use_linker: Option<String> = "use-linker",
940941
allow_old_toolchain: Option<bool> = "allow-old-toolchain",
942+
offload: Option<bool> = "offload",
941943
polly: Option<bool> = "polly",
942944
clang: Option<bool> = "clang",
943945
enable_warnings: Option<bool> = "enable-warnings",
@@ -1647,6 +1649,7 @@ impl Config {
16471649
// we'll infer default values for them later
16481650
let mut llvm_tests = None;
16491651
let mut llvm_enzyme = None;
1652+
let mut llvm_offload = None;
16501653
let mut llvm_plugins = None;
16511654
let mut debug = None;
16521655
let mut debug_assertions = None;
@@ -1884,6 +1887,7 @@ impl Config {
18841887
use_libcxx,
18851888
use_linker,
18861889
allow_old_toolchain,
1890+
offload,
18871891
polly,
18881892
clang,
18891893
enable_warnings,
@@ -1900,6 +1904,7 @@ impl Config {
19001904
set(&mut config.ninja_in_file, ninja);
19011905
llvm_tests = tests;
19021906
llvm_enzyme = enzyme;
1907+
llvm_offload = offload;
19031908
llvm_plugins = plugins;
19041909
set(&mut config.llvm_optimize, optimize_toml);
19051910
set(&mut config.llvm_thin_lto, thin_lto);
@@ -1921,6 +1926,7 @@ impl Config {
19211926
set(&mut config.llvm_use_libcxx, use_libcxx);
19221927
config.llvm_use_linker.clone_from(&use_linker);
19231928
config.llvm_allow_old_toolchain = allow_old_toolchain.unwrap_or(false);
1929+
config.llvm_offload = offload.unwrap_or(false);
19241930
config.llvm_polly = polly.unwrap_or(false);
19251931
config.llvm_clang = clang.unwrap_or(false);
19261932
config.llvm_enable_warnings = enable_warnings.unwrap_or(false);
@@ -2097,6 +2103,7 @@ impl Config {
20972103

20982104
config.llvm_tests = llvm_tests.unwrap_or(false);
20992105
config.llvm_enzyme = llvm_enzyme.unwrap_or(false);
2106+
config.llvm_offload = llvm_offload.unwrap_or(false);
21002107
config.llvm_plugins = llvm_plugins.unwrap_or(false);
21012108
config.rust_optimize = optimize.unwrap_or(RustOptimize::Bool(true));
21022109

@@ -2963,6 +2970,7 @@ pub(crate) fn check_incompatible_options_for_ci_llvm(
29632970
use_libcxx,
29642971
use_linker,
29652972
allow_old_toolchain,
2973+
offload,
29662974
polly,
29672975
clang,
29682976
enable_warnings,
@@ -2985,6 +2993,7 @@ pub(crate) fn check_incompatible_options_for_ci_llvm(
29852993
err!(current_llvm_config.use_libcxx, use_libcxx);
29862994
err!(current_llvm_config.use_linker, use_linker);
29872995
err!(current_llvm_config.allow_old_toolchain, allow_old_toolchain);
2996+
err!(current_llvm_config.offload, offload);
29882997
err!(current_llvm_config.polly, polly);
29892998
err!(current_llvm_config.clang, clang);
29902999
err!(current_llvm_config.build_config, build_config);

src/bootstrap/src/utils/change_tracker.rs

+5
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
285285
severity: ChangeSeverity::Info,
286286
summary: "New option `build.compiletest-diff-tool` that adds support for a custom differ for compiletest",
287287
},
288+
ChangeInfo {
289+
change_id: 131513,
290+
severity: ChangeSeverity::Info,
291+
summary: "New option `llvm.offload` to control whether the llvm offload runtime for GPU support is built. Implicitly enables the openmp runtime as dependency.",
292+
},
288293
];

0 commit comments

Comments
 (0)