FetchSpecStore loads GPU specs and availability from the API concurrently and merges them into a SpecStore. Specs are required; availability is best-effort — a failure leaves configurations unmarked rather than aborting.
(client *api.Client)
| 29 | // merges them into a SpecStore. Specs are required; availability is best-effort |
| 30 | // — a failure leaves configurations unmarked rather than aborting. |
| 31 | func FetchSpecStore(client *api.Client) (*SpecStore, error) { |
| 32 | var ( |
| 33 | specsMap map[string]api.GpuSpecConfig |
| 34 | specsErr error |
| 35 | availability map[string]string |
| 36 | wg sync.WaitGroup |
| 37 | ) |
| 38 | wg.Add(2) |
| 39 | go func() { |
| 40 | defer wg.Done() |
| 41 | specsMap, specsErr = client.GetSpecs() |
| 42 | }() |
| 43 | go func() { |
| 44 | defer wg.Done() |
| 45 | if avail, err := client.GetAvailability(); err == nil && avail != nil { |
| 46 | availability = avail.Specs |
| 47 | } |
| 48 | }() |
| 49 | wg.Wait() |
| 50 | |
| 51 | if specsErr != nil { |
| 52 | return nil, fmt.Errorf("failed to fetch GPU specs: %w", specsErr) |
| 53 | } |
| 54 | return NewSpecStoreWithAvailability(specsMap, availability), nil |
| 55 | } |
| 56 | |
| 57 | func publicConfigKey(gpuType string, gpuCount int) string { |
| 58 | return fmt.Sprintf("%s_x%d", gpuType, gpuCount) |
no test coverage detected