Skip to content

Commit c42fdaa

Browse files
committed
add inference acceleartor filter support
1 parent 643074a commit c42fdaa

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ t3a.medium 2 4
132132

133133
**Wide Table Output**
134134
```
135-
$ ec2-instance-selector --memory 4 --vcpus 2 --cpu-architecture x86_64 -r us-east-1 -o table-wideInstance Type VCPUs Mem (GiB) Hypervisor Current Gen Hibernation Support CPU Arch Network Performance ENIs GPUs GPU Mem (GiB) GPU Info On-Demand Price/Hr Spot Price/Hr (30d avg)
135+
$ ec2-instance-selector --memory 4 --vcpus 2 --cpu-architecture x86_64 -r us-east-1 -o table-wide
136+
Instance Type VCPUs Mem (GiB) Hypervisor Current Gen Hibernation Support CPU Arch Network Performance ENIs GPUs GPU Mem (GiB) GPU Info On-Demand Price/Hr Spot Price/Hr (30d avg)
136137
------------- ----- --------- ---------- ----------- ------------------- -------- ------------------- ---- ---- ------------- -------- ------------------ -----------------------
137138
c5.large 2 4 nitro true true x86_64 Up to 10 Gigabit 3 0 0 $0.085 $0.04708
138139
c5a.large 2 4 nitro true false x86_64 Up to 10 Gigabit 3 0 0 $0.077 $0.03249
@@ -194,6 +195,9 @@ Filter Flags:
194195
--gpus-min int Minimum Total Number of GPUs (Example: 4) If --gpus-max is not specified, the upper bound will be infinity
195196
--hibernation-support Hibernation supported
196197
--hypervisor string Hypervisor: [xen or nitro]
198+
--inference-accelerators int Total Number of inference accelerators (Example: 4) (sets --inference-accelerators-min and -max to the same value)
199+
--inference-accelerators-max int Maximum Total Number of inference accelerators (Example: 4) If --inference-accelerators-min is not specified, the lower bound will be 0
200+
--inference-accelerators-min int Minimum Total Number of inference accelerators (Example: 4) If --inference-accelerators-max is not specified, the upper bound will be infinity
197201
--instance-storage string Amount of local instance storage (Example: 4 GiB) (sets --instance-storage-min and -max to the same value)
198202
--instance-storage-max string Maximum Amount of local instance storage (Example: 4 GiB) If --instance-storage-min is not specified, the lower bound will be 0
199203
--instance-storage-min string Minimum Amount of local instance storage (Example: 4 GiB) If --instance-storage-max is not specified, the upper bound will be infinity

cmd/main.go

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const (
6060
cpuArchitecture = "cpu-architecture"
6161
gpus = "gpus"
6262
gpuMemoryTotal = "gpu-memory-total"
63+
inferenceAccelerators = "inference-accelerators"
6364
placementGroupStrategy = "placement-group-strategy"
6465
usageClass = "usage-class"
6566
rootDeviceType = "root-device-type"
@@ -147,6 +148,7 @@ Full docs can be found at github.com/aws/amazon-` + binName
147148
cli.StringOptionsFlag(cpuArchitecture, cli.StringMe("a"), nil, "CPU architecture [x86_64/amd64, x86_64_mac, i386, or arm64]", []string{"x86_64", "x86_64_mac", "amd64", "i386", "arm64"})
148149
cli.IntMinMaxRangeFlags(gpus, cli.StringMe("g"), nil, "Total Number of GPUs (Example: 4)")
149150
cli.ByteQuantityMinMaxRangeFlags(gpuMemoryTotal, nil, nil, "Number of GPUs' total memory (Example: 4 GiB)")
151+
cli.IntMinMaxRangeFlags(inferenceAccelerators, nil, nil, "Total Number of inference accelerators (Example: 4)")
150152
cli.StringOptionsFlag(placementGroupStrategy, nil, nil, "Placement group strategy: [cluster, partition, spread]", []string{"cluster", "partition", "spread"})
151153
cli.StringOptionsFlag(usageClass, cli.StringMe("u"), nil, "Usage class: [spot or on-demand]", []string{"spot", "on-demand"})
152154
cli.StringOptionsFlag(rootDeviceType, nil, nil, "Supported root device types: [ebs or instance-store]", []string{"ebs", "instance-store"})
@@ -256,6 +258,7 @@ Full docs can be found at github.com/aws/amazon-` + binName
256258
CPUArchitecture: cli.StringMe(flags[cpuArchitecture]),
257259
GpusRange: cli.IntRangeMe(flags[gpus]),
258260
GpuMemoryRange: cli.ByteQuantityRangeMe(flags[gpuMemoryTotal]),
261+
InferenceAcceleratorsRange: cli.IntRangeMe(flags[inferenceAccelerators]),
259262
PlacementGroupStrategy: cli.StringMe(flags[placementGroupStrategy]),
260263
UsageClass: cli.StringMe(flags[usageClass]),
261264
RootDeviceType: cli.StringMe(flags[rootDeviceType]),

pkg/selector/comparators.go

+11
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@ func isSupportedWithBool(instanceTypeValue *bool, target *bool) bool {
111111

112112
// Helper functions for aggregating data parsed from AWS API calls
113113

114+
func getTotalAcceleratorsCount(acceleratorInfo *ec2.InferenceAcceleratorInfo) *int64 {
115+
if acceleratorInfo == nil {
116+
return nil
117+
}
118+
total := aws.Int64(0)
119+
for _, accel := range acceleratorInfo.Accelerators {
120+
total = aws.Int64(*total + *accel.Count)
121+
}
122+
return total
123+
}
124+
114125
func getTotalGpusCount(gpusInfo *ec2.GpuInfo) *int64 {
115126
if gpusInfo == nil {
116127
return nil

pkg/selector/selector.go

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const (
5555
memoryRange = "memoryRange"
5656
gpuMemoryRange = "gpuMemoryRange"
5757
gpusRange = "gpusRange"
58+
inferenceAcceleratorsRange = "inferenceAcceleratorsRange"
5859
placementGroupStrategy = "placementGroupStrategy"
5960
hypervisor = "hypervisor"
6061
baremetal = "baremetal"
@@ -255,6 +256,7 @@ func (itf Selector) rawFilter(filters Filters) ([]*instancetypes.Details, error)
255256
memoryRange: {filters.MemoryRange, instanceTypeInfo.MemoryInfo.SizeInMiB},
256257
gpuMemoryRange: {filters.GpuMemoryRange, getTotalGpuMemory(instanceTypeInfo.GpuInfo)},
257258
gpusRange: {filters.GpusRange, getTotalGpusCount(instanceTypeInfo.GpuInfo)},
259+
inferenceAcceleratorsRange: {filters.InferenceAcceleratorsRange, getTotalAcceleratorsCount(instanceTypeInfo.InferenceAcceleratorInfo)},
258260
placementGroupStrategy: {filters.PlacementGroupStrategy, instanceTypeInfo.PlacementGroupInfo.SupportedStrategies},
259261
hypervisor: {filters.Hypervisor, instanceTypeInfo.Hypervisor},
260262
baremetal: {filters.BareMetal, instanceTypeInfo.BareMetal},

pkg/selector/types.go

+3
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ type Filters struct {
137137
// GpuMemoryRange filter is a range of acceptable GPU memory in Gibibytes (GiB) available to an EC2 instance type in aggreagte across all GPUs.
138138
GpuMemoryRange *ByteQuantityRangeFilter
139139

140+
// InferenceAcceleratorsRange filters inference acclerators available to the instance type
141+
InferenceAcceleratorsRange *IntRangeFilter
142+
140143
// HibernationSupported denotes whether EC2 hibernate is supported
141144
// Possible values are: true or false
142145
HibernationSupported *bool

0 commit comments

Comments
 (0)