|
| 1 | += SYCL Proposals: Filter Selector |
| 2 | +James Brodman < james[email protected]> |
| 3 | +v0.1 |
| 4 | +:source-highlighter: pygments |
| 5 | +:icons: font |
| 6 | +== Introduction |
| 7 | +This document presents an extension on top of the SYCL specification. The goal of this extension is to provide a new device selector class that allows expressing common but non-trivial requirements for device selection in a simple manner. |
| 8 | + |
| 9 | +== Filter Selector |
| 10 | + |
| 11 | +The filter selector is a new device selector class that accepts a string of one or more filters that refine the set of devices that may be returned when the selector's `select_device` method is invoked. Devices that match the specified filter(s) are ranked by the `default_selector` to determine which device is ultimately selected. The `default_selector` is used to prefer an implementation's preferences for one device over another when multiple devices satisfy the provided filters. |
| 12 | + |
| 13 | +=== DSL for Specifying Filters |
| 14 | + |
| 15 | +A string passed to the selector defines one or more filters. Filters have a certain syntax that must be followed. A filter is specified as a triple of the form: |
| 16 | + |
| 17 | +[source] |
| 18 | +-- |
| 19 | +Backend:DeviceType:RelativeDeviceNumber |
| 20 | +-- |
| 21 | + |
| 22 | +Every element of the triple is optional, but a filter must contain at least one component. |
| 23 | + |
| 24 | +`Backend` specifies the desired backend for the wanted devices. `DeviceType` specifies the type of the desired device. `RelativeDeviceNumber` refers to the number of device that matches any other requirements, starting from `0`, which means "the first device that matches the requirements". Incorrect input will result in an a `runtime_error` being thrown. |
| 25 | + |
| 26 | +.Supported Backends |
| 27 | +[width=25%] |
| 28 | +|==== |
| 29 | +| Backend |
| 30 | + |
| 31 | +|`cuda` |
| 32 | +|`host` |
| 33 | +| `opencl` |
| 34 | +|`level_zero` |
| 35 | +|==== |
| 36 | + |
| 37 | +.Supported Device Types |
| 38 | +[width=25%] |
| 39 | +|==== |
| 40 | +| Device Type |
| 41 | + |
| 42 | +| `accelerator` |
| 43 | +| `cpu` |
| 44 | +| `gpu` |
| 45 | +| `host` |
| 46 | +|==== |
| 47 | + |
| 48 | +=== Specifying Multiple Filters |
| 49 | + |
| 50 | +Multiple filters may be specified in the string passed to the selector by using `,` to separate additional filters. |
| 51 | + |
| 52 | +[source] |
| 53 | +-- |
| 54 | +Backend0:DeviceType0:RelativeDeviceNumber0,Backend1:DeviceType1:RelativeDeviceNumber1,... |
| 55 | +-- |
| 56 | + |
| 57 | +== Examples |
| 58 | + |
| 59 | +[source,c++] |
| 60 | +---- |
| 61 | +
|
| 62 | +// Return a device that uses the opencl backend |
| 63 | +filter_selector("opencl") |
| 64 | +
|
| 65 | +// Return a cpu device that uses the opencl backend |
| 66 | +filter_selector("opencl:cpu") |
| 67 | +
|
| 68 | +// Return a gpu device |
| 69 | +filter_selector("gpu") |
| 70 | +
|
| 71 | +// Return the first device found |
| 72 | +filter_selector("0") |
| 73 | +
|
| 74 | +// Return the second opencl gpu found |
| 75 | +filter_selector("opencl:gpu:1") |
| 76 | +
|
| 77 | +// Return either a gpu or cpu |
| 78 | +filter_selector("gpu,cpu") |
| 79 | +
|
| 80 | +// Return either a cuda gpu or an opencl cpu |
| 81 | +filter_selector("cuda:gpu,opencl:cpu") |
| 82 | +
|
| 83 | +// Return either the second level_zero gpu or the host device |
| 84 | +filter_selector("level_zero:gpu:1,host") |
| 85 | +---- |
0 commit comments