Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gpus not being considered when counting allocatables #2108

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions hack/generate-gpu-count-table.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2024 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -euo pipefail

BIN="$(dirname "$(realpath "${BASH_SOURCE[0]}")")/../bin"

function get_gpus_for_region() {
REGION="${1}"
echo "Getting gpu counts for ${REGION}..." >&2
"${BIN}/aws" ec2 describe-instance-types --region "${REGION}" --query "InstanceTypes[?GpuInfo!=null].[InstanceType, GpuInfo]" |
jq -r 'map("\"" + .[0] + "\": " + (.[1].Gpus | map(.Count) | add | tostring) + ",") | .[]'
}

function get_all_gpus() {
"${BIN}/aws" account list-regions --max-results 50 | jq -r '.Regions | map(.RegionName) | .[]' | while read REGION; do
get_gpus_for_region $REGION
ElijahQuinones marked this conversation as resolved.
Show resolved Hide resolved
done
}

get_all_gpus | sort | uniq
2 changes: 1 addition & 1 deletion hack/generate-instance-store-table.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ BIN="$(dirname "$(realpath "${BASH_SOURCE[0]}")")/../bin"

function get_instance_stores_for_region() {
REGION="${1}"
echo "Getting limits for ${REGION}..." >&2
echo "Getting instance store limits for ${REGION}..." >&2
"${BIN}/aws" ec2 describe-instance-types --region "${REGION}" --filters "Name=instance-storage-supported,Values=true" --query "InstanceTypes[].[InstanceType, InstanceStorageInfo]" |
jq -r 'map("\"" + .[0] + "\": " + (.[1].Disks | map(.Count) | add | tostring) + ",") | .[]'
}
Expand Down
69 changes: 65 additions & 4 deletions pkg/cloud/volume_limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,17 @@ func GetDedicatedLimitForInstanceType(it string) int {
}
}

func GetNVMeInstanceStoreVolumesForInstanceType(it string) int {
if v, ok := nvmeInstanceStoreVolumes[it]; ok {
return v
func GetReservedSlotsForInstanceType(it string) int {
ElijahQuinones marked this conversation as resolved.
Show resolved Hide resolved
total := 0
nvmeInstanceStoreVolumes, ok := nvmeInstanceStoreVolumes[it]
if ok {
total += nvmeInstanceStoreVolumes
}
return 0
gpus, ok := gpuInstanceGpus[it]
if ok {
total += gpus
}
return total
}

// / https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-store-volumes.html
Expand Down Expand Up @@ -489,3 +495,58 @@ var nvmeInstanceStoreVolumes = map[string]int{
"z1d.metal": 2,
"z1d.xlarge": 1,
}

// / https://aws.amazon.com/ec2/instance-types
var gpuInstanceGpus = map[string]int{
ElijahQuinones marked this conversation as resolved.
Show resolved Hide resolved
"dl1.24xlarge": 8,
"g3.16xlarge": 4,
"g3.4xlarge": 1,
"g3.8xlarge": 2,
"g3s.xlarge": 1,
"g4ad.16xlarge": 4,
"g4ad.2xlarge": 1,
"g4ad.4xlarge": 1,
"g4ad.8xlarge": 2,
"g4ad.xlarge": 1,
"g4dn.12xlarge": 4,
"g4dn.16xlarge": 1,
"g4dn.2xlarge": 1,
"g4dn.4xlarge": 1,
"g4dn.8xlarge": 1,
"g4dn.metal": 8,
"g4dn.xlarge": 1,
"g5.12xlarge": 4,
"g5.16xlarge": 1,
"g5.24xlarge": 4,
"g5.2xlarge": 1,
"g5.48xlarge": 8,
"g5.4xlarge": 1,
"g5.8xlarge": 1,
"g5g.16xlarge": 2,
"g5g.2xlarge": 1,
"g5g.4xlarge": 1,
"g5g.8xlarge": 1,
"g5g.metal": 2,
"g5g.xlarge": 1,
"g5.xlarge": 1,
"g6.12xlarge": 4,
"g6.16xlarge": 1,
"g6.24xlarge": 4,
"g6.2xlarge": 1,
"g6.48xlarge": 8,
"g6.4xlarge": 1,
"g6.8xlarge": 1,
"g6.xlarge": 1,
"gr6.4xlarge": 1,
"gr6.8xlarge": 1,
"p2.16xlarge": 16,
"p2.8xlarge": 8,
"p2.xlarge": 1,
"p3.16xlarge": 8,
"p3.2xlarge": 1,
"p3.8xlarge": 4,
"p3dn.24xlarge": 8,
"p4d.24xlarge": 8,
"p4de.24xlarge": 8,
"p5.48xlarge": 8,
}
2 changes: 1 addition & 1 deletion pkg/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ func (d *NodeService) getVolumesLimit() int64 {
availableAttachments = dedicatedLimit
} else if isNitro {
enis := d.metadata.GetNumAttachedENIs()
nvmeInstanceStoreVolumes := cloud.GetNVMeInstanceStoreVolumesForInstanceType(instanceType)
nvmeInstanceStoreVolumes := cloud.GetReservedSlotsForInstanceType(instanceType)
availableAttachments = availableAttachments - enis - nvmeInstanceStoreVolumes
}
availableAttachments = availableAttachments - reservedVolumeAttachments
Expand Down
51 changes: 51 additions & 0 deletions pkg/driver/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,57 @@ func TestGetVolumesLimit(t *testing.T) {
return m
},
},
// 1 gpu
{
name: "g4dn.xlarge_volume_attach_limit",
options: &Options{
VolumeAttachLimit: -1,
ReservedVolumeAttachments: -1,
},
expectedVal: 24,
metadataMock: func(ctrl *gomock.Controller) *metadata.MockMetadataService {
m := metadata.NewMockMetadataService(ctrl)
m.EXPECT().GetRegion().Return("us-west-2")
m.EXPECT().GetInstanceType().Return("g4dn.xlarge")
m.EXPECT().GetNumBlockDeviceMappings().Return(0)
m.EXPECT().GetNumAttachedENIs().Return(1)
return m
},
},
// 1 gpu
{
name: "g4ad.xlarge_volume_attach_limit",
options: &Options{
VolumeAttachLimit: -1,
ReservedVolumeAttachments: -1,
},
expectedVal: 24,
metadataMock: func(ctrl *gomock.Controller) *metadata.MockMetadataService {
m := metadata.NewMockMetadataService(ctrl)
m.EXPECT().GetRegion().Return("us-west-2")
m.EXPECT().GetInstanceType().Return("g4ad.xlarge")
m.EXPECT().GetNumBlockDeviceMappings().Return(0)
m.EXPECT().GetNumAttachedENIs().Return(1)
return m
},
},
// 4 gpus
ElijahQuinones marked this conversation as resolved.
Show resolved Hide resolved
{
name: "g4dn.12xlarge_volume_attach_limit",
options: &Options{
VolumeAttachLimit: -1,
ReservedVolumeAttachments: -1,
},
expectedVal: 21,
metadataMock: func(ctrl *gomock.Controller) *metadata.MockMetadataService {
m := metadata.NewMockMetadataService(ctrl)
m.EXPECT().GetRegion().Return("us-west-2")
m.EXPECT().GetInstanceType().Return("g4dn.12xlarge")
m.EXPECT().GetNumBlockDeviceMappings().Return(0)
m.EXPECT().GetNumAttachedENIs().Return(1)
return m
},
},
}

for _, tc := range testCases {
Expand Down