github.com/ferranbt/nomad@v0.9.3-0.20190607002617-85c449b7667c/website/source/docs/job-specification/device.html.md (about)

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