Skip to content

Commit 42e0f98

Browse files
committed
add -Zoffload=Enable flag, to enable gpu (host) code generation
1 parent 5b482d2 commit 42e0f98

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, PartialEq, Hash, Debug)]
231238
pub enum AutoDiff {
@@ -3118,7 +3125,7 @@ pub(crate) mod dep_tracking {
31183125
AutoDiff, BranchProtection, CFGuard, CFProtection, CollapseMacroDebuginfo, CoverageOptions,
31193126
CrateType, DebugInfo, DebugInfoCompression, ErrorOutputType, FmtDebug, FunctionReturn,
31203127
InliningThreshold, InstrumentCoverage, InstrumentXRay, LinkerPluginLto, LocationDetail,
3121-
LtoCli, MirStripDebugInfo, NextSolverConfig, OomStrategy, OptLevel, OutFileName,
3128+
LtoCli, MirStripDebugInfo, NextSolverConfig, Offload, OomStrategy, OptLevel, OutFileName,
31223129
OutputType, OutputTypes, PatchableFunctionEntry, Polonius, RemapPathScopeComponents,
31233130
ResolveDocLinks, SourceFileHashAlgorithm, SplitDwarfKind, SwitchWithOptPath,
31243131
SymbolManglingVersion, WasiExecModel,
@@ -3165,6 +3172,7 @@ pub(crate) mod dep_tracking {
31653172
impl_dep_tracking_hash_via_hash!(
31663173
(),
31673174
AutoDiff,
3175+
Offload,
31683176
bool,
31693177
usize,
31703178
NonZero<usize>,

compiler/rustc_session/src/options.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,7 @@ mod desc {
726726
pub(crate) const parse_list_with_polarity: &str =
727727
"a comma-separated list of strings, with elements beginning with + or -";
728728
pub(crate) const parse_autodiff: &str = "a comma separated list of settings: `Enable`, `PrintSteps`, `PrintTA`, `PrintTAFn`, `PrintAA`, `PrintPerf`, `PrintModBefore`, `PrintModAfter`, `PrintModFinal`, `PrintPasses`, `NoPostopt`, `LooseTypes`, `Inline`";
729+
pub(crate) const parse_offload: &str = "a comma separated list of settings: `Enable`";
729730
pub(crate) const parse_comma_list: &str = "a comma-separated list of strings";
730731
pub(crate) const parse_opt_comma_list: &str = parse_comma_list;
731732
pub(crate) const parse_number: &str = "a number";
@@ -1357,6 +1358,27 @@ pub mod parse {
13571358
}
13581359
}
13591360

1361+
pub(crate) fn parse_offload(slot: &mut Vec<Offload>, v: Option<&str>) -> bool {
1362+
let Some(v) = v else {
1363+
*slot = vec![];
1364+
return true;
1365+
};
1366+
let mut v: Vec<&str> = v.split(",").collect();
1367+
v.sort_unstable();
1368+
for &val in v.iter() {
1369+
let variant = match val {
1370+
"Enable" => Offload::Enable,
1371+
_ => {
1372+
// FIXME(ZuseZ4): print an error saying which value is not recognized
1373+
return false;
1374+
}
1375+
};
1376+
slot.push(variant);
1377+
}
1378+
1379+
true
1380+
}
1381+
13601382
pub(crate) fn parse_autodiff(slot: &mut Vec<AutoDiff>, v: Option<&str>) -> bool {
13611383
let Some(v) = v else {
13621384
*slot = vec![];
@@ -2399,6 +2421,11 @@ options! {
23992421
"do not use unique names for text and data sections when -Z function-sections is used"),
24002422
normalize_docs: bool = (false, parse_bool, [TRACKED],
24012423
"normalize associated items in rustdoc when generating documentation"),
2424+
offload: Vec<crate::config::Offload> = (Vec::new(), parse_offload, [TRACKED],
2425+
"a list of offload flags to enable
2426+
Mandatory setting:
2427+
`=Enable`
2428+
Currently the only option available"),
24022429
on_broken_pipe: OnBrokenPipe = (OnBrokenPipe::Default, parse_on_broken_pipe, [TRACKED],
24032430
"behavior of std::io::ErrorKind::BrokenPipe (SIGPIPE)"),
24042431
oom: OomStrategy = (OomStrategy::Abort, parse_oom_strategy, [TRACKED],

0 commit comments

Comments
 (0)