Skip to content

Keep MIG attribute order when matching a profile - #121

Merged
tariq1890 merged 1 commit into
NVIDIA:mainfrom
SashaMIT:fix/mig-match-keeps-attribute-order
Oct 6, 2026
Merged

tariq1890 merged 1 commit into
NVIDIA:mainfrom
SashaMIT:fix/mig-match-keeps-attribute-order

Conversation

@SashaMIT

@SashaMIT SashaMIT commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #120

Matches sorted the attribute slices it was given. Those slices share the profile's backing array, so the sort sticks.

parseMigProfile("1g.5gb+me,gfx").String() is 1g.5gb+me,gfx. After Matches("1g.5gb+gfx,me") returns true, String() is 1g.5gb+gfx,me. Negative attributes go through the same helper.

The comparison now sorts copies. A matching profile stays 1g.5gb+me,gfx. 1g.5gb+gfx,me still matches.

TestMatchesKeepsAttributeOrder is red on tip (1g.5gb+gfx,me) and green after. TestParseMigProfile still passes.

Comment thread pkg/nvlib/device/mig_profile.go Outdated
sort.Strings(attrs2)
for i, a := range attrs2 {
if a != attrs1[i] {
left := append([]string(nil), attrs1...)

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.

Why not use slices.Clone instead?

See here for an example of how it is used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks. slices.Clone is the same copy, and it keeps a nil slice nil. That is commit 81c855f. go test ./pkg/nvlib/device passed.

@tariq1890

Copy link
Copy Markdown
Contributor

Thank you, @SashaMIT !

@tariq1890

Copy link
Copy Markdown
Contributor

Can you squash your commit history?

Matches sorted the profile's own attribute slices, so a successful
match rewrote 1g.5gb+me,gfx as 1g.5gb+gfx,me. Compare copies instead.
The copies use slices.Clone.

Signed-off-by: Sasha Mitchell <sash.t.mitchell@gmail.com>
@SashaMIT
SashaMIT force-pushed the fix/mig-match-keeps-attribute-order branch from 81c855f to 1f124ab Compare October 6, 2026 06:11
@SashaMIT

SashaMIT commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Done. Those two commits are now one, 1f124ab.

@tariq1890
tariq1890 merged commit 96d3659 into NVIDIA:main Oct 6, 2026
5 checks passed
@SashaMIT

SashaMIT commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for merging it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Matches reorders a MIG profile's attributes

2 participants