Skip to content

Commit ff28d68

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

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
@@ -1182,8 +1182,8 @@ enum SandboxCommands {
11821182

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

11891189
/// CPU limit for the sandbox (for example: 500m, 1, 2.5).
@@ -4049,6 +4049,32 @@ mod tests {
40494049
}
40504050
}
40514051

4052+
#[test]
4053+
fn sandbox_create_gpu_device_parses_without_gpu_flag() {
4054+
let cli = Cli::try_parse_from([
4055+
"openshell",
4056+
"sandbox",
4057+
"create",
4058+
"--gpu-device",
4059+
"nvidia.com/gpu=0",
4060+
])
4061+
.expect("sandbox create --gpu-device should parse without --gpu");
4062+
4063+
if let Some(Commands::Sandbox {
4064+
command:
4065+
Some(SandboxCommands::Create {
4066+
gpu, gpu_device, ..
4067+
}),
4068+
..
4069+
}) = cli.command
4070+
{
4071+
assert!(!gpu);
4072+
assert_eq!(gpu_device.as_deref(), Some("nvidia.com/gpu=0"));
4073+
} else {
4074+
panic!("expected SandboxCommands::Create");
4075+
}
4076+
}
4077+
40524078
#[test]
40534079
fn service_expose_accepts_positional_target_port_and_service() {
40544080
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
@@ -1668,7 +1668,9 @@ pub async fn sandbox_create(
16681668
}
16691669
None => None,
16701670
};
1671-
let requested_gpu = gpu || image.as_deref().is_some_and(image_requests_gpu);
1671+
let requested_gpu = gpu
1672+
|| gpu_device.is_some_and(|device_id| !device_id.is_empty())
1673+
|| image.as_deref().is_some_and(image_requests_gpu);
16721674

16731675
let inferred_types: Vec<String> = inferred_provider_type(command).into_iter().collect();
16741676
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)