Skip to content

Commit

Permalink
fix(bidengine): make GPU attributes as struct (#122)
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian authored Jun 12, 2023
1 parent 6f642e5 commit 82f5313
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
13 changes: 11 additions & 2 deletions bidengine/pricing.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,18 @@ type storageElement struct {
Size uint64 `json:"size"`
}

type gpuVendorAttributes struct {
Model string `json:"model"`
RAM *string `json:"ram,omitempty"`
}

type gpuAttributes struct {
Vendor map[string]gpuVendorAttributes `json:"vendor,omitempty"`
}

type gpuElement struct {
Units uint64 `json:"units"`
Attributes map[string]map[string]string `json:"attributes,omitempty"`
Units uint64 `json:"units"`
Attributes gpuAttributes `json:"attributes"`
}

type dataForScriptElement struct {
Expand Down
28 changes: 23 additions & 5 deletions bidengine/shellscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,34 @@ func parseMemory(res *atypes.Memory) uint64 {

func parseGPU(resource *atypes.GPU) gpuElement {
res := gpuElement{
Units: resource.Units.Value(),
Attributes: make(map[string]map[string]string),
Units: resource.Units.Value(),
Attributes: gpuAttributes{
Vendor: make(map[string]gpuVendorAttributes),
},
}

for _, attr := range resource.Attributes {
tokens := strings.Split(attr.Key, "/")
if _, exists := res.Attributes[tokens[0]]; !exists {
res.Attributes[tokens[0]] = make(map[string]string)

// vendor/nvidia/model/a100
switch tokens[0] {
case "vendor":
vendor := tokens[1]
model := tokens[3]
var ram *string

// vendor/nvidia/model/a100/ram/80Gi
if len(tokens) == 6 && tokens[4] == "ram" {
ram = new(string)
*ram = tokens[5]
}

res.Attributes.Vendor[vendor] = gpuVendorAttributes{
Model: model,
RAM: ram,
}
default:
}
res.Attributes[tokens[0]][tokens[1]] = tokens[2]
}

return res
Expand Down

0 comments on commit 82f5313

Please sign in to comment.