mirror of
https://github.com/docker/compose.git
synced 2025-07-23 05:34:36 +02:00
Implement device requests for GPU support
Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
parent
843621dfb8
commit
854c003359
@ -524,7 +524,8 @@
|
|||||||
"properties": {
|
"properties": {
|
||||||
"cpus": {"type": ["number", "string"]},
|
"cpus": {"type": ["number", "string"]},
|
||||||
"memory": {"type": "string"},
|
"memory": {"type": "string"},
|
||||||
"generic_resources": {"$ref": "#/definitions/generic_resources"}
|
"generic_resources": {"$ref": "#/definitions/generic_resources"},
|
||||||
|
"devices": {"$ref": "#/definitions/devices"}
|
||||||
},
|
},
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"patternProperties": {"^x-": {}}
|
"patternProperties": {"^x-": {}}
|
||||||
@ -590,6 +591,23 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"devices": {
|
||||||
|
"id": "#/definitions/devices",
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"capabilities": {"$ref": "#/definitions/list_of_strings"},
|
||||||
|
"count": {"type": ["string", "integer"]},
|
||||||
|
"device_ids": {"$ref": "#/definitions/list_of_strings"},
|
||||||
|
"driver":{"type": "string"},
|
||||||
|
"options":{"$ref": "#/definitions/list_or_dict"}
|
||||||
|
},
|
||||||
|
"additionalProperties": false,
|
||||||
|
"patternProperties": {"^x-": {}}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
"network": {
|
"network": {
|
||||||
"id": "#/definitions/network",
|
"id": "#/definitions/network",
|
||||||
"type": ["object", "null"],
|
"type": ["object", "null"],
|
||||||
|
@ -128,7 +128,7 @@ class Project:
|
|||||||
config_data.secrets)
|
config_data.secrets)
|
||||||
|
|
||||||
service_dict['scale'] = project.get_service_scale(service_dict)
|
service_dict['scale'] = project.get_service_scale(service_dict)
|
||||||
|
device_requests = project.get_device_requests(service_dict)
|
||||||
service_dict = translate_credential_spec_to_security_opt(service_dict)
|
service_dict = translate_credential_spec_to_security_opt(service_dict)
|
||||||
service_dict, ignored_keys = translate_deploy_keys_to_container_config(
|
service_dict, ignored_keys = translate_deploy_keys_to_container_config(
|
||||||
service_dict
|
service_dict
|
||||||
@ -154,6 +154,7 @@ class Project:
|
|||||||
ipc_mode=ipc_mode,
|
ipc_mode=ipc_mode,
|
||||||
platform=service_dict.pop('platform', None),
|
platform=service_dict.pop('platform', None),
|
||||||
default_platform=default_platform,
|
default_platform=default_platform,
|
||||||
|
device_requests=device_requests,
|
||||||
extra_labels=extra_labels,
|
extra_labels=extra_labels,
|
||||||
**service_dict)
|
**service_dict)
|
||||||
)
|
)
|
||||||
@ -331,6 +332,31 @@ class Project:
|
|||||||
max_replicas))
|
max_replicas))
|
||||||
return scale
|
return scale
|
||||||
|
|
||||||
|
def get_device_requests(self, service_dict):
|
||||||
|
deploy_dict = service_dict.get('deploy', None)
|
||||||
|
if not deploy_dict:
|
||||||
|
return
|
||||||
|
|
||||||
|
resources = deploy_dict.get('resources', None)
|
||||||
|
if not resources or not resources.get('reservations', None):
|
||||||
|
return
|
||||||
|
devices = resources['reservations'].get('devices')
|
||||||
|
if not devices:
|
||||||
|
return
|
||||||
|
|
||||||
|
for dev in devices:
|
||||||
|
count = dev.get("count", -1)
|
||||||
|
if not isinstance(count, int):
|
||||||
|
if count != "all":
|
||||||
|
raise ConfigurationError(
|
||||||
|
'Invalid value "{}" for devices count'.format(dev["count"]),
|
||||||
|
'(expected integer or "all")')
|
||||||
|
dev["count"] = -1
|
||||||
|
|
||||||
|
if 'capabilities' in dev:
|
||||||
|
dev['capabilities'] = [dev['capabilities']]
|
||||||
|
return devices
|
||||||
|
|
||||||
def start(self, service_names=None, **options):
|
def start(self, service_names=None, **options):
|
||||||
containers = []
|
containers = []
|
||||||
|
|
||||||
|
@ -77,6 +77,7 @@ HOST_CONFIG_KEYS = [
|
|||||||
'cpuset',
|
'cpuset',
|
||||||
'device_cgroup_rules',
|
'device_cgroup_rules',
|
||||||
'devices',
|
'devices',
|
||||||
|
'device_requests',
|
||||||
'dns',
|
'dns',
|
||||||
'dns_search',
|
'dns_search',
|
||||||
'dns_opt',
|
'dns_opt',
|
||||||
@ -180,6 +181,7 @@ class Service:
|
|||||||
pid_mode=None,
|
pid_mode=None,
|
||||||
default_platform=None,
|
default_platform=None,
|
||||||
extra_labels=None,
|
extra_labels=None,
|
||||||
|
device_requests=None,
|
||||||
**options
|
**options
|
||||||
):
|
):
|
||||||
self.name = name
|
self.name = name
|
||||||
@ -195,6 +197,7 @@ class Service:
|
|||||||
self.secrets = secrets or []
|
self.secrets = secrets or []
|
||||||
self.scale_num = scale
|
self.scale_num = scale
|
||||||
self.default_platform = default_platform
|
self.default_platform = default_platform
|
||||||
|
self.device_requests = device_requests
|
||||||
self.options = options
|
self.options = options
|
||||||
self.extra_labels = extra_labels or []
|
self.extra_labels = extra_labels or []
|
||||||
|
|
||||||
@ -1016,6 +1019,7 @@ class Service:
|
|||||||
privileged=options.get('privileged', False),
|
privileged=options.get('privileged', False),
|
||||||
network_mode=self.network_mode.mode,
|
network_mode=self.network_mode.mode,
|
||||||
devices=options.get('devices'),
|
devices=options.get('devices'),
|
||||||
|
device_requests=self.device_requests,
|
||||||
dns=options.get('dns'),
|
dns=options.get('dns'),
|
||||||
dns_opt=options.get('dns_opt'),
|
dns_opt=options.get('dns_opt'),
|
||||||
dns_search=options.get('dns_search'),
|
dns_search=options.get('dns_search'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user