KhronosGroup / KhronosGroup/SYCL-Docs
Function object void specializations for sycl::half
- Dominant language
- JavaScript
- Stars
- 158
- Forks
- 80
- Avg merge
- 7d 6h
- Merged PRs (30d)
- 5
Description
# Context
Section 4.17.2. of the SYCL2020 specification defines several function objects. It is stated that: "Each function object is additionally specialized for `void` as a transparent function object that deduces its parameter types and return type.". I believe the deduction rules for `sycl::half` to not be well defined.
# Problem
If I understand it correctly, for `minimum` and `maximum`, the return type would have to be determined by the type of the conditional operator. However, since `sycl::half` is not part of C++, the implicit conversion rules in the C++ standard for the conditional operator do not apply to `sycl::half`.
In practice, if one writes a test for the expected value of the void-specialization for `minimum` like so:
```c++
template
struct builtin_return_t, LhsT, RhsT> {
// obtain common type using ternary operator, condition has no effect on type
using type = decltype(false ? LhsT{} : RhsT{});
};
```
and a `sycl::half` is one of the operand types, it is not clear what conversion should happen. For instance, for `sycl::half` and `int`, what will be the resulting type?
# SYCL specification on `half`
4.14.1.: "[`sycl::half` is] A 16-bit floating-point. The half data type must conform to the IEEE 754-2008 half precision storage format. This type is only supported on devices that have `aspect::fp16`. `std::numeric_limits` must be specialized for the half data type."
But this format only specifies what the data type itself looks like, not how conversions are done.
C.9.1.: "The conversion rules for half precision types follow the same rules as in the OpenCL 1.2 extensions specification [par. 9.5.1](https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#openclext12)." This paragraph of the OpenCL 1.2. spec states: "The implicit conversion rules specified in section 6.2.1 now include the `half` scalar and `halfn` vector data types.". Section 6.2.1. states: "Implicit conversions between scalar built-in types defined in table 6.1 (except `void` and `half`) are supported.".
However, the latter paragraph dose (as far as I can tell) not detail how the conversion for `half` actually should be done. The OpenCL 1.2. spec on conversions (Section 6.2.6.) has rules for vector types, and if the type is not a vector type, use Section 6.3.1.8. of the C99 standard. But the latter has no rules for `half` types.
Furthermore, it is not clear to me whether Appendix C applies to an OpenCL `half` type that is different from `sycl::half` and whether it applies always or only when SYCL is mapped on top of OpenCL.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with SYCL 2020 sections 4.17.2, 4.14.1, and C.9.1, then compare the referenced OpenCL 1.2 sections 6.2.1 and 6.2.6 with C99 6.3.1.8. Done means the specification clearly states whether and how void function-object deduction handles sycl::half, including mixed operands such as sycl::half and int.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100