Skip to content

Commit 5ae5def

Browse files
committed
unify both ol and omp runtime builds into one step
1 parent 46c7035 commit 5ae5def

File tree

2 files changed

+14
-194
lines changed

2 files changed

+14
-194
lines changed

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,8 +1442,7 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
14421442
}
14431443
let llvm::LlvmResult { host_llvm_config, .. } = builder.ensure(llvm::Llvm { target });
14441444
if builder.config.llvm_offload {
1445-
builder.ensure(llvm::Openmp { target });
1446-
builder.ensure(llvm::Offload { target });
1445+
builder.ensure(llvm::OmpOffload { target });
14471446
cargo.env("LLVM_OFFLOAD", "1");
14481447
}
14491448

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

Lines changed: 13 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -911,23 +911,24 @@ fn get_var(var_base: &str, host: &str, target: &str) -> Option<OsString> {
911911
}
912912

913913
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
914-
pub struct Openmp {
914+
pub struct OmpOffload {
915915
pub target: TargetSelection,
916916
}
917917

918-
impl Step for Openmp {
918+
impl Step for OmpOffload {
919919
type Output = PathBuf;
920920
const IS_HOST: bool = true;
921921

922922
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
923-
run.path("src/llvm-project/openmp")
923+
run.path("src/llvm-project/offload")
924924
}
925925

926926
fn make_run(run: RunConfig<'_>) {
927-
run.builder.ensure(Openmp { target: run.target });
927+
run.builder.ensure(OmpOffload { target: run.target });
928928
}
929929

930930
/// Compile OpenMP offload runtimes for `target`.
931+
#[allow(unused)]
931932
fn run(self, builder: &Builder<'_>) -> PathBuf {
932933
if builder.config.dry_run() {
933934
return PathBuf::from("/");
@@ -941,7 +942,7 @@ impl Step for Openmp {
941942
//let smart_stamp_hash = STAMP_HASH_MEMO.get_or_init(|| {
942943
// generate_smart_stamp_hash(
943944
// builder,
944-
// &builder.config.src.join("src/llvm-project/openmp"),
945+
// &builder.config.src.join("src/llvm-project/offload"),
945946
// builder.offload_info.sha().unwrap_or_default(),
946947
// )
947948
//});
@@ -963,8 +964,8 @@ impl Step for Openmp {
963964
// return out_dir;
964965
//}
965966

966-
trace!(?target, "(re)building openmp artifacts");
967-
builder.info(&format!("Building OpenMP for {target}"));
967+
trace!(?target, "(re)building offload artifacts");
968+
builder.info(&format!("Building Omp/Offload for {target}"));
968969
//t!(stamp.remove());
969970
let _time = helpers::timeit(builder);
970971
t!(fs::create_dir_all(&out_dir));
@@ -987,10 +988,7 @@ impl Step for Openmp {
987988
.profile(profile)
988989
.env("LLVM_CONFIG_REAL", &host_llvm_config)
989990
.define("LLVM_ENABLE_ASSERTIONS", "ON")
990-
.define("TARGET_TRIPLE", &target.triple)
991-
.define("LLVM_ENABLE_RUNTIMES", "offload")
992-
//.define("CMAKE_C_COMPILER", builder.cc(target))
993-
//.define("CMAKE_CXX_COMPILER", builder.cxx(target).unwrap())
991+
.define("LLVM_ENABLE_RUNTIMES", "openmp;offload")
994992
//.define(
995993
// "CMAKE_C_COMPILER",
996994
// "/tmp/drehwald1/prog/rust/build/x86_64-unknown-linux-gnu/llvm/bin/clang",
@@ -999,197 +997,20 @@ impl Step for Openmp {
999997
// "CMAKE_CXX_COMPILER",
1000998
// "/tmp/drehwald1/prog/rust/build/x86_64-unknown-linux-gnu/llvm/bin/clang++",
1001999
//)
1000+
.define("CMAKE_C_COMPILER", builder.cc(target))
1001+
.define("CMAKE_CXX_COMPILER", builder.cxx(target).unwrap())
10021002
.define("LLVM_DEFAULT_TARGET_TRIPLE", &target.triple)
1003-
.define("OFFLOAD_STANDALONE_BUILD", "ON")
1004-
.define("LLVM_ROOT", builder.llvm_out(target))
1003+
.define("OPENMP_STANDALONE_BUILD", "ON")
1004+
.define("LLVM_ROOT", builder.llvm_out(target).join("build"))
10051005
//.define(
10061006
// "LLVM_ROOT",
10071007
// "/tmp/drehwald1/prog/rust/build/x86_64-unknown-linux-gnu/llvm/build/",
10081008
//)
10091009
.define("LLVM_DIR", builder.llvm_out(target).join("lib").join("cmake").join("llvm"));
1010-
1011-
if builder.config.llvm_clang {
1012-
// This is likely the case locally. If we just build clang in the previous step, we
1013-
// should use it. We wouldn't even need a standalone build here, but it's easier to
1014-
// unify this with the case below, which needs standalone builds.
1015-
// We likely wouldn't need to specify these here, they should be found by default.
1016-
cfg.define("CMAKE_C_COMPILER", builder.cc(target))
1017-
.define("CMAKE_CXX_COMPILER", builder.cxx(target).unwrap());
1018-
} else {
1019-
// This is the (more complicated) case which we have e.g. in CI. We first build a
1020-
// standalone llvm/llvm-project including clang. Then we use this clang to build the
1021-
// llvm submodule of rustc in src/llvm-project. In this case we do *NOT* build clang
1022-
// again in the llvm submodule to save compile times, this is a hard requirement.
1023-
// If we build the offload and openmp runtimes in-tree, they assume that clang was
1024-
// already build in-tree, which is not the case here. We therefore must use standalone
1025-
// builds of these two runtimes. We now have to specify clang(++) manually to match the
1026-
// one we build in llvm/llvm-project
1027-
cfg.define("CMAKE_C_COMPILER", builder.cc(target))
1028-
.define("CMAKE_CXX_COMPILER", builder.cxx(target).unwrap());
1029-
}
1030-
// /tmp/drehwald1/prog/rust/build/x86_64-unknown-linux-gnu/llvm/lib/cmake/llvm
1031-
//$> cmake ../runtimes \ # Point to the runtimes build
1032-
// -G Ninja \
1033-
// -DLLVM_ENABLE_RUNTIMES=openmp \
1034-
// -DCMAKE_C_COMPILER=$TARGET_C_COMPILER \
1035-
// -DCMAKE_CXX_COMPILER=$TARGET_CXX_COMPILER \
1036-
// -DLLVM_DEFAULT_TARGET_TRIPLE=$TARGET_TRIPLE \
1037-
// -DCMAKE_BUILD_TYPE=Release
10381010
cfg.build();
10391011

10401012
//t!(stamp.write());
10411013
out_dir
1042-
1043-
//$> cd llvm-project # The llvm-project checkout
1044-
//$> mkdir build # A different build directory for the build tools
1045-
//$> cd build
1046-
//$> TARGET_TRIPLE=<amdgcn-amd-amdhsa or nvptx64-nvidia-cuda>
1047-
//$> TARGET_C_COMPILER=</path/to/clang>
1048-
//$> TARGET_CXX_COMPILER=</path/to/clang++>
1049-
//$> ninja install
1050-
//
1051-
//You can do the same thing for the offload project.
1052-
//
1053-
//$> TARGET_C_COMPILER=</path/to/clang>
1054-
//$> TARGET_CXX_COMPILER=</path/to/clang++>
1055-
//$> cmake ../runtimes \ # Point to the runtimes build
1056-
// -G Ninja \
1057-
// -DLLVM_ENABLE_RUNTIMES=openmp \
1058-
// -DCMAKE_C_COMPILER=$TARGET_C_COMPILER \
1059-
// -DCMAKE_CXX_COMPILER=$TARGET_CXX_COMPILER \
1060-
// -DCMAKE_BUILD_TYPE=Release
1061-
//$> ninja install
1062-
}
1063-
}
1064-
1065-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
1066-
pub struct Offload {
1067-
pub target: TargetSelection,
1068-
}
1069-
1070-
impl Step for Offload {
1071-
type Output = PathBuf;
1072-
const IS_HOST: bool = true;
1073-
1074-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1075-
run.path("src/llvm-project/offload")
1076-
}
1077-
1078-
fn make_run(run: RunConfig<'_>) {
1079-
run.builder.ensure(Offload { target: run.target });
1080-
}
1081-
1082-
/// Compile OpenMP offload runtimes for `target`.
1083-
fn run(self, builder: &Builder<'_>) -> PathBuf {
1084-
if builder.config.dry_run() {
1085-
return PathBuf::from("/");
1086-
}
1087-
let target = self.target;
1088-
1089-
let LlvmResult { host_llvm_config, .. } = builder.ensure(Llvm { target: self.target });
1090-
1091-
let out_dir = builder.llvm_out(target);
1092-
static STAMP_HASH_MEMO: OnceLock<String> = OnceLock::new();
1093-
//let smart_stamp_hash = STAMP_HASH_MEMO.get_or_init(|| {
1094-
// generate_smart_stamp_hash(
1095-
// builder,
1096-
// &builder.config.src.join("src/llvm-project/offload"),
1097-
// builder.offload_info.sha().unwrap_or_default(),
1098-
// )
1099-
//});
1100-
//let stamp = BuildStamp::new(&out_dir).with_prefix("enzyme").add_stamp(smart_stamp_hash);
1101-
1102-
trace!("checking build stamp to see if we need to rebuild offload/openmp artifacts");
1103-
//if stamp.is_up_to_date() {
1104-
// trace!(?out_dir, "offload/openmp build artifacts are up to date");
1105-
// if stamp.stamp().is_empty() {
1106-
// builder.info(
1107-
// "Could not determine the Offload submodule commit hash. \
1108-
// Assuming that an Offload rebuild is not necessary.",
1109-
// );
1110-
// builder.info(&format!(
1111-
// "To force Offload to rebuild, remove the file `{}`",
1112-
// stamp.path().display()
1113-
// ));
1114-
// }
1115-
// return out_dir;
1116-
//}
1117-
1118-
trace!(?target, "(re)building offload artifacts");
1119-
builder.info(&format!("Building Offload for {target}"));
1120-
//t!(stamp.remove());
1121-
let _time = helpers::timeit(builder);
1122-
t!(fs::create_dir_all(&out_dir));
1123-
1124-
builder.config.update_submodule(Path::new("src").join("llvm-project").to_str().unwrap());
1125-
let mut cfg = cmake::Config::new(builder.src.join("src/llvm-project/runtimes/"));
1126-
configure_cmake(builder, target, &mut cfg, true, LdFlags::default(), &[]);
1127-
1128-
// Re-use the same flags as llvm to control the level of debug information
1129-
// generated by Enzyme.
1130-
// FIXME(ZuseZ4): Find a nicer way to use Enzyme Debug builds.
1131-
let profile = match (builder.config.llvm_optimize, builder.config.llvm_release_debuginfo) {
1132-
(false, _) => "Debug",
1133-
(true, false) => "Release",
1134-
(true, true) => "RelWithDebInfo",
1135-
};
1136-
trace!(?profile);
1137-
1138-
cfg.out_dir(&out_dir)
1139-
.profile(profile)
1140-
.env("LLVM_CONFIG_REAL", &host_llvm_config)
1141-
.define("LLVM_ENABLE_ASSERTIONS", "ON")
1142-
.define("TARGET_TRIPLE", &target.triple)
1143-
.define("LLVM_ENABLE_RUNTIMES", "openmp")
1144-
.define(
1145-
"CMAKE_C_COMPILER",
1146-
"/tmp/drehwald1/prog/rust/build/x86_64-unknown-linux-gnu/llvm/bin/clang",
1147-
)
1148-
.define(
1149-
"CMAKE_CXX_COMPILER",
1150-
"/tmp/drehwald1/prog/rust/build/x86_64-unknown-linux-gnu/llvm/bin/clang++",
1151-
)
1152-
//.define("CMAKE_C_COMPILER", builder.cc(target))
1153-
//.define("CMAKE_CXX_COMPILER", builder.cxx(target).unwrap())
1154-
.define("LLVM_DEFAULT_TARGET_TRIPLE", &target.triple)
1155-
.define("OPENMP_STANDALONE_BUILD", "ON")
1156-
.define(
1157-
"LLVM_ROOT",
1158-
"/tmp/drehwald1/prog/rust/build/x86_64-unknown-linux-gnu/llvm/build/",
1159-
)
1160-
.define("LLVM_DIR", builder.llvm_out(target).join("lib").join("cmake").join("llvm"));
1161-
///tmp/drehwald1/prog/rust/build/x86_64-unknown-linux-gnu/llvm/lib/cmake/llvm
1162-
//$> cmake ../runtimes \ # Point to the runtimes build
1163-
// -G Ninja \
1164-
// -DLLVM_ENABLE_RUNTIMES=openmp \
1165-
// -DCMAKE_C_COMPILER=$TARGET_C_COMPILER \
1166-
// -DCMAKE_CXX_COMPILER=$TARGET_CXX_COMPILER \
1167-
// -DLLVM_DEFAULT_TARGET_TRIPLE=$TARGET_TRIPLE \
1168-
// -DCMAKE_BUILD_TYPE=Release
1169-
cfg.build();
1170-
1171-
//t!(stamp.write());
1172-
out_dir
1173-
1174-
//$> cd llvm-project # The llvm-project checkout
1175-
//$> mkdir build # A different build directory for the build tools
1176-
//$> cd build
1177-
//$> TARGET_TRIPLE=<amdgcn-amd-amdhsa or nvptx64-nvidia-cuda>
1178-
//$> TARGET_C_COMPILER=</path/to/clang>
1179-
//$> TARGET_CXX_COMPILER=</path/to/clang++>
1180-
//$> ninja install
1181-
//
1182-
//You can do the same thing for the offload project.
1183-
//
1184-
//$> TARGET_C_COMPILER=</path/to/clang>
1185-
//$> TARGET_CXX_COMPILER=</path/to/clang++>
1186-
//$> cmake ../runtimes \ # Point to the runtimes build
1187-
// -G Ninja \
1188-
// -DLLVM_ENABLE_RUNTIMES=openmp \
1189-
// -DCMAKE_C_COMPILER=$TARGET_C_COMPILER \
1190-
// -DCMAKE_CXX_COMPILER=$TARGET_CXX_COMPILER \
1191-
// -DCMAKE_BUILD_TYPE=Release
1192-
//$> ninja install
11931014
}
11941015
}
11951016

0 commit comments

Comments
 (0)