-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
instance.go
84 lines (73 loc) · 3.11 KB
/
instance.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package instance
import (
"strings"
"github.com/aws/aws-sdk-go-v2/aws"
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
)
// IsARMInstanceType returns true if the instance type is ARM architecture
func IsARMInstanceType(instanceType string) bool {
return strings.HasPrefix(instanceType, "a1") ||
strings.HasPrefix(instanceType, "t4g") ||
strings.HasPrefix(instanceType, "m6g") ||
strings.HasPrefix(instanceType, "m7g") ||
strings.HasPrefix(instanceType, "c6g") ||
strings.HasPrefix(instanceType, "c7g") ||
strings.HasPrefix(instanceType, "r6g") ||
strings.HasPrefix(instanceType, "r7g") ||
strings.HasPrefix(instanceType, "im4g") ||
strings.HasPrefix(instanceType, "is4g") ||
strings.HasPrefix(instanceType, "g5g") ||
strings.HasPrefix(instanceType, "hpc7g") ||
strings.HasPrefix(instanceType, "x2g")
}
// IsGPUInstanceType returns true if the instance type is GPU optimised
func IsGPUInstanceType(instanceType string) bool {
return IsNvidiaInstanceType(instanceType) ||
IsInferentiaInstanceType(instanceType) ||
IsTrainiumInstanceType(instanceType)
}
// IsNeuronInstanceType returns true if the instance type requires AWS Neuron
func IsNeuronInstanceType(instanceType string) bool {
return IsInferentiaInstanceType(instanceType) ||
IsTrainiumInstanceType(instanceType)
}
// IsARMGPUInstanceType returns true if the instance type is ARM-GPU architecture
func IsARMGPUInstanceType(instanceType string) bool {
return strings.HasPrefix(instanceType, "g5g")
}
// IsNvidiaInstanceType returns true if the instance type has NVIDIA accelerated hardware
func IsNvidiaInstanceType(instanceType string) bool {
return strings.HasPrefix(instanceType, "p2") ||
strings.HasPrefix(instanceType, "p3") ||
strings.HasPrefix(instanceType, "p4") ||
strings.HasPrefix(instanceType, "p5") ||
strings.HasPrefix(instanceType, "g3") ||
strings.HasPrefix(instanceType, "g4") ||
strings.HasPrefix(instanceType, "g5") ||
strings.HasPrefix(instanceType, "g6")
}
// IsInferentiaInstanceType returns true if the instance type requires AWS Neuron
func IsInferentiaInstanceType(instanceType string) bool {
return strings.HasPrefix(instanceType, "inf1")
}
// IsTrainiumnstanceType returns true if the instance type requires AWS Neuron
func IsTrainiumInstanceType(instanceType string) bool {
return strings.HasPrefix(instanceType, "trn1")
}
// GetSmallestInstanceType returns the smallest instance type in instanceTypes.
// Instance types that have a smaller vCPU are considered smaller.
// instanceTypes must be non-empty or it will panic.
func GetSmallestInstanceType(instanceTypes []ec2types.InstanceTypeInfo) string {
smallestInstanceTypeInfo := instanceTypes[0]
for _, it := range instanceTypes[1:] {
switch vCPUs, smallestVCPUs := aws.ToInt32(it.VCpuInfo.DefaultVCpus), aws.ToInt32(smallestInstanceTypeInfo.VCpuInfo.DefaultVCpus); {
case vCPUs < smallestVCPUs:
smallestInstanceTypeInfo = it
case vCPUs == smallestVCPUs:
if aws.ToInt64(it.MemoryInfo.SizeInMiB) < aws.ToInt64(smallestInstanceTypeInfo.MemoryInfo.SizeInMiB) {
smallestInstanceTypeInfo = it
}
}
}
return string(smallestInstanceTypeInfo.InstanceType)
}