Skip to content

[SYCL] is_device_copyable: false for pointer to members - #23291

Open
inteltdelisle wants to merge 3 commits into
intel:syclfrom
inteltdelisle:tdelisle/runtime/device_copyable_member_pointers
Open

inteltdelisle wants to merge 3 commits into
intel:syclfrom
inteltdelisle:tdelisle/runtime/device_copyable_member_pointers

Conversation

@inteltdelisle

Copy link
Copy Markdown
Contributor

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.

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>
@inteltdelisle
inteltdelisle requested a review from a team as a code owner September 28, 2026 17:26
Comment on lines +91 to +93
// 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.)

@againull againull Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

@inteltdelisle inteltdelisle Sep 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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>
@inteltdelisle
inteltdelisle marked this pull request as draft October 7, 2026 19:42
@inteltdelisle
inteltdelisle marked this pull request as ready for review October 27, 2026 15:20

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants