@@ -199,7 +199,7 @@ func (m *NvidiaDevicePlugin) unhealthy(dev *pluginapi.Device) {
199199// Allocate which return list of devices.
200200func (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
247252func (m * NvidiaDevicePlugin ) PreStartContainer (context.Context , * pluginapi.PreStartContainerRequest ) (* pluginapi.PreStartContainerResponse , error ) {
0 commit comments