Skip to content

Commit

Permalink
introduce service.gpus
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Oct 4, 2024
1 parent 8158217 commit ead2aba
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 183 deletions.
26 changes: 26 additions & 0 deletions loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2224,6 +2224,32 @@ services:
assert.ErrorContains(t, err, `capabilities is required`)
}

func TestServiceGpus(t *testing.T) {
p, err := loadYAML(`
name: service-gpus
services:
test:
image: redis:alpine
gpus:
- driver: nvidia
- driver: 3dfx
device_ids: ["voodoo2"]
capabilities: ["directX"]
`)
assert.NilError(t, err)
assert.DeepEqual(t, p.Services["test"].Gpus, []types.DeviceRequest{
{
Driver: "nvidia",
Count: -1,
},
{
Capabilities: []string{"directX"},
Driver: "3dfx",
IDs: []string{"voodoo2"},
},
})
}

func TestServicePullPolicy(t *testing.T) {
actual, err := loadYAML(`
name: service-pull-policy
Expand Down
18 changes: 18 additions & 0 deletions schema/compose-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@
},
"external_links": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
"extra_hosts": {"$ref": "#/definitions/extra_hosts"},
"gpus": {"$ref": "#/definitions/gpus"},
"group_add": {
"type": "array",
"items": {
Expand Down Expand Up @@ -649,6 +650,23 @@
}
},

"gpus": {
"id": "#/definitions/gpus",
"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-": {}}
}
},

"include": {
"id": "#/definitions/include",
"oneOf": [
Expand Down
1 change: 1 addition & 0 deletions transform/canonical.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func init() {
transformers["services.*.deploy.resources.reservations.devices.*"] = transformDeviceRequest
transformers["services.*.env_file"] = transformEnvFile
transformers["services.*.extends"] = transformExtends
transformers["services.*.gpus.*"] = transformDeviceRequest
transformers["services.*.networks"] = transformServiceNetworks
transformers["services.*.volumes.*"] = transformVolumeMount
transformers["services.*.devices.*"] = transformDeviceMapping
Expand Down
Loading

0 comments on commit ead2aba

Please sign in to comment.