-
Notifications
You must be signed in to change notification settings - Fork 35
feat(hardware): use NVML to grab the hardware profile during the regi… #314
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 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9fa4720
feat(hardware): use NVML to grab the hardware profile during the regi…
mistercodedor 6a6d007
cgo cross compile, bugfix in fetch devplane proto, uncomment todos
drewmalin 42ec5a0
also use cgo_enabled=1 iin goreleaser
drewmalin 1cc4b80
lint
drewmalin bc41666
fix: address hardware profile PR comments
mistercodedor 15b4a01
update goreleaser
drewmalin 75ebd43
makefile updates
drewmalin beeebff
remove unused local build
drewmalin 95e0202
update cross version
drewmalin 74d6200
release closer to cross
drewmalin ce8252b
review feedback
patelspratik 90b0a17
Merge branch 'main' into codedor/register/hardware_profiler
patelspratik e75f724
merge conflicts
patelspratik 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
Some comments aren't visible on the classic Files Changed page.
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 |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ before: | |
| - go mod download | ||
| builds: | ||
| - env: | ||
| - CGO_ENABLED=0 | ||
| - CGO_ENABLED=1 | ||
| goos: | ||
| - darwin | ||
| - linux | ||
|
|
||
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 |
|---|---|---|
| @@ -1,19 +1,39 @@ | ||
| .DEFAULT_GOAL := fast-build | ||
| VERSION := dev-$(shell git rev-parse HEAD | cut -c 1-8) | ||
|
|
||
| # Cross-compilation via Docker (golang:1.24 native Linux container). | ||
| # When arch=<GOOS>/<GOARCH> is provided, spin up a container that matches | ||
| # the target platform so CGO uses the native Linux gcc/GNU ld toolchain | ||
| _GOMODCACHE := $(shell go env GOMODCACHE) | ||
| ifdef arch | ||
| _CROSS_GOOS := $(word 1,$(subst /, ,$(arch))) | ||
| _CROSS_GOARCH := $(word 2,$(subst /, ,$(arch))) | ||
| _BUILD_PREFIX := docker run --rm \ | ||
| --platform $(_CROSS_GOOS)/$(_CROSS_GOARCH) \ | ||
| -v $(CURDIR):/app \ | ||
| -v $(_GOMODCACHE):/go/pkg/mod \ | ||
| -e CGO_ENABLED=1 \ | ||
| -e GOPRIVATE=github.com/brevdev/* \ | ||
| -e GONOSUMDB=github.com/brevdev/* \ | ||
| -w /app \ | ||
| golang:1.24 | ||
| else | ||
| _BUILD_PREFIX := CGO_ENABLED=1 | ||
| endif | ||
|
|
||
| .PHONY: fast-build | ||
| fast-build: ## go build -o brev | ||
| $(call print-target) | ||
| echo ${VERSION} | ||
| CGO_ENABLED=0 go build -o brev -ldflags "-X github.com/brevdev/brev-cli/pkg/cmd/version.Version=${VERSION}" | ||
| CGO_ENABLED=1 go build -o brev -ldflags "-X github.com/brevdev/brev-cli/pkg/cmd/version.Version=${VERSION}" | ||
|
|
||
| .PHONY: local | ||
| local: ## build with env wrapper (use: make local env=dev0|dev1|dev2|stg arch=linux/amd64, or make local for defaults) | ||
| $(call print-target) | ||
| ifdef env | ||
| @echo "Building with env=$(env) wrapper..." | ||
| @echo ${VERSION} | ||
| $(if $(arch),GOOS=$(word 1,$(subst /, ,$(arch))) GOARCH=$(word 2,$(subst /, ,$(arch))),) CGO_ENABLED=0 go build -o brev-local -ldflags "-X github.com/brevdev/brev-cli/pkg/cmd/version.Version=${VERSION}" | ||
| $(_BUILD_PREFIX) go build -o brev-local -ldflags "-X github.com/brevdev/brev-cli/pkg/cmd/version.Version=${VERSION}" | ||
| @echo '#!/bin/sh' > brev | ||
| @echo '# Auto-generated wrapper with environment overrides' >> brev | ||
| @echo 'export BREV_CONSOLE_URL="https://localhost.nvidia.com:3000"' >> brev | ||
|
|
@@ -26,7 +46,7 @@ ifdef env | |
| @chmod +x brev | ||
| else | ||
| @echo "Building without environment overrides (using config.go defaults)..." | ||
| $(if $(arch),GOOS=$(word 1,$(subst /, ,$(arch))) GOARCH=$(word 2,$(subst /, ,$(arch))),) CGO_ENABLED=0 go build -o brev -ldflags "-X github.com/brevdev/brev-cli/pkg/cmd/version.Version=${VERSION}" | ||
| $(_BUILD_PREFIX) go build -o brev -ldflags "-X github.com/brevdev/brev-cli/pkg/cmd/version.Version=${VERSION}" | ||
| endif | ||
|
|
||
| .PHONY: install-dev | ||
|
|
@@ -305,8 +325,8 @@ develop-with-nix: | |
| update-devplane-deps: ## update devplane dependencies (use: make update-devplane-deps commit=<hash-or-tag>, defaults to latest) | ||
| @COMMIT=$${commit:-latest}; \ | ||
| echo "Updating devplane dependencies to: $$COMMIT"; \ | ||
| go get -u github.com/brevdev/dev-plane@$$COMMIT; \ | ||
| GOPRIVATE=github.com/brevdev/* go get -u github.com/brevdev/dev-plane@$$COMMIT; \ | ||
| go get buf.build/gen/go/brevdev/devplane/grpc/go@$$COMMIT; \ | ||
| go get buf.build/gen/go/brevdev/devplane/protocolbuffers/go@$$COMMIT; \ | ||
| go mod tidy; \ | ||
| GOPRIVATE=github.com/brevdev/* go mod tidy; \ | ||
| echo "Successfully updated to $$COMMIT" | ||
|
Comment on lines
-308
to
356
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated but this allows for fetching internal dependencies without relying on the |
||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| //go:build linux || windows | ||
|
|
||
| package register | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/NVIDIA/go-nvml/pkg/nvml" | ||
| ) | ||
|
|
||
| // archName returns the GPU architecture name for the given CUDA compute capability. | ||
| func archName(major, minor int) string { | ||
| switch major { | ||
| case 1: | ||
| return "Tesla" | ||
| case 2: | ||
| return "Fermi" | ||
| case 3: | ||
| return "Kepler" | ||
| case 5: | ||
| return "Maxwell" | ||
| case 6: | ||
| return "Pascal" | ||
| case 7: | ||
| if minor >= 5 { | ||
| return "Turing" | ||
| } | ||
| return "Volta" | ||
| case 8: | ||
| if minor >= 9 { | ||
| return "Ada Lovelace" | ||
| } | ||
| return "Ampere" | ||
| case 9: | ||
| return "Hopper" | ||
| case 10: | ||
| return "Blackwell" | ||
| case 12: | ||
| return "Vera Rubin" | ||
| default: | ||
| return "" | ||
| } | ||
| } | ||
|
|
||
| // probeGPUsNVML uses NVML to detect GPUs and interconnects. | ||
| // Returns (nil, nil) if NVML is unavailable (e.g. no driver installed). | ||
| func probeGPUsNVML() ([]GPU, []Interconnect) { | ||
| ret := nvml.Init() | ||
| if ret != nvml.SUCCESS { | ||
| return nil, nil | ||
| } | ||
| defer func() { _ = nvml.Shutdown() }() | ||
|
|
||
| count, ret := nvml.DeviceGetCount() | ||
| if ret != nvml.SUCCESS || count == 0 { | ||
| return nil, nil | ||
| } | ||
|
|
||
| type gpuKey struct { | ||
| model string | ||
| arch string | ||
| mem int64 | ||
| } | ||
| counts := make(map[gpuKey]int32) | ||
| var order []gpuKey | ||
| var interconnects []Interconnect | ||
|
|
||
| for i := 0; i < count; i++ { | ||
| device, ret := nvml.DeviceGetHandleByIndex(i) | ||
| if ret != nvml.SUCCESS { | ||
| continue | ||
| } | ||
|
|
||
| name, ret := device.GetName() | ||
| if ret != nvml.SUCCESS { | ||
| name = "Unknown" | ||
| } | ||
|
|
||
| var memBytes int64 | ||
| memInfo, ret := device.GetMemoryInfo() | ||
| if ret == nvml.SUCCESS { | ||
| memBytes = int64(memInfo.Total) | ||
| } | ||
|
|
||
| arch := "" | ||
| major, minor, ret := device.GetCudaComputeCapability() | ||
| if ret == nvml.SUCCESS { | ||
| if name := archName(major, minor); name != "" { | ||
| arch = name | ||
| } else { | ||
| arch = fmt.Sprintf("sm_%d%d", major, minor) | ||
| } | ||
| } | ||
|
|
||
| key := gpuKey{model: name, arch: arch, mem: memBytes} | ||
| if counts[key] == 0 { | ||
| order = append(order, key) | ||
| } | ||
| counts[key]++ | ||
|
|
||
| // Probe NVLink interconnects for this device. | ||
| interconnects = append(interconnects, probeNVLink(device, i)...) | ||
|
|
||
| // Probe PCIe interconnect for this device. | ||
| if ic := probePCIe(device, i); ic != nil { | ||
| interconnects = append(interconnects, *ic) | ||
| } | ||
| } | ||
|
|
||
| gpus := make([]GPU, 0, len(order)) | ||
| for _, key := range order { | ||
| mem := key.mem | ||
| g := GPU{ | ||
| Model: key.model, | ||
| Architecture: key.arch, | ||
| Count: counts[key], | ||
| } | ||
| if mem > 0 { | ||
| g.MemoryBytes = &mem | ||
| } | ||
| gpus = append(gpus, g) | ||
| } | ||
|
|
||
| return gpus, interconnects | ||
| } | ||
|
|
||
| // probeNVLink checks NVLink connections for a device. | ||
| func probeNVLink(device nvml.Device, deviceIdx int) []Interconnect { | ||
| var ics []Interconnect | ||
| activeLinks := 0 | ||
|
|
||
| // NVLink link count varies by architecture; try up to 18 links. | ||
| var nvlinkVersion uint32 | ||
| for link := 0; link < 18; link++ { | ||
| state, ret := device.GetNvLinkState(link) | ||
| if ret != nvml.SUCCESS { | ||
| break | ||
| } | ||
| if state == nvml.FEATURE_ENABLED { | ||
| activeLinks++ | ||
| if nvlinkVersion == 0 { | ||
| ver, ret := device.GetNvLinkVersion(link) | ||
| if ret == nvml.SUCCESS { | ||
| nvlinkVersion = ver | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if activeLinks > 0 { | ||
| ics = append(ics, Interconnect{ | ||
| Type: "NVLink", | ||
| Device: fmt.Sprintf("GPU %d", deviceIdx), | ||
| ActiveLinks: activeLinks, | ||
| Version: nvlinkVersion, | ||
| }) | ||
| } | ||
|
|
||
| return ics | ||
| } | ||
|
|
||
| // probePCIe reads PCIe generation and width for a device. | ||
| func probePCIe(device nvml.Device, deviceIdx int) *Interconnect { | ||
| gen, ret := device.GetCurrPcieLinkGeneration() | ||
| if ret != nvml.SUCCESS { | ||
| return nil | ||
| } | ||
| width, ret := device.GetCurrPcieLinkWidth() | ||
| if ret != nvml.SUCCESS { | ||
| return nil | ||
| } | ||
| return &Interconnect{ | ||
| Type: "PCIe", | ||
| Device: fmt.Sprintf("GPU %d", deviceIdx), | ||
| Generation: gen, | ||
| Width: width, | ||
| } | ||
| } |
Oops, something went wrong.
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.
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.
We now always need CGO