Skip to content

Commit 22a499f

Browse files
committed
add -Zoffload=Enable flag, to enable gpu (host) code generation
1 parent 3debe14 commit 22a499f

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ pub struct ModuleConfig {
120120
pub emit_lifetime_markers: bool,
121121
pub llvm_plugins: Vec<String>,
122122
pub autodiff: Vec<config::AutoDiff>,
123+
pub offload: Vec<config::Offload>,
123124
}
124125

125126
impl ModuleConfig {
@@ -268,6 +269,7 @@ impl ModuleConfig {
268269
emit_lifetime_markers: sess.emit_lifetime_markers(),
269270
llvm_plugins: if_regular!(sess.opts.unstable_opts.llvm_plugins.clone(), vec![]),
270271
autodiff: if_regular!(sess.opts.unstable_opts.autodiff.clone(), vec![]),
272+
offload: if_regular!(sess.opts.unstable_opts.offload.clone(), vec![]),
271273
}
272274
}
273275

compiler/rustc_session/src/config.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ pub enum CoverageLevel {
226226
Mcdc,
227227
}
228228

229+
// The different settings that the `-Z offload` flag can have.
230+
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
231+
pub enum Offload {
232+
/// Enable the llvm offload pipeline
233+
Enable,
234+
}
235+
229236
/// The different settings that the `-Z autodiff` flag can have.
230237
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
231238
pub enum AutoDiff {
@@ -3073,7 +3080,7 @@ pub(crate) mod dep_tracking {
30733080
AutoDiff, BranchProtection, CFGuard, CFProtection, CollapseMacroDebuginfo, CoverageOptions,
30743081
CrateType, DebugInfo, DebugInfoCompression, ErrorOutputType, FmtDebug, FunctionReturn,
30753082
InliningThreshold, InstrumentCoverage, InstrumentXRay, LinkerPluginLto, LocationDetail,
3076-
LtoCli, MirStripDebugInfo, NextSolverConfig, OomStrategy, OptLevel, OutFileName,
3083+
LtoCli, MirStripDebugInfo, NextSolverConfig, Offload, OomStrategy, OptLevel, OutFileName,
30773084
OutputType, OutputTypes, PatchableFunctionEntry, Polonius, RemapPathScopeComponents,
30783085
ResolveDocLinks, SourceFileHashAlgorithm, SplitDwarfKind, SwitchWithOptPath,
30793086
SymbolManglingVersion, WasiExecModel,
@@ -3120,6 +3127,7 @@ pub(crate) mod dep_tracking {
31203127
impl_dep_tracking_hash_via_hash!(
31213128
(),
31223129
AutoDiff,
3130+
Offload,
31233131
bool,
31243132
usize,
31253133
NonZero<usize>,

compiler/rustc_session/src/options.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,7 @@ mod desc {
720720
pub(crate) const parse_list_with_polarity: &str =
721721
"a comma-separated list of strings, with elements beginning with + or -";
722722
pub(crate) const parse_autodiff: &str = "a comma separated list of settings: `Enable`, `PrintSteps`, `PrintTA`, `PrintAA`, `PrintPerf`, `PrintModBefore`, `PrintModAfter`, `PrintModFinal`, `PrintPasses`, `NoPostopt`, `LooseTypes`, `Inline`";
723+
pub(crate) const parse_offload: &str = "a comma separated list of settings: `Enable`";
723724
pub(crate) const parse_comma_list: &str = "a comma-separated list of strings";
724725
pub(crate) const parse_opt_comma_list: &str = parse_comma_list;
725726
pub(crate) const parse_number: &str = "a number";
@@ -1351,6 +1352,27 @@ pub mod parse {
13511352
}
13521353
}
13531354

1355+
pub(crate) fn parse_offload(slot: &mut Vec<Offload>, v: Option<&str>) -> bool {
1356+
let Some(v) = v else {
1357+
*slot = vec![];
1358+
return true;
1359+
};
1360+
let mut v: Vec<&str> = v.split(",").collect();
1361+
v.sort_unstable();
1362+
for &val in v.iter() {
1363+
let variant = match val {
1364+
"Enable" => Offload::Enable,
1365+
_ => {
1366+
// FIXME(ZuseZ4): print an error saying which value is not recognized
1367+
return false;
1368+
}
1369+
};
1370+
slot.push(variant);
1371+
}
1372+
1373+
true
1374+
}
1375+
13541376
pub(crate) fn parse_autodiff(slot: &mut Vec<AutoDiff>, v: Option<&str>) -> bool {
13551377
let Some(v) = v else {
13561378
*slot = vec![];
@@ -2378,6 +2400,11 @@ options! {
23782400
"do not use unique names for text and data sections when -Z function-sections is used"),
23792401
normalize_docs: bool = (false, parse_bool, [TRACKED],
23802402
"normalize associated items in rustdoc when generating documentation"),
2403+
offload: Vec<crate::config::Offload> = (Vec::new(), parse_offload, [TRACKED],
2404+
"a list of offload flags to enable
2405+
Mandatory setting:
2406+
`=Enable`
2407+
Currently the only option available"),
23812408
on_broken_pipe: OnBrokenPipe = (OnBrokenPipe::Default, parse_on_broken_pipe, [TRACKED],
23822409
"behavior of std::io::ErrorKind::BrokenPipe (SIGPIPE)"),
23832410
oom: OomStrategy = (OomStrategy::Abort, parse_oom_strategy, [TRACKED],

0 commit comments

Comments
 (0)