Skip to content

Commit c2fbb42

Browse files
authored
feat(host): support Hygon DCU HAMI vdev core allocation (#25274)
1 parent 0b6c26c commit c2fbb42

27 files changed

Lines changed: 736 additions & 159 deletions

cmd/climc/shell/llm/llm_router_agent.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88

99
"yunion.io/x/jsonutils"
10+
1011
"yunion.io/x/onecloud/cmd/climc/shell"
1112
"yunion.io/x/onecloud/pkg/mcclient"
1213
modules "yunion.io/x/onecloud/pkg/mcclient/modules/llm"

pkg/aiproxy/chatlog/chatlog.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/aws/aws-sdk-go-v2/aws"
3131
"github.com/aws/aws-sdk-go-v2/credentials"
3232
"github.com/aws/aws-sdk-go-v2/service/s3"
33+
3334
"yunion.io/x/log"
3435
)
3536

pkg/aiproxy/extensions/visual/messages.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import (
2121
"strings"
2222

2323
"yunion.io/x/jsonutils"
24-
"yunion.io/x/onecloud/pkg/mcclient/auth"
2524

2625
"yunion.io/x/onecloud/pkg/aiproxy/models"
2726
"yunion.io/x/onecloud/pkg/aiproxy/providers/openai"
27+
"yunion.io/x/onecloud/pkg/mcclient/auth"
2828
)
2929

3030
var ErrVisualStreamingUnsupported = fmt.Errorf("visual extension does not support streaming")

pkg/aiproxy/extensions/visual/responses.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import (
1919
"fmt"
2020

2121
"yunion.io/x/jsonutils"
22-
"yunion.io/x/onecloud/pkg/mcclient/auth"
2322

2423
"yunion.io/x/onecloud/pkg/aiproxy/models"
2524
"yunion.io/x/onecloud/pkg/aiproxy/providers/openai"
25+
"yunion.io/x/onecloud/pkg/mcclient/auth"
2626
)
2727

2828
// ShouldHandle reports whether the Responses visual orchestration path should run.

pkg/aiproxy/ft/interactive.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"strings"
2323

2424
"golang.org/x/term"
25+
2526
"yunion.io/x/pkg/errors"
2627
)
2728

pkg/aiproxy/models/ai_providers_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"testing"
77

88
"yunion.io/x/jsonutils"
9+
910
api "yunion.io/x/onecloud/pkg/apis/aiproxy"
1011
"yunion.io/x/onecloud/pkg/cloudcommon/db"
1112
)

pkg/aiproxy/providers/registry.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@ import (
1919
"sync"
2020

2121
"yunion.io/x/onecloud/pkg/aiproxy/providerapi"
22-
api "yunion.io/x/onecloud/pkg/apis/aiproxy"
23-
// "yunion.io/x/onecloud/pkg/aiproxy/providers/aliyun" // uncommon
24-
"yunion.io/x/onecloud/pkg/aiproxy/providers/anthropic"
25-
// "yunion.io/x/onecloud/pkg/aiproxy/providers/azure" // uncommon
22+
"yunion.io/x/onecloud/pkg/aiproxy/providers/anthropic" // "yunion.io/x/onecloud/pkg/aiproxy/providers/azure" // uncommon
2623
// "yunion.io/x/onecloud/pkg/aiproxy/providers/baidu" // uncommon
2724
// "yunion.io/x/onecloud/pkg/aiproxy/providers/cohere" // uncommon
2825
"yunion.io/x/onecloud/pkg/aiproxy/providers/gemini"
2926
"yunion.io/x/onecloud/pkg/aiproxy/providers/openai"
3027
"yunion.io/x/onecloud/pkg/aiproxy/providers/vllm"
28+
api "yunion.io/x/onecloud/pkg/apis/aiproxy" // "yunion.io/x/onecloud/pkg/aiproxy/providers/aliyun" // uncommon
3129
)
3230

