Skip to content

Commit 120c27a

Browse files
committed
feat(sdl): parse amd gpu
refs akash-network/support#142 Signed-off-by: Artur Troian <troian.ap@gmail.com>
1 parent 36b9884 commit 120c27a

File tree

6 files changed

+320
-155
lines changed

6 files changed

+320
-155
lines changed

.github/labeler.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"C:x/audit":
2+
- changed-files:
3+
- any-glob-to-any-file: x/audit/**/*
4+
"C:x/cert":
5+
- changed-files:
6+
- any-glob-to-any-file: x/cert/**/*
7+
"C:x/deployment":
8+
- changed-files:
9+
- any-glob-to-any-file: x/deployment/**/*
10+
"C:x/escrow":
11+
- changed-files:
12+
- any-glob-to-any-file: x/escrow/**/*
13+
"C:x/gov":
14+
- changed-files:
15+
- any-glob-to-any-file: x/gov/**/*
16+
"C:x/inflation":
17+
- changed-files:
18+
- any-glob-to-any-file: x/inflation/**/*
19+
"C:x/market":
20+
- changed-files:
21+
- any-glob-to-any-file: x/market/**/*
22+
"C:x/provider":
23+
- changed-files:
24+
- any-glob-to-any-file: x/provider/**/*
25+
"C:x/staking":
26+
- changed-files:
27+
- any-glob-to-any-file: x/staking/**/*
28+
"C:x/take":
29+
- changed-files:
30+
- any-glob-to-any-file: x/take/**/*
31+
"C:CLI":
32+
- changed-files:
33+
- any-glob-to-any-file: cmd/**/*
34+
- changed-files:
35+
- any-glob-to-any-file: x/*/client/cli/*
36+
"C:upgrades":
37+
- changed-files:
38+
- any-glob-to-any-file: upgrades/**/*
39+
"Type: Build":
40+
- changed-files:
41+
- any-glob-to-any-file: Makefile
42+
- changed-files:
43+
- any-glob-to-any-file: Dockerfile
44+
- changed-files:
45+
- any-glob-to-any-file: script/*
46+
- changed-files:
47+
- any-glob-to-any-file: make/*
48+
- changed-files:
49+
- any-glob-to-any-file: .goreleaser*
50+
"Type: CI":
51+
- changed-files:
52+
- any-glob-to-any-file: .github/**/*

.github/pr_labeler.yaml

Lines changed: 0 additions & 33 deletions
This file was deleted.

.github/workflows/pr_labeler.yaml renamed to .github/workflows/labeler.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ permissions:
66
contents: read
77

88
jobs:
9-
pr-labeler:
9+
labeler:
1010
permissions:
1111
contents: read # for actions/labeler to determine modified files
1212
pull-requests: write # for actions/labeler to add labels to PRs
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/labeler@main
15+
- uses: actions/checkout@v3
16+
- uses: actions/labeler@v5
1617
with:
1718
configuration-path: .github/pr_labeler.yaml
1819
repo-token: "${{ secrets.GITHUB_TOKEN }}"
20+
dot: true

sdl/gpu.go

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package sdl
22

33
import (
4+
"errors"
45
"fmt"
56
"sort"
67

@@ -9,25 +10,28 @@ import (
910
types "github.com/akash-network/akash-api/go/node/types/v1beta3"
1011
)
1112

12-
type v2GPUNvidia struct {
13+
var (
14+
ErrResourceGPUEmptyVendors = errors.New("sdl: invalid GPU attributes. at least one vendor must be set")
15+
)
16+
17+
type v2GPU struct {
1318
Model string `yaml:"model"`
1419
RAM *memoryQuantity `yaml:"ram,omitempty"`
1520
}
1621

17-
func (sdl *v2GPUNvidia) String() string {
22+
func (sdl *v2GPU) String() string {
1823
key := sdl.Model
1924
if sdl.RAM != nil {
20-
key += "/" + sdl.RAM.StringWithSuffix("Gi")
25+
key += "/ram/" + sdl.RAM.StringWithSuffix("Gi")
2126
}
2227

2328
return key
2429
}
2530

26-
type v2GPUsNvidia []v2GPUNvidia
31+
type v2GPUs []v2GPU
2732

28-
type gpuVendor struct {
29-
Nvidia v2GPUsNvidia `yaml:"nvidia,omitempty"`
30-
}
33+
type gpuVendors map[string]v2GPUs
34+
type gpuVendorAttributes map[string]types.Attributes
3135

3236
type v2GPUAttributes types.Attributes
3337

@@ -66,37 +70,54 @@ func (sdl *v2ResourceGPU) UnmarshalYAML(node *yaml.Node) error {
6670
func (sdl *v2GPUAttributes) UnmarshalYAML(node *yaml.Node) error {
6771
var res types.Attributes
6872

69-
var vendor *gpuVendor
73+
vendors := make(gpuVendors)
7074

7175
for i := 0; i < len(node.Content); i += 2 {
7276
switch node.Content[i].Value {
7377
case "vendor":
74-
if err := node.Content[i+1].Decode(&vendor); err != nil {
78+
if err := node.Content[i+1].Decode(&vendors); err != nil {
7579
return err
7680
}
7781
default:
7882
return fmt.Errorf("sdl: unsupported attribute (%s) for GPU resource", node.Content[i].Value)
7983
}
8084
}
8185

82-
if vendor == nil {
83-
return fmt.Errorf("sdl: invalid GPU attributes. at least one vendor must be set")
86+
if len(vendors) == 0 {
87+
return ErrResourceGPUEmptyVendors
8488
}
8589

86-
res = make(types.Attributes, 0, len(vendor.Nvidia))
90+
resPrealloc := 0
8791

88-
for _, model := range vendor.Nvidia {
89-
res = append(res, types.Attribute{
90-
Key: fmt.Sprintf("vendor/nvidia/model/%s", model.String()),
91-
Value: "true",
92-
})
92+
for _, models := range vendors {
93+
if len(models) == 0 {
94+
resPrealloc += 1
95+
} else {
96+
resPrealloc += len(models)
97+
}
9398
}
9499

95-
if len(res) == 0 {
96-
res = append(res, types.Attribute{
97-
Key: "vendor/nvidia/model/*",
98-
Value: "true",
99-
})
100+
for vendor, models := range vendors {
101+
switch vendor {
102+
case "nvidia":
103+
case "amd":
104+
default:
105+
return fmt.Errorf("sdl: unsupported GPU vendor (%s)", vendor)
106+
}
107+
108+
for _, model := range models {
109+
res = append(res, types.Attribute{
110+
Key: fmt.Sprintf("vendor/%s/model/%s", vendor, model.String()),
111+
Value: "true",
112+
})
113+
}
114+
115+
if len(models) == 0 {
116+
res = append(res, types.Attribute{
117+
Key: fmt.Sprintf("vendor/%s/model/*", vendor),
118+
Value: "true",
119+
})
120+
}
100121
}
101122

102123
sort.Sort(res)

0 commit comments

Comments
 (0)