github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/job-specification/device.mdx (about) 1 --- 2 layout: docs 3 page_title: device Stanza - Job Specification 4 description: |- 5 The "device" stanza is used to require a certain device be made available 6 to the task. 7 --- 8 9 # `device` Stanza 10 11 <Placement groups={['job', 'group', 'task', 'resources', 'device']} /> 12 13 The `device` stanza is used to create both a scheduling and runtime requirement 14 that the given task has access to the specified devices. A device is a hardware 15 device that is attached to the node and may be made available to the task. 16 Examples are GPUs, FPGAs, and TPUs. 17 18 When a `device` stanza is added, Nomad will schedule the task onto a node that 19 contains the set of device(s) that meet the specified requirements. The `device` stanza 20 allows the operator to specify as little as just the type of device required, 21 such as `gpu`, all the way to specifying arbitrary constraints and affinities. 22 Once the scheduler has placed the allocation on a suitable node, the Nomad 23 Client will invoke the device plugin to retrieve information on how to mount the 24 device and what environment variables to expose. For more information on the 25 runtime environment, please consult the individual device plugin's documentation. 26 27 See the [device plugin's documentation][devices] for a list of supported devices. 28 29 ```hcl 30 job "docs" { 31 group "example" { 32 task "server" { 33 resources { 34 device "nvidia/gpu" { 35 count = 2 36 37 constraint { 38 attribute = "${device.attr.memory}" 39 operator = ">=" 40 value = "2 GiB" 41 } 42 43 affinity { 44 attribute = "${device.attr.memory}" 45 operator = ">=" 46 value = "4 GiB" 47 weight = 75 48 } 49 } 50 } 51 } 52 } 53 } 54 ``` 55 56 In the above example, the task is requesting two GPUs, from the Nvidia vendor, 57 but is not specifying the specific model required. Instead it is placing a hard 58 constraint that the device has at least 2 GiB of memory and that it would prefer 59 to use GPUs that have at least 4 GiB. This examples shows how expressive the 60 `device` stanza can be. 61 62 ~> Device support is currently limited to Linux, and container based drivers 63 due to the ability to isolate devices to specific tasks. 64 65 ## `device` Parameters 66 67 - `name` `(string: "")` - Specifies the device required. The following inputs 68 are valid: 69 70 - `<device_type>`: If a single value is given, it is assumed to be the device 71 type, such as "gpu", or "fpga". 72 73 - `<vendor>/<device_type>`: If two values are given separated by a `/`, the 74 given device type will be selected, constraining on the provided vendor. 75 Examples include "nvidia/gpu" or "amd/gpu". 76 77 - `<vendor>/<device_type>/<model>`: If three values are given separated by a `/`, the 78 given device type will be selected, constraining on the provided vendor, and 79 model name. Examples include "nvidia/gpu/1080ti" or "nvidia/gpu/2080ti". 80 81 - `count` `(int: 1)` - Specifies the number of instances of the given device 82 that are required. 83 84 - `constraint` <code>([Constraint][]: nil)</code> - Constraints to restrict 85 which devices are eligible. This can be provided multiple times to define 86 additional constraints. See below for available attributes. 87 88 - `affinity` <code>([Affinity][]: nil)</code> - Affinity to specify a preference 89 for which devices get selected. This can be provided multiple times to define 90 additional affinities. See below for available attributes. 91 92 ## `device` Constraint and Affinity Attributes 93 94 The set of attributes available for use in a `constraint` or `affinity` are as 95 follows: 96 97 <table> 98 <thead> 99 <tr> 100 <th>Variable</th> 101 <th>Description</th> 102 <th>Example Value</th> 103 </tr> 104 </thead> 105 <tbody> 106 <tr> 107 <td> 108 <code>{'${device.type}'}</code> 109 </td> 110 <td>The type of device</td> 111 <td> 112 <code>"gpu", "tpu", "fpga"</code> 113 </td> 114 </tr> 115 <tr> 116 <td> 117 <code>{'${device.vendor}'}</code> 118 </td> 119 <td>The device's vendor</td> 120 <td> 121 <code>"amd", "nvidia", "intel"</code> 122 </td> 123 </tr> 124 <tr> 125 <td> 126 <code>{'${device.model}'}</code> 127 </td> 128 <td>The device's model</td> 129 <td> 130 <code>"1080ti"</code> 131 </td> 132 </tr> 133 <tr> 134 <td> 135 <code> 136 ${'{'}device.attr.<property>{'}'} 137 </code> 138 </td> 139 <td>Property of the device</td> 140 <td> 141 <code>{'${device.attr.memory} => 8 GiB'}</code> 142 </td> 143 </tr> 144 </tbody> 145 </table> 146 147 For the set of attributes available, please see the individual [device plugin's 148 documentation][devices]. 149 150 ### Attribute Units and Conversions 151 152 Devices report their attributes with strict types and can also provide unit 153 information. For example, when a GPU is reporting its memory, it can report that 154 it is "4096 MiB". Since Nomad has the associated unit information, a constraint 155 that requires greater than "3.5 GiB" can match since Nomad can convert between 156 these units. 157 158 The units Nomad supports are as follows: 159 160 <table> 161 <thead> 162 <tr> 163 <th>Base Unit</th> 164 <th>Values</th> 165 </tr> 166 </thead> 167 <tbody> 168 <tr> 169 <td> 170 <code>Byte</code> 171 </td> 172 <td> 173 <code> 174 <strong>Base 2</strong>: KiB, MiB, GiB, TiB, PiB, EiB 175 </code> 176 <br /> 177 <code> 178 <strong>Base 10</strong>: kB, KB (equivalent to kB), MB, GB, TB, PB, 179 EB 180 </code> 181 </td> 182 </tr> 183 <tr> 184 <td> 185 <code>Byte Rates</code> 186 </td> 187 <td> 188 <code> 189 <strong>Base 2</strong>: KiB/s, MiB/s, GiB/s, TiB/s, PiB/s, EiB/s 190 </code> 191 <br /> 192 <code> 193 <strong>Base 10</strong>: kB/s, KB/s (equivalent to kB/s), MB/s, GB/s, 194 TB/s, PB/s,EB/s 195 </code> 196 </td> 197 </tr> 198 <tr> 199 <td> 200 <code>Hertz</code> 201 </td> 202 <td> 203 <code>MHz, GHz</code> 204 </td> 205 </tr> 206 <tr> 207 <td> 208 <code>Watts</code> 209 </td> 210 <td> 211 <code>mW, W, kW, MW, GW</code> 212 </td> 213 </tr> 214 </tbody> 215 </table> 216 217 Conversion is only possible within the same base unit. 218 219 ## `device` Examples 220 221 The following examples only show the `device` stanzas. Remember that the 222 `device` stanza is only valid in the placements listed above. 223 224 ### Single Nvidia GPU 225 226 This example schedules a task with a single Nvidia GPU made available. 227 228 ```hcl 229 device "nvidia/gpu" {} 230 ``` 231 232 ### Multiple Nvidia GPU 233 234 This example schedules a task with a two Nvidia GPU made available. 235 236 ```hcl 237 device "nvidia/gpu" { 238 count = 2 239 } 240 ``` 241 242 ### Single Nvidia GPU with Specific Model 243 244 This example schedules a task with a single Nvidia GPU made available and uses 245 the name to specify the exact model to be used. 246 247 ```hcl 248 device "nvidia/gpu/1080ti" {} 249 ``` 250 251 This is a simplification of the following: 252 253 ```hcl 254 device "gpu" { 255 count = 1 256 257 constraint { 258 attribute = "${device.vendor}" 259 value = "nvidia" 260 } 261 262 constraint { 263 attribute = "${device.model}" 264 value = "1080ti" 265 } 266 } 267 ``` 268 269 ### Affinity with Unit Conversion 270 271 This example uses an affinity to tell the scheduler it would prefer if the GPU 272 had at least 1.5 GiB of memory. The following are both equivalent as Nomad can 273 do unit conversions. 274 275 Specified in `GiB`: 276 277 ```hcl 278 device "nvidia/gpu" { 279 affinity { 280 attribute = "${device.attr.memory}" 281 operator = ">=" 282 value = "1.5 GiB" 283 weight = 75 284 } 285 } 286 ``` 287 288 Specified in `MiB`: 289 290 ```hcl 291 device "nvidia/gpu" { 292 affinity { 293 attribute = "${device.attr.memory}" 294 operator = ">=" 295 value = "1500 MiB" 296 weight = 75 297 } 298 } 299 ``` 300 301 [affinity]: /docs/job-specification/affinity 'Nomad affinity Job Specification' 302 [constraint]: /docs/job-specification/constraint 'Nomad constraint Job Specification' 303 [devices]: /docs/devices 'Nomad Device Plugins'