Skip to content

Commit

Permalink
feat(sdl): parse amd gpu
Browse files Browse the repository at this point in the history
refs akash-network/support#142

Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Dec 9, 2023
1 parent 36b9884 commit 120c27a
Show file tree
Hide file tree
Showing 6 changed files with 320 additions and 155 deletions.
52 changes: 52 additions & 0 deletions .github/labeler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"C:x/audit":
- changed-files:
- any-glob-to-any-file: x/audit/**/*
"C:x/cert":
- changed-files:
- any-glob-to-any-file: x/cert/**/*
"C:x/deployment":
- changed-files:
- any-glob-to-any-file: x/deployment/**/*
"C:x/escrow":
- changed-files:
- any-glob-to-any-file: x/escrow/**/*
"C:x/gov":
- changed-files:
- any-glob-to-any-file: x/gov/**/*
"C:x/inflation":
- changed-files:
- any-glob-to-any-file: x/inflation/**/*
"C:x/market":
- changed-files:
- any-glob-to-any-file: x/market/**/*
"C:x/provider":
- changed-files:
- any-glob-to-any-file: x/provider/**/*
"C:x/staking":
- changed-files:
- any-glob-to-any-file: x/staking/**/*
"C:x/take":
- changed-files:
- any-glob-to-any-file: x/take/**/*
"C:CLI":
- changed-files:
- any-glob-to-any-file: cmd/**/*
- changed-files:
- any-glob-to-any-file: x/*/client/cli/*
"C:upgrades":
- changed-files:
- any-glob-to-any-file: upgrades/**/*
"Type: Build":
- changed-files:
- any-glob-to-any-file: Makefile
- changed-files:
- any-glob-to-any-file: Dockerfile
- changed-files:
- any-glob-to-any-file: script/*
- changed-files:
- any-glob-to-any-file: make/*
- changed-files:
- any-glob-to-any-file: .goreleaser*
"Type: CI":
- changed-files:
- any-glob-to-any-file: .github/**/*
33 changes: 0 additions & 33 deletions .github/pr_labeler.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ permissions:
contents: read

jobs:
pr-labeler:
labeler:
permissions:
contents: read # for actions/labeler to determine modified files
pull-requests: write # for actions/labeler to add labels to PRs
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@main
- uses: actions/checkout@v3
- uses: actions/labeler@v5
with:
configuration-path: .github/pr_labeler.yaml
repo-token: "${{ secrets.GITHUB_TOKEN }}"
dot: true
65 changes: 43 additions & 22 deletions sdl/gpu.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sdl

import (
"errors"
"fmt"
"sort"

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

type v2GPUNvidia struct {
var (
ErrResourceGPUEmptyVendors = errors.New("sdl: invalid GPU attributes. at least one vendor must be set")
)

type v2GPU struct {
Model string `yaml:"model"`
RAM *memoryQuantity `yaml:"ram,omitempty"`
}

func (sdl *v2GPUNvidia) String() string {
func (sdl *v2GPU) String() string {
key := sdl.Model
if sdl.RAM != nil {
key += "/" + sdl.RAM.StringWithSuffix("Gi")
key += "/ram/" + sdl.RAM.StringWithSuffix("Gi")
}

return key
}

type v2GPUsNvidia []v2GPUNvidia
type v2GPUs []v2GPU

type gpuVendor struct {
Nvidia v2GPUsNvidia `yaml:"nvidia,omitempty"`
}
type gpuVendors map[string]v2GPUs
type gpuVendorAttributes map[string]types.Attributes

Check failure on line 34 in sdl/gpu.go

View workflow job for this annotation

GitHub Actions / lint

type `gpuVendorAttributes` is unused (unused)

Check failure on line 34 in sdl/gpu.go

View workflow job for this annotation

GitHub Actions / lint

type `gpuVendorAttributes` is unused (unused)

type v2GPUAttributes types.Attributes

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

var vendor *gpuVendor
vendors := make(gpuVendors)

for i := 0; i < len(node.Content); i += 2 {
switch node.Content[i].Value {
case "vendor":
if err := node.Content[i+1].Decode(&vendor); err != nil {
if err := node.Content[i+1].Decode(&vendors); err != nil {
return err
}
default:
return fmt.Errorf("sdl: unsupported attribute (%s) for GPU resource", node.Content[i].Value)
}
}

if vendor == nil {
return fmt.Errorf("sdl: invalid GPU attributes. at least one vendor must be set")
if len(vendors) == 0 {
return ErrResourceGPUEmptyVendors
}

res = make(types.Attributes, 0, len(vendor.Nvidia))
resPrealloc := 0

for _, model := range vendor.Nvidia {
res = append(res, types.Attribute{
Key: fmt.Sprintf("vendor/nvidia/model/%s", model.String()),
Value: "true",
})
for _, models := range vendors {
if len(models) == 0 {
resPrealloc += 1
} else {
resPrealloc += len(models)
}
}

if len(res) == 0 {
res = append(res, types.Attribute{
Key: "vendor/nvidia/model/*",
Value: "true",
})
for vendor, models := range vendors {
switch vendor {
case "nvidia":
case "amd":
default:
return fmt.Errorf("sdl: unsupported GPU vendor (%s)", vendor)
}

for _, model := range models {
res = append(res, types.Attribute{
Key: fmt.Sprintf("vendor/%s/model/%s", vendor, model.String()),
Value: "true",
})
}

if len(models) == 0 {
res = append(res, types.Attribute{
Key: fmt.Sprintf("vendor/%s/model/*", vendor),
Value: "true",
})
}
}

sort.Sort(res)
Expand Down
Loading

0 comments on commit 120c27a

Please sign in to comment.