3331
var (

pkg/hostman/guestman/pod.go

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import (
5757
"yunion.io/x/onecloud/pkg/hostman/hostinfo"
5858
"yunion.io/x/onecloud/pkg/hostman/hostutils"
5959
"yunion.io/x/onecloud/pkg/hostman/isolated_device"
60+
"yunion.io/x/onecloud/pkg/hostman/isolated_device/container_device"
6061
_ "yunion.io/x/onecloud/pkg/hostman/isolated_device/container_device/cdi"
6162
"yunion.io/x/onecloud/pkg/hostman/options"
6263
"yunion.io/x/onecloud/pkg/hostman/storageman"
@@ -2253,7 +2254,11 @@ func (s *sPodGuestInstance) createContainer(ctx context.Context, userCred mcclie
22532254
}
22542255
ctrCfg.Devices = append(ctrCfg.Devices, ctrDevs...)
22552256
}
2256-
if err := s.getIsolatedDeviceExtraConfig(spec, ctrCfg); err != nil {
2257+
if err := func() error {
2258+
container_device.SetHygonContainerContext(s.GetId(), input.Name)
2259+
defer container_device.ClearHygonContainerContext()
2260+
return s.getIsolatedDeviceExtraConfig(spec, ctrCfg)
2261+
}(); err != nil {
22572262
return "", err
22582263
}
22592264
} else {
@@ -2447,6 +2452,38 @@ func (s *sPodGuestInstance) getIsolatedDeviceExtraConfig(spec *hostapi.Container
24472452
return nil
24482453
}
24492454

2455+
func (s *sPodGuestInstance) releaseIsolatedContainerDevices(devs []*hostapi.ContainerDevice) {
2456+
devsByMan := map[isolated_device.IContainerDeviceManager][]*hostapi.ContainerDevice{}
2457+
manOrder := []isolated_device.IContainerDeviceManager{}
2458+
for i := range devs {
2459+
dev := devs[i]
2460+
if dev.IsolatedDevice == nil {
2461+
continue
2462+
}
2463+
devType := dev.IsolatedDevice.DeviceType
2464+
if devType != computeapi.GPU_TYPE && devType != computeapi.NPU_TYPE {
2465+
continue
2466+
}
2467+
if dev.IsolatedDevice.IsCDIUsed() || len(dev.IsolatedDevice.OnlyEnv) > 0 {
2468+
continue
2469+
}
2470+
iDev := hostinfo.Instance().IsolatedDeviceMan.GetDeviceByCloudId(dev.IsolatedDevice.Id)
2471+
if iDev == nil {
2472+
continue
2473+
}
2474+
devMan := iDev.GetContainerDeviceManager()
2475+
if _, ok := devsByMan[devMan]; !ok {
2476+
manOrder = append(manOrder, devMan)
2477+
}
2478+
devsByMan[devMan] = append(devsByMan[devMan], dev)
2479+
}
2480+
for _, devMan := range manOrder {
2481+
if rel, ok := devMan.(isolated_device.IContainerDeviceReleaseManager); ok {
2482+
rel.ReleaseContainerDevices(devsByMan[devMan])
2483+
}
2484+
}
2485+
}
2486+
24502487
func (s *sPodGuestInstance) getContainerSystemCpusDir(ctrId string) string {
24512488
rootFsPath, _ := s.GetRootFsMountPath(ctrId)
24522489
if rootFsPath != "" {
@@ -2607,6 +2644,9 @@ func (s *sPodGuestInstance) ensureContainerSystemCpufreqHostDir(cpuDir, hostCpuP
26072644
}
26082645

26092646
func (s *sPodGuestInstance) DeleteContainer(ctx context.Context, userCred mcclient.TokenCredential, ctrId string) (jsonutils.JSONObject, error) {
2647+
if ctr := s.GetContainerById(ctrId); ctr != nil {
2648+
s.releaseIsolatedContainerDevices(ctr.Spec.Devices)
2649+
}
26102650
criId, err := s.getContainerCRIId(ctrId)
26112651
if err != nil && errors.Cause(err) != errors.ErrNotFound {
26122652
return nil, errors.Wrap(err, "getContainerCRIId")

pkg/hostman/hostinfo/hostinfo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,7 +2347,7 @@ func (h *SHostInfo) probeSyncIsolatedDevices() (*jsonutils.JSONArray, error) {
23472347
options.HostOptions.HostType, h.IsContainerHost(), h.IsKvmSupport())
23482348
log.Infof("==== probeSyncIsolatedDevices hygon config: enableDCU=%v enableHAMI=%v hySmiPath=%s hyhalPath=%s dtkPath=%s",
23492349
options.HostOptions.EnableContainerHygonDCU,
2350-
options.HostOptions.EnableContainerHygonDCUHAMI,
2350+
options.HostOptions.EnableContainerHygonDCUHami,
23512351
options.HostOptions.HygonHySmiPath,
23522352
options.HostOptions.HygonHyhalPath,
23532353
options.HostOptions.HygonDtkPath,
@@ -2361,7 +2361,7 @@ func (h *SHostInfo) probeSyncIsolatedDevices() (*jsonutils.JSONArray, error) {
23612361
EnableContainerAscendNpu: options.HostOptions.EnableContainerAscendNPU,
23622362
EnableContainerAscendNpuHAMI: options.HostOptions.EnableContainerAscendNPUHami,
23632363
EnableContainerHygonDCU: options.HostOptions.EnableContainerHygonDCU,
2364-
EnableContainerHygonDCUHAMI: options.HostOptions.EnableContainerHygonDCUHAMI,
2364+
EnableContainerHygonDCUHAMI: options.HostOptions.EnableContainerHygonDCUHami,
23652365
EnableWhitelist: options.HostOptions.EnableIsolatedDeviceWhitelist,
23662366
SriovNics: sriovNics,
23672367
OvsOffloadNics: offloadNics,

pkg/hostman/isolated_device/container_device.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ type IContainerDeviceManager interface {
100100
GetContainerExtraConfigures(devs []*hostapi.ContainerDevice) ([]*runtimeapi.KeyValue, []*runtimeapi.Mount)
101101
}
102102

103+
// IContainerDeviceReleaseManager is implemented by device managers that need cleanup on container delete.
104+
type IContainerDeviceReleaseManager interface {
105+
ReleaseContainerDevices(devs []*hostapi.ContainerDevice)
106+
}
107+
103108
type IContainerCDIManager interface {
104109
GetKind() apis.ContainerCDIKind
105110
GetSpecFilePath() string

0 commit comments

Comments
 (0)