2024-04-11 23:04:30 +02:00
|
|
|
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
2022-09-07 12:24:45 +02:00
|
|
|
// All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package schema
|
|
|
|
|
2023-04-06 18:09:36 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
)
|
2022-09-07 12:24:45 +02:00
|
|
|
|
|
|
|
type Accelerator struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
Model string `json:"model"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Topology struct {
|
|
|
|
Node []int `json:"node"`
|
|
|
|
Socket [][]int `json:"socket"`
|
|
|
|
MemoryDomain [][]int `json:"memoryDomain"`
|
2023-03-22 19:21:11 +01:00
|
|
|
Die [][]*int `json:"die,omitempty"`
|
2022-09-07 12:24:45 +02:00
|
|
|
Core [][]int `json:"core"`
|
2023-03-22 19:21:11 +01:00
|
|
|
Accelerators []*Accelerator `json:"accelerators,omitempty"`
|
2022-09-07 12:24:45 +02:00
|
|
|
}
|
|
|
|
|
2023-03-10 12:13:40 +01:00
|
|
|
type MetricValue struct {
|
|
|
|
Unit Unit `json:"unit"`
|
|
|
|
Value float64 `json:"value"`
|
|
|
|
}
|
|
|
|
|
2022-09-07 12:24:45 +02:00
|
|
|
type SubCluster struct {
|
2024-07-02 10:13:11 +02:00
|
|
|
Name string `json:"name"`
|
|
|
|
Nodes string `json:"nodes"`
|
|
|
|
ProcessorType string `json:"processorType"`
|
|
|
|
Topology Topology `json:"topology"`
|
|
|
|
FlopRateScalar MetricValue `json:"flopRateScalar"`
|
|
|
|
FlopRateSimd MetricValue `json:"flopRateSimd"`
|
|
|
|
MemoryBandwidth MetricValue `json:"memoryBandwidth"`
|
|
|
|
MetricConfig []MetricConfig `json:"metricConfig,omitempty"`
|
|
|
|
Footprint []string `json:"footprint,omitempty"`
|
|
|
|
SocketsPerNode int `json:"socketsPerNode"`
|
|
|
|
CoresPerSocket int `json:"coresPerSocket"`
|
|
|
|
ThreadsPerCore int `json:"threadsPerCore"`
|
2022-09-07 12:24:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type SubClusterConfig struct {
|
2024-06-28 16:48:10 +02:00
|
|
|
Name string `json:"name"`
|
|
|
|
Peak float64 `json:"peak"`
|
|
|
|
Normal float64 `json:"normal"`
|
|
|
|
Caution float64 `json:"caution"`
|
|
|
|
Alert float64 `json:"alert"`
|
|
|
|
Footprint bool `json:"footprint"`
|
|
|
|
Remove bool `json:"remove"`
|
2022-09-07 12:24:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type MetricConfig struct {
|
2022-10-04 10:12:35 +02:00
|
|
|
Unit Unit `json:"unit"`
|
2024-06-28 16:48:10 +02:00
|
|
|
Name string `json:"name"`
|
2022-09-07 12:24:45 +02:00
|
|
|
Scope MetricScope `json:"scope"`
|
2023-03-22 19:21:11 +01:00
|
|
|
Aggregation string `json:"aggregation"`
|
2024-06-28 16:48:10 +02:00
|
|
|
SubClusters []*SubClusterConfig `json:"subClusters,omitempty"`
|
2022-09-07 12:24:45 +02:00
|
|
|
Timestep int `json:"timestep"`
|
2023-03-22 19:21:11 +01:00
|
|
|
Peak float64 `json:"peak"`
|
|
|
|
Normal float64 `json:"normal"`
|
|
|
|
Caution float64 `json:"caution"`
|
|
|
|
Alert float64 `json:"alert"`
|
2024-06-28 16:48:10 +02:00
|
|
|
Footprint bool `json:"footprint"`
|
2022-09-07 12:24:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type Cluster struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
MetricConfig []*MetricConfig `json:"metricConfig"`
|
|
|
|
SubClusters []*SubCluster `json:"subClusters"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return a list of socket IDs given a list of hwthread IDs. Even if just one
|
|
|
|
// hwthread is in that socket, add it to the list. If no hwthreads other than
|
|
|
|
// those in the argument list are assigned to one of the sockets in the first
|
|
|
|
// return value, return true as the second value. TODO: Optimize this, there
|
|
|
|
// must be a more efficient way/algorithm.
|
|
|
|
func (topo *Topology) GetSocketsFromHWThreads(
|
2024-06-28 16:48:10 +02:00
|
|
|
hwthreads []int,
|
|
|
|
) (sockets []int, exclusive bool) {
|
2022-09-07 12:24:45 +02:00
|
|
|
socketsMap := map[int]int{}
|
|
|
|
for _, hwthread := range hwthreads {
|
|
|
|
for socket, hwthreadsInSocket := range topo.Socket {
|
|
|
|
for _, hwthreadInSocket := range hwthreadsInSocket {
|
|
|
|
if hwthread == hwthreadInSocket {
|
|
|
|
socketsMap[socket] += 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exclusive = true
|
|
|
|
hwthreadsPerSocket := len(topo.Node) / len(topo.Socket)
|
|
|
|
sockets = make([]int, 0, len(socketsMap))
|
|
|
|
for socket, count := range socketsMap {
|
|
|
|
sockets = append(sockets, socket)
|
|
|
|
exclusive = exclusive && count == hwthreadsPerSocket
|
|
|
|
}
|
|
|
|
|
|
|
|
return sockets, exclusive
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return a list of core IDs given a list of hwthread IDs. Even if just one
|
|
|
|
// hwthread is in that core, add it to the list. If no hwthreads other than
|
|
|
|
// those in the argument list are assigned to one of the cores in the first
|
|
|
|
// return value, return true as the second value. TODO: Optimize this, there
|
|
|
|
// must be a more efficient way/algorithm.
|
|
|
|
func (topo *Topology) GetCoresFromHWThreads(
|
2024-06-28 16:48:10 +02:00
|
|
|
hwthreads []int,
|
|
|
|
) (cores []int, exclusive bool) {
|
2022-09-07 12:24:45 +02:00
|
|
|
coresMap := map[int]int{}
|
|
|
|
for _, hwthread := range hwthreads {
|
|
|
|
for core, hwthreadsInCore := range topo.Core {
|
|
|
|
for _, hwthreadInCore := range hwthreadsInCore {
|
|
|
|
if hwthread == hwthreadInCore {
|
|
|
|
coresMap[core] += 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exclusive = true
|
|
|
|
hwthreadsPerCore := len(topo.Node) / len(topo.Core)
|
|
|
|
cores = make([]int, 0, len(coresMap))
|
|
|
|
for core, count := range coresMap {
|
|
|
|
cores = append(cores, core)
|
|
|
|
exclusive = exclusive && count == hwthreadsPerCore
|
|
|
|
}
|
|
|
|
|
|
|
|
return cores, exclusive
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return a list of memory domain IDs given a list of hwthread IDs. Even if
|
|
|
|
// just one hwthread is in that memory domain, add it to the list. If no
|
|
|
|
// hwthreads other than those in the argument list are assigned to one of the
|
|
|
|
// memory domains in the first return value, return true as the second value.
|
|
|
|
// TODO: Optimize this, there must be a more efficient way/algorithm.
|
|
|
|
func (topo *Topology) GetMemoryDomainsFromHWThreads(
|
2024-06-28 16:48:10 +02:00
|
|
|
hwthreads []int,
|
|
|
|
) (memDoms []int, exclusive bool) {
|
2022-09-07 12:24:45 +02:00
|
|
|
memDomsMap := map[int]int{}
|
|
|
|
for _, hwthread := range hwthreads {
|
|
|
|
for memDom, hwthreadsInmemDom := range topo.MemoryDomain {
|
|
|
|
for _, hwthreadInmemDom := range hwthreadsInmemDom {
|
|
|
|
if hwthread == hwthreadInmemDom {
|
|
|
|
memDomsMap[memDom] += 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exclusive = true
|
|
|
|
hwthreadsPermemDom := len(topo.Node) / len(topo.MemoryDomain)
|
|
|
|
memDoms = make([]int, 0, len(memDomsMap))
|
|
|
|
for memDom, count := range memDomsMap {
|
|
|
|
memDoms = append(memDoms, memDom)
|
|
|
|
exclusive = exclusive && count == hwthreadsPermemDom
|
|
|
|
}
|
|
|
|
|
|
|
|
return memDoms, exclusive
|
|
|
|
}
|
|
|
|
|
2023-04-06 18:09:36 +02:00
|
|
|
// Temporary fix to convert back from int id to string id for accelerators
|
|
|
|
func (topo *Topology) GetAcceleratorID(id int) (string, error) {
|
2023-06-01 15:26:53 +02:00
|
|
|
if id < 0 {
|
|
|
|
fmt.Printf("ID smaller than 0!\n")
|
|
|
|
return topo.Accelerators[0].ID, nil
|
|
|
|
} else if id < len(topo.Accelerators) {
|
2023-04-06 18:09:36 +02:00
|
|
|
return topo.Accelerators[id].ID, nil
|
|
|
|
} else {
|
2023-06-01 15:26:53 +02:00
|
|
|
return "", fmt.Errorf("index %d out of range", id)
|
2023-04-06 18:09:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-07 12:24:45 +02:00
|
|
|
func (topo *Topology) GetAcceleratorIDs() ([]int, error) {
|
|
|
|
accels := make([]int, 0)
|
|
|
|
for _, accel := range topo.Accelerators {
|
|
|
|
id, err := strconv.Atoi(accel.ID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
accels = append(accels, id)
|
|
|
|
}
|
|
|
|
return accels, nil
|
|
|
|
}
|