This repository was archived by the owner on Dec 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslots.ts
More file actions
98 lines (84 loc) · 3.12 KB
/
slots.ts
File metadata and controls
98 lines (84 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import * as pulumi from "@pulumi/pulumi"
import * as AWS from "aws-sdk"
import * as pulumiConfig from "./config"
const workerReservedMemoryMB = 1024
interface ResourceClass {
readonly id: string
readonly description: string
readonly name: string
readonly order: number
readonly resource: {
readonly slots: number
}
}
interface Slot {
readonly cpu: number
readonly memory: number
}
export interface SlotConfig {
readonly classes: ResourceClass[]
readonly defaultClass: string
readonly slot: Slot
readonly workerReservedMemoryMB: number
readonly slotsPerWorker: number
}
export interface SlotsConfig {
general: SlotConfig
gpu: SlotConfig
}
const idNamesArray = [
{ id: "xsmall", name: "X-Small", slots: 1 },
{ id: "small", name: "Small", slots: 2 },
{ id: "2xsmall", name: "2x Small", slots: 4 },
{ id: "medium", name: "Medium", slots: 8 },
{ id: "large", name: "Large", slots: 16 },
{ id: "2xlarge", name: "2x Large", slots: 32 },
{ id: "3xlarge", name: "3x Large", slots: 48 },
{ id: "4xlarge", name: "4x Large", slots: 64 },
{ id: "5xlarge", name: "5x Large", slots: 72 },
{ id: "6xlarge", name: "6x Large", slots: 96 },
]
function getSlotsFromInfo(instanceTypeInfo: AWS.EC2.InstanceTypeInfo, gpu: Boolean) : SlotConfig {
let slotsPerWorker = gpu ? instanceTypeInfo.GpuInfo!.Gpus![0].Count : instanceTypeInfo.VCpuInfo!.DefaultVCpus
const slot: Slot = {
cpu: (instanceTypeInfo.VCpuInfo!.DefaultVCpus! / slotsPerWorker!),
memory: Math.round(((instanceTypeInfo.MemoryInfo!.SizeInMiB! - workerReservedMemoryMB) / slotsPerWorker!) * 1000 * 1000),
}
let classes : ResourceClass[] = idNamesArray.filter(v => v.slots <= slotsPerWorker!).map((v, _i) => {
let desc = `${v.slots * slot.cpu} cores / ${Math.round(slot.memory / 1000 / 1000 / 1000) * v.slots} GB RAM`
if (gpu) {
desc = `${v.slots} GPUs / ` + desc
}
return {
id: v.id,
description: desc,
name: v.name,
order: _i + 1,
resource: {
slots: v.slots,
},
}
})
return {
classes,
defaultClass: classes[0].id,
slot,
workerReservedMemoryMB: workerReservedMemoryMB,
slotsPerWorker: slotsPerWorker!,
}
}
export const config = pulumi.output<SlotsConfig>(new AWS.EC2({apiVersion: "2016-11-15", region: pulumiConfig.aws.region}).describeInstanceTypes({
InstanceTypes: [
pulumiConfig.workers.general.instanceType,
pulumiConfig.workers.gpu.instanceType,
],
}).promise().then((data) => {
if (data.InstanceTypes?.length != 2) {
throw new pulumi.RunError(`Could not get worker instance type from AWS: ${pulumiConfig.workers.general.instanceType}`)
}
let resources : SlotsConfig = {
general: getSlotsFromInfo(data.InstanceTypes.find(v => v.InstanceType == pulumiConfig.workers.general.instanceType)!, false),
gpu: getSlotsFromInfo(data.InstanceTypes.find(v => v.InstanceType == pulumiConfig.workers.gpu.instanceType)!, true),
}
return resources
}))