From 4332b302719a97738e4b9da76bb5226bdd1da5ae Mon Sep 17 00:00:00 2001 From: Sinan KARAKAYA Date: Tue, 21 Apr 2026 15:44:56 +0200 Subject: [PATCH 1/4] feat(hardware_info): Add support for Qualcomm NPU devices and FastRPC bus Introduce the FastRPC bus type and restrict it to NPU devices. Add Qualcomm hardware detection by checking for fastrpc nodes. Include NodeGlob field for NPU devices and update disk info gathering to silently skip nonexistent directories. Signed-off-by: Sinan KARAKAYA --- pkg/engines/busses.go | 31 +++++++ pkg/engines/busses_test.go | 9 ++ pkg/engines/devices_test.go | 23 +++++ pkg/engines/types.go | 4 +- pkg/hardware_info/disk/disk_info.go | 9 ++ pkg/hardware_info/hardware-info.go | 24 ++++++ pkg/hardware_info/qualcomm/qualcomm.go | 94 +++++++++++++++++++++ pkg/hardware_info/qualcomm/qualcomm_test.go | 86 +++++++++++++++++++ pkg/selector/fastrpc/fastrpc.go | 58 +++++++++++++ pkg/selector/fastrpc/fastrpc_test.go | 50 +++++++++++ pkg/selector/fastrpc_test.go | 52 ++++++++++++ pkg/selector/select_stack.go | 19 +++++ pkg/types/detected_devices.go | 12 +++ pkg/types/hw_info.go | 2 + 14 files changed, 471 insertions(+), 2 deletions(-) create mode 100644 pkg/hardware_info/qualcomm/qualcomm.go create mode 100644 pkg/hardware_info/qualcomm/qualcomm_test.go create mode 100644 pkg/selector/fastrpc/fastrpc.go create mode 100644 pkg/selector/fastrpc/fastrpc_test.go create mode 100644 pkg/selector/fastrpc_test.go create mode 100644 pkg/types/detected_devices.go diff --git a/pkg/engines/busses.go b/pkg/engines/busses.go index 1f2b2869..46f79c80 100644 --- a/pkg/engines/busses.go +++ b/pkg/engines/busses.go @@ -12,6 +12,8 @@ func (device Device) validateBus(extraFields []string) error { return device.validatePci(extraFields) case "usb": return device.validateUsb(extraFields) + case "fastrpc": + return device.validateFastRpc(extraFields) case "": // default to pci bus return device.validatePci(extraFields) default: @@ -49,3 +51,32 @@ func (device Device) validatePci(extraFields []string) error { return nil } + +func (device Device) validateFastRpc(extraFields []string) error { + if device.Type != "" && device.Type != "npu" { + return fmt.Errorf("fastrpc bus only supports npu devices") + } + + validFields := []string{ + "Type", + "Bus", + "NodeGlob", + "SnapConnections", + } + validFields = append(validFields, extraFields...) + + t := reflect.TypeOf(device) + v := reflect.ValueOf(device) + + for i := 0; i < t.NumField(); i++ { + fieldName := t.Field(i).Name + fieldValue := v.FieldByName(fieldName) + if fieldValue.IsValid() && !fieldValue.IsZero() { + if !slices.Contains(validFields, fieldName) { + return fmt.Errorf("fastrpc: invalid field: %s", fieldName) + } + } + } + + return nil +} diff --git a/pkg/engines/busses_test.go b/pkg/engines/busses_test.go index a8abd686..6155aa99 100644 --- a/pkg/engines/busses_test.go +++ b/pkg/engines/busses_test.go @@ -42,4 +42,13 @@ func TestDeviceBus(t *testing.T) { } t.Log(err) }) + + t.Run("FastRPC bus with non-NPU type", func(t *testing.T) { + device.Bus = "fastrpc" + err := device.validate() + if err == nil { + t.Fatal("FastRPC bus should be invalid for GPU type") + } + t.Log(err) + }) } diff --git a/pkg/engines/devices_test.go b/pkg/engines/devices_test.go index 168b3565..5531036b 100644 --- a/pkg/engines/devices_test.go +++ b/pkg/engines/devices_test.go @@ -130,6 +130,29 @@ func TestDeviceNpu(t *testing.T) { } t.Log(err) }) + + t.Run("NPU fastrpc valid fields", func(t *testing.T) { + device = Device{Type: "npu", Bus: "fastrpc"} + nodeGlob := "/dev/fastrpc-cdsp*" + device.NodeGlob = &nodeGlob + + err := device.validate() + if err != nil { + t.Fatalf("NPU fastrpc fields should be valid: %v", err) + } + }) + + t.Run("NPU fastrpc invalid fields", func(t *testing.T) { + device = Device{Type: "npu", Bus: "fastrpc"} + hexValue := types.HexInt(0xAA) + device.VendorId = &hexValue + + err := device.validate() + if err == nil { + t.Fatal("NPU fastrpc fields should be invalid") + } + t.Log(err) + }) } func TestDeviceTypeless(t *testing.T) { diff --git a/pkg/engines/types.go b/pkg/engines/types.go index 803c120a..05c7da14 100644 --- a/pkg/engines/types.go +++ b/pkg/engines/types.go @@ -45,7 +45,7 @@ type Devices struct { type Device struct { // General Type string `yaml:"type,omitempty" json:"type,omitempty"` // cpu, gpu, npu or nil - Bus string `yaml:"bus,omitempty" json:"bus,omitempty"` // pci, usb or nil + Bus string `yaml:"bus,omitempty" json:"bus,omitempty"` // pci, usb, fastrpc or nil // CPUs Architecture *string `yaml:"architecture,omitempty" json:"architecture,omitempty"` @@ -69,7 +69,7 @@ type Device struct { ComputeCapability *string `yaml:"compute-capability,omitempty" json:"compute-capability,omitempty"` // NPU - // no additional properties for now + NodeGlob *string `yaml:"node-glob,omitempty" json:"node-glob,omitempty"` // Drivers SnapConnections []string `yaml:"snap-connections,omitempty" json:"snap-connections,omitempty"` diff --git a/pkg/hardware_info/disk/disk_info.go b/pkg/hardware_info/disk/disk_info.go index 1781be2a..7858efde 100644 --- a/pkg/hardware_info/disk/disk_info.go +++ b/pkg/hardware_info/disk/disk_info.go @@ -2,6 +2,7 @@ package disk import ( "fmt" + "os" "github.com/canonical/inference-snaps-cli/pkg/constants" "github.com/canonical/inference-snaps-cli/pkg/types" @@ -16,6 +17,14 @@ func Info() (map[string]types.DirStats, error) { var info = make(map[string]types.DirStats) for _, dir := range directories { + // Skip directories that don't exist + if _, err := os.Stat(dir); err != nil { + if os.IsNotExist(err) { + continue + } + return nil, fmt.Errorf("checking directory %s: %v", dir, err) + } + dirInfo, err := statFs(dir) if err != nil { return nil, fmt.Errorf("getting directory info for %s: %v", dir, err) diff --git a/pkg/hardware_info/hardware-info.go b/pkg/hardware_info/hardware-info.go index b6e9d278..a28b01ed 100644 --- a/pkg/hardware_info/hardware-info.go +++ b/pkg/hardware_info/hardware-info.go @@ -4,12 +4,14 @@ import ( "encoding/json" "fmt" "os" + "strings" "testing" "github.com/canonical/inference-snaps-cli/pkg/hardware_info/cpu" "github.com/canonical/inference-snaps-cli/pkg/hardware_info/disk" "github.com/canonical/inference-snaps-cli/pkg/hardware_info/memory" "github.com/canonical/inference-snaps-cli/pkg/hardware_info/pci" + "github.com/canonical/inference-snaps-cli/pkg/hardware_info/qualcomm" "github.com/canonical/inference-snaps-cli/pkg/types" ) @@ -40,6 +42,13 @@ func Get(friendlyNames bool) (*types.HwInfo, error) { } hwInfo.PciDevices = pciDevices + platforms, devices, err := qualcomm.Info() + if err != nil { + return nil, fmt.Errorf("getting qualcomm devices: %v", err) + } + hwInfo.Platforms = platforms + hwInfo.Devices = devices + return &hwInfo, nil } @@ -97,6 +106,21 @@ func GetFromRawData(t *testing.T, device string, friendlyNames bool, testDir str } hwInfo.PciDevices = pciDevices + fastrpcNodesFile := devicePath + "fastrpc-nodes.txt" + if _, err := os.Stat(fastrpcNodesFile); err == nil { + nodesData, err := os.ReadFile(fastrpcNodesFile) + if err != nil { + t.Fatal(err) + } + + nodes := strings.Fields(string(nodesData)) + platforms, devices := qualcomm.DetectFromNodes(nodes) + hwInfo.Platforms = platforms + hwInfo.Devices = devices + } else if !os.IsNotExist(err) { + t.Fatalf("error checking file '%s': %v\n", fastrpcNodesFile, err) + } + // Additional properties - we append these directly from a file, as we can not run the vendor specific tools on the machine addPropsFile := devicePath + "additional-properties.json" _, err = os.Stat(addPropsFile) diff --git a/pkg/hardware_info/qualcomm/qualcomm.go b/pkg/hardware_info/qualcomm/qualcomm.go new file mode 100644 index 00000000..27ca2742 --- /dev/null +++ b/pkg/hardware_info/qualcomm/qualcomm.go @@ -0,0 +1,94 @@ +package qualcomm + +import ( + "fmt" + "path/filepath" + "sort" + "strings" + + "github.com/canonical/inference-snaps-cli/pkg/types" +) + +var devRoot = "/dev" + +func Info() ([]types.PlatformInfo, []types.DetectedDevice, error) { + fastrpcNodes, err := globSorted(filepath.Join(devRoot, "fastrpc-*")) + if err != nil { + return nil, nil, fmt.Errorf("detecting fastrpc nodes: %v", err) + } + + cdspNodes, err := globSorted(filepath.Join(devRoot, "fastrpc-cdsp*")) + if err != nil { + return nil, nil, fmt.Errorf("detecting cdsp fastrpc nodes: %v", err) + } + + var platforms []types.PlatformInfo + if len(fastrpcNodes) > 0 { + platforms = append(platforms, types.PlatformInfo{ + Vendor: "qualcomm", + Name: "dragonwing", + }) + } + + var devices []types.DetectedDevice + if len(cdspNodes) > 0 { + devices = append(devices, types.DetectedDevice{ + Type: "npu", + Bus: "fastrpc", + Nodes: cdspNodes, + }) + } + + return platforms, devices, nil +} + +func DetectFromNodes(nodes []string) ([]types.PlatformInfo, []types.DetectedDevice) { + var fastrpcNodes []string + var cdspNodes []string + + for _, node := range nodes { + node = strings.TrimSpace(node) + if node == "" { + continue + } + + base := filepath.Base(node) + if strings.HasPrefix(base, "fastrpc-") { + fastrpcNodes = append(fastrpcNodes, node) + } + if strings.HasPrefix(base, "fastrpc-cdsp") { + cdspNodes = append(cdspNodes, node) + } + } + + sort.Strings(fastrpcNodes) + sort.Strings(cdspNodes) + + var platforms []types.PlatformInfo + if len(fastrpcNodes) > 0 { + platforms = append(platforms, types.PlatformInfo{ + Vendor: "qualcomm", + Name: "dragonwing", + }) + } + + var devices []types.DetectedDevice + if len(cdspNodes) > 0 { + devices = append(devices, types.DetectedDevice{ + Type: "npu", + Bus: "fastrpc", + Nodes: cdspNodes, + }) + } + + return platforms, devices +} + +func globSorted(pattern string) ([]string, error) { + matches, err := filepath.Glob(pattern) + if err != nil { + return nil, err + } + sort.Strings(matches) + return matches, nil +} diff --git a/pkg/hardware_info/qualcomm/qualcomm_test.go b/pkg/hardware_info/qualcomm/qualcomm_test.go new file mode 100644 index 00000000..cf7914c1 --- /dev/null +++ b/pkg/hardware_info/qualcomm/qualcomm_test.go @@ -0,0 +1,86 @@ +package qualcomm + +import ( + "os" + "path/filepath" + "reflect" + "testing" + + "github.com/canonical/inference-snaps-cli/pkg/types" +) + +func TestInfo(t *testing.T) { + tmp := t.TempDir() + originalRoot := devRoot + devRoot = tmp + t.Cleanup(func() { + devRoot = originalRoot + }) + + _, err := os.Create(filepath.Join(tmp, "fastrpc-adsp-secure")) + if err != nil { + t.Fatal(err) + } + _, err = os.Create(filepath.Join(tmp, "fastrpc-cdsp")) + if err != nil { + t.Fatal(err) + } + _, err = os.Create(filepath.Join(tmp, "fastrpc-cdsp1")) + if err != nil { + t.Fatal(err) + } + + platforms, devices, err := Info() + if err != nil { + t.Fatal(err) + } + + expectedPlatforms := []types.PlatformInfo{{ + Vendor: "qualcomm", + Name: "dragonwing", + }} + if !reflect.DeepEqual(platforms, expectedPlatforms) { + t.Fatalf("platforms=%+v expected=%+v", platforms, expectedPlatforms) + } + + expectedDevices := []types.DetectedDevice{{ + Type: "npu", + Bus: "fastrpc", + Nodes: []string{ + filepath.Join(tmp, "fastrpc-cdsp"), + filepath.Join(tmp, "fastrpc-cdsp1"), + }, + }} + if !reflect.DeepEqual(devices, expectedDevices) { + t.Fatalf("devices=%+v expected=%+v", devices, expectedDevices) + } +} + +func TestDetectFromNodes(t *testing.T) { + nodes := []string{ + "/dev/fastrpc-cdsp1-secure", + "/dev/fastrpc-adsp", + "/dev/something-else", + "/dev/fastrpc-cdsp", + } + + platforms, devices := DetectFromNodes(nodes) + if len(platforms) != 1 { + t.Fatalf("expected 1 platform, got %d", len(platforms)) + } + if platforms[0].Vendor != "qualcomm" || platforms[0].Name != "dragonwing" { + t.Fatalf("unexpected platform %+v", platforms[0]) + } + + if len(devices) != 1 { + t.Fatalf("expected 1 device, got %d", len(devices)) + } + if devices[0].Type != "npu" || devices[0].Bus != "fastrpc" { + t.Fatalf("unexpected device %+v", devices[0]) + } + + expectedNodes := []string{"/dev/fastrpc-cdsp", "/dev/fastrpc-cdsp1-secure"} + if !reflect.DeepEqual(devices[0].Nodes, expectedNodes) { + t.Fatalf("nodes=%v expected=%v", devices[0].Nodes, expectedNodes) + } +} diff --git a/pkg/selector/fastrpc/fastrpc.go b/pkg/selector/fastrpc/fastrpc.go new file mode 100644 index 00000000..c3823311 --- /dev/null +++ b/pkg/selector/fastrpc/fastrpc.go @@ -0,0 +1,58 @@ +package fastrpc + +import ( + "fmt" + "path/filepath" + "testing" + + "github.com/canonical/go-snapctl" + "github.com/canonical/inference-snaps-cli/pkg/engines" + "github.com/canonical/inference-snaps-cli/pkg/selector/weights" + "github.com/canonical/inference-snaps-cli/pkg/types" +) + +const defaultNpuNodeGlob = "/dev/fastrpc-cdsp*" + +func Match(manifestDevice engines.Device, hostDevices []types.DetectedDevice) (int, []string) { + nodeGlob := defaultNpuNodeGlob + if manifestDevice.NodeGlob != nil { + nodeGlob = *manifestDevice.NodeGlob + } + + for _, hostDevice := range hostDevices { + if hostDevice.Bus != "fastrpc" { + continue + } + if manifestDevice.Type != "" && hostDevice.Type != manifestDevice.Type { + continue + } + + for _, node := range hostDevice.Nodes { + matched, err := filepath.Match(nodeGlob, node) + if err != nil { + return 0, []string{fmt.Sprintf("invalid node-glob %q: %v", nodeGlob, err)} + } + if !matched { + continue + } + + score := weights.PciDevice + weights.PciDeviceType + for _, connection := range manifestDevice.SnapConnections { + if testing.Testing() { + continue + } + connected, err := snapctl.IsConnected(connection).Run() + if err != nil { + return 0, []string{fmt.Sprintf("checking snap connection %q: %v", connection, err)} + } + if !connected { + return 0, []string{fmt.Sprintf("%q is not connected", connection)} + } + } + + return score, nil + } + } + + return 0, []string{fmt.Sprintf("device node matching %q not found", nodeGlob)} +} diff --git a/pkg/selector/fastrpc/fastrpc_test.go b/pkg/selector/fastrpc/fastrpc_test.go new file mode 100644 index 00000000..33065305 --- /dev/null +++ b/pkg/selector/fastrpc/fastrpc_test.go @@ -0,0 +1,50 @@ +package fastrpc + +import ( + "testing" + + "github.com/canonical/inference-snaps-cli/pkg/engines" + "github.com/canonical/inference-snaps-cli/pkg/types" +) + +func TestMatch(t *testing.T) { + hostDevices := []types.DetectedDevice{ + { + Type: "npu", + Bus: "fastrpc", + Nodes: []string{ + "/dev/fastrpc-cdsp", + "/dev/fastrpc-cdsp1-secure", + }, + }, + } + + t.Run("default pattern", func(t *testing.T) { + device := engines.Device{Type: "npu", Bus: "fastrpc"} + score, issues := Match(device, hostDevices) + if score == 0 || len(issues) > 0 { + t.Fatalf("expected a positive score with no issues, score=%d issues=%v", score, issues) + } + }) + + t.Run("custom node glob", func(t *testing.T) { + nodeGlob := "/dev/fastrpc-cdsp1*" + device := engines.Device{Type: "npu", Bus: "fastrpc", NodeGlob: &nodeGlob} + score, issues := Match(device, hostDevices) + if score == 0 || len(issues) > 0 { + t.Fatalf("expected a positive score with no issues, score=%d issues=%v", score, issues) + } + }) + + t.Run("no matching node", func(t *testing.T) { + nodeGlob := "/dev/fastrpc-gdsp*" + device := engines.Device{Type: "npu", Bus: "fastrpc", NodeGlob: &nodeGlob} + score, issues := Match(device, hostDevices) + if score != 0 { + t.Fatalf("expected score=0, got %d", score) + } + if len(issues) == 0 { + t.Fatal("expected compatibility issues") + } + }) +} diff --git a/pkg/selector/fastrpc_test.go b/pkg/selector/fastrpc_test.go new file mode 100644 index 00000000..dd2132ac --- /dev/null +++ b/pkg/selector/fastrpc_test.go @@ -0,0 +1,52 @@ +package selector + +import ( + "testing" + + "github.com/canonical/inference-snaps-cli/pkg/engines" + "github.com/canonical/inference-snaps-cli/pkg/types" +) + +func TestFastRpcNpuSelection(t *testing.T) { + hwInfo := &types.HwInfo{ + Memory: types.MemoryInfo{TotalRam: 8 * 1024 * 1024 * 1024}, + Disk: map[string]types.DirStats{ + "/var/lib/snapd/snaps": { + Avail: 20 * 1024 * 1024 * 1024, + }, + }, + Devices: []types.DetectedDevice{ + { + Type: "npu", + Bus: "fastrpc", + Nodes: []string{ + "/dev/fastrpc-cdsp", + }, + }, + }, + } + + manifest := engines.Manifest{ + Name: "qualcomm-npu", + Description: "qualcomm dragonwing npu", + Vendor: "qualcomm", + Grade: "stable", + Devices: engines.Devices{ + Anyof: []engines.Device{{ + Type: "npu", + Bus: "fastrpc", + }}, + }, + } + + score, report, err := checkEngine(hwInfo, manifest) + if err != nil { + t.Fatal(err) + } + if !report.EngineCompatible() { + t.Fatalf("expected engine to be compatible: %+v", report) + } + if score <= 0 { + t.Fatalf("expected positive score, got %d", score) + } +} diff --git a/pkg/selector/select_stack.go b/pkg/selector/select_stack.go index 671f52c1..bd84a5db 100644 --- a/pkg/selector/select_stack.go +++ b/pkg/selector/select_stack.go @@ -8,6 +8,7 @@ import ( "github.com/canonical/inference-snaps-cli/pkg/constants" "github.com/canonical/inference-snaps-cli/pkg/engines" "github.com/canonical/inference-snaps-cli/pkg/selector/cpu" + "github.com/canonical/inference-snaps-cli/pkg/selector/fastrpc" "github.com/canonical/inference-snaps-cli/pkg/selector/pci" "github.com/canonical/inference-snaps-cli/pkg/types" "github.com/canonical/inference-snaps-cli/pkg/utils" @@ -165,6 +166,15 @@ func scoreDevicesAll(hardwareInfo *types.HwInfo, devices []engines.Device) int { compatible = false devices[i].CompatibilityIssues = append(devices[i].CompatibilityIssues, "usb device matching not implemented") + } else if devices[i].Bus == "fastrpc" { + fastRpcScore, fastRpcIssues := fastrpc.Match(devices[i], hardwareInfo.Devices) + if len(fastRpcIssues) > 0 { + compatible = false + devices[i].CompatibilityIssues = append(devices[i].CompatibilityIssues, fastRpcIssues...) + } else { + compatibilityScore += fastRpcScore + } + } else if devices[i].Bus == "" || devices[i].Bus == "pci" { // Fallback to PCI as default bus pciScore, pciIssues := pci.Match(devices[i], hardwareInfo.PciDevices) @@ -204,6 +214,15 @@ func scoreDevicesAny(hardwareInfo *types.HwInfo, devices []engines.Device) int { compatible = false device.CompatibilityIssues = append(device.CompatibilityIssues, "usb device matching not implemented") + } else if device.Bus == "fastrpc" { + fastRpcScore, fastRpcIssues := fastrpc.Match(device, hardwareInfo.Devices) + if len(fastRpcIssues) > 0 { + devices[i].CompatibilityIssues = append(device.CompatibilityIssues, fastRpcIssues...) + } else { + devicesFound++ + compatibilityScore += fastRpcScore + } + } else if device.Bus == "" || device.Bus == "pci" { // Fallback to PCI as default bus pciScore, pciIssues := pci.Match(device, hardwareInfo.PciDevices) diff --git a/pkg/types/detected_devices.go b/pkg/types/detected_devices.go new file mode 100644 index 00000000..7db5cfc5 --- /dev/null +++ b/pkg/types/detected_devices.go @@ -0,0 +1,12 @@ +package types + +type PlatformInfo struct { + Vendor string `json:"vendor" yaml:"vendor"` + Name string `json:"name" yaml:"name"` +} + +type DetectedDevice struct { + Type string `json:"type" yaml:"type"` + Bus string `json:"bus" yaml:"bus"` + Nodes []string `json:"nodes,omitempty" yaml:"nodes,omitempty"` +} diff --git a/pkg/types/hw_info.go b/pkg/types/hw_info.go index 9548c730..f31b35ba 100644 --- a/pkg/types/hw_info.go +++ b/pkg/types/hw_info.go @@ -5,4 +5,6 @@ type HwInfo struct { Memory MemoryInfo `json:"memory,omitempty" yaml:"memory,omitempty"` Disk map[string]DirStats `json:"disk,omitempty" yaml:"disk,omitempty"` PciDevices []PciDevice `json:"pci,omitempty" yaml:"pci"` + Platforms []PlatformInfo `json:"platforms,omitempty" yaml:"platforms,omitempty"` + Devices []DetectedDevice `json:"devices,omitempty" yaml:"devices,omitempty"` } From f6cb7886ef7471ef13341b5a5b6e1c528e0cd51f Mon Sep 17 00:00:00 2001 From: Sinan KARAKAYA Date: Fri, 24 Apr 2026 16:23:06 +0200 Subject: [PATCH 2/4] refator(hw-detection: Flatted QC NPU nodes, moved Platforms to DetectedDevices Flattened NPU nodes (ADSP, CDSP, GDSP) to be considered as distinct devices rather than relying on DetectedDevice.Nodes. PlatformsInfo was moved from Devices to DetectedDevices, to avoid having to keep a relationship between each devices and their respective platform's metadata. Signed-off-by: Sinan KARAKAYA Co-authored-by: Copilot --- pkg/hardware_info/hardware-info.go | 6 +- pkg/hardware_info/qualcomm/qualcomm.go | 82 +++++++------------ pkg/hardware_info/qualcomm/qualcomm_test.go | 91 ++++++++++++++------- pkg/selector/fastrpc/fastrpc.go | 65 ++++++++++----- pkg/selector/fastrpc/fastrpc_test.go | 16 +++- pkg/selector/fastrpc_test.go | 6 +- pkg/types/detected_devices.go | 3 +- pkg/types/hw_info.go | 1 - 8 files changed, 154 insertions(+), 116 deletions(-) diff --git a/pkg/hardware_info/hardware-info.go b/pkg/hardware_info/hardware-info.go index a28b01ed..7db51d09 100644 --- a/pkg/hardware_info/hardware-info.go +++ b/pkg/hardware_info/hardware-info.go @@ -42,11 +42,10 @@ func Get(friendlyNames bool) (*types.HwInfo, error) { } hwInfo.PciDevices = pciDevices - platforms, devices, err := qualcomm.Info() + devices, err := qualcomm.Info() if err != nil { return nil, fmt.Errorf("getting qualcomm devices: %v", err) } - hwInfo.Platforms = platforms hwInfo.Devices = devices return &hwInfo, nil @@ -114,8 +113,7 @@ func GetFromRawData(t *testing.T, device string, friendlyNames bool, testDir str } nodes := strings.Fields(string(nodesData)) - platforms, devices := qualcomm.DetectFromNodes(nodes) - hwInfo.Platforms = platforms + devices := qualcomm.DetectFromNodes(nodes) hwInfo.Devices = devices } else if !os.IsNotExist(err) { t.Fatalf("error checking file '%s': %v\n", fastrpcNodesFile, err) diff --git a/pkg/hardware_info/qualcomm/qualcomm.go b/pkg/hardware_info/qualcomm/qualcomm.go index 27ca2742..643d4aa7 100644 --- a/pkg/hardware_info/qualcomm/qualcomm.go +++ b/pkg/hardware_info/qualcomm/qualcomm.go @@ -11,40 +11,17 @@ import ( var devRoot = "/dev" -func Info() ([]types.PlatformInfo, []types.DetectedDevice, error) { - fastrpcNodes, err := globSorted(filepath.Join(devRoot, "fastrpc-*")) +func Info() ([]types.DetectedDevice, error) { + nodes, err := globSorted(filepath.Join(devRoot, "fastrpc-*")) if err != nil { - return nil, nil, fmt.Errorf("detecting fastrpc nodes: %v", err) + return nil, fmt.Errorf("detecting fastrpc nodes: %v", err) } - cdspNodes, err := globSorted(filepath.Join(devRoot, "fastrpc-cdsp*")) - if err != nil { - return nil, nil, fmt.Errorf("detecting cdsp fastrpc nodes: %v", err) - } - - var platforms []types.PlatformInfo - if len(fastrpcNodes) > 0 { - platforms = append(platforms, types.PlatformInfo{ - Vendor: "qualcomm", - Name: "dragonwing", - }) - } - - var devices []types.DetectedDevice - if len(cdspNodes) > 0 { - devices = append(devices, types.DetectedDevice{ - Type: "npu", - Bus: "fastrpc", - Nodes: cdspNodes, - }) - } - - return platforms, devices, nil + return DetectFromNodes(nodes), nil } -func DetectFromNodes(nodes []string) ([]types.PlatformInfo, []types.DetectedDevice) { - var fastrpcNodes []string - var cdspNodes []string +func DetectFromNodes(nodes []string) []types.DetectedDevice { + var devices []types.DetectedDevice for _, node := range nodes { node = strings.TrimSpace(node) @@ -53,35 +30,35 @@ func DetectFromNodes(nodes []string) ([]types.PlatformInfo, []types.DetectedDevi } base := filepath.Base(node) - if strings.HasPrefix(base, "fastrpc-") { - fastrpcNodes = append(fastrpcNodes, node) - } - if strings.HasPrefix(base, "fastrpc-cdsp") { - cdspNodes = append(cdspNodes, node) + if !strings.HasPrefix(base, "fastrpc-") { + continue } - } - - sort.Strings(fastrpcNodes) - sort.Strings(cdspNodes) - - var platforms []types.PlatformInfo - if len(fastrpcNodes) > 0 { - platforms = append(platforms, types.PlatformInfo{ - Vendor: "qualcomm", - Name: "dragonwing", - }) - } - var devices []types.DetectedDevice - if len(cdspNodes) > 0 { devices = append(devices, types.DetectedDevice{ - Type: "npu", - Bus: "fastrpc", - Nodes: cdspNodes, + Type: detectNpuType(base), + Bus: "fastrpc", + PlatformInfo: &types.PlatformInfo{ + Vendor: "qualcomm", + Name: node, + SoC: "dragonwing", + }, }) } - return platforms, devices + sort.Slice(devices, func(i, j int) bool { + return devices[i].PlatformInfo.Name < devices[j].PlatformInfo.Name + }) + + return devices +} + +func detectNpuType(nodeBaseName string) string { + const prefix = "fastrpc-" + if strings.HasPrefix(nodeBaseName, prefix) { + suffix := strings.TrimPrefix(nodeBaseName, prefix) + return fmt.Sprintf("NPU - %s", suffix) + } + return "NPU" } func globSorted(pattern string) ([]string, error) { @@ -89,6 +66,7 @@ func globSorted(pattern string) ([]string, error) { if err != nil { return nil, err } + sort.Strings(matches) return matches, nil } diff --git a/pkg/hardware_info/qualcomm/qualcomm_test.go b/pkg/hardware_info/qualcomm/qualcomm_test.go index cf7914c1..820f99fa 100644 --- a/pkg/hardware_info/qualcomm/qualcomm_test.go +++ b/pkg/hardware_info/qualcomm/qualcomm_test.go @@ -30,27 +30,40 @@ func TestInfo(t *testing.T) { t.Fatal(err) } - platforms, devices, err := Info() + devices, err := Info() if err != nil { t.Fatal(err) } - expectedPlatforms := []types.PlatformInfo{{ - Vendor: "qualcomm", - Name: "dragonwing", - }} - if !reflect.DeepEqual(platforms, expectedPlatforms) { - t.Fatalf("platforms=%+v expected=%+v", platforms, expectedPlatforms) - } - - expectedDevices := []types.DetectedDevice{{ - Type: "npu", - Bus: "fastrpc", - Nodes: []string{ - filepath.Join(tmp, "fastrpc-cdsp"), - filepath.Join(tmp, "fastrpc-cdsp1"), + expectedDevices := []types.DetectedDevice{ + { + Type: "NPU - adsp-secure", + Bus: "fastrpc", + PlatformInfo: &types.PlatformInfo{ + Vendor: "qualcomm", + Name: filepath.Join(tmp, "fastrpc-adsp-secure"), + SoC: "dragonwing", + }, + }, + { + Type: "NPU - cdsp", + Bus: "fastrpc", + PlatformInfo: &types.PlatformInfo{ + Vendor: "qualcomm", + Name: filepath.Join(tmp, "fastrpc-cdsp"), + SoC: "dragonwing", + }, + }, + { + Type: "NPU - cdsp1", + Bus: "fastrpc", + PlatformInfo: &types.PlatformInfo{ + Vendor: "qualcomm", + Name: filepath.Join(tmp, "fastrpc-cdsp1"), + SoC: "dragonwing", + }, }, - }} + } if !reflect.DeepEqual(devices, expectedDevices) { t.Fatalf("devices=%+v expected=%+v", devices, expectedDevices) } @@ -64,23 +77,39 @@ func TestDetectFromNodes(t *testing.T) { "/dev/fastrpc-cdsp", } - platforms, devices := DetectFromNodes(nodes) - if len(platforms) != 1 { - t.Fatalf("expected 1 platform, got %d", len(platforms)) - } - if platforms[0].Vendor != "qualcomm" || platforms[0].Name != "dragonwing" { - t.Fatalf("unexpected platform %+v", platforms[0]) - } + devices := DetectFromNodes(nodes) - if len(devices) != 1 { - t.Fatalf("expected 1 device, got %d", len(devices)) - } - if devices[0].Type != "npu" || devices[0].Bus != "fastrpc" { - t.Fatalf("unexpected device %+v", devices[0]) + expectedDevices := []types.DetectedDevice{ + { + Type: "NPU - adsp", + Bus: "fastrpc", + PlatformInfo: &types.PlatformInfo{ + Vendor: "qualcomm", + Name: "/dev/fastrpc-adsp", + SoC: "dragonwing", + }, + }, + { + Type: "NPU - cdsp", + Bus: "fastrpc", + PlatformInfo: &types.PlatformInfo{ + Vendor: "qualcomm", + Name: "/dev/fastrpc-cdsp", + SoC: "dragonwing", + }, + }, + { + Type: "NPU - cdsp1-secure", + Bus: "fastrpc", + PlatformInfo: &types.PlatformInfo{ + Vendor: "qualcomm", + Name: "/dev/fastrpc-cdsp1-secure", + SoC: "dragonwing", + }, + }, } - expectedNodes := []string{"/dev/fastrpc-cdsp", "/dev/fastrpc-cdsp1-secure"} - if !reflect.DeepEqual(devices[0].Nodes, expectedNodes) { - t.Fatalf("nodes=%v expected=%v", devices[0].Nodes, expectedNodes) + if !reflect.DeepEqual(devices, expectedDevices) { + t.Fatalf("devices=%+v expected=%+v", devices, expectedDevices) } } diff --git a/pkg/selector/fastrpc/fastrpc.go b/pkg/selector/fastrpc/fastrpc.go index c3823311..a75e357b 100644 --- a/pkg/selector/fastrpc/fastrpc.go +++ b/pkg/selector/fastrpc/fastrpc.go @@ -3,6 +3,7 @@ package fastrpc import ( "fmt" "path/filepath" + "strings" "testing" "github.com/canonical/go-snapctl" @@ -23,36 +24,56 @@ func Match(manifestDevice engines.Device, hostDevices []types.DetectedDevice) (i if hostDevice.Bus != "fastrpc" { continue } - if manifestDevice.Type != "" && hostDevice.Type != manifestDevice.Type { + if !deviceTypeMatch(manifestDevice.Type, hostDevice.Type) { + continue + } + if hostDevice.PlatformInfo == nil || hostDevice.PlatformInfo.Name == "" { continue } - for _, node := range hostDevice.Nodes { - matched, err := filepath.Match(nodeGlob, node) - if err != nil { - return 0, []string{fmt.Sprintf("invalid node-glob %q: %v", nodeGlob, err)} - } - if !matched { + matched, err := filepath.Match(nodeGlob, hostDevice.PlatformInfo.Name) + if err != nil { + return 0, []string{fmt.Sprintf("invalid node-glob %q: %v", nodeGlob, err)} + } + if !matched { + continue + } + + score := weights.PciDevice + weights.PciDeviceType + for _, connection := range manifestDevice.SnapConnections { + if testing.Testing() { continue } - - score := weights.PciDevice + weights.PciDeviceType - for _, connection := range manifestDevice.SnapConnections { - if testing.Testing() { - continue - } - connected, err := snapctl.IsConnected(connection).Run() - if err != nil { - return 0, []string{fmt.Sprintf("checking snap connection %q: %v", connection, err)} - } - if !connected { - return 0, []string{fmt.Sprintf("%q is not connected", connection)} - } + connected, err := snapctl.IsConnected(connection).Run() + if err != nil { + return 0, []string{fmt.Sprintf("checking snap connection %q: %v", connection, err)} + } + if !connected { + return 0, []string{fmt.Sprintf("%q is not connected", connection)} } - - return score, nil } + + return score, nil } return 0, []string{fmt.Sprintf("device node matching %q not found", nodeGlob)} } + +func deviceTypeMatch(manifestType, hostType string) bool { + if manifestType == "" { + return true + } + + manifest := strings.ToLower(strings.TrimSpace(manifestType)) + host := strings.ToLower(strings.TrimSpace(hostType)) + + if manifest == host { + return true + } + + if manifest == "npu" && strings.HasPrefix(host, "npu") { + return true + } + + return false +} diff --git a/pkg/selector/fastrpc/fastrpc_test.go b/pkg/selector/fastrpc/fastrpc_test.go index 33065305..1c94b53e 100644 --- a/pkg/selector/fastrpc/fastrpc_test.go +++ b/pkg/selector/fastrpc/fastrpc_test.go @@ -12,9 +12,19 @@ func TestMatch(t *testing.T) { { Type: "npu", Bus: "fastrpc", - Nodes: []string{ - "/dev/fastrpc-cdsp", - "/dev/fastrpc-cdsp1-secure", + PlatformInfo: &types.PlatformInfo{ + Vendor: "qualcomm", + Name: "/dev/fastrpc-cdsp", + SoC: "dragonwing", + }, + }, + { + Type: "npu", + Bus: "fastrpc", + PlatformInfo: &types.PlatformInfo{ + Vendor: "qualcomm", + Name: "/dev/fastrpc-cdsp1-secure", + SoC: "dragonwing", }, }, } diff --git a/pkg/selector/fastrpc_test.go b/pkg/selector/fastrpc_test.go index dd2132ac..e753160a 100644 --- a/pkg/selector/fastrpc_test.go +++ b/pkg/selector/fastrpc_test.go @@ -19,8 +19,10 @@ func TestFastRpcNpuSelection(t *testing.T) { { Type: "npu", Bus: "fastrpc", - Nodes: []string{ - "/dev/fastrpc-cdsp", + PlatformInfo: &types.PlatformInfo{ + Vendor: "qualcomm", + Name: "/dev/fastrpc-cdsp", + SoC: "dragonwing", }, }, }, diff --git a/pkg/types/detected_devices.go b/pkg/types/detected_devices.go index 7db5cfc5..b657e52f 100644 --- a/pkg/types/detected_devices.go +++ b/pkg/types/detected_devices.go @@ -3,10 +3,11 @@ package types type PlatformInfo struct { Vendor string `json:"vendor" yaml:"vendor"` Name string `json:"name" yaml:"name"` + SoC string `json:"soc,omitempty" yaml:"soc,omitempty"` } type DetectedDevice struct { Type string `json:"type" yaml:"type"` Bus string `json:"bus" yaml:"bus"` - Nodes []string `json:"nodes,omitempty" yaml:"nodes,omitempty"` + PlatformInfo *PlatformInfo `json:"platform_info,omitempty" yaml:"platform_info,omitempty"` } diff --git a/pkg/types/hw_info.go b/pkg/types/hw_info.go index f31b35ba..a8acc817 100644 --- a/pkg/types/hw_info.go +++ b/pkg/types/hw_info.go @@ -5,6 +5,5 @@ type HwInfo struct { Memory MemoryInfo `json:"memory,omitempty" yaml:"memory,omitempty"` Disk map[string]DirStats `json:"disk,omitempty" yaml:"disk,omitempty"` PciDevices []PciDevice `json:"pci,omitempty" yaml:"pci"` - Platforms []PlatformInfo `json:"platforms,omitempty" yaml:"platforms,omitempty"` Devices []DetectedDevice `json:"devices,omitempty" yaml:"devices,omitempty"` } From edc7d10b010524c0c4cb74db096543ab455687d4 Mon Sep 17 00:00:00 2001 From: Sinan KARAKAYA Date: Mon, 27 Apr 2026 11:14:24 +0200 Subject: [PATCH 3/4] refactor(DetectedDevice): renamed PlatformInfo->DeviceMetadata and SoC->VendorName Co-authored-by: Copilot --- pkg/hardware_info/qualcomm/qualcomm.go | 6 +++--- pkg/hardware_info/qualcomm/qualcomm_test.go | 24 ++++++++++----------- pkg/selector/fastrpc/fastrpc.go | 4 ++-- pkg/selector/fastrpc/fastrpc_test.go | 8 +++---- pkg/selector/fastrpc_test.go | 4 ++-- pkg/types/detected_devices.go | 14 ++++++------ 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/pkg/hardware_info/qualcomm/qualcomm.go b/pkg/hardware_info/qualcomm/qualcomm.go index 643d4aa7..0923b0cb 100644 --- a/pkg/hardware_info/qualcomm/qualcomm.go +++ b/pkg/hardware_info/qualcomm/qualcomm.go @@ -37,16 +37,16 @@ func DetectFromNodes(nodes []string) []types.DetectedDevice { devices = append(devices, types.DetectedDevice{ Type: detectNpuType(base), Bus: "fastrpc", - PlatformInfo: &types.PlatformInfo{ + Metadata: &types.DeviceMetadata{ Vendor: "qualcomm", Name: node, - SoC: "dragonwing", + VendorName: "dragonwing", }, }) } sort.Slice(devices, func(i, j int) bool { - return devices[i].PlatformInfo.Name < devices[j].PlatformInfo.Name + return devices[i].Metadata.Name < devices[j].Metadata.Name }) return devices diff --git a/pkg/hardware_info/qualcomm/qualcomm_test.go b/pkg/hardware_info/qualcomm/qualcomm_test.go index 820f99fa..7bdc8a9f 100644 --- a/pkg/hardware_info/qualcomm/qualcomm_test.go +++ b/pkg/hardware_info/qualcomm/qualcomm_test.go @@ -39,28 +39,28 @@ func TestInfo(t *testing.T) { { Type: "NPU - adsp-secure", Bus: "fastrpc", - PlatformInfo: &types.PlatformInfo{ + Metadata: &types.DeviceMetadata{ Vendor: "qualcomm", Name: filepath.Join(tmp, "fastrpc-adsp-secure"), - SoC: "dragonwing", + VendorName: "dragonwing", }, }, { Type: "NPU - cdsp", Bus: "fastrpc", - PlatformInfo: &types.PlatformInfo{ + Metadata: &types.DeviceMetadata{ Vendor: "qualcomm", Name: filepath.Join(tmp, "fastrpc-cdsp"), - SoC: "dragonwing", + VendorName: "dragonwing", }, }, { Type: "NPU - cdsp1", Bus: "fastrpc", - PlatformInfo: &types.PlatformInfo{ + Metadata: &types.DeviceMetadata{ Vendor: "qualcomm", Name: filepath.Join(tmp, "fastrpc-cdsp1"), - SoC: "dragonwing", + VendorName: "dragonwing", }, }, } @@ -83,28 +83,28 @@ func TestDetectFromNodes(t *testing.T) { { Type: "NPU - adsp", Bus: "fastrpc", - PlatformInfo: &types.PlatformInfo{ + Metadata: &types.DeviceMetadata{ Vendor: "qualcomm", Name: "/dev/fastrpc-adsp", - SoC: "dragonwing", + VendorName: "dragonwing", }, }, { Type: "NPU - cdsp", Bus: "fastrpc", - PlatformInfo: &types.PlatformInfo{ + Metadata: &types.DeviceMetadata{ Vendor: "qualcomm", Name: "/dev/fastrpc-cdsp", - SoC: "dragonwing", + VendorName: "dragonwing", }, }, { Type: "NPU - cdsp1-secure", Bus: "fastrpc", - PlatformInfo: &types.PlatformInfo{ + Metadata: &types.DeviceMetadata{ Vendor: "qualcomm", Name: "/dev/fastrpc-cdsp1-secure", - SoC: "dragonwing", + VendorName: "dragonwing", }, }, } diff --git a/pkg/selector/fastrpc/fastrpc.go b/pkg/selector/fastrpc/fastrpc.go index a75e357b..dafe7c0a 100644 --- a/pkg/selector/fastrpc/fastrpc.go +++ b/pkg/selector/fastrpc/fastrpc.go @@ -27,11 +27,11 @@ func Match(manifestDevice engines.Device, hostDevices []types.DetectedDevice) (i if !deviceTypeMatch(manifestDevice.Type, hostDevice.Type) { continue } - if hostDevice.PlatformInfo == nil || hostDevice.PlatformInfo.Name == "" { + if hostDevice.Metadata == nil || hostDevice.Metadata.Name == "" { continue } - matched, err := filepath.Match(nodeGlob, hostDevice.PlatformInfo.Name) + matched, err := filepath.Match(nodeGlob, hostDevice.Metadata.Name) if err != nil { return 0, []string{fmt.Sprintf("invalid node-glob %q: %v", nodeGlob, err)} } diff --git a/pkg/selector/fastrpc/fastrpc_test.go b/pkg/selector/fastrpc/fastrpc_test.go index 1c94b53e..4dd9871d 100644 --- a/pkg/selector/fastrpc/fastrpc_test.go +++ b/pkg/selector/fastrpc/fastrpc_test.go @@ -12,19 +12,19 @@ func TestMatch(t *testing.T) { { Type: "npu", Bus: "fastrpc", - PlatformInfo: &types.PlatformInfo{ + Metadata: &types.DeviceMetadata{ Vendor: "qualcomm", Name: "/dev/fastrpc-cdsp", - SoC: "dragonwing", + VendorName: "dragonwing", }, }, { Type: "npu", Bus: "fastrpc", - PlatformInfo: &types.PlatformInfo{ + Metadata: &types.DeviceMetadata{ Vendor: "qualcomm", Name: "/dev/fastrpc-cdsp1-secure", - SoC: "dragonwing", + VendorName: "dragonwing", }, }, } diff --git a/pkg/selector/fastrpc_test.go b/pkg/selector/fastrpc_test.go index e753160a..a25d113f 100644 --- a/pkg/selector/fastrpc_test.go +++ b/pkg/selector/fastrpc_test.go @@ -19,10 +19,10 @@ func TestFastRpcNpuSelection(t *testing.T) { { Type: "npu", Bus: "fastrpc", - PlatformInfo: &types.PlatformInfo{ + Metadata: &types.DeviceMetadata{ Vendor: "qualcomm", Name: "/dev/fastrpc-cdsp", - SoC: "dragonwing", + VendorName: "dragonwing", }, }, }, diff --git a/pkg/types/detected_devices.go b/pkg/types/detected_devices.go index b657e52f..96b70985 100644 --- a/pkg/types/detected_devices.go +++ b/pkg/types/detected_devices.go @@ -1,13 +1,13 @@ package types -type PlatformInfo struct { - Vendor string `json:"vendor" yaml:"vendor"` - Name string `json:"name" yaml:"name"` - SoC string `json:"soc,omitempty" yaml:"soc,omitempty"` +type DeviceMetadata struct { + Vendor string `json:"vendor" yaml:"vendor"` + Name string `json:"name" yaml:"name"` + VendorName string `json:"vendor_name,omitempty" yaml:"vendor_name,omitempty"` } type DetectedDevice struct { - Type string `json:"type" yaml:"type"` - Bus string `json:"bus" yaml:"bus"` - PlatformInfo *PlatformInfo `json:"platform_info,omitempty" yaml:"platform_info,omitempty"` + Type string `json:"type" yaml:"type"` + Bus string `json:"bus" yaml:"bus"` + Metadata *DeviceMetadata `json:"metadata,omitempty" yaml:"metadata,omitempty"` } From 659de4b8d07a1d978ab3195056ae088c8ba66220 Mon Sep 17 00:00:00 2001 From: Sinan KARAKAYA Date: Mon, 27 Apr 2026 15:39:19 +0200 Subject: [PATCH 4/4] refactor(hw-detection): correct naming and values for DetectedDevice metadata Co-authored-by: Copilot --- pkg/hardware_info/qualcomm/qualcomm.go | 7 +++-- pkg/hardware_info/qualcomm/qualcomm_test.go | 30 +++++++++------------ pkg/selector/fastrpc/fastrpc.go | 4 +-- pkg/selector/fastrpc/fastrpc_test.go | 10 +++---- pkg/selector/fastrpc_test.go | 5 ++-- pkg/types/detected_devices.go | 5 ++-- 6 files changed, 25 insertions(+), 36 deletions(-) diff --git a/pkg/hardware_info/qualcomm/qualcomm.go b/pkg/hardware_info/qualcomm/qualcomm.go index 0923b0cb..08d7bb93 100644 --- a/pkg/hardware_info/qualcomm/qualcomm.go +++ b/pkg/hardware_info/qualcomm/qualcomm.go @@ -38,15 +38,14 @@ func DetectFromNodes(nodes []string) []types.DetectedDevice { Type: detectNpuType(base), Bus: "fastrpc", Metadata: &types.DeviceMetadata{ - Vendor: "qualcomm", - Name: node, - VendorName: "dragonwing", + VendorName: "qualcomm", + ProductName: node, }, }) } sort.Slice(devices, func(i, j int) bool { - return devices[i].Metadata.Name < devices[j].Metadata.Name + return devices[i].Metadata.ProductName < devices[j].Metadata.ProductName }) return devices diff --git a/pkg/hardware_info/qualcomm/qualcomm_test.go b/pkg/hardware_info/qualcomm/qualcomm_test.go index 7bdc8a9f..d189e526 100644 --- a/pkg/hardware_info/qualcomm/qualcomm_test.go +++ b/pkg/hardware_info/qualcomm/qualcomm_test.go @@ -40,27 +40,24 @@ func TestInfo(t *testing.T) { Type: "NPU - adsp-secure", Bus: "fastrpc", Metadata: &types.DeviceMetadata{ - Vendor: "qualcomm", - Name: filepath.Join(tmp, "fastrpc-adsp-secure"), - VendorName: "dragonwing", + VendorName: "qualcomm", + ProductName: filepath.Join(tmp, "fastrpc-adsp-secure"), }, }, { Type: "NPU - cdsp", Bus: "fastrpc", Metadata: &types.DeviceMetadata{ - Vendor: "qualcomm", - Name: filepath.Join(tmp, "fastrpc-cdsp"), - VendorName: "dragonwing", + VendorName: "qualcomm", + ProductName: filepath.Join(tmp, "fastrpc-cdsp"), }, }, { Type: "NPU - cdsp1", Bus: "fastrpc", Metadata: &types.DeviceMetadata{ - Vendor: "qualcomm", - Name: filepath.Join(tmp, "fastrpc-cdsp1"), - VendorName: "dragonwing", + VendorName: "qualcomm", + ProductName: filepath.Join(tmp, "fastrpc-cdsp1"), }, }, } @@ -84,27 +81,24 @@ func TestDetectFromNodes(t *testing.T) { Type: "NPU - adsp", Bus: "fastrpc", Metadata: &types.DeviceMetadata{ - Vendor: "qualcomm", - Name: "/dev/fastrpc-adsp", - VendorName: "dragonwing", + VendorName: "qualcomm", + ProductName: "/dev/fastrpc-adsp", }, }, { Type: "NPU - cdsp", Bus: "fastrpc", Metadata: &types.DeviceMetadata{ - Vendor: "qualcomm", - Name: "/dev/fastrpc-cdsp", - VendorName: "dragonwing", + VendorName: "qualcomm", + ProductName: "/dev/fastrpc-cdsp", }, }, { Type: "NPU - cdsp1-secure", Bus: "fastrpc", Metadata: &types.DeviceMetadata{ - Vendor: "qualcomm", - Name: "/dev/fastrpc-cdsp1-secure", - VendorName: "dragonwing", + VendorName: "qualcomm", + ProductName: "/dev/fastrpc-cdsp1-secure", }, }, } diff --git a/pkg/selector/fastrpc/fastrpc.go b/pkg/selector/fastrpc/fastrpc.go index dafe7c0a..ba0111be 100644 --- a/pkg/selector/fastrpc/fastrpc.go +++ b/pkg/selector/fastrpc/fastrpc.go @@ -27,11 +27,11 @@ func Match(manifestDevice engines.Device, hostDevices []types.DetectedDevice) (i if !deviceTypeMatch(manifestDevice.Type, hostDevice.Type) { continue } - if hostDevice.Metadata == nil || hostDevice.Metadata.Name == "" { + if hostDevice.Metadata == nil || hostDevice.Metadata.ProductName == "" { continue } - matched, err := filepath.Match(nodeGlob, hostDevice.Metadata.Name) + matched, err := filepath.Match(nodeGlob, hostDevice.Metadata.ProductName) if err != nil { return 0, []string{fmt.Sprintf("invalid node-glob %q: %v", nodeGlob, err)} } diff --git a/pkg/selector/fastrpc/fastrpc_test.go b/pkg/selector/fastrpc/fastrpc_test.go index 4dd9871d..1c849e1d 100644 --- a/pkg/selector/fastrpc/fastrpc_test.go +++ b/pkg/selector/fastrpc/fastrpc_test.go @@ -13,18 +13,16 @@ func TestMatch(t *testing.T) { Type: "npu", Bus: "fastrpc", Metadata: &types.DeviceMetadata{ - Vendor: "qualcomm", - Name: "/dev/fastrpc-cdsp", - VendorName: "dragonwing", + VendorName: "qualcomm", + ProductName: "/dev/fastrpc-cdsp", }, }, { Type: "npu", Bus: "fastrpc", Metadata: &types.DeviceMetadata{ - Vendor: "qualcomm", - Name: "/dev/fastrpc-cdsp1-secure", - VendorName: "dragonwing", + VendorName: "qualcomm", + ProductName: "/dev/fastrpc-cdsp1-secure", }, }, } diff --git a/pkg/selector/fastrpc_test.go b/pkg/selector/fastrpc_test.go index a25d113f..7f5796c7 100644 --- a/pkg/selector/fastrpc_test.go +++ b/pkg/selector/fastrpc_test.go @@ -20,9 +20,8 @@ func TestFastRpcNpuSelection(t *testing.T) { Type: "npu", Bus: "fastrpc", Metadata: &types.DeviceMetadata{ - Vendor: "qualcomm", - Name: "/dev/fastrpc-cdsp", - VendorName: "dragonwing", + VendorName: "qualcomm", + ProductName: "/dev/fastrpc-cdsp", }, }, }, diff --git a/pkg/types/detected_devices.go b/pkg/types/detected_devices.go index 96b70985..6595cadc 100644 --- a/pkg/types/detected_devices.go +++ b/pkg/types/detected_devices.go @@ -1,9 +1,8 @@ package types type DeviceMetadata struct { - Vendor string `json:"vendor" yaml:"vendor"` - Name string `json:"name" yaml:"name"` - VendorName string `json:"vendor_name,omitempty" yaml:"vendor_name,omitempty"` + VendorName string `json:"vendor_name" yaml:"vendor_name"` + ProductName string `json:"product_name,omitempty" yaml:"product_name,omitempty"` } type DetectedDevice struct {