CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/compute/cloud/hyperstack/util.ts
Views: 687
1
import type { PurchaseOption } from "@cocalc/util/compute/cloud/hyperstack/pricing";
2
import { GPU_SPECS } from "@cocalc/util/compute/gpu-specs";
3
import { field_cmp } from "@cocalc/util/misc";
4
5
// Return list of GPU models that Hyperstack sells along with links to their pages.
6
// This could just be hardcoded, but instead we compute it from actual pricing data
7
// that comes from their api, combined with our specs data about GPU's. In the
8
// longrun this should be more maintainable and dynamic.
9
export function getModelLinks(priceData) {
10
const x: { [name: string]: { url?: string; cost: number } } = {};
11
for (const option of Object.values(priceData.options) as PurchaseOption[]) {
12
const { cost_per_hour, gpu_count, gpu } = option;
13
const name = toGPU(gpu);
14
if (typeof cost_per_hour == "string") {
15
continue;
16
}
17
const cost = cost_per_hour / gpu_count;
18
if (x[name] != null && x[name].cost <= cost) {
19
continue;
20
}
21
const gpuSpec = GPU_SPECS[name];
22
if (gpuSpec == null) {
23
continue;
24
}
25
x[name] = { url: gpuSpec?.hyperstack ?? gpuSpec?.datasheet, cost };
26
}
27
const models: { name: string; url?: string; cost: number }[] = [];
28
for (const name in x) {
29
models.push({ name: name.replace("-PCIe", ""), ...x[name] });
30
}
31
models.sort(field_cmp("cost"));
32
models.reverse();
33
return models;
34
}
35
36
export function toGPU(gpu) {
37
gpu = gpu.replace("G-", "GB-");
38
if (gpu.endsWith("-sm")) {
39
return gpu.slice(0, -3);
40
}
41
gpu = gpu.replace("-NVLink", "");
42
gpu = gpu.replace("-k8s", "");
43
gpu = gpu.replace("-ada", "");
44
return gpu;
45
}
46
47
48