Skip to content

Commit

Permalink
Standardize vertex structure with both tree and block children
Browse files Browse the repository at this point in the history
Signed-off-by: Ritika Srivastava <[email protected]>
  • Loading branch information
ritikasrivastava committed Nov 26, 2024
1 parent 43a3ff3 commit 52efde3
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 75 deletions.
2 changes: 0 additions & 2 deletions pkg/engines/k8s/labeler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

"github.com/stretchr/testify/require"

"github.com/NVIDIA/topograph/pkg/topology"
"github.com/NVIDIA/topograph/pkg/translate"
)

Expand All @@ -41,7 +40,6 @@ func (l *testLabeler) AddNodeLabels(_ context.Context, nodeName string, labels m

func TestApplyNodeLabels(t *testing.T) {
root, _ := translate.GetTreeTestSet(true)
require.Equal(t, root.Metadata[topology.KeyPlugin], topology.TopologyTree)
labeler := &testLabeler{data: make(map[string]map[string]string)}
data := map[string]map[string]string{
"Node201": {"topology.kubernetes.io/network-level-1": "S2", "topology.kubernetes.io/network-level-2": "S1"},
Expand Down
9 changes: 9 additions & 0 deletions pkg/engines/slurm/slurm.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,17 @@ func GenerateOutputParams(ctx context.Context, tree *topology.Vertex, params *Pa
plugin = tree.Metadata[topology.KeyPlugin]
}
if len(plugin) == 0 {
if tree.Vertices[topology.TopologyBlock] != nil {
plugin = topology.TopologyBlock
} else {
plugin = topology.TopologyTree
}
} else if plugin == topology.TopologyBlock && tree.Vertices[topology.TopologyBlock] == nil {
klog.Infof("Admin provided plugin %v not valid, overriding with %v", plugin, topology.TopologyTree)
plugin = topology.TopologyTree
tree.Metadata[topology.KeyPlugin] = plugin
}

if _, err := buf.WriteString(fmt.Sprintf(TopologyHeader, plugin)); err != nil {
return nil, err
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/engines/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package test
import (
"context"
"errors"
"fmt"

"github.com/NVIDIA/topograph/internal/config"
"github.com/NVIDIA/topograph/pkg/engines"
Expand Down Expand Up @@ -59,10 +58,6 @@ func (eng *TestEngine) GenerateOutput(ctx context.Context, tree *topology.Vertex
return nil, err
}

if len(tree.Metadata) == 0 {
return nil, fmt.Errorf("metadata for test engine not set")
}

if len(p.Plugin) != 0 {
tree.Metadata[topology.KeyPlugin] = p.Plugin
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/ib/ib.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ func GenerateTopologyConfig(data []byte) (*topology.Vertex, error) {
}
seen = make(map[int]map[string]*Switch)
root.simplify(root.getHeight())
rootNode, err := root.toGraph()
treeNode, err := root.toGraph()
if err != nil {
return nil, err
}
rootNode.Metadata = map[string]string{
topology.KeyPlugin: topology.TopologyTree,
rootNode := &topology.Vertex{
Vertices: make(map[string]*topology.Vertex),
}
rootNode.Vertices[topology.TopologyTree] = treeNode
return rootNode, nil
}

Expand Down
16 changes: 9 additions & 7 deletions pkg/models/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,15 @@ func (model *Model) ToGraph() (*topology.Vertex, map[string]string) {
for k, v := range blockVertexMap {
blockRoot.Vertices[k] = v
}

rootNode := &topology.Vertex{
Vertices: make(map[string]*topology.Vertex),
}

if block_topology {
root := &topology.Vertex{
Vertices: map[string]*topology.Vertex{topology.TopologyBlock: blockRoot, topology.TopologyTree: treeRoot},
Metadata: map[string]string{topology.KeyPlugin: topology.TopologyBlock},
}
return root, instance2node
rootNode.Vertices[topology.TopologyBlock] = blockRoot
}
treeRoot.Metadata = map[string]string{topology.KeyPlugin: topology.TopologyTree}
return treeRoot, instance2node

rootNode.Vertices[topology.TopologyTree] = treeRoot
return rootNode, instance2node
}
11 changes: 6 additions & 5 deletions pkg/providers/aws/instance_topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,16 @@ func toGraph(top []types.InstanceTopology, cis []topology.ComputeInstances) (*to
forest[topology.NoTopology] = sw
}

root := &topology.Vertex{
treeRoot := &topology.Vertex{
Vertices: make(map[string]*topology.Vertex),
Metadata: map[string]string{
topology.KeyPlugin: topology.TopologyTree,
},
}
for name, node := range forest {
root.Vertices[name] = node
treeRoot.Vertices[name] = node
}

root := &topology.Vertex{
Vertices: make(map[string]*topology.Vertex),
}
root.Vertices[topology.TopologyTree] = treeRoot
return root, nil
}
9 changes: 5 additions & 4 deletions pkg/providers/aws/instance_topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@ func TestNewInstanceTopology(t *testing.T) {
Vertices: map[string]*topology.Vertex{"nn-224a2a4d9df61a975": v2},
}

expected := &topology.Vertex{
v0 := &topology.Vertex{
Vertices: map[string]*topology.Vertex{"nn-098f9e7674016cb1c": v1},
Metadata: map[string]string{
topology.KeyPlugin: topology.TopologyTree,
},
}

expected := &topology.Vertex{
Vertices: map[string]*topology.Vertex{topology.TopologyTree: v0},
}

tree, err := toGraph(top, []topology.ComputeInstances{{Instances: i2n}})
Expand Down
4 changes: 0 additions & 4 deletions pkg/providers/baremetal/mnnvl.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"

"github.com/NVIDIA/topograph/internal/exec"
"github.com/NVIDIA/topograph/pkg/engines"
"github.com/NVIDIA/topograph/pkg/ib"
"github.com/NVIDIA/topograph/pkg/topology"
)
Expand Down Expand Up @@ -208,9 +207,6 @@ func toGraph(domainMap map[string]domain, treeRoot *topology.Vertex) *topology.V
}
blockRoot.Vertices[domainName] = tree
}
// add root metadata
root.Metadata[topology.KeyEngine] = engines.EngineSLURM
root.Metadata[topology.KeyPlugin] = topology.TopologyBlock
root.Vertices[topology.TopologyBlock] = blockRoot
return root
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/providers/gcp/instance_topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,17 @@ func (cfg *InstanceTopology) toGraph() (*topology.Vertex, error) {
sw1.Vertices[id2] = sw2
}

root := &topology.Vertex{
treeRoot := &topology.Vertex{
Vertices: make(map[string]*topology.Vertex),
Metadata: map[string]string{
topology.KeyPlugin: topology.TopologyTree,
},
}
for name, node := range forest {
root.Vertices[name] = node
treeRoot.Vertices[name] = node
}

root := &topology.Vertex{
Vertices: make(map[string]*topology.Vertex),
}
root.Vertices[topology.TopologyTree] = treeRoot

return root, nil
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/providers/oci/instance_topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,17 @@ func toGraph(bareMetalHostSummaries []*core.ComputeBareMetalHostSummary, cis []t
forest[topology.NoTopology] = sw
}

root := &topology.Vertex{
treeRoot := &topology.Vertex{
Vertices: make(map[string]*topology.Vertex),
Metadata: map[string]string{
topology.KeyPlugin: topology.TopologyTree,
},
}
for name, node := range forest {
root.Vertices[name] = node
treeRoot.Vertices[name] = node
}

root := &topology.Vertex{
Vertices: make(map[string]*topology.Vertex),
}
root.Vertices[topology.TopologyTree] = treeRoot
return root, nil

}
Expand Down
19 changes: 7 additions & 12 deletions pkg/server/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,24 +169,19 @@ func toGraph(response *pb.TopologyResponse, cis []topology.ComputeInstances, for
treeRoot.Vertices[name] = node
}

metadata := map[string]string{topology.KeyPlugin: format}
root := &topology.Vertex{
Vertices: make(map[string]*topology.Vertex),
}
if format == topology.TopologyBlock {
blockRoot := &topology.Vertex{
Vertices: make(map[string]*topology.Vertex),
}
for name, domain := range blocks {
blockRoot.Vertices[name] = domain
}

return &topology.Vertex{
Vertices: map[string]*topology.Vertex{
topology.TopologyBlock: blockRoot,
topology.TopologyTree: treeRoot,
},
Metadata: metadata,
}
} else {
treeRoot.Metadata = metadata
return treeRoot
root.Vertices[topology.TopologyBlock] = blockRoot
}
root.Vertices[topology.TopologyTree] = treeRoot
return root

}
1 change: 0 additions & 1 deletion pkg/server/grpc_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ func TestToGraph(t *testing.T) {
blockRoot := &topology.Vertex{Vertices: map[string]*topology.Vertex{"nvlink-nv1": nv1}}
root := &topology.Vertex{
Vertices: map[string]*topology.Vertex{topology.TopologyBlock: blockRoot, topology.TopologyTree: treeRoot},
Metadata: map[string]string{topology.KeyPlugin: topology.TopologyBlock},
}

require.Equal(t, root, toGraph(&pb.TopologyResponse{Instances: instances}, cis, topology.TopologyBlock))
Expand Down
17 changes: 4 additions & 13 deletions pkg/translate/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (

"k8s.io/klog/v2"

"github.com/NVIDIA/topograph/pkg/engines"
"github.com/NVIDIA/topograph/pkg/metrics"
"github.com/NVIDIA/topograph/pkg/topology"
)
Expand All @@ -39,7 +38,10 @@ func ToGraph(wr io.Writer, root *topology.Vertex) error {
return toTreeTopology(wr, root)
}
}
return fmt.Errorf("topology metadata not set in root node")
if root.Vertices[topology.TopologyBlock] != nil {
return toBlockTopology(wr, root)
}
return toTreeTopology(wr, root)
}

func printBlock(wr io.Writer, block *topology.Vertex, domainVisited map[string]int) error {
Expand Down Expand Up @@ -383,9 +385,6 @@ func GetTreeTestSet(testForLongLabelName bool) (*topology.Vertex, map[string]str
}
root := &topology.Vertex{
Vertices: map[string]*topology.Vertex{"S1": sw1},
Metadata: map[string]string{
topology.KeyPlugin: topology.TopologyTree,
},
}

return root, instance2node
Expand Down Expand Up @@ -477,8 +476,6 @@ func GetBlockWithMultiIBTestSet() (*topology.Vertex, map[string]string) {
root := &topology.Vertex{
Vertices: map[string]*topology.Vertex{topology.TopologyBlock: blockRoot, topology.TopologyTree: treeRoot},
Metadata: map[string]string{
topology.KeyEngine: engines.EngineSLURM,
topology.KeyPlugin: topology.TopologyBlock,
topology.KeyBlockSizes: "3",
},
}
Expand Down Expand Up @@ -531,8 +528,6 @@ func GetBlockWithIBTestSet() (*topology.Vertex, map[string]string) {
root := &topology.Vertex{
Vertices: map[string]*topology.Vertex{topology.TopologyBlock: blockRoot, topology.TopologyTree: treeRoot},
Metadata: map[string]string{
topology.KeyEngine: engines.EngineSLURM,
topology.KeyPlugin: topology.TopologyBlock,
topology.KeyBlockSizes: "3",
},
}
Expand Down Expand Up @@ -605,8 +600,6 @@ func GetBlockWithDFSIBTestSet() (*topology.Vertex, map[string]string) {
root := &topology.Vertex{
Vertices: map[string]*topology.Vertex{topology.TopologyBlock: blockRoot, topology.TopologyTree: treeRoot},
Metadata: map[string]string{
topology.KeyEngine: engines.EngineSLURM,
topology.KeyPlugin: topology.TopologyBlock,
topology.KeyBlockSizes: "1",
},
}
Expand Down Expand Up @@ -643,8 +636,6 @@ func GetBlockTestSet() (*topology.Vertex, map[string]string) {
root := &topology.Vertex{
Vertices: map[string]*topology.Vertex{topology.TopologyBlock: blockRoot},
Metadata: map[string]string{
topology.KeyEngine: engines.EngineSLURM,
topology.KeyPlugin: topology.TopologyBlock,
topology.KeyBlockSizes: "3",
},
}
Expand Down
9 changes: 0 additions & 9 deletions pkg/translate/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ SwitchName=switch.1.2 Nodes=node-2

func TestToTreeTopology(t *testing.T) {
v, _ := GetTreeTestSet(false)
require.Equal(t, v.Metadata[topology.KeyPlugin], topology.TopologyTree)
buf := &bytes.Buffer{}
err := ToGraph(buf, v)
require.NoError(t, err)
Expand All @@ -72,7 +71,6 @@ func TestToTreeTopology(t *testing.T) {

func TestToBlockTopology(t *testing.T) {
v, _ := GetBlockTestSet()
require.Equal(t, v.Metadata[topology.KeyPlugin], topology.TopologyBlock)
buf := &bytes.Buffer{}
err := ToGraph(buf, v)
require.NoError(t, err)
Expand All @@ -81,7 +79,6 @@ func TestToBlockTopology(t *testing.T) {

func TestToBlockMultiIBTopology(t *testing.T) {
v, _ := GetBlockWithMultiIBTestSet()
require.Equal(t, v.Metadata[topology.KeyPlugin], topology.TopologyBlock)
buf := &bytes.Buffer{}
err := ToGraph(buf, v)
require.NoError(t, err)
Expand All @@ -95,7 +92,6 @@ func TestToBlockMultiIBTopology(t *testing.T) {

func TestToBlockIBTopology(t *testing.T) {
v, _ := GetBlockWithIBTestSet()
require.Equal(t, v.Metadata[topology.KeyPlugin], topology.TopologyBlock)
buf := &bytes.Buffer{}
err := ToGraph(buf, v)
require.NoError(t, err)
Expand All @@ -109,7 +105,6 @@ func TestToBlockIBTopology(t *testing.T) {

func TestToBlockDFSIBTopology(t *testing.T) {
v, _ := GetBlockWithDFSIBTestSet()
require.Equal(t, v.Metadata[topology.KeyPlugin], topology.TopologyBlock)
buf := &bytes.Buffer{}
err := ToGraph(buf, v)
require.NoError(t, err)
Expand Down Expand Up @@ -163,12 +158,8 @@ func TestToSlurmNameShortener(t *testing.T) {
},
},
},
Metadata: map[string]string{
topology.KeyPlugin: topology.TopologyTree,
},
}

require.Equal(t, v.Metadata[topology.KeyPlugin], topology.TopologyTree)
buf := &bytes.Buffer{}
err := ToGraph(buf, v)
require.NoError(t, err)
Expand Down

0 comments on commit 52efde3

Please sign in to comment.