Parse reservation.devices for GPU requests

Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
aiordache 2021-01-05 16:40:52 +01:00
Родитель c6cdfec530
Коммит fef73b8af3
4 изменённых файлов: 48 добавлений и 4 удалений

Просмотреть файл

@ -66,7 +66,9 @@ var compatibleComposeAttributes = []string{
"services.deploy.resources.reservations.cpus",
"services.deploy.resources.reservations.memory",
"services.deploy.resources.reservations.devices",
"services.deploy.resources.reservations.devices.capabilities",
"services.deploy.resources.reservations.devices.count",
"services.deploy.resources.reservations.devices.driver",
"services.deploy.resources.reservations.generic_resources",
"services.deploy.resources.reservations.generic_resources.discrete_resource_spec",
"services.deploy.update_config",
@ -167,3 +169,9 @@ func (c *fargateCompatibilityChecker) CheckDeployResourcesDevicesCapabilities(s
}
}
}
func (c *fargateCompatibilityChecker) CheckDeployResourcesDevicesDriver(s string, r types.DeviceRequest) {
if r.Driver != "" && r.Driver != "nvidia" {
c.Unsupported("services.deploy.resources.%s.devices.driver = %s", s, r.Driver)
}
}

Просмотреть файл

@ -181,6 +181,25 @@ func toTaskResourceRequirements(reservations *types.Resource) []ecs.TaskDefiniti
})
}
}
for _, r := range reservations.Devices {
hasGpuCap := false
for _, c := range r.Capabilities {
if c == "gpu" {
hasGpuCap = true
break
}
}
if hasGpuCap {
count := r.Count
if count <= 0 {
count = 1
}
requirements = append(requirements, ecs.TaskDefinition_ResourceRequirement{
Type: ecsapi.ResourceTypeGpu,
Value: fmt.Sprint(count),
})
}
}
return requirements
}

Просмотреть файл

@ -132,7 +132,7 @@ type resourceRequirements struct {
func getResourceRequirements(project *types.Project) (*resourceRequirements, error) {
return toResourceRequirementsSlice(project).
filter(func(requirements *resourceRequirements) bool {
return requirements.gpus != 0
return requirements != nil && requirements.gpus != 0
}).
max()
}
@ -184,6 +184,23 @@ func toResourceRequirements(service types.ServiceConfig) (*resourceRequirements,
}
}
for _, r := range reservations.Devices {
requiresGpus := false
for _, c := range r.Capabilities {
if c == "gpu" {
requiresGpus = true
break
}
}
if requiresGpus {
requiredGPUs = r.Count
if requiredGPUs <= 0 {
requiredGPUs = 1
}
break
}
}
var nanocpu float64
if reservations.NanoCPUs != "" {
v, err := strconv.ParseFloat(reservations.NanoCPUs, 64)