|
| 1 | +| Proposal ID | CP024 | |
| 2 | +| ---------------- | ------------------------------------------------------------------------------------------------------------------ | |
| 3 | +| Name | Dimensionality-dependent maximum work-item sizes | |
| 4 | +| Date of Creation | 23 January 2020 | |
| 5 | +| Target | SYCL 1.2.1 extension | |
| 6 | +| Current Status | Draft | |
| 7 | +| Original author | Steffen Larsen steffen.larsen@codeplay.com | |
| 8 | +| Contributors | Steffen Larsen steffen.larsen@codeplay.com, Gordon Brown gordon@codeplay.com, Ruyman Reyes ruyman@codeplay.com | |
| 9 | + |
| 10 | +# Dimensionality-dependent maximum work-item sizes |
| 11 | + |
| 12 | +## Overview |
| 13 | + |
| 14 | +Consider a device that when queried for `CL_DEVICE_MAX_WORK_ITEM_SIZES` using |
| 15 | +`clGetDeviceInfo` returns `{1024, 1024, 64}`. With the changes imposed by |
| 16 | +[this clarification](https://github.com/KhronosGroup/SYCL-Docs/pull/56) the |
| 17 | +result of querying `get_info` with `max_work_item_sizes` is `{64, 1024, 1024}`. |
| 18 | +Let `q` be a SYCL queue for this device. For `q` the code |
| 19 | + |
| 20 | +```cpp |
| 21 | +range<3> wg_size{128,1,1}; |
| 22 | +q.submit([&](handler &cgh) { |
| 23 | + cgh.parallel_for<class wg_size_c>( |
| 24 | + nd_range<3>(wg_size, wg_size), |
| 25 | + [=](nd_item<3> it) { |
| 26 | + ... |
| 27 | + }); |
| 28 | +}); |
| 29 | +``` |
| 30 | + |
| 31 | +is illegal as the work group size exceeds the max work-item size in the first |
| 32 | +dimension. However, if the dimensionality of the work-group is decreased to 2 |
| 33 | +dimensions, we have |
| 34 | + |
| 35 | +```cpp |
| 36 | +range<2> wg_size{128,1}; |
| 37 | +q.submit([&](handler &cgh) { |
| 38 | + cgh.parallel_for<class wg_size_c>( |
| 39 | + nd_range<2>(wg_size, wg_size), |
| 40 | + [=](nd_item<2> it) { |
| 41 | + ... |
| 42 | + }); |
| 43 | +}); |
| 44 | +``` |
| 45 | + |
| 46 | +which works as intended. This behaviour is caused by the mapping illustrated in |
| 47 | +Table 4.89 of the SYCL 1.2.1 specification (Rev 6) as the dimensionality has an |
| 48 | +effect on how the indices of the ranges are mapped to the dimensions, i.e. |
| 49 | +the work-group size that OpenCL gets are `{1,1,128}` and `{1,128,1}` in the two |
| 50 | +examples, respectively. |
| 51 | +Let `maxWGSize` be the result of querying `get_info` with `max_work_item_sizes`. |
| 52 | +Consider a range `A` used to define the work-group size. The following table |
| 53 | +shows how the different number of dimensions for `A` affects the local work size |
| 54 | +used for OpenCL and its effect on the relation to `maxWGSize`: |
| 55 | + |
| 56 | +| `A` | OpenCL local work size | Constraints | |
| 57 | +| ----------- | ---------------------- | -------------------------------------------------------------------------------- | |
| 58 | +| `{x, y, z}` | `{z, y, x}` | `A[0] <= maxWGSize[0] &&`<br>`A[1] <= maxWGSize[1] &&`<br>`A[2] <= maxWGSize[2]` | |
| 59 | +| `{x, y}` | `{y, x, 1}` | `A[0] <= maxWGSize[1] &&`<br>`A[1] <= maxWGSize[2]` | |
| 60 | +| `{x}` | `{x, 1, 1}` | `A[0] <= maxWGSize[2]` | |
| 61 | + |
| 62 | + |
| 63 | +This proposal introduces a number of enumerators to `cl::sycl::info::device` |
| 64 | +intended to replace the `max_work_item_sizes` enumerator. The result of querying |
| 65 | +`get_info` with any of these enumerators is an `id<D>` where each value |
| 66 | +represents the maximum width allowed in the corresponding dimension of a |
| 67 | +`range<D>` given to a `parallel_for`, where `D` is a number of dimensions |
| 68 | +specified by the enumerator. |
| 69 | + |
| 70 | +## Interface changes |
| 71 | + |
| 72 | +Three device information descriptors are added: |
| 73 | + |
| 74 | +| Descriptor | Return type | Description | |
| 75 | +| -------------------------------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 76 | +| `info::device::max_work_item_sizes_1d` | `id<1>` | Returns the maximum number of work-items that are permitted in a work-group of a 1-dimensional `nd_range`. The minimum value is 1 for `device`s that are not of device type `info::device_type::custom`. | |
| 77 | +| `info::device::max_work_item_sizes_2d` | `id<2>` | Returns the maximum number of work-items that are permitted in each dimension of a work-group of a 2-dimensional `nd_range`. The minimum value is (1,1) for `device`s that are not of device type `info::device_type::custom`. | |
| 78 | +| `info::device::max_work_item_sizes_3d` | `id<3>` | Returns the maximum number of work-items that are permitted in each dimension of a work-group of a 3-dimensional `nd_range`. The minimum value is (1,1,1) for `device`s that are not of device type `info::device_type::custom`. | |
| 79 | + |
| 80 | +The `max_work_item_sizes` descriptor is deprecated and the new descriptors are |
| 81 | +added as enumerators to `cl::sycl::info::device`: |
| 82 | + |
| 83 | +```cpp |
| 84 | +namespace cl { |
| 85 | +namespace sycl { |
| 86 | +namespace info { |
| 87 | + |
| 88 | +enum class device : int { |
| 89 | + ... |
| 90 | + max_work_item_sizes, // Deprecated |
| 91 | + max_work_item_sizes_1d, |
| 92 | + max_work_item_sizes_2d, |
| 93 | + max_work_item_sizes_3d, |
| 94 | + ... |
| 95 | +} |
| 96 | + |
| 97 | +} // namespace info |
| 98 | +} // namespace sycl |
| 99 | +} // namespace cl |
| 100 | +``` |
0 commit comments