-
Notifications
You must be signed in to change notification settings - Fork 26
feat: add HardwareDetector interface and measurement keys for NFD integration #482
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
be04d3e
feat: add NFD API dependency, measurement keys, timeout, and Hardware…
ArangoGutierrez 0358c03
fix: remove blank NFD import to avoid init() side-effects
ArangoGutierrez 7953cb4
fix: add DetectionSource field to HardwareInfo
ArangoGutierrez 59a4309
fix: add error-path test case and nil guard for HardwareDetector
ArangoGutierrez 7177911
fix: rename measurement keys to follow KeyGPU* convention
ArangoGutierrez 82479c2
Merge branch 'main' into feat/nfd-infrastructure
mchmarny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved. | ||
| // | ||
| // 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. | ||
|
|
||
| package gpu | ||
|
|
||
| import "context" | ||
|
|
||
| // HardwareDetector abstracts GPU hardware detection for testability. | ||
| // Implementations enumerate PCI devices and kernel module state without | ||
| // requiring GPU drivers to be installed. | ||
| type HardwareDetector interface { | ||
| // Detect discovers GPU hardware and driver module state. | ||
| // Returns HardwareInfo describing what was found, or an error if | ||
| // detection could not be performed (e.g., sysfs not available). | ||
| Detect(ctx context.Context) (*HardwareInfo, error) | ||
| } | ||
|
|
||
| // HardwareInfo describes the GPU hardware state detected without drivers. | ||
| type HardwareInfo struct { | ||
| // GPUPresent is true if at least one NVIDIA GPU was found via PCI enumeration. | ||
| GPUPresent bool | ||
|
|
||
| // GPUCount is the number of NVIDIA GPUs detected via PCI enumeration. | ||
| GPUCount int | ||
|
|
||
| // DriverLoaded is true if the nvidia kernel module is currently loaded. | ||
| DriverLoaded bool | ||
|
|
||
| // DetectionSource identifies which detection method produced this result | ||
| // (e.g., "nfd", "sysfs"). | ||
| DetectionSource string | ||
| } | ||
mchmarny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| // Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved. | ||
| // | ||
| // 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. | ||
|
|
||
| package gpu | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/NVIDIA/aicr/pkg/errors" | ||
| ) | ||
|
|
||
| // mockHardwareDetector is a test double for the HardwareDetector interface. | ||
| type mockHardwareDetector struct { | ||
| info *HardwareInfo | ||
| err error | ||
| } | ||
|
|
||
| func (m *mockHardwareDetector) Detect(_ context.Context) (*HardwareInfo, error) { | ||
| return m.info, m.err | ||
| } | ||
|
|
||
| func TestHardwareDetectorInterface(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| detector HardwareDetector | ||
| wantPresent bool | ||
| wantCount int | ||
| wantDriver bool | ||
| wantDetSrc string | ||
| wantErr bool | ||
| }{ | ||
| { | ||
| name: "GPU present with driver", | ||
| detector: &mockHardwareDetector{ | ||
| info: &HardwareInfo{ | ||
| GPUPresent: true, | ||
| GPUCount: 2, | ||
| DriverLoaded: true, | ||
| DetectionSource: "nfd", | ||
| }, | ||
| }, | ||
| wantPresent: true, | ||
| wantCount: 2, | ||
| wantDriver: true, | ||
| wantDetSrc: "nfd", | ||
| }, | ||
| { | ||
| name: "no GPU hardware", | ||
| detector: &mockHardwareDetector{ | ||
| info: &HardwareInfo{ | ||
| GPUPresent: false, | ||
| GPUCount: 0, | ||
| DriverLoaded: false, | ||
| DetectionSource: "nfd", | ||
| }, | ||
| }, | ||
| wantPresent: false, | ||
| wantCount: 0, | ||
| wantDriver: false, | ||
| wantDetSrc: "nfd", | ||
| }, | ||
| { | ||
| name: "detection failure", | ||
| detector: &mockHardwareDetector{ | ||
| info: nil, | ||
| err: errors.New(errors.ErrCodeInternal, "sysfs not available"), | ||
| }, | ||
| wantErr: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| info, err := tt.detector.Detect(context.Background()) | ||
| if (err != nil) != tt.wantErr { | ||
| t.Errorf("Detect() error = %v, wantErr %v", err, tt.wantErr) | ||
| return | ||
| } | ||
| if err != nil { | ||
| return // error expected and received; skip field assertions | ||
| } | ||
| if info.GPUPresent != tt.wantPresent { | ||
| t.Errorf("GPUPresent = %v, want %v", info.GPUPresent, tt.wantPresent) | ||
| } | ||
mchmarny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if info.GPUCount != tt.wantCount { | ||
| t.Errorf("GPUCount = %v, want %v", info.GPUCount, tt.wantCount) | ||
| } | ||
| if info.DriverLoaded != tt.wantDriver { | ||
| t.Errorf("DriverLoaded = %v, want %v", info.DriverLoaded, tt.wantDriver) | ||
| } | ||
| if info.DetectionSource != tt.wantDetSrc { | ||
| t.Errorf("DetectionSource = %v, want %v", info.DetectionSource, tt.wantDetSrc) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
mchmarny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.