Skip to content

Commit 8a145eb

Browse files
committed
fix(cli): allow gpu-device to imply GPU requests
Signed-off-by: Evan Lezar <elezar@nvidia.com>
1 parent 95f9be8 commit 8a145eb

3 files changed

Lines changed: 38 additions & 3 deletions

File tree

crates/openshell-cli/src/main.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,8 +1086,8 @@ enum SandboxCommands {
10861086

10871087
/// Target a driver-specific GPU device. Docker and Podman use CDI device IDs
10881088
/// (for example "nvidia.com/gpu=0"); VM uses a PCI BDF or index.
1089-
/// Only valid with --gpu. When omitted with --gpu, the driver uses its default GPU selection.
1090-
#[arg(long, requires = "gpu")]
1089+
/// Implies a GPU request. When omitted with --gpu, the driver uses its default GPU selection.
1090+
#[arg(long)]
10911091
gpu_device: Option<String>,
10921092

10931093
/// CPU limit for the sandbox (for example: 500m, 1, 2.5).
@@ -3687,6 +3687,32 @@ mod tests {
36873687
}
36883688
}
36893689

3690+
#[test]
3691+
fn sandbox_create_gpu_device_parses_without_gpu_flag() {
3692+
let cli = Cli::try_parse_from([
3693+
"openshell",
3694+
"sandbox",
3695+
"create",
3696+
"--gpu-device",
3697+
"nvidia.com/gpu=0",
3698+
])
3699+
.expect("sandbox create --gpu-device should parse without --gpu");
3700+
3701+
if let Some(Commands::Sandbox {
3702+
command:
3703+
Some(SandboxCommands::Create {
3704+
gpu, gpu_device, ..
3705+
}),
3706+
..
3707+
}) = cli.command
3708+
{
3709+
assert!(!gpu);
3710+
assert_eq!(gpu_device.as_deref(), Some("nvidia.com/gpu=0"));
3711+
} else {
3712+
panic!("expected SandboxCommands::Create");
3713+
}
3714+
}
3715+
36903716
#[test]
36913717
fn service_expose_accepts_positional_target_port_and_service() {
36923718
let cli = Cli::try_parse_from([

crates/openshell-cli/src/run.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,9 @@ pub async fn sandbox_create(
16641664
}
16651665
None => None,
16661666
};
1667-
let requested_gpu = gpu || image.as_deref().is_some_and(image_requests_gpu);
1667+
let requested_gpu = gpu
1668+
|| gpu_device.is_some_and(|device_id| !device_id.is_empty())
1669+
|| image.as_deref().is_some_and(image_requests_gpu);
16681670

16691671
let inferred_types: Vec<String> = inferred_provider_type(command).into_iter().collect();
16701672
let configured_providers = ensure_required_providers(

docs/sandboxes/manage-sandboxes.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ To request GPU resources, add `--gpu`:
5151
openshell sandbox create --gpu -- claude
5252
```
5353
54+
To request a driver-specific GPU device directly, use `--gpu-device`. This also
55+
requests GPU resources for the sandbox.
56+
57+
```shell
58+
openshell sandbox create --gpu-device nvidia.com/gpu=0 -- claude
59+
```
60+
5461
For Docker-backed sandboxes, GPU injection uses Docker CDI. If you enable Docker
5562
CDI after the gateway starts, restart the gateway so OpenShell can detect the
5663
updated Docker daemon capability.

0 commit comments

Comments
 (0)