CI / test (push) Successful in 11m47s
On Ubuntu, node add (and server init for its own machine) installs the server driver ubuntu-drivers recommends for the cards on the PCI bus, with the kernel modules Canonical builds and signs for the kernel: no DKMS, and nothing to enrol under Secure Boot. nvidia-smi comes with it, and on an HGX board the fabric manager, with nvlsm on Blackwell. When the driver loads only after a restart, the console asks before restarting the machine and goes on once it is back; --reboot restarts without asking, --no-driver leaves the driver to the operator. `llmgw driver status` and `llmgw driver install` do the same by hand. Tried on node04 with a sysfs naming an RTX PRO 6000 Blackwell: real apt and ubuntu-drivers installed 595-server-open and the 6.8.0-151 kernel its signed modules are built for, and said a restart was needed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
126 lines
3.7 KiB
Go
126 lines
3.7 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"runtime"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"gitea.mynodes.xyz/ilker/llmgw/internal/driver"
|
|
)
|
|
|
|
func newDriverCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "driver",
|
|
Short: "Check this machine's NVIDIA driver, or install the one its cards need",
|
|
Long: `A node with an NVIDIA card needs the card's driver before it can serve on it.
|
|
node add, join and server init install it themselves; these commands do it by
|
|
hand on this machine.`,
|
|
}
|
|
var statusJSON bool
|
|
status := &cobra.Command{
|
|
Use: "status",
|
|
Short: "Say whether this machine's NVIDIA cards have a working driver",
|
|
Args: cobra.NoArgs,
|
|
RunE: func(cmd *cobra.Command, _ []string) error {
|
|
st := (&driver.Machine{Sys: os.Getenv(driver.SysEnv)}).Check(cmd.Context())
|
|
if statusJSON {
|
|
return json.NewEncoder(cmd.OutOrStdout()).Encode(st)
|
|
}
|
|
printDriverStatus(cmd.OutOrStdout(), st)
|
|
return nil
|
|
},
|
|
}
|
|
status.Flags().BoolVar(&statusJSON, "json", false, "write the status as JSON")
|
|
|
|
var installJSON bool
|
|
install := &cobra.Command{
|
|
Use: "install",
|
|
Short: "Install the NVIDIA driver this machine's cards need",
|
|
Long: `Installs the NVIDIA driver for the cards on this machine's PCI bus and loads it.
|
|
|
|
On Ubuntu it is the server driver ubuntu-drivers recommends for the cards, with
|
|
the kernel modules Canonical builds and signs for the running kernel, so
|
|
Secure Boot needs nothing enrolled; nvidia-smi comes with it, and on an HGX
|
|
board the fabric manager. A driver that already works is left alone.
|
|
|
|
When something holds the cards (nouveau, usually), the driver loads only after
|
|
a restart: the command says so and does not restart the machine itself.`,
|
|
Args: cobra.NoArgs,
|
|
RunE: func(cmd *cobra.Command, _ []string) error {
|
|
if runtime.GOOS != "linux" {
|
|
return fmt.Errorf("the driver is installed on Linux; this is %s", runtime.GOOS)
|
|
}
|
|
if os.Geteuid() != 0 {
|
|
return errors.New("run it as root — sudo llmgw driver install — since it installs packages")
|
|
}
|
|
out := cmd.OutOrStdout()
|
|
m := &driver.Machine{Sys: os.Getenv(driver.SysEnv)}
|
|
if !installJSON {
|
|
m.Log = prefixWriter{out, " .. "}
|
|
}
|
|
ctx, cancel := context.WithTimeout(cmd.Context(), driver.Wait)
|
|
defer cancel()
|
|
res, err := m.Install(ctx)
|
|
if installJSON {
|
|
type answer struct {
|
|
driver.Result
|
|
Error string `json:"error,omitempty"`
|
|
}
|
|
a := answer{Result: res}
|
|
if err != nil {
|
|
a.Error = err.Error()
|
|
}
|
|
if jerr := json.NewEncoder(out).Encode(a); jerr != nil {
|
|
return jerr
|
|
}
|
|
return err
|
|
}
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Fprintln(out, res.Message)
|
|
if res.Reboot {
|
|
fmt.Fprintln(out, "restart the machine (sudo reboot); nvidia-smi then lists the card(s)")
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
install.Flags().BoolVar(&installJSON, "json", false, "write the result as JSON")
|
|
cmd.AddCommand(status, install)
|
|
return cmd
|
|
}
|
|
|
|
func printDriverStatus(w io.Writer, st driver.Status) {
|
|
switch {
|
|
case st.Cards == 0:
|
|
fmt.Fprintln(w, "no NVIDIA card on this machine")
|
|
case st.Working:
|
|
fmt.Fprintf(w, "%d NVIDIA card(s), driver %s works\n", st.Cards, st.Version)
|
|
case st.Present:
|
|
fmt.Fprintf(w, "%d NVIDIA card(s); a driver is installed but not loaded: restart the machine\n", st.Cards)
|
|
case st.Supported:
|
|
fmt.Fprintf(w, "%d NVIDIA card(s) and no driver: sudo llmgw driver install\n", st.Cards)
|
|
default:
|
|
fmt.Fprintf(w, "%d NVIDIA card(s) and no driver; %s\n", st.Cards, st.Reason)
|
|
}
|
|
}
|
|
|
|
// prefixWriter writes every line it is given with a prefix.
|
|
type prefixWriter struct {
|
|
w io.Writer
|
|
prefix string
|
|
}
|
|
|
|
func (p prefixWriter) Write(b []byte) (int, error) {
|
|
if _, err := io.WriteString(p.w, p.prefix); err != nil {
|
|
return 0, err
|
|
}
|
|
return p.w.Write(b)
|
|
}
|