func()

in pkg/gpu/nvidia/beta_plugin.go [56:93]


func (s *pluginServiceV1Beta1) Allocate(ctx context.Context, requests *pluginapi.AllocateRequest) (*pluginapi.AllocateResponse, error) {
	resps := new(pluginapi.AllocateResponse)
	for _, rqt := range requests.ContainerRequests {
		// Validate if the request is for shared GPUs and check if the request meets the GPU sharing conditions.
		if err := gpusharing.ValidateRequest(rqt.DevicesIDs, len(s.ngm.ListPhysicalDevices())); err != nil {
			return nil, err
		}

		resp := new(pluginapi.ContainerAllocateResponse)
		// Add all requested devices to Allocate Response
		for _, id := range rqt.DevicesIDs {
			devices, err := s.ngm.DeviceSpec(id)
			if err != nil {
				return nil, err
			}

			for i := range devices {
				resp.Devices = append(resp.Devices, &devices[i])
			}
		}
		// Add all default devices to Allocate Response
		for _, d := range s.ngm.defaultDevices {
			resp.Devices = append(resp.Devices, &pluginapi.DeviceSpec{
				HostPath:      d,
				ContainerPath: d,
				Permissions:   "mrw",
			})
		}

		for i := range s.ngm.mountPaths {
			resp.Mounts = append(resp.Mounts, &s.ngm.mountPaths[i])
		}

		resp.Envs = s.ngm.Envs(len(rqt.DevicesIDs))
		resps.ContainerResponses = append(resps.ContainerResponses, resp)
	}
	return resps, nil
}