-
Notifications
You must be signed in to change notification settings - Fork 38
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
Changes from 3 commits
9fa4720
6a6d007
42ec5a0
1cc4b80
bc41666
15b4a01
75ebd43
beeebff
95e0202
74d6200
ce8252b
90b0a17
e75f724
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
||
| 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 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| //go:build linux || windows | ||
|
|
||
| package register | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/NVIDIA/go-nvml/pkg/nvml" | ||
| ) | ||
|
|
||
| // archNames maps NVML compute capability (major version) to GPU architecture name. | ||
| var archNames = map[int]string{ | ||
|
Contributor
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.
|
||
| 1: "Tesla", | ||
| 2: "Fermi", | ||
| 3: "Kepler", | ||
| 5: "Maxwell", | ||
| 6: "Pascal", | ||
| 7: "Volta/Turing", | ||
| 8: "Ampere", | ||
| 9: "Hopper/Ada Lovelace", | ||
| 10: "Blackwell", | ||
| 12: "Vera Rubin", | ||
| } | ||
|
|
||
| // 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 archName, ok := archNames[major]; ok { | ||
| arch = archName | ||
| } 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 = uint32(ver) | ||
|
Check failure on line 124 in pkg/cmd/register/gpu_nvml.go
|
||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| 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, | ||
| } | ||
| } | ||
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