-
Notifications
You must be signed in to change notification settings - Fork 17
CP029 Image accessors with format information #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
steffenlarsen
wants to merge
3
commits into
codeplaysoftware:master
Choose a base branch
from
steffenlarsen:steffen/CP029_accessor_iamge_format
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
| Proposal ID | CP029 | | ||
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| Name | Image accessors with format information | | ||
| Date of Creation | 2 July 2020 | | ||
| Target | Vendor extension | | ||
| Current Status | *Under Review* | | ||
| Original authors | Steffen Larsen [email protected], Alexander Johnston [email protected] | | ||
| Contributors | Steffen Larsen [email protected], Alexander Johnston [email protected], Victor Lomüller [email protected], Ruyman Reyes [email protected] | | ||
|
||
# Image accessors with format information | ||
|
||
## Motivation | ||
|
||
In SYCL 1.2.1 operations on images are closely tied to the corresponding | ||
operations in OpenCL thus only allowing read and write operations to be done | ||
using 4-element vectors of 32-bit floating points, 32-bit signed integers, | ||
32-bit unsigned integers, or 16-bit floating points, which are in turn converted | ||
to the types of the channels in the image. Because of this, backends that cannot | ||
query the types of the channels in the image cannot determine the necessary | ||
conversions to do. | ||
|
||
## Overview | ||
|
||
This extension adds `sycl::short4`, `sycl::ushort4`, `sycl::schar4`, and | ||
`sycl::uchar4` to the list of types supported for `dataT` for image accessors. | ||
In order to carry information about the format of the image, the | ||
`image_format` enumerator from SYCL 2020 is adopted, given as | ||
|
||
```c++ | ||
namespace sycl { | ||
enum class image_format : unsigned int { | ||
r8g8b8a8_unorm, | ||
r16g16b16a16_unorm, | ||
r8g8b8a8_sint, | ||
r16g16b16a16_sint, | ||
r32b32g32a32_sint, | ||
r8g8b8a8_uint, | ||
r16g16b16a16_uint, | ||
r32b32g32a32_uint, | ||
r16b16g16a16_sfloat, | ||
r32g32b32a32_sfloat, | ||
}; | ||
} // namespace sycl | ||
``` | ||
|
||
and mappings from `image_format` to the corresponding accessor data type is | ||
defined as | ||
|
||
```c++ | ||
|
||
namespace sycl { | ||
template<image_format> struct image_access; | ||
|
||
template<> struct image_access<image_format::r8g8b8a8_snorm> { | ||
using type = float4; | ||
}; | ||
template<> struct image_access<image_format::r16g16b16a16_snorm> { | ||
using type = float4; | ||
}; | ||
template<> struct image_access<image_format::r8g8b8a8_unorm> { | ||
using type = float4; | ||
}; | ||
template<> struct image_access<image_format::r16g16b16a16_unorm> { | ||
using type = float4; | ||
}; | ||
template<> struct image_access<image_format::r8g8b8a8_sint> { | ||
using type = schar4; | ||
}; | ||
template<> struct image_access<image_format::r16g16b16a16_sint> { | ||
using type = short4; | ||
}; | ||
template<> struct image_access<image_format::r32b32g32a32_sint> { | ||
using type = int4; | ||
}; | ||
template<> struct image_access<image_format::r8g8b8a8_uint> { | ||
using type = uchar4; | ||
}; | ||
template<> struct image_access<image_format::r16g16b16a16_uint> { | ||
using type = ushort4; | ||
}; | ||
template<> struct image_access<image_format::r32b32g32a32_uint> { | ||
using type = uint4; | ||
}; | ||
template<> struct image_access<image_format::r16b16g16a16_sfloat> { | ||
using type = half4; | ||
}; | ||
template<> struct image_access<image_format::r32g32b32a32_sfloat> { | ||
using type = float4; | ||
}; | ||
|
||
template<image_format format> | ||
using image_access_t = typename image_access<format>::type; | ||
} // namespace sycl | ||
``` | ||
|
||
With these, a new overload of `get_access` is added to `image` defined as | ||
|
||
```c++ | ||
template <image_format format, access::mode accessMode> | ||
accessor<image_access_t<format>, dimensions, accessMode, access::target::image> | ||
get_access(handler & commandGroupHandler); | ||
``` | ||
|
||
Calling `read` or `write` on an image accessor retrieved through the new | ||
`get_access` above causes undefined behaviour unless the `image_channel_type` of | ||
the underlying image and the `image_format` given to `get_access` is one of the | ||
combinations shown in the following table: | ||
|
||
| `image_channel_type` | `image_format` | | ||
|----------------------|-----------------------| | ||
| `snorm_int8` | `r8g8b8a8_snorm` | | ||
| `snorm_int16` | `r16g16b16a16_snorm` | | ||
| `unorm_int8` | `r8g8b8a8_unorm` | | ||
| `unorm_int16` | `r16g16b16a16_unorm` | | ||
| `signed_int8` | `r8g8b8a8_sint` | | ||
| `signed_int16` | `r16g16b16a16_sint` | | ||
| `signed_int32` | `r32b32g32a32_sint` | | ||
| `unsigned_int8` | `r8g8b8a8_uint` | | ||
| `unsigned_int16` | `r16g16b16a16_uint` | | ||
| `unsigned_int32` | `r32b32g32a32_uint` | | ||
| `fp16` | `r16b16g16a16_sfloat` | | ||
| `fp32` | `r32g32b32a32_sfloat` | | ||
|
||
## Example | ||
|
||
```c++ | ||
cl::sycl::image<2> image(hostPtr, cl::sycl::image_channel_order::rgba, | ||
cl::sycl::image_channel_type::unsigned_int8, | ||
cl::sycl::range<2>{4, 4}); | ||
|
||
cl::sycl::buffer<cl::sycl::uchar4, 1> resultDataBuf(&resultData, | ||
cl::sycl::range<1>(1)); | ||
|
||
cl::sycl::queue myQueue(selector); | ||
myQueue.submit([&](cl::sycl::handler &cgh) { | ||
auto imageAcc = | ||
image.get_access<image_format::r8g8b8a8_uint, cl::sycl::access::mode::read>(cgh); | ||
cl::sycl::accessor<cl::sycl::uchar4, 1, cl::sycl::access::mode::write> | ||
resultDataAcc(resultDataBuf, cgh); | ||
|
||
cgh.single_task<unsampled_kernel_class>([=]() { | ||
cl::sycl::uchar4 RetColor = imageAcc.read(coord); | ||
resultDataAcc[0] = RetColor; | ||
}); | ||
}); | ||
``` | ||
|
||
## OpenCL implementation Note | ||
|
||
Given that image read and write operations in OpenCL only support `cl_int4`, | ||
`cl_uint4`, `cl_float4`, and `cl_half4`, which have direct relation to the | ||
previously supported data types for image accessors, namely `sycl::int4`, | ||
`sycl::uint4`, `sycl::float4`, and `sycl::half4` respectively. By adding support | ||
for `sycl::short4`, `sycl::ushort4`, `sycl::schar4`, and `sycl::uchar4` an | ||
OpenCL backend will require conversions to the types corresponding to those | ||
supported by OpenCL after a read and before a write. That is `sycl::short4` and | ||
`sycl::schar4` must be converted to and from `sycl::int4`, whereas | ||
`sycl::ushort4` and `sycl::uchar4` must be converted to and from `sycl::uint4`. | ||
|
||
## SYCL 2020 Note | ||
|
||
Though not included in this proposal, we believe a change in this direction or a | ||
similar one should be made to the SYCL 2020 provisional too. In SYCL 2020 the | ||
data type of an image accessor is also currently restricted to `sycl::int4`, | ||
`sycl::uint4`, `sycl::float4`, and `sycl::half4`. This should be updated to be | ||
deduced from the `image_format` of the image the image accessor is produced | ||
from. This will enable each backend to perform appropriate hardware supported | ||
operations for image reads and writes, and use the appropriate data type for | ||
them. The OpenCL backend will still be able to use the four types listed | ||
above, while the CUDA backend, and others where appropriate, will be able to | ||
take and data types suitable for their hardware operations. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we maybe also define a helper alias:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. I have added this and changed the data type of the accessor returned by the new
get_accessor
to use this.I'm not completely convinced that
image_format_type
is the best name for this struct, so I'm open to alternatives.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps
image_access_type
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's a good name, though I'm not fond of the
_type
suffix. I've renamed it toimage_access
. What do you think?