Tell independent fabrics apart by their subnet manager, not their name
A fabric was what agent.yaml called it. With several independent InfiniBand fabrics at a site, two given one name would have had a replica spread across both, starting and then hanging on its first collective. Each active InfiniBand port now reports the master subnet manager it sees (sminfo, asked once a minute), which every port on one fabric shares and ports on separate fabrics cannot; a RoCE port reports the IP network of its RoCE v2 address. Ports also carry their node and port GUIDs. Placement divides a declared fabric by that physical identity and forms a replica on one part only; a node whose adapters for one name are on two fabrics is refused, and a node that cannot say is kept apart from those that can. /api/v1/fabrics and the cluster page list each physical fabric with its subnet manager, and say when one name covers two fabrics, two names one fabric, an adapter is up but undeclared, or a node cannot be checked. doctor reports each port's subnet manager, and an agent on a node with adapters installs infiniband-diags when sminfo is missing. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
51f1606b53
commit
77fe801892
21 files changed
+1130
-58
No files matched your search
@@ -10,6 +10,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/control/fabrics"
|
||||
"io"
|
||||
"net/http"
|
||||
"slices"
|
||||
@@ -48,6 +49,9 @@ func (a *API) Register(mux *http.ServeMux) {
|
||||
mux.HandleFunc("GET /api/v1/capacity", a.listCapacity)
|
||||
mux.HandleFunc("GET /api/v1/usage", a.usageByScope)
|
||||
mux.HandleFunc("GET /api/v1/nodes", a.listNodes)
|
||||
mux.HandleFunc("GET /api/v1/fabrics", func(w http.ResponseWriter, _ *http.Request) {
|
||||
writeJSON(w, http.StatusOK, a.Fabrics())
|
||||
})
|
||||
mux.HandleFunc("GET /api/v1/models", a.listModels)
|
||||
mux.HandleFunc("GET /api/v1/replicas", a.listReplicas)
|
||||
// Listing is a read and deleting is a separate verb, so a mistyped
|
||||
@@ -134,6 +138,10 @@ type IBPortView struct {
|
||||
Active bool `json:"active"`
|
||||
// Fabric is the declared fabric this port's adapter carries, if any.
|
||||
Fabric string `json:"fabric,omitempty"`
|
||||
// Physical is the fabric the port is physically on: its subnet manager,
|
||||
// or its RoCE network. SMError says why that is not known.
|
||||
Physical string `json:"physical,omitempty"`
|
||||
SMError string `json:"sm_error,omitempty"`
|
||||
// Errors are the error counters that are not zero, by name.
|
||||
Errors map[string]uint64 `json:"errors,omitempty"`
|
||||
TxBytes uint64 `json:"tx_bytes,omitempty"`
|
||||
@@ -336,7 +344,13 @@ func (a *API) Nodes() []NodeView {
|
||||
for _, p := range n.IBPorts {
|
||||
pv := IBPortView{HCA: p.HCA, Port: p.Port, State: p.State, PhysState: p.PhysState,
|
||||
RateGbps: p.RateGbps, LinkLayer: p.LinkLayer, Active: p.Active(), Fabric: fabricOf[p.HCA],
|
||||
TxBytes: p.Counters["port_xmit_data"], RxBytes: p.Counters["port_rcv_data"]}
|
||||
TxBytes: p.Counters["port_xmit_data"], RxBytes: p.Counters["port_rcv_data"], SMError: p.SMError}
|
||||
switch {
|
||||
case p.RoCE() && p.Network != "":
|
||||
pv.Physical = "RoCE " + p.Network
|
||||
case p.SMGUID != "":
|
||||
pv.Physical = fmt.Sprintf("SM %s (LID %d)", p.SMGUID, p.SMLID)
|
||||
}
|
||||
for name, c := range p.Counters {
|
||||
if c > 0 && name != "port_xmit_data" && name != "port_rcv_data" {
|
||||
if pv.Errors == nil {
|
||||
@@ -818,3 +832,9 @@ func (a *API) profileChanged(model, profile, was string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Fabrics is the physical fabrics the adapters are on, against the names
|
||||
// the nodes gave them.
|
||||
func (a *API) Fabrics() fabrics.Report {
|
||||
return fabrics.Analyze(a.ctl.Inventory().Nodes())
|
||||
}
|
||||
@@ -411,6 +411,9 @@ func (s *Service) applyHeartbeat(nodeID string, hb *llmgwv1.Heartbeat) {
|
||||
HCA: p.GetHca(), Port: int(p.GetPort()), State: p.GetState(),
|
||||
PhysState: p.GetPhysState(), RateGbps: int(p.GetRateGbps()),
|
||||
LinkLayer: p.GetLinkLayer(), Counters: maps.Clone(p.GetCounters()),
|
||||
NodeGUID: p.GetNodeGuid(), PortGUID: p.GetPortGuid(), GIDPrefix: p.GetGidPrefix(),
|
||||
SMGUID: p.GetSmGuid(), SMLID: int(p.GetSmLid()), SMPriority: int(p.GetSmPriority()),
|
||||
SMState: p.GetSmState(), SMError: p.GetSmError(), Network: p.GetNetwork(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,243 @@
|
||||
// Package fabrics works out which physical fabrics the cluster's adapters
|
||||
// are on, and where that disagrees with what the nodes were told.
|
||||
//
|
||||
// A fabric's name is configuration. What it is physically is what the
|
||||
// adapters report: on InfiniBand the master subnet manager every port on one
|
||||
// fabric sees, on RoCE the IP network. Kept apart so a site with several
|
||||
// independent fabrics can see each, and see at once when two were given one
|
||||
// name, one was given two, or an adapter is cabled somewhere nobody declared.
|
||||
package fabrics
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/control/inventory"
|
||||
)
|
||||
|
||||
// Level is how much a problem matters.
|
||||
type Level string
|
||||
|
||||
// The levels.
|
||||
const (
|
||||
Fail Level = "fail"
|
||||
Warn Level = "warn"
|
||||
Info Level = "info"
|
||||
)
|
||||
|
||||
// Problem is one disagreement, in words.
|
||||
type Problem struct {
|
||||
Level Level `json:"level"`
|
||||
Fabric string `json:"fabric,omitempty"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// Physical is one fabric as the adapters find it.
|
||||
type Physical struct {
|
||||
Key string `json:"key"`
|
||||
// Kind is infiniband or roce.
|
||||
Kind string `json:"kind"`
|
||||
// Label is the key as a person reads it.
|
||||
Label string `json:"label"`
|
||||
// SM is the master subnet manager, on InfiniBand.
|
||||
SM *SM `json:"sm,omitempty"`
|
||||
// Declared are the names nodes gave this fabric; one, when all is well.
|
||||
Declared []string `json:"declared"`
|
||||
Members []Member `json:"members"`
|
||||
RateGbps int `json:"rate_gbps"`
|
||||
GIDPrefix string `json:"gid_prefix,omitempty"`
|
||||
}
|
||||
|
||||
// SM is a subnet manager as the ports see it.
|
||||
type SM struct {
|
||||
GUID string `json:"guid"`
|
||||
LID int `json:"lid"`
|
||||
Priority int `json:"priority"`
|
||||
State string `json:"state"`
|
||||
}
|
||||
|
||||
// Member is one node's adapters on a physical fabric.
|
||||
type Member struct {
|
||||
Node string `json:"node"`
|
||||
HCAs []string `json:"hcas"`
|
||||
// Declared is the name this node gives these adapters, empty when it
|
||||
// declares them in no fabric.
|
||||
Declared string `json:"declared,omitempty"`
|
||||
}
|
||||
|
||||
// Report is the whole picture.
|
||||
type Report struct {
|
||||
Physical []Physical `json:"physical"`
|
||||
Problems []Problem `json:"problems"`
|
||||
// Unverified are declared fabrics some of whose nodes cannot say which
|
||||
// physical fabric they are on, with why.
|
||||
Unverified map[string][]string `json:"unverified,omitempty"`
|
||||
}
|
||||
|
||||
// Analyze reads every node's ports.
|
||||
func Analyze(nodes []inventory.Node) Report {
|
||||
r := Report{Unverified: map[string][]string{}}
|
||||
byKey := map[string]*Physical{}
|
||||
declaredKeys := map[string]map[string][]string{} // declared -> key -> nodes
|
||||
|
||||
for _, n := range nodes {
|
||||
declOf := map[string]string{} // hca -> declared fabric
|
||||
for _, f := range n.Fabrics {
|
||||
for _, h := range f.HCAs {
|
||||
declOf[h] = f.Fabric
|
||||
}
|
||||
}
|
||||
// Which physical fabric each declared fabric's adapters are on here.
|
||||
seenDecl := map[string]map[string]bool{}
|
||||
members := map[string]*Member{} // key -> this node's membership
|
||||
|
||||
for _, p := range n.IBPorts {
|
||||
key := p.FabricKey()
|
||||
decl := declOf[p.HCA]
|
||||
if key == "" {
|
||||
if p.Active() && decl != "" && !p.RoCE() && p.SMError != "" {
|
||||
r.Unverified[decl] = appendOnce(r.Unverified[decl], n.ID+": "+p.SMError)
|
||||
}
|
||||
continue
|
||||
}
|
||||
ph := byKey[key]
|
||||
if ph == nil {
|
||||
ph = &Physical{Key: key, Kind: "infiniband", GIDPrefix: p.GIDPrefix}
|
||||
if p.RoCE() {
|
||||
ph.Kind, ph.Label = "roce", "RoCE "+p.Network
|
||||
} else {
|
||||
ph.SM = &SM{GUID: p.SMGUID, LID: p.SMLID, Priority: p.SMPriority, State: p.SMState}
|
||||
ph.Label = fmt.Sprintf("subnet manager %s (LID %d)", p.SMGUID, p.SMLID)
|
||||
}
|
||||
byKey[key] = ph
|
||||
}
|
||||
if p.RateGbps > 0 && (ph.RateGbps == 0 || p.RateGbps < ph.RateGbps) {
|
||||
ph.RateGbps = p.RateGbps
|
||||
}
|
||||
m := members[key]
|
||||
if m == nil {
|
||||
m = &Member{Node: n.ID, Declared: decl}
|
||||
members[key] = m
|
||||
}
|
||||
m.HCAs = appendOnce(m.HCAs, p.HCA)
|
||||
if decl != "" {
|
||||
if seenDecl[decl] == nil {
|
||||
seenDecl[decl] = map[string]bool{}
|
||||
}
|
||||
seenDecl[decl][key] = true
|
||||
ph.Declared = appendOnce(ph.Declared, decl)
|
||||
if declaredKeys[decl] == nil {
|
||||
declaredKeys[decl] = map[string][]string{}
|
||||
}
|
||||
declaredKeys[decl][key] = appendOnce(declaredKeys[decl][key], n.ID)
|
||||
} else {
|
||||
r.Problems = append(r.Problems, Problem{Level: Warn, Message: fmt.Sprintf(
|
||||
"%s: %s is up on %s but declared in no fabric, so llmgw sends nothing over it",
|
||||
n.ID, p.HCA, ph.Label)})
|
||||
}
|
||||
}
|
||||
for decl, keys := range seenDecl {
|
||||
if len(keys) > 1 {
|
||||
r.Problems = append(r.Problems, Problem{Level: Fail, Fabric: decl, Message: fmt.Sprintf(
|
||||
"%s: the adapters it declares as %s are cabled to %d different fabrics; it is left out of multi-node work on %s",
|
||||
n.ID, decl, len(keys), decl)})
|
||||
}
|
||||
}
|
||||
for key, m := range members {
|
||||
byKey[key].Members = append(byKey[key].Members, *m)
|
||||
}
|
||||
}
|
||||
|
||||
for decl, keys := range declaredKeys {
|
||||
if len(keys) < 2 {
|
||||
continue
|
||||
}
|
||||
var parts []string
|
||||
for _, k := range sortedKeys(keys) {
|
||||
parts = append(parts, fmt.Sprintf("%s: %s", byKey[k].Label, strings.Join(keys[k], ", ")))
|
||||
}
|
||||
r.Problems = append(r.Problems, Problem{Level: Fail, Fabric: decl, Message: fmt.Sprintf(
|
||||
"%s is %d separate fabrics — %s. A replica is kept to one of them; give each its own name",
|
||||
decl, len(keys), strings.Join(parts, "; "))})
|
||||
}
|
||||
for _, ph := range byKey {
|
||||
sort.Strings(ph.Declared)
|
||||
sort.Slice(ph.Members, func(i, j int) bool { return ph.Members[i].Node < ph.Members[j].Node })
|
||||
if len(ph.Declared) > 1 {
|
||||
r.Problems = append(r.Problems, Problem{Level: Warn, Fabric: ph.Declared[0], Message: fmt.Sprintf(
|
||||
"%s are one fabric (%s): a replica could use all of them, but each name is placed on alone",
|
||||
strings.Join(ph.Declared, " and "), ph.Label)})
|
||||
}
|
||||
r.Physical = append(r.Physical, *ph)
|
||||
}
|
||||
sort.Slice(r.Physical, func(i, j int) bool {
|
||||
a, b := r.Physical[i], r.Physical[j]
|
||||
if na, nb := first(a.Declared), first(b.Declared); na != nb {
|
||||
return na < nb
|
||||
}
|
||||
return a.Key < b.Key
|
||||
})
|
||||
|
||||
// Separate InfiniBand fabrics on one subnet prefix: harmless while they
|
||||
// stay apart, and the reason their GIDs cannot tell them apart.
|
||||
byPrefix := map[string][]string{}
|
||||
for _, ph := range r.Physical {
|
||||
if ph.Kind == "infiniband" && ph.GIDPrefix != "" {
|
||||
byPrefix[ph.GIDPrefix] = append(byPrefix[ph.GIDPrefix], ph.Label)
|
||||
}
|
||||
}
|
||||
for prefix, labels := range byPrefix {
|
||||
if len(labels) > 1 {
|
||||
r.Problems = append(r.Problems, Problem{Level: Info, Message: fmt.Sprintf(
|
||||
"%d separate fabrics share the subnet prefix %s; that is the default, and fine while they stay apart — a distinct subnet_prefix per subnet manager makes their GIDs unique",
|
||||
len(labels), prefix)})
|
||||
}
|
||||
}
|
||||
for decl, why := range r.Unverified {
|
||||
r.Problems = append(r.Problems, Problem{Level: Info, Fabric: decl, Message: fmt.Sprintf(
|
||||
"%s cannot be checked on every node: %s", decl, strings.Join(why, "; "))})
|
||||
}
|
||||
|
||||
sort.SliceStable(r.Problems, func(i, j int) bool {
|
||||
if li, lj := rank(r.Problems[i].Level), rank(r.Problems[j].Level); li != lj {
|
||||
return li < lj
|
||||
}
|
||||
return r.Problems[i].Message < r.Problems[j].Message
|
||||
})
|
||||
return r
|
||||
}
|
||||
|
||||
func rank(l Level) int {
|
||||
switch l {
|
||||
case Fail:
|
||||
return 0
|
||||
case Warn:
|
||||
return 1
|
||||
}
|
||||
return 2
|
||||
}
|
||||
|
||||
func first(s []string) string {
|
||||
if len(s) == 0 {
|
||||
return "~" // undeclared last
|
||||
}
|
||||
return s[0]
|
||||
}
|
||||
|
||||
func appendOnce(s []string, v string) []string {
|
||||
if slices.Contains(s, v) {
|
||||
return s
|
||||
}
|
||||
return append(s, v)
|
||||
}
|
||||
|
||||
func sortedKeys[V any](m map[string]V) []string {
|
||||
out := make([]string, 0, len(m))
|
||||
for k := range m {
|
||||
out = append(out, k)
|
||||
}
|
||||
sort.Strings(out)
|
||||
return out
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package fabrics
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/control/inventory"
|
||||
)
|
||||
|
||||
func ibNode(id, declared, sm string, hcas ...string) inventory.Node {
|
||||
n := inventory.Node{ID: id}
|
||||
if declared != "" {
|
||||
n.Fabrics = []inventory.FabricAttachment{{Fabric: declared, HCAs: hcas}}
|
||||
}
|
||||
for _, h := range hcas {
|
||||
n.IBPorts = append(n.IBPorts, inventory.IBPort{HCA: h, Port: 1, State: "ACTIVE", RateGbps: 400,
|
||||
LinkLayer: "InfiniBand", SMGUID: sm, SMLID: 1, GIDPrefix: "fe80:0000:0000:0000"})
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func problem(t *testing.T, r Report, l Level, fragment string) {
|
||||
t.Helper()
|
||||
for _, p := range r.Problems {
|
||||
if p.Level == l && strings.Contains(p.Message, fragment) {
|
||||
return
|
||||
}
|
||||
}
|
||||
t.Errorf("no %s problem containing %q in %+v", l, fragment, r.Problems)
|
||||
}
|
||||
|
||||
func TestIndependentFabricsWithTheirOwnNamesAreFine(t *testing.T) {
|
||||
r := Analyze([]inventory.Node{
|
||||
ibNode("a1", "ib-a", "0x01", "mlx5_0"), ibNode("a2", "ib-a", "0x01", "mlx5_0"),
|
||||
ibNode("b1", "ib-b", "0x02", "mlx5_0"),
|
||||
})
|
||||
if len(r.Physical) != 2 {
|
||||
t.Fatalf("physical = %+v", r.Physical)
|
||||
}
|
||||
if r.Physical[0].Declared[0] != "ib-a" || len(r.Physical[0].Members) != 2 || r.Physical[0].SM.GUID != "0x01" {
|
||||
t.Errorf("ib-a = %+v", r.Physical[0])
|
||||
}
|
||||
for _, p := range r.Problems {
|
||||
if p.Level != Info {
|
||||
t.Errorf("unexpected problem: %+v", p)
|
||||
}
|
||||
}
|
||||
// Both on the default prefix: said, quietly.
|
||||
problem(t, r, Info, "share the subnet prefix")
|
||||
}
|
||||
|
||||
func TestOneNameOnTwoFabricsIsAFailure(t *testing.T) {
|
||||
r := Analyze([]inventory.Node{
|
||||
ibNode("a1", "ib-a", "0x01", "mlx5_0"), ibNode("b1", "ib-a", "0x02", "mlx5_0"),
|
||||
})
|
||||
problem(t, r, Fail, "ib-a is 2 separate fabrics")
|
||||
}
|
||||
|
||||
func TestTwoNamesOnOneFabricAreSaid(t *testing.T) {
|
||||
r := Analyze([]inventory.Node{
|
||||
ibNode("a1", "ib-a", "0x01", "mlx5_0"), ibNode("b1", "ib-b", "0x01", "mlx5_0"),
|
||||
})
|
||||
problem(t, r, Warn, "ib-a and ib-b are one fabric")
|
||||
}
|
||||
|
||||
func TestAnAdapterUpButUndeclaredIsSaid(t *testing.T) {
|
||||
n := ibNode("a1", "ib-a", "0x01", "mlx5_0")
|
||||
n.IBPorts = append(n.IBPorts, inventory.IBPort{HCA: "mlx5_3", Port: 1, State: "ACTIVE", LinkLayer: "InfiniBand", SMGUID: "0x09"})
|
||||
problem(t, Analyze([]inventory.Node{n}), Warn, "mlx5_3 is up on subnet manager 0x09")
|
||||
}
|
||||
|
||||
func TestOneNodesAdaptersOnTwoFabricsAreAFailure(t *testing.T) {
|
||||
n := ibNode("x", "ib-a", "0x01", "mlx5_0", "mlx5_1")
|
||||
n.IBPorts[1].SMGUID = "0x02"
|
||||
problem(t, Analyze([]inventory.Node{n}), Fail, "cabled to 2 different fabrics")
|
||||
}
|
||||
|
||||
func TestANodeThatCannotSayIsReported(t *testing.T) {
|
||||
n := ibNode("x", "ib-a", "", "mlx5_0")
|
||||
n.IBPorts[0].SMError = "sminfo not found: install infiniband-diags"
|
||||
problem(t, Analyze([]inventory.Node{n}), Info, "install infiniband-diags")
|
||||
}
|
||||
|
||||
func TestRoCEIsItsNetwork(t *testing.T) {
|
||||
n := inventory.Node{ID: "r1", Fabrics: []inventory.FabricAttachment{{Fabric: "roce-a", HCAs: []string{"mlx5_0"}}},
|
||||
IBPorts: []inventory.IBPort{{HCA: "mlx5_0", Port: 1, State: "ACTIVE", LinkLayer: "Ethernet", Network: "10.8.0.0/24"}}}
|
||||
r := Analyze([]inventory.Node{n})
|
||||
if len(r.Physical) != 1 || r.Physical[0].Kind != "roce" || r.Physical[0].Label != "RoCE 10.8.0.0/24" {
|
||||
t.Errorf("physical = %+v", r.Physical)
|
||||
}
|
||||
}
|
||||
@@ -120,7 +120,7 @@ type Node struct {
|
||||
IBPorts []IBPort `json:"-"`
|
||||
}
|
||||
|
||||
// IBPort is one port's state and cumulative counters.
|
||||
// IBPort is one port's state, identity and cumulative counters.
|
||||
type IBPort struct {
|
||||
HCA string
|
||||
Port int
|
||||
@@ -129,11 +129,64 @@ type IBPort struct {
|
||||
RateGbps int
|
||||
LinkLayer string
|
||||
Counters map[string]uint64
|
||||
|
||||
NodeGUID string
|
||||
PortGUID string
|
||||
GIDPrefix string
|
||||
// SMGUID and the rest are the master subnet manager this port sees;
|
||||
// SMError says why they are empty on an active InfiniBand port.
|
||||
SMGUID string
|
||||
SMLID int
|
||||
SMPriority int
|
||||
SMState string
|
||||
SMError string
|
||||
// Network is a RoCE port's IP network.
|
||||
Network string
|
||||
}
|
||||
|
||||
// Active reports whether the port can carry traffic.
|
||||
func (p IBPort) Active() bool { return strings.EqualFold(p.State, "ACTIVE") }
|
||||
|
||||
// RoCE reports whether the port is Ethernet carrying RDMA.
|
||||
func (p IBPort) RoCE() bool { return strings.EqualFold(p.LinkLayer, "Ethernet") }
|
||||
|
||||
// FabricKey names the physical fabric the port is on: its master subnet
|
||||
// manager on InfiniBand, its IP network on RoCE. Empty when not known, and
|
||||
// for a port that is not up.
|
||||
func (p IBPort) FabricKey() string {
|
||||
if !p.Active() {
|
||||
return ""
|
||||
}
|
||||
switch {
|
||||
case p.RoCE() && p.Network != "":
|
||||
return "roce:" + p.Network
|
||||
case !p.RoCE() && p.SMGUID != "":
|
||||
return "sm:" + p.SMGUID
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// PhysicalFabric is the physical fabric this node's adapters for a declared
|
||||
// fabric are on. Known is false when none of them says; ok is false when
|
||||
// they disagree — two adapters declared as one fabric that are cabled to two.
|
||||
func (n Node) PhysicalFabric(fabric string) (key string, known, ok bool) {
|
||||
hcas := n.HCAsFor(fabric)
|
||||
for _, p := range n.IBPorts {
|
||||
if !slices.Contains(hcas, p.HCA) {
|
||||
continue
|
||||
}
|
||||
k := p.FabricKey()
|
||||
if k == "" {
|
||||
continue
|
||||
}
|
||||
if key != "" && k != key {
|
||||
return "", true, false
|
||||
}
|
||||
key = k
|
||||
}
|
||||
return key, key != "", true
|
||||
}
|
||||
|
||||
// Load is a node's use of its CPU and memory, and each engine's share.
|
||||
type Load struct {
|
||||
At time.Time
|
||||
|
||||
@@ -247,52 +247,113 @@ func (s *Scheduler) placeMultiNode(p Profile, avoid []string) (*Placement, []Rej
|
||||
}
|
||||
|
||||
for _, fabric := range fabrics {
|
||||
pool := fabric + "/" + p.classLabel()
|
||||
candidates := s.eligibleNodes(p, fabric, avoid, &rejections)
|
||||
|
||||
if len(candidates) < p.Nodes {
|
||||
rejections = append(rejections, Rejection{
|
||||
Profile: p.Name, Pool: pool,
|
||||
Reason: fmt.Sprintf("needs %d nodes, only %d qualify", p.Nodes, len(candidates)),
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
||||
// Prefer the emptiest nodes for multi-node work: a replica spanning
|
||||
// nodes is the least movable thing in the cluster, so give it the
|
||||
// cleanest machines rather than squeezing it into the gaps.
|
||||
sort.SliceStable(candidates, func(i, j int) bool {
|
||||
return len(candidates[i].free) > len(candidates[j].free)
|
||||
})
|
||||
|
||||
assignments := make([]NodeAssignment, 0, p.Nodes)
|
||||
for rank, c := range candidates[:p.Nodes] {
|
||||
gpus := s.pickGPUs(c.node, c.free, p.GPUsPerNode, c.node.HCAsFor(fabric))
|
||||
if gpus == nil {
|
||||
assignments = nil
|
||||
rejections = append(rejections, Rejection{
|
||||
Profile: p.Name, Pool: pool, Node: c.node.ID,
|
||||
Reason: fmt.Sprintf("no usable set of %d GPUs", p.GPUsPerNode),
|
||||
})
|
||||
break
|
||||
all := s.eligibleNodes(p, fabric, avoid, &rejections)
|
||||
for _, group := range physicalGroups(fabric, all, p, &rejections) {
|
||||
pool := fabric + "/" + p.classLabel()
|
||||
if group.key != "" && group.split {
|
||||
pool = fabric + "@" + shortKey(group.key) + "/" + p.classLabel()
|
||||
}
|
||||
if pl := s.placeOnFabric(p, fabric, pool, group.nodes, &rejections); pl != nil {
|
||||
return pl, rejections
|
||||
}
|
||||
assignments = append(assignments, NodeAssignment{
|
||||
NodeID: c.node.ID,
|
||||
Rank: rank,
|
||||
GPUIndices: gpus,
|
||||
// Only this fabric's adapters, never the node's others.
|
||||
HCAs: c.node.HCAsFor(fabric),
|
||||
})
|
||||
}
|
||||
if assignments == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
return &Placement{Profile: p, Fabric: fabric, Pool: pool, Nodes: assignments}, rejections
|
||||
}
|
||||
return nil, rejections
|
||||
}
|
||||
|
||||
// fabricGroup is the candidates on one physical fabric.
|
||||
type fabricGroup struct {
|
||||
key string
|
||||
nodes []candidate
|
||||
// split is set when the declared fabric turned out to be several.
|
||||
split bool
|
||||
}
|
||||
|
||||
// physicalGroups divides a declared fabric's candidates by the physical
|
||||
// fabric their adapters are on.
|
||||
//
|
||||
// A fabric's name is what an operator typed, and two separate fabrics given
|
||||
// one name would have had a replica spread across both: it starts, and hangs
|
||||
// on its first collective, since nothing routes between them. Grouped by the
|
||||
// subnet manager each node's ports see (by IP network on RoCE), a replica
|
||||
// stays on one. Nodes that do not say — an agent without infiniband-diags —
|
||||
// are a group of their own rather than trusted to join one that does.
|
||||
func physicalGroups(fabric string, cands []candidate, p Profile, rejections *[]Rejection) []fabricGroup {
|
||||
by := map[string][]candidate{}
|
||||
for _, c := range cands {
|
||||
key, _, ok := c.node.PhysicalFabric(fabric)
|
||||
if !ok {
|
||||
*rejections = append(*rejections, Rejection{
|
||||
Profile: p.Name, Pool: fabric + "/" + p.classLabel(), Node: c.node.ID,
|
||||
Reason: "its adapters declared as " + fabric + " are cabled to different fabrics",
|
||||
})
|
||||
continue
|
||||
}
|
||||
by[key] = append(by[key], c)
|
||||
}
|
||||
out := make([]fabricGroup, 0, len(by))
|
||||
for k, v := range by {
|
||||
out = append(out, fabricGroup{key: k, nodes: v, split: len(by) > 1})
|
||||
}
|
||||
// Largest first, then by key, so the choice is the same every time.
|
||||
sort.Slice(out, func(i, j int) bool {
|
||||
if len(out[i].nodes) != len(out[j].nodes) {
|
||||
return len(out[i].nodes) > len(out[j].nodes)
|
||||
}
|
||||
return out[i].key < out[j].key
|
||||
})
|
||||
return out
|
||||
}
|
||||
|
||||
// shortKey is a physical fabric's key as a pool name carries it.
|
||||
func shortKey(k string) string {
|
||||
if i := strings.IndexByte(k, ':'); i >= 0 {
|
||||
k = k[i+1:]
|
||||
}
|
||||
if len(k) > 10 && strings.HasPrefix(k, "0x") {
|
||||
return "sm-" + k[len(k)-6:]
|
||||
}
|
||||
return k
|
||||
}
|
||||
|
||||
// placeOnFabric forms a replica from candidates that share one fabric.
|
||||
func (s *Scheduler) placeOnFabric(p Profile, fabric, pool string, candidates []candidate, rejections *[]Rejection) *Placement {
|
||||
if len(candidates) < p.Nodes {
|
||||
*rejections = append(*rejections, Rejection{
|
||||
Profile: p.Name, Pool: pool,
|
||||
Reason: fmt.Sprintf("needs %d nodes, only %d qualify", p.Nodes, len(candidates)),
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
// Prefer the emptiest nodes for multi-node work: a replica spanning
|
||||
// nodes is the least movable thing in the cluster, so give it the
|
||||
// cleanest machines rather than squeezing it into the gaps.
|
||||
sort.SliceStable(candidates, func(i, j int) bool {
|
||||
return len(candidates[i].free) > len(candidates[j].free)
|
||||
})
|
||||
|
||||
assignments := make([]NodeAssignment, 0, p.Nodes)
|
||||
for rank, c := range candidates[:p.Nodes] {
|
||||
gpus := s.pickGPUs(c.node, c.free, p.GPUsPerNode, c.node.HCAsFor(fabric))
|
||||
if gpus == nil {
|
||||
*rejections = append(*rejections, Rejection{
|
||||
Profile: p.Name, Pool: pool, Node: c.node.ID,
|
||||
Reason: fmt.Sprintf("no usable set of %d GPUs", p.GPUsPerNode),
|
||||
})
|
||||
return nil
|
||||
}
|
||||
assignments = append(assignments, NodeAssignment{
|
||||
NodeID: c.node.ID,
|
||||
Rank: rank,
|
||||
GPUIndices: gpus,
|
||||
// Only this fabric's adapters, never the node's others.
|
||||
HCAs: c.node.HCAsFor(fabric),
|
||||
})
|
||||
}
|
||||
return &Placement{Profile: p, Fabric: fabric, Pool: pool, Nodes: assignments}
|
||||
}
|
||||
|
||||
// candidate is a node that passed the hard constraints.
|
||||
type candidate struct {
|
||||
node inventory.Node
|
||||
|
||||
@@ -888,3 +888,73 @@ func TestWithoutTopologyItIsTheLowestIndices(t *testing.T) {
|
||||
t.Errorf("chose %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
// onSM puts a node's declared adapters on the fabric a subnet manager runs.
|
||||
func onSM(n inventory.Node, sm string) inventory.Node {
|
||||
for _, f := range n.Fabrics {
|
||||
for _, h := range f.HCAs {
|
||||
n.IBPorts = append(n.IBPorts, inventory.IBPort{HCA: h, Port: 1, State: "ACTIVE",
|
||||
LinkLayer: "InfiniBand", SMGUID: sm})
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func TestTwoFabricsGivenOneNameAreNeverSpanned(t *testing.T) {
|
||||
// Somebody named two separate fabrics ib-a. Each has two free nodes; the
|
||||
// replica needs three. Spread across both it would start and hang on its
|
||||
// first collective, since nothing routes between them.
|
||||
st := store(
|
||||
onSM(node("a1", "h100-80g", 8, "ib-a"), "0x01"), onSM(node("a2", "h100-80g", 8, "ib-a"), "0x01"),
|
||||
onSM(node("b1", "h100-80g", 8, "ib-a"), "0x02"), onSM(node("b2", "h100-80g", 8, "ib-a"), "0x02"),
|
||||
)
|
||||
res := New(st).Place([]Profile{{Name: "big", GPUClass: "h100-80g", GPUsPerNode: 8, Nodes: 3}}, nil)
|
||||
if res.Placement != nil {
|
||||
t.Fatalf("placed across two physical fabrics: %+v", res.Placement.Nodes)
|
||||
}
|
||||
if !strings.Contains(res.Explain(), "ib-a@") {
|
||||
t.Errorf("the explanation should name the physical fabrics:\n%s", res.Explain())
|
||||
}
|
||||
|
||||
// Two nodes fit on either; they come from one.
|
||||
res = New(st).Place([]Profile{{Name: "pair", GPUClass: "h100-80g", GPUsPerNode: 8, Nodes: 2}}, nil)
|
||||
if res.Placement == nil {
|
||||
t.Fatalf("no placement:\n%s", res.Explain())
|
||||
}
|
||||
first := res.Placement.Nodes[0].NodeID[0]
|
||||
for _, a := range res.Placement.Nodes {
|
||||
if a.NodeID[0] != first {
|
||||
t.Errorf("a pair spans fabrics: %+v", res.Placement.Nodes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestANodeThatDoesNotSayIsNotTrustedToJoin(t *testing.T) {
|
||||
// Without infiniband-diags a node cannot say which fabric it is on. It is
|
||||
// kept apart from nodes that can, rather than assumed to be with them.
|
||||
st := store(
|
||||
onSM(node("a1", "h100-80g", 8, "ib-a"), "0x01"),
|
||||
node("u1", "h100-80g", 8, "ib-a"),
|
||||
)
|
||||
if res := New(st).Place([]Profile{{Name: "pair", GPUClass: "h100-80g", GPUsPerNode: 8, Nodes: 2}}, nil); res.Placement != nil {
|
||||
t.Errorf("a node of unknown fabric was paired with one of known: %+v", res.Placement.Nodes)
|
||||
}
|
||||
// Where no node says, the declared name is all there is, as before.
|
||||
st = store(node("u1", "h100-80g", 8, "ib-a"), node("u2", "h100-80g", 8, "ib-a"))
|
||||
if res := New(st).Place([]Profile{{Name: "pair", GPUClass: "h100-80g", GPUsPerNode: 8, Nodes: 2}}, nil); res.Placement == nil {
|
||||
t.Errorf("no placement:\n%s", res.Explain())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdaptersOfOneDeclaredFabricOnTwoAreRefused(t *testing.T) {
|
||||
n := node("x", "h100-80g", 8, "ib-a")
|
||||
n.IBPorts = []inventory.IBPort{
|
||||
{HCA: "mlx5_0", Port: 1, State: "ACTIVE", LinkLayer: "InfiniBand", SMGUID: "0x01"},
|
||||
{HCA: "mlx5_1", Port: 1, State: "ACTIVE", LinkLayer: "InfiniBand", SMGUID: "0x02"},
|
||||
}
|
||||
res := New(store(n, onSM(node("y", "h100-80g", 8, "ib-a"), "0x01"))).Place(
|
||||
[]Profile{{Name: "pair", GPUClass: "h100-80g", GPUsPerNode: 8, Nodes: 2}}, nil)
|
||||
if res.Placement != nil || !strings.Contains(res.Explain(), "cabled to different fabrics") {
|
||||
t.Errorf("expected a refusal naming the cabling:\n%s", res.Explain())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user