-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix gpu resource error #4873
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
base: master
Are you sure you want to change the base?
Fix gpu resource error #4873
Conversation
Summary of ChangesHello @sailorvii, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refactors the GPU resource allocation logic to resolve a latency issue encountered during the pod allocation state. Previously, the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request correctly fixes a GPU resource double-counting bug by introducing a new function, addToPodMap, to handle resource accounting during the allocation phase. The core logic of the fix is sound. My review includes a couple of suggestions to improve the implementation of the new function for better readability, maintainability, and to correct a minor inconsistency in an error message.
| func (gs *GPUDevices) addToPodMap(annotations map[string]string, pod *v1.Pod) { | ||
| ids, ok := annotations[AssignedIDsAnnotations] | ||
| if !ok { | ||
| klog.Errorf("pod %s has no annotation volcano.sh/devices-to-allocate", pod.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message refers to the annotation volcano.sh/devices-to-allocate (AssignedIDsToAllocateAnnotations), but the code checks for AssignedIDsAnnotations (volcano.sh/vgpu-ids-new). This can be confusing when debugging. To improve clarity, the error message should refer to the annotation key that is actually being checked by using the constant.
| klog.Errorf("pod %s has no annotation volcano.sh/devices-to-allocate", pod.Name) | |
| klog.Errorf("pod %s has no annotation %s", pod.Name, AssignedIDsAnnotations) |
| for index, gsdevice := range gs.Device { | ||
| if strings.Contains(deviceused.UUID, gsdevice.UUID) { | ||
| podUID := string(pod.UID) | ||
| _, ok := gsdevice.PodMap[podUID] | ||
| if !ok { | ||
| gsdevice.PodMap[podUID] = &GPUUsage{ | ||
| UsedMem: 0, | ||
| UsedCore: 0, | ||
| } | ||
| } | ||
|
|
||
| gsdevice.PodMap[podUID].UsedMem += deviceused.Usedmem | ||
| gsdevice.PodMap[podUID].UsedCore += deviceused.Usedcores | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This loop can be improved for readability and to remove the unused index variable. The logic for initializing and updating gsdevice.PodMap can also be simplified. For a minor performance improvement, podUID could be calculated once outside these nested loops.
Additionally, there is significant code duplication with the addResource function. It would be beneficial to consider refactoring this into a shared helper function in a follow-up PR to improve maintainability.
for _, gsdevice := range gs.Device {
if strings.Contains(deviceused.UUID, gsdevice.UUID) {
podUID := string(pod.UID)
usage, ok := gsdevice.PodMap[podUID]
if !ok {
usage = &GPUUsage{}
gsdevice.PodMap[podUID] = usage
}
usage.UsedMem += deviceused.Usedmem
usage.UsedCore += deviceused.Usedcores
}
}| } | ||
|
|
||
| gsdevice.PodMap[podUID].UsedMem += deviceused.Usedmem | ||
| gsdevice.PodMap[podUID].UsedCore += deviceused.Usedcores |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not copy gs.AddPodMetrics(index, string(pod.UID), pod.Name) from addPod here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The AddResource routine will do this.
|
Hi @sailorvii this PR has code-building failures, that's why all CIs failed, please fix it |
e00ec13 to
e4540a0
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
At allocate state, the function checkNodeGPUSharingPredicateAndScore will add the used mem/core to the structure. For avoiding the pod allocated info updating latency, we use addResource it to add the pod the pod map. But it also add the used mem/core. To address this, we new a function that only add pod the map. Signed-off-by: chenw66 <chenw66@chinaunicom.cn>
At allocate state, the function checkNodeGPUSharingPredicateAndScore will add the used mem/core to the structure. For avoiding the pod allocated info updating latency, we use addResource it to add the pod the pod map. But it also add the used mem/core. To address this, we new a function that only add pod the map.
What type of PR is this?
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes # #4809
Special notes for your reviewer:
Does this PR introduce a user-facing change?