From 87d07f14ef69061689787ddcbdbe6f2b877df6b8 Mon Sep 17 00:00:00 2001 From: james Date: Tue, 2 Jun 2026 16:48:58 +0800 Subject: [PATCH] feat: support vgpu Signed-off-by: james --- pkg/brgpu/kata.go | 13 ++++--------- pkg/brgpu/plugin.go | 2 ++ pkg/brgpu/register.go | 4 ++-- pkg/brgpu/runc.go | 2 +- pkg/utils/util.go | 2 +- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/pkg/brgpu/kata.go b/pkg/brgpu/kata.go index ceac427..9f93cf4 100644 --- a/pkg/brgpu/kata.go +++ b/pkg/brgpu/kata.go @@ -201,15 +201,10 @@ func vfDeviceDiscover() (PFDeviceInfoList, error) { } vfs = append(vfs, VFDeviceInfo{ - DeviceID: deviceID, - IOMMUGroup: iommuGroup, - Addr: vfAddr, - ResourceName: func() string { - if vfNum == 1 { - return "gpu" - } - return fmt.Sprintf("1-%d-gpu", vfNum) - }(), + DeviceID: deviceID, + IOMMUGroup: iommuGroup, + Addr: vfAddr, + ResourceName: "gpu", }) } pdl = append(pdl, PFDeviceInfo{ diff --git a/pkg/brgpu/plugin.go b/pkg/brgpu/plugin.go index cd62e0d..7499704 100644 --- a/pkg/brgpu/plugin.go +++ b/pkg/brgpu/plugin.go @@ -245,6 +245,7 @@ func (p *Plugin) ListAndWatch(e *pluginapi.Empty, s pluginapi.DevicePlugin_ListA } func (p *Plugin) Allocate(ctx context.Context, r *pluginapi.AllocateRequest) (*pluginapi.AllocateResponse, error) { + logrus.Info("Allocate") var current *v1.Pod success := false defer func() { @@ -287,6 +288,7 @@ func (p *Plugin) Allocate(ctx context.Context, r *pluginapi.AllocateRequest) (*p utils.PodAllocationFailed(GetNodeName(), current) return nil, err } + logrus.Infof("Allocate request %v", devreq) if len(devreq) != len(req.DevicesIDs) { utils.PodAllocationFailed(GetNodeName(), current) return nil, fmt.Errorf("device number not matched") diff --git a/pkg/brgpu/register.go b/pkg/brgpu/register.go index 3de8934..00d9780 100644 --- a/pkg/brgpu/register.go +++ b/pkg/brgpu/register.go @@ -65,10 +65,10 @@ func RegisterHAMiWithRawDevice(devs DevicesInfoList) error { apiDevices := make([]*utils.DeviceInfo, 0, len(devs)) // hami currently believes that the index starts from 0 and is continuous. index := 0 - for i, dev := range devs { + for _, dev := range devs { for _, ins := range dev.Instances { device := &utils.DeviceInfo{ - Index: uint(i), + Index: uint(index), ID: ins.CardID, Type: dev.Name, Health: true, diff --git a/pkg/brgpu/runc.go b/pkg/brgpu/runc.go index da06169..c7aca2f 100644 --- a/pkg/brgpu/runc.go +++ b/pkg/brgpu/runc.go @@ -263,7 +263,7 @@ func DeviceDiscover() (DevicesInfoList, error) { di.Instances = append(di.Instances, Instance{ UUID: fmt.Sprintf("%s-instance-%d", phyUUID, j), Memory: int(mem.Total), - ResourceName: fmt.Sprintf("1-%d-gpu", sviCount), + ResourceName: "gpu", CardID: cardIDFormat(id), }) } diff --git a/pkg/utils/util.go b/pkg/utils/util.go index 22dfb03..b12c88e 100644 --- a/pkg/utils/util.go +++ b/pkg/utils/util.go @@ -59,7 +59,7 @@ var ( func init() { InRequestDevices = make(map[string]string) SupportDevices = make(map[string]string) - InRequestDevices[DeviceType] = "hami.io/Biren-devices-allocated" + InRequestDevices[DeviceType] = "hami.io/Biren-devices-to-allocate" SupportDevices[DeviceType] = "hami.io/Biren-devices-allocated" }