Skip to content

Commit

Permalink
feat(sdl): add gpu filtering with interface (#1938)
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <troian.ap@gmail.com>
  • Loading branch information
troian authored Mar 28, 2024
1 parent 41df5c6 commit 900f9a9
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
26 changes: 23 additions & 3 deletions sdl/gpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,22 @@ import (
types "github.com/akash-network/akash-api/go/node/types/v1beta3"
)

type gpuInterface string

type v2GPUNvidia struct {
Model string `yaml:"model"`
RAM *memoryQuantity `yaml:"ram,omitempty"`
Model string `yaml:"model"`
RAM *memoryQuantity `yaml:"ram,omitempty"`
Interface *gpuInterface `yaml:"interface,omitempty"`
}

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

if sdl.Interface != nil {
key = fmt.Sprintf("%s/interface/%s", key, *sdl.Interface)
}

return key
Expand Down Expand Up @@ -109,3 +116,16 @@ func (sdl *v2GPUAttributes) UnmarshalYAML(node *yaml.Node) error {

return nil
}

func (sdl *gpuInterface) UnmarshalYAML(node *yaml.Node) error {
switch node.Value {
case "pcie":
case "sxm":
default:
return fmt.Errorf("sdl: invalid GPU interface %s. expected \"pcie|sxm\"", node.Value)
}

*sdl = gpuInterface(node.Value)

return nil
}
35 changes: 35 additions & 0 deletions sdl/gpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,41 @@ attributes:
require.Error(t, err)
}

func TestV2ResourceGPU_InterfaceInvalid(t *testing.T) {
var stream = `
units: 1
attributes:
vendor:
nvidia:
- model: a100
interface: pciex
`
var p v2ResourceGPU

err := yaml.Unmarshal([]byte(stream), &p)
require.Error(t, err)
}

func TestV2ResourceGPU_RamWithInterface(t *testing.T) {
var stream = `
units: 1
attributes:
vendor:
nvidia:
- model: a100
ram: 80Gi
interface: pcie
`
var p v2ResourceGPU

err := yaml.Unmarshal([]byte(stream), &p)
require.NoError(t, err)
require.Equal(t, gpuQuantity(1), p.Units)
require.Equal(t, 1, len(p.Attributes))
require.Equal(t, "vendor/nvidia/model/a100/ram/80Gi/interface/pcie", p.Attributes[0].Key)
require.Equal(t, "true", p.Attributes[0].Value)
}

func TestV2ResourceGPU_MultipleModels(t *testing.T) {
var stream = `
units: 1
Expand Down

0 comments on commit 900f9a9

Please sign in to comment.