Skip to content

Commit 4cb0d38

Browse files
ndeloofglours
authored andcommitted
support gpus: all alias
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 4874a29 commit 4cb0d38

File tree

4 files changed

+68
-13
lines changed

4 files changed

+68
-13
lines changed

loader/loader_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3738,3 +3738,15 @@ services:
37383738
assert.NilError(t, err)
37393739
assert.Equal(t, len(p.Services["test"].DNS), 0)
37403740
}
3741+
3742+
func TestAllGPUS(t *testing.T) {
3743+
p, err := loadYAML(`
3744+
name: load-all-gpus
3745+
services:
3746+
test:
3747+
gpus: all
3748+
`)
3749+
assert.NilError(t, err)
3750+
assert.Equal(t, len(p.Services["test"].Gpus), 1)
3751+
assert.Equal(t, p.Services["test"].Gpus[0].Count, types.DeviceCount(-1))
3752+
}

schema/compose-spec.json

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -657,19 +657,23 @@
657657

658658
"gpus": {
659659
"id": "#/definitions/gpus",
660-
"type": "array",
661-
"items": {
662-
"type": "object",
663-
"properties": {
664-
"capabilities": {"$ref": "#/definitions/list_of_strings"},
665-
"count": {"type": ["string", "integer"]},
666-
"device_ids": {"$ref": "#/definitions/list_of_strings"},
667-
"driver":{"type": "string"},
668-
"options":{"$ref": "#/definitions/list_or_dict"}
669-
},
670-
"additionalProperties": false,
671-
"patternProperties": {"^x-": {}}
672-
}
660+
"oneOf": [
661+
{"type": "string", "enum": ["all"]},
662+
{"type": "array",
663+
"items": {
664+
"type": "object",
665+
"properties": {
666+
"capabilities": {"$ref": "#/definitions/list_of_strings"},
667+
"count": {"type": ["string", "integer"]},
668+
"device_ids": {"$ref": "#/definitions/list_of_strings"},
669+
"driver":{"type": "string"},
670+
"options":{"$ref": "#/definitions/list_or_dict"}
671+
}
672+
},
673+
"additionalProperties": false,
674+
"patternProperties": {"^x-": {}}
675+
}
676+
]
673677
},
674678

675679
"include": {

transform/canonical.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func init() {
3232
transformers["services.*.env_file"] = transformEnvFile
3333
transformers["services.*.label_file"] = transformStringOrList
3434
transformers["services.*.extends"] = transformExtends
35+
transformers["services.*.gpus"] = transformGpus
3536
transformers["services.*.networks"] = transformServiceNetworks
3637
transformers["services.*.volumes.*"] = transformVolumeMount
3738
transformers["services.*.dns"] = transformStringOrList

transform/gpus.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Copyright 2020 The Compose Specification Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package transform
18+
19+
import (
20+
"fmt"
21+
22+
"github.com/compose-spec/compose-go/v2/tree"
23+
)
24+
25+
func transformGpus(data any, p tree.Path, ignoreParseError bool) (any, error) {
26+
switch v := data.(type) {
27+
case []any:
28+
return transformSequence(v, p, ignoreParseError)
29+
case string:
30+
return []any{
31+
map[string]any{
32+
"count": "all",
33+
},
34+
}, nil
35+
default:
36+
return data, fmt.Errorf("%s: invalid type %T for gpus", p, v)
37+
}
38+
}

0 commit comments

Comments
 (0)