Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ old date is a hint to look at the driver, not a finding that it is broken. See
Manage multiple side-by-side ROCm runtimes:

```
rocm runtimes list
rocm runtimes list [--json]
rocm runtimes activate <runtime-key> [--restart-services [--yes]]
rocm runtimes rollback [--restart-services [--yes]]
rocm runtimes uninstall <runtime-key> [--yes] [--dry-run]
Expand Down Expand Up @@ -896,6 +896,13 @@ version alone, so one version can appear more than once: a `--devel` install
and a plain one of the same version are two separate runtimes, as are two
installs that resolved different GPU device payloads.

`list --json` prints the same listing as one JSON document on stdout for
scripts: each runtime with its key, version, mode, status and toolchain, its
`provenance` as an object with the same four facts, and `active` and
`rollback_target` flags in place of the `*` and `-` markers. Unset values,
including a provenance fact the text shows as `unrecorded`, are `null`. Fields
may be added in later releases; existing ones are not renamed or removed.

`activate` and `rollback` change which runtime the next install or server
picks up. A server that is already running is not moved: it keeps serving on
the runtime it started with until it is restarted. Both commands count the
Expand Down
24 changes: 23 additions & 1 deletion apps/rocm/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,11 @@ pub(crate) enum RuntimesCommand {
/// generation and exact GPU target as its manifest recorded them. A fact
/// recorded nowhere, or recorded blank, is shown as `unrecorded`; nothing
/// is guessed from other facts.
List,
List {
/// Print the runtime list as JSON instead of text.
#[arg(long)]
json: bool,
},
/// Use the selected ROCm runtime by default.
Activate {
/// Runtime key or friendly runtime selector.
Expand Down Expand Up @@ -2133,6 +2137,24 @@ mod tests {
}
}

/// `--json` belongs to `list` alone: bare `rocm runtimes` stays the text
/// listing, so a script has to name the subcommand to get JSON.
#[test]
fn runtimes_json_is_a_list_flag() {
for (args, json) in [(&["list", "--json"][..], true), (&["list"][..], false)] {
match parse_runtimes(args).expect("runtimes list parses").command {
Some(Command::Runtimes {
command: Some(RuntimesCommand::List { json: parsed }),
}) => assert_eq!(parsed, json, "{args:?}"),
other => panic!("expected runtimes list, got {other:?}"),
}
}
assert!(
parse_runtimes(&["--json"]).is_err(),
"`rocm runtimes --json` must be rejected, not read as `list --json`"
);
}

fn parse_serve(args: &[&str]) -> Result<Cli, clap::Error> {
let mut argv = vec!["rocm", "serve", "qwen"];
argv.extend_from_slice(args);
Expand Down
8 changes: 5 additions & 3 deletions apps/rocm/src/dash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,11 @@ fn runtime_summaries(paths: &AppPaths, config: &RocmCliConfig) -> Vec<RuntimeSum
let active_key = config.active_runtime_key.as_deref();
let prev_key = config.previous_runtime_key.as_deref();
let default_id = config.default_runtime_id.as_deref();
// Mirror `render_runtimes_text`: a runtime is active by an explicit
// active_runtime_key, or — absent one — by being the single manifest whose
// runtime_id matches the configured default_runtime_id.
// The dash matches exactly: a runtime is active when its key equals
// active_runtime_key, or, with no active_runtime_key, when it is the single
// runtime whose id equals default_runtime_id; it is the rollback target
// when its key equals previous_runtime_key. docs/json-output.md compares
// these rules with what `rocm runtimes list` marks.
let default_matches: Vec<&str> = manifests
.iter()
.filter(|m| Some(m.runtime_id.as_str()) == default_id)
Expand Down
42 changes: 27 additions & 15 deletions apps/rocm/src/runtime_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,25 +250,30 @@ pub(crate) struct RuntimeProvenance<'a> {
pub device_target: Option<&'a str>,
}

impl RuntimeProvenance<'_> {
impl<'a> RuntimeProvenance<'a> {
/// Each fact as `(name, recorded value)`, in display order, with `None` for
/// a fact that was not recorded.
///
/// The one place the names and their order are written down:
/// [`Self::fields`] shows these, and `rocm runtimes list --json` writes them
/// as its `provenance` object, with `null` for `None`.
pub(crate) const fn recorded_fields(&self) -> [(&'static str, Option<&'a str>); 4] {
[
("channel", self.channel),
("source", self.source),
("source_layout_generation", self.source_layout_generation),
("device_target", self.device_target),
]
}

/// Each fact as `(name, shown value)`, in display order, with
/// [`UNRECORDED_PROVENANCE`] for a fact that was not recorded.
///
/// `rocm runtimes list` and `rocm examine` both print from this, so the
/// names and values the two show for one runtime cannot drift apart.
pub(crate) fn fields(&self) -> [(&'static str, &str); 4] {
fn shown(value: Option<&str>) -> &str {
value.unwrap_or(UNRECORDED_PROVENANCE)
}
[
("channel", shown(self.channel)),
("source", shown(self.source)),
(
"source_layout_generation",
shown(self.source_layout_generation),
),
("device_target", shown(self.device_target)),
]
pub(crate) fn fields(&self) -> [(&'static str, &'a str); 4] {
self.recorded_fields()
.map(|(name, value)| (name, value.unwrap_or(UNRECORDED_PROVENANCE)))
}
}

Expand Down Expand Up @@ -768,10 +773,17 @@ pub(crate) fn select_runtime_manifest<'a>(
pub(crate) fn runtime_usability_status(manifest: &InstalledRuntimeManifest) -> String {
match validate_runtime_manifest_for_activation(manifest) {
Ok(()) => "ready".to_owned(),
Err(error) => format!("unusable ({error})"),
Err(error) => unusable_status_text(&error.to_string()),
}
}

/// How the text reports name a runtime that fails the manifest check
/// activation applies, given the reason it fails it. `rocm runtimes list`
/// prints the same words from the reason it also carries in its JSON.
pub(crate) fn unusable_status_text(reason: &str) -> String {
format!("unusable ({reason})")
}

pub(crate) fn validate_runtime_manifest_for_activation(
manifest: &InstalledRuntimeManifest,
) -> Result<()> {
Expand Down
Loading
Loading