Skip to content

Commit 7a45349

Browse files
authored
Merge pull request Project-HAMi#26 from DSFans2014/feat/set_numa_info
feat: set `NetworkID`
2 parents 6b488a7 + 157198d commit 7a45349

4 files changed

Lines changed: 48 additions & 6 deletions

File tree

cmd/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"os"
2424
"syscall"
2525

26+
"github.com/Project-HAMi/HAMi/pkg/util/client"
2627
"github.com/Project-HAMi/ascend-device-plugin/internal"
2728
"github.com/Project-HAMi/ascend-device-plugin/internal/manager"
2829
"github.com/Project-HAMi/ascend-device-plugin/internal/server"
@@ -136,6 +137,7 @@ func main() {
136137
if err != nil {
137138
klog.Fatalf("init PluginServer failed, error is %v", err)
138139
}
140+
client.InitGlobalClient()
139141

140142
err = start(server)
141143
if err != nil {

config.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,23 @@ vnpus:
5757
memory: 12288
5858
aiCore: 4
5959
aiCPU: 4
60+
- chipName: 910ProB
61+
commonWord: Ascend910ProB
62+
resourceName: huawei.com/Ascend910ProB
63+
resourceMemoryName: huawei.com/Ascend910ProB-memory
64+
memoryAllocatable: 32768
65+
memoryCapacity: 32768
66+
aiCore: 30
67+
templates:
68+
- name: vir02
69+
memory: 2184
70+
aiCore: 2
71+
- name: vir04
72+
memory: 4369
73+
aiCore: 4
74+
- name: vir08
75+
memory: 8738
76+
aiCore: 8
77+
- name: vir16
78+
memory: 17476
79+
aiCore: 16

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ require (
5757
)
5858

5959
replace (
60-
github.com/Project-HAMi/HAMi v0.0.0 => github.com/Project-HAMi/HAMi v0.0.0-20250107033239-d04fc8baaad6
60+
github.com/Project-HAMi/HAMi v0.0.0 => github.com/Project-HAMi/HAMi v0.0.0-20250901013025-61c6cbe7d480
6161
huawei.com/npu-exporter/v6 => gitee.com/ascend/ascend-npu-exporter/v6 v6.0.0-RC3
6262
)

internal/server/server.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ import (
2323
"net"
2424
"os"
2525
"path"
26+
"strings"
2627
"time"
2728

29+
"github.com/Project-HAMi/HAMi/pkg/device"
2830
"github.com/Project-HAMi/HAMi/pkg/device/ascend"
2931
"github.com/Project-HAMi/HAMi/pkg/util"
3032
"github.com/Project-HAMi/HAMi/pkg/util/nodelock"
@@ -40,7 +42,8 @@ import (
4042
const (
4143
// RegisterAnnos = "hami.io/node-register-ascend"
4244
// PodAllocAnno = "huawei.com/AscendDevices"
43-
NodeLockAscend = "hami.io/mutex.lock"
45+
NodeLockAscend = "hami.io/mutex.lock"
46+
Ascend910Prefix = "Ascend910"
4447
)
4548

4649
var (
@@ -188,12 +191,19 @@ func (ps *PluginServer) registerKubelet() error {
188191
return nil
189192
}
190193

194+
func (ps *PluginServer) getDeviceNetworkID(idx int) (int, error) {
195+
if idx > 3 {
196+
return 1, nil
197+
}
198+
return 0, nil
199+
}
200+
191201
func (ps *PluginServer) registerHAMi() error {
192202
devs := ps.mgr.GetDevices()
193-
apiDevices := make([]*util.DeviceInfo, 0, len(devs))
203+
apiDevices := make([]*device.DeviceInfo, 0, len(devs))
194204
// hami currently believes that the index starts from 0 and is continuous.
195205
for i, dev := range devs {
196-
apiDevices = append(apiDevices, &util.DeviceInfo{
206+
device := &device.DeviceInfo{
197207
Index: uint(i),
198208
ID: dev.UUID,
199209
Count: int32(ps.mgr.VDeviceCount()),
@@ -202,10 +212,20 @@ func (ps *PluginServer) registerHAMi() error {
202212
Type: ps.mgr.CommonWord(),
203213
Numa: 0,
204214
Health: dev.Health,
205-
})
215+
}
216+
if strings.HasPrefix(device.Type, Ascend910Prefix) {
217+
NetworkID, err := ps.getDeviceNetworkID(i)
218+
if err != nil {
219+
return fmt.Errorf("get networkID error: %v", err)
220+
}
221+
device.CustomInfo = map[string]any{
222+
"NetworkID": NetworkID,
223+
}
224+
}
225+
apiDevices = append(apiDevices, device)
206226
}
207227
annos := make(map[string]string)
208-
annos[ps.registerAnno] = util.MarshalNodeDevices(apiDevices)
228+
annos[ps.registerAnno] = device.MarshalNodeDevices(apiDevices)
209229
annos[ps.handshakeAnno] = "Reported_" + time.Now().Add(time.Duration(*reportTimeOffset)*time.Second).Format("2006.01.02 15:04:05")
210230
node, err := util.GetNode(ps.nodeName)
211231
if err != nil {

0 commit comments

Comments
 (0)