Skip to content

refactor: extract checkUUID function for reuse - #1622

Merged
hami-robot[bot] merged 2 commits into
Project-HAMi:masterfrom
DSFans2014:refact/checkUUID
Jan 23, 2026
Merged

refactor: extract checkUUID function for reuse#1622
hami-robot[bot] merged 2 commits into
Project-HAMi:masterfrom
DSFans2014:refact/checkUUID

Conversation

@DSFans2014

Copy link
Copy Markdown
Member

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

Make checkUUID function as a common utility function

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @DSFans2014, 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 streamlines the codebase by centralizing the logic for validating device UUIDs based on pod annotations. By extracting this common functionality into a single utility function, it enhances maintainability and consistency across various device implementations, making the code cleaner and easier to manage.

Highlights

  • Code Refactoring: The checkUUID function, previously duplicated across multiple device-specific packages (AMD, Ascend, AWSNeuron, Cambricon, Enflame, Hygon, Iluvatar, Kunlun, Metax, Mthreads, Nvidia), has been extracted into a common utility function device.CheckUUID.
  • Code Simplification: All individual checkUUID methods within device packages have been removed, and their calls updated to use the new shared device.CheckUUID function, significantly reducing code duplication.
  • Testing: Corresponding unit tests for the removed checkUUID methods have been deleted, and a new test TestCheckUUID has been added in pkg/device/devices_test.go to cover the new common utility.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Signed-off-by: james <open4pd@4paradigm.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 is a good refactoring effort that centralizes the checkUUID logic into a common utility function device.CheckUUID, effectively reducing code duplication across various device packages. The implementation of the new function is correct and the refactoring is applied consistently. I've found a minor issue in a test case for the new function that needs to be addressed.

Comment thread pkg/device/devices_test.go Outdated
Signed-off-by: james <open4pd@4paradigm.com>
@codecov

codecov Bot commented Jan 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/device/iluvatar/device.go 0.00% 0 Missing and 1 partial ⚠️
Flag Coverage Δ
unittests 50.76% <95.45%> (-0.39%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pkg/device/amd/device.go 75.18% <100.00%> (-0.68%) ⬇️
pkg/device/ascend/device.go 79.93% <100.00%> (-0.76%) ⬇️
pkg/device/awsneuron/device.go 75.35% <100.00%> (-1.02%) ⬇️
pkg/device/cambricon/device.go 82.99% <100.00%> (-0.79%) ⬇️
pkg/device/devices.go 81.99% <100.00%> (+0.86%) ⬆️
pkg/device/enflame/device.go 82.88% <100.00%> (-0.03%) ⬇️
pkg/device/hygon/device.go 90.74% <100.00%> (-0.49%) ⬇️
pkg/device/kunlun/device.go 10.92% <ø> (+1.00%) ⬆️
pkg/device/kunlun/vdevice.go 3.35% <ø> (+0.25%) ⬆️
pkg/device/metax/sdevice.go 76.72% <100.00%> (+0.36%) ⬆️
... and 3 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@FouoF

FouoF commented Jan 23, 2026

Copy link
Copy Markdown
Contributor

/lgtm

@hami-robot hami-robot Bot added the lgtm label Jan 23, 2026

@archlitchi archlitchi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@hami-robot

hami-robot Bot commented Jan 23, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: archlitchi, DSFans2014

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@hami-robot hami-robot Bot added the approved label Jan 23, 2026
@hami-robot
hami-robot Bot merged commit 46bd7a8 into Project-HAMi:master Jan 23, 2026
13 checks passed
@DSFans2014
DSFans2014 deleted the refact/checkUUID branch January 23, 2026 08:37
mesutoezdil pushed a commit to mesutoezdil/HAMi that referenced this pull request Jun 14, 2026
* refactor: extract checkUUID function for reuse

Signed-off-by: james <open4pd@4paradigm.com>

* fix: fix test case

Signed-off-by: james <open4pd@4paradigm.com>

---------

Signed-off-by: james <open4pd@4paradigm.com>
Lakshya77089 added a commit to Lakshya77089/HAMi that referenced this pull request Aug 19, 2026
KunlunUseUUID and KunlunNoUseUUID were defined but never read, so a pod
asking for baidu.com/use-gpuuuid was scheduled onto any XPU and
nouse-gpuuuid could not exclude a card. Every other backend calls
device.CheckUUID in Fit(); kunlun was missed when the shared helper landed
in Project-HAMi#1622 and again when Project-HAMi#2045 changed it.

graghSelect derives topology from a device's position in the slice, so the
check goes into the fitFn it already takes rather than filtering the slice,
which would shift devices between wings. Both KunlunDevices and
KunlunVDevices are covered, and an allocation that fails only because of
the annotations now reports CardUuidMismatch instead of NumaNotFit.

Signed-off-by: Lakshya77089 <lakshyasharma7708@gmail.com>
hami-robot Bot pushed a commit that referenced this pull request Aug 20, 2026
* fix(kunlun): honour use-gpuuuid and nouse-gpuuuid annotations

KunlunUseUUID and KunlunNoUseUUID were defined but never read, so a pod
asking for baidu.com/use-gpuuuid was scheduled onto any XPU and
nouse-gpuuuid could not exclude a card. Every other backend calls
device.CheckUUID in Fit(); kunlun was missed when the shared helper landed
in #1622 and again when #2045 changed it.

graghSelect derives topology from a device's position in the slice, so the
check goes into the fitFn it already takes rather than filtering the slice,
which would shift devices between wings. Both KunlunDevices and
KunlunVDevices are covered, and an allocation that fails only because of
the annotations now reports CardUuidMismatch instead of NumaNotFit.

Signed-off-by: Lakshya77089 <lakshyasharma7708@gmail.com>

* fix(kunlun): reuse the xpu uuid annotations and dedupe the mismatch count

graghSelect can call fitFn more than once for the same device, so the plain
counter reported the same card twice. Track mismatched ids in a map instead.

The physical path now reads the same hami.io/use-xpu-uuid and
hami.io/no-use-xpu-uuid keys vdevice.go already defines, rather than a new
pair, so both kunlun paths honour one documented annotation. baidu.com/
stays as the legacy alias. Added a test that uses the literal key so a
rename of the constant cannot silently break it.

Signed-off-by: Lakshya77089 <lakshyasharma7708@gmail.com>

---------

Signed-off-by: Lakshya77089 <lakshyasharma7708@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants