Skip to content

Commit db96b90

Browse files
committed
Add allocation log
Signed-off-by: ghokun <[email protected]>
1 parent be5519e commit db96b90

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

manifests/device-plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ spec:
4545
capabilities:
4646
add: ["SYS_ADMIN"]
4747
containers:
48-
- image: ghcr.io/kuartis/kuartis-virtual-gpu-device-plugin:0.3.2
48+
- image: ghcr.io/kuartis/kuartis-virtual-gpu-device-plugin:0.3.3
4949
name: kuartis-virtual-gpu-device-plugin-ctr
5050
command:
5151
- /usr/bin/virtual-gpu-device-plugin

pkg/gpu/nvidia/server.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func (m *NvidiaDevicePlugin) unhealthy(dev *pluginapi.Device) {
199199
// Allocate which return list of devices.
200200
func (m *NvidiaDevicePlugin) Allocate(ctx context.Context, reqs *pluginapi.AllocateRequest) (*pluginapi.AllocateResponse, error) {
201201
devs := m.devs
202-
responses := pluginapi.AllocateResponse{}
202+
response := new(pluginapi.AllocateResponse)
203203
physicalDevsMap := make(map[string]bool)
204204
for _, req := range reqs.ContainerRequests {
205205
for _, id := range req.DevicesIDs {
@@ -228,20 +228,25 @@ func (m *NvidiaDevicePlugin) Allocate(ctx context.Context, reqs *pluginapi.Alloc
228228
for visibleDev := range physicalDevsMap {
229229
visibleDevs = append(visibleDevs, visibleDev)
230230
}
231-
response := pluginapi.ContainerAllocateResponse{
232-
Envs: map[string]string{
233-
"NVIDIA_VISIBLE_DEVICES": strings.Join(visibleDevs, ","),
234-
"CUDA_MPS_ACTIVE_THREAD_PERCENTAGE": fmt.Sprintf("%d", 100*len(req.DevicesIDs)/len(m.devs)),
235-
},
236-
Annotations: map[string]string{
237-
"k8s.kuartis.com/gpu-ids": strings.Join(visibleDevs, ","),
238-
"k8s.kuartis.com/vgpu-ids": strings.Join(req.DevicesIDs, ","),
239-
},
240-
}
241-
responses.ContainerResponses = append(responses.ContainerResponses, &response)
231+
232+
cresp := new(pluginapi.ContainerAllocateResponse)
233+
234+
cresp.Envs = map[string]string{}
235+
cresp.Envs["NVIDIA_VISIBLE_DEVICES"] = strings.Join(visibleDevs, ",")
236+
cresp.Envs["CUDA_MPS_ACTIVE_THREAD_PERCENTAGE"] = fmt.Sprintf("%d", 100*len(req.DevicesIDs)/len(m.devs))
237+
238+
cresp.Annotations = map[string]string{}
239+
cresp.Annotations["k8s.kuartis.com/gpu-ids"] = strings.Join(visibleDevs, ",")
240+
cresp.Annotations["k8s.kuartis.com/vgpu-ids"] = strings.Join(req.DevicesIDs, ",")
241+
242+
log.Printf("Allocated physical devices: %s", strings.Join(visibleDevs, ","))
243+
log.Printf("Allocated virtual devices: %s", strings.Join(req.DevicesIDs, ","))
244+
log.Printf("Allocated MPS ACTIVE THREAD PERCENTAGE: %s", fmt.Sprintf("%d", 100*len(req.DevicesIDs)/len(m.devs)))
245+
246+
response.ContainerResponses = append(response.ContainerResponses, cresp)
242247
}
243248

244-
return &responses, nil
249+
return response, nil
245250
}
246251

247252
func (m *NvidiaDevicePlugin) PreStartContainer(context.Context, *pluginapi.PreStartContainerRequest) (*pluginapi.PreStartContainerResponse, error) {

0 commit comments

Comments
 (0)