github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/website/pages/docs/job-specification/device.mdx (about)

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