Repository navigation
[SYCL] is_device_copyable: false for pointer to members - #23291
inteltdelisle wants to merge 3 commits into
Conversation
The SYCL 2020 specification does not currently require the representation, size, or alignment of pointer-to-member types to match across host and device compilation. Added explicit specialization to is_device_copyable for pointer to member functions in order to match the specification. Signed-off-by: Delisle, Thierry <thierry.delisle@intel.com>
| // copyable in practice. Use of these types as the types of a data member or | ||
| // captured variable likewise renders the enclosing class type or lambda closure | ||
| // as not device copyable. |
There was a problem hiding this comment.
This comment overstates what's actually implemented:
struct WrapData {
int S::*p;
};
struct WrapFn {
void (S::*p)(int);
};
static_assert(!sycl::is_device_copyable_v<WrapData>); // currently fails
static_assert(!sycl::is_device_copyable_v<WrapFn>); // currently fails
Both assertions fail.
Also, please add test for cv-qualified member pointer types.
There was a problem hiding this comment.
I updated the comment. I think the warning that structs with pointer-to-member members is relevant, but I'm not sure the complexity of attempting the reflection needed to enforce this is worth it.
@againull Is this new comment clearer about what is and isn't implemented.
(Also added cv-qualified member pointer tests.)
There was a problem hiding this comment.
@inteltdelisle I must be missing something.
"// Use of these types as the types of a data member would likewise render the
// enclosing class type as not device copyable, but this is not enforced by this
// specialization."
This new comment still says that if somebody has some enclosing class type like WrapData in my example, then it will be reported as non device copyable (not enforced by this specialization but something else) - it is not true right now. If you check the example I posted, WrapData is still device copyable.
Can you please clarify what are trying to say with this comment.
There was a problem hiding this comment.
@againull The distinction I'm trying to make is that structs containing pointer-to-members currently will be reported as device copyable, but my understanding of the SYCL spec is that it is not safe for them to be copied from the host to and from devices.
There was a problem hiding this comment.
@againull After coming back to this and re-reading the comments, I think I understand where the confusion lies. Is this explanation clearer:
The SYCL 2020 specification does not currently require the representation, size, or alignment of pointer-to-member types to match across host and device compilation. According to section 3.13.1. Device copyable of the SYCL 2020, pointer-to-member are not device copyable because it is not always safe to perform bitwise copy of them.
Your WrapData struct is not device copyable because of this, but the way the trait is implemented, sycl::is_device_copyable_v<WrapData> will be true. This is a limitation of the implementation, which has limited static reflection capabilities. Section 4.12.3. is_device_copyable type trait states that
"""
If is_device_copyable is specialized such that is_device_copyable_v == true on a T that does not satisfy all the requirements of a device copyable type, the results are unspecified.
"""
which is the behavior I wanted to warn about.
Signed-off-by: Delisle, Thierry <thierry.delisle@intel.com>
The SYCL 2020 specification does not currently require the representation, size, or alignment of pointer-to-member types to match across host and device compilation. Added explicit specialization to is_device_copyable for pointer to member functions in order to match the specification.