@@ -86,8 +86,7 @@ func WithGPUs(opts ...Opts) oci.SpecOpts {
8686}
8787
8888type config struct {
89- Devices []int
90- DeviceUUID string
89+ Devices []string
9190 Capabilities []Capability
9291 LoadKmods bool
9392 LDCache string
@@ -108,10 +107,7 @@ func (c *config) args() []string {
108107 "configure" ,
109108 )
110109 if len (c .Devices ) > 0 {
111- args = append (args , fmt .Sprintf ("--device=%s" , strings .Join (toStrings (c .Devices ), "," )))
112- }
113- if c .DeviceUUID != "" {
114- args = append (args , fmt .Sprintf ("--device=%s" , c .DeviceUUID ))
110+ args = append (args , fmt .Sprintf ("--device=%s" , strings .Join (c .Devices , "," )))
115111 }
116112 for _ , c := range c .Capabilities {
117113 args = append (args , fmt .Sprintf ("--%s" , capFlags [c ]))
@@ -135,36 +131,30 @@ var capFlags = map[Capability]string{
135131 Display : "display" ,
136132}
137133
138- func toStrings (ints []int ) []string {
139- var s []string
140- for _ , i := range ints {
141- s = append (s , strconv .Itoa (i ))
142- }
143- return s
144- }
145-
146134// Opts are options for configuring gpu support
147135type Opts func (* config ) error
148136
149137// WithDevices adds the provided device indexes to the container
150138func WithDevices (ids ... int ) Opts {
151139 return func (c * config ) error {
152- c .Devices = ids
140+ for _ , i := range ids {
141+ c .Devices = append (c .Devices , strconv .Itoa (i ))
142+ }
153143 return nil
154144 }
155145}
156146
157- // WithDeviceUUID adds the specific device UUID to the container
158- func WithDeviceUUID ( guid string ) Opts {
147+ // WithDeviceUUIDs adds the specific device UUID to the container
148+ func WithDeviceUUIDs ( uuids ... string ) Opts {
159149 return func (c * config ) error {
160- c .DeviceUUID = guid
150+ c .Devices = append ( c . Devices , uuids ... )
161151 return nil
162152 }
163153}
164154
165155// WithAllDevices adds all gpus to the container
166156func WithAllDevices (c * config ) error {
167- c .DeviceUUID = "all"
157+ c .Devices = [] string { "all" }
168158 return nil
169159}
170160
@@ -176,6 +166,14 @@ func WithAllCapabilities(c *config) error {
176166 return nil
177167}
178168
169+ // WithCapabilities adds the specified capabilities to the container for the gpus
170+ func WithCapabilities (caps ... Capability ) Opts {
171+ return func (c * config ) error {
172+ c .Capabilities = append (c .Capabilities , caps ... )
173+ return nil
174+ }
175+ }
176+
179177// WithRequiredCUDAVersion sets the required cuda version
180178func WithRequiredCUDAVersion (major , minor int ) Opts {
181179 return func (c * config ) error {
0 commit comments