Skip to content

Commit c41129d

Browse files
committed
feat: convert GPU resource limits from scalar values to per-device JSON maps
1 parent a55ca0e commit c41129d

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

internal/worker/worker.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,35 @@ func (wg *WorkerGenerator) GenerateWorkerPod(
109109
Value: strconv.Itoa(port),
110110
}, corev1.EnvVar{
111111
Name: constants.WorkerCudaUpLimitTflopsEnv,
112-
Value: strconv.FormatInt(limits.Tflops.Value(), 10),
112+
Value: func() string {
113+
tflopsMap := make(map[string]int64)
114+
for _, gpu := range gpus {
115+
tflopsMap[gpu.Status.UUID] = limits.Tflops.Value()
116+
}
117+
jsonBytes, _ := json.Marshal(tflopsMap)
118+
return string(jsonBytes)
119+
}(),
113120
}, corev1.EnvVar{
114121
Name: constants.WorkerCudaUpLimitEnv,
115-
Value: strconv.FormatInt(int64(math.Ceil(float64(limits.Tflops.Value())/float64(info.Fp16TFlops.Value())*100)), 10),
122+
Value: func() string {
123+
upLimitMap := make(map[string]int64)
124+
for _, gpu := range gpus {
125+
upLimitMap[gpu.Status.UUID] = int64(math.Ceil(float64(limits.Tflops.Value())/float64(info.Fp16TFlops.Value())*100))
126+
}
127+
jsonBytes, _ := json.Marshal(upLimitMap)
128+
return string(jsonBytes)
129+
}(),
116130
}, corev1.EnvVar{
117131
Name: constants.WorkerCudaMemLimitEnv,
118132
// bytesize
119-
Value: strconv.FormatInt(limits.Vram.Value(), 10),
133+
Value: func() string {
134+
memLimitMap := make(map[string]int64)
135+
for _, gpu := range gpus {
136+
memLimitMap[gpu.Status.UUID] = limits.Vram.Value()
137+
}
138+
jsonBytes, _ := json.Marshal(memLimitMap)
139+
return string(jsonBytes)
140+
}(),
120141
}, corev1.EnvVar{
121142
Name: constants.WorkerPodNameEnv,
122143
ValueFrom: &corev1.EnvVarSource{

0 commit comments

Comments
 (0)