Skip to content

Commit c2d3e93

Browse files
authored
Switch GPU selection to model instead of counts (#2807)
* Switch GPU selection to model instead of counts * update gpu model names * rename to --vm-gpu-kind
1 parent c5e383f commit c2d3e93

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed

api/machine_types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const (
2525
MachineStateStopped = "stopped"
2626
MachineStateCreated = "created"
2727
DefaultVMSize = "shared-cpu-1x"
28+
DefaultGPUVMSize = "performance-8x"
2829
)
2930

3031
type Machine struct {
@@ -321,7 +322,7 @@ type MachineGuest struct {
321322
CPUKind string `json:"cpu_kind,omitempty"`
322323
CPUs int `json:"cpus,omitempty"`
323324
MemoryMB int `json:"memory_mb,omitempty"`
324-
GPUs int `json:"gpus,omitempty"`
325+
GPUKind string `json:"gpu_kind,omitempty"`
325326

326327
KernelArgs []string `json:"kernel_args,omitempty"`
327328
}

internal/command/console/console.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func determineEphemeralConsoleMachineGuest(ctx context.Context) (*api.MachineGue
240240
}
241241
}
242242

243-
if cpuKind := flag.GetString(ctx, "vm-cpukind"); cpuKind != "" {
243+
if cpuKind := flag.GetString(ctx, "vm-cpu-kind"); cpuKind != "" {
244244
desiredGuest.CPUKind = cpuKind
245245
}
246246

internal/flag/machines.go

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,61 @@ package flag
33
import (
44
"context"
55
"fmt"
6+
"slices"
7+
"strings"
68

79
"github.com/superfly/flyctl/api"
810
)
911

12+
var validGPUKinds = []string{"a100-pcie-40gb", "a100-sxm4-80gb"}
13+
1014
// Returns a MachineGuest based on the flags provided overwriting a default VM
1115
func GetMachineGuest(ctx context.Context, guest *api.MachineGuest) (*api.MachineGuest, error) {
16+
defaultVMSize := api.DefaultVMSize
17+
if IsSpecified(ctx, "vm-gpu-kind") {
18+
defaultVMSize = api.DefaultGPUVMSize
19+
}
20+
1221
if guest == nil {
1322
guest = &api.MachineGuest{}
14-
guest.SetSize(api.DefaultVMSize)
23+
guest.SetSize(defaultVMSize)
1524
}
1625

1726
if IsSpecified(ctx, "vm-size") {
1827
if err := guest.SetSize(GetString(ctx, "vm-size")); err != nil {
1928
return nil, err
2029
}
2130
}
31+
2232
if IsSpecified(ctx, "vm-cpus") {
2333
guest.CPUs = GetInt(ctx, "vm-cpus")
2434
if guest.CPUs == 0 {
25-
return nil, fmt.Errorf("cannot have zero cpus")
35+
return nil, fmt.Errorf("--vm-cpus cannot be zero")
2636
}
2737
}
2838

2939
if IsSpecified(ctx, "vm-memory") {
3040
guest.MemoryMB = GetInt(ctx, "vm-memory")
3141
if guest.MemoryMB == 0 {
32-
return nil, fmt.Errorf("memory cannot be zero")
42+
return nil, fmt.Errorf("--vm-memory cannot be zero")
3343
}
3444
}
3545

36-
if IsSpecified(ctx, "vm-cpukind") {
37-
guest.CPUKind = GetString(ctx, "vm-cpukind")
46+
if IsSpecified(ctx, "vm-cpu-kind") {
47+
guest.CPUKind = GetString(ctx, "vm-cpu-kind")
3848
if k := guest.CPUKind; k != "shared" && k != "performance" {
39-
return nil, fmt.Errorf("cpukind must be set to 'shared' or 'performance'")
49+
return nil, fmt.Errorf("--vm-cpu-kind must be set to 'shared' or 'performance'")
4050
}
4151
}
42-
if IsSpecified(ctx, "vm-gpus") {
43-
guest.GPUs = GetInt(ctx, "vm-gpus")
52+
53+
if IsSpecified(ctx, "vm-gpu-kind") {
54+
m := GetString(ctx, "vm-gpu-kind")
55+
if !slices.Contains(validGPUKinds, m) {
56+
return nil, fmt.Errorf("--vm-gpu-kind must be set to one of: %v", strings.Join(validGPUKinds, ", "))
57+
}
58+
guest.GPUKind = m
4459
}
60+
4561
return guest, nil
4662
}
4763

@@ -57,16 +73,18 @@ var VMSizeFlags = Set{
5773
Aliases: []string{"cpus"},
5874
},
5975
String{
60-
Name: "vm-cpukind",
76+
Name: "vm-cpu-kind",
6177
Description: "The kind of CPU to use ('shared' or 'performance')",
78+
Aliases: []string{"vm-cpukind"},
6279
},
6380
Int{
6481
Name: "vm-memory",
6582
Description: "Memory (in megabytes) to attribute to the VM",
6683
Aliases: []string{"memory"},
6784
},
68-
Int{
69-
Name: "vm-gpus",
70-
Description: "Number of GPUs",
85+
String{
86+
Name: "vm-gpu-kind",
87+
Description: fmt.Sprintf("If set, the GPU model to attach (%v)", strings.Join(validGPUKinds, ", ")),
88+
Aliases: []string{"vm-gpukind"},
7189
},
7290
}

test/preflight/apps_v2_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ func TestLaunchCpusMem(t *testing.T) {
487487
f := testlib.NewTestEnvFromEnv(t)
488488
appName := f.CreateRandomAppName()
489489

490-
f.Fly("launch --org %s --name %s --region %s --now --internal-port 80 --image nginx --auto-confirm --vm-cpus 4 --vm-memory 8192 --vm-cpukind performance", f.OrgSlug(), appName, f.PrimaryRegion())
490+
f.Fly("launch --org %s --name %s --region %s --now --internal-port 80 --image nginx --auto-confirm --vm-cpus 4 --vm-memory 8192 --vm-cpu-kind performance", f.OrgSlug(), appName, f.PrimaryRegion())
491491
machines := f.MachinesList(appName)
492492
firstMachineGuest := machines[0].Config.Guest
493493

0 commit comments

Comments
 (0)