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

Supports sum the GPU counts of Aliyun and Volcano #2490

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 6 additions & 1 deletion ray-operator/controllers/ray/raycluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"reflect"
"regexp"
"runtime"
"strconv"
"strings"
Expand Down Expand Up @@ -1619,8 +1620,12 @@ func (r *RayClusterReconciler) updateRayClusterStatus(ctx context.Context, origi
func sumGPUs(resources map[corev1.ResourceName]resource.Quantity) resource.Quantity {
totalGPUs := resource.Quantity{}

// Define a regular expression to match valid GPU resource names
gpuPattern := regexp.MustCompile(`^(.*?/)?(gpu(-count)?|gpu-core\.percentage)$`)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to add these in the list of well known accelerators instread: https://github.com/ray-project/kuberay/blob/master/ray-operator/controllers/ray/common/pod.go#L41-L43


for key, val := range resources {
if strings.HasSuffix(string(key), "gpu") && !val.IsZero() {
// Check if the resource name matches the GPU pattern and if the quantity is non-zero
if gpuPattern.MatchString(string(key)) && !val.IsZero() {
totalGPUs.Add(val)
}
}
Expand Down
14 changes: 14 additions & 0 deletions ray-operator/controllers/ray/raycluster_controller_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2933,6 +2933,8 @@ func TestReconcile_NumOfHosts(t *testing.T) {
func TestSumGPUs(t *testing.T) {
nvidiaGPUResourceName := corev1.ResourceName("nvidia.com/gpu")
googleTPUResourceName := corev1.ResourceName("google.com/tpu")
volcanoGPUCorePercentageResourceName := corev1.ResourceName("volcano.sh/gpu-core.percentage")
aliyunGPUCountResourceName := corev1.ResourceName("aliyun.com/gpu-count")

tests := map[string]struct {
input map[corev1.ResourceName]resource.Quantity
Expand Down Expand Up @@ -2961,6 +2963,18 @@ func TestSumGPUs(t *testing.T) {
},
resource.MustParse("5"),
},
"volcano GPU type specified": {
map[corev1.ResourceName]resource.Quantity{
volcanoGPUCorePercentageResourceName: resource.MustParse("5"),
},
resource.MustParse("5"),
},
"aliyun GPU type specified": {
map[corev1.ResourceName]resource.Quantity{
aliyunGPUCountResourceName: resource.MustParse("5"),
},
resource.MustParse("5"),
},
}

for name, tc := range tests {
Expand Down