Skip to content
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

Add more forward declarations to sycl_traits.h #1497

Merged
merged 5 commits into from
Apr 19, 2024

Conversation

adamfidel
Copy link
Contributor

@adamfidel adamfidel commented Apr 11, 2024

The kernel template tests no longer compile after #1394 due to missing forward declarations. This PR gets the tests to compile again.

@adamfidel adamfidel changed the base branch from main to dev/adamfidel/device_copyable_namespace April 11, 2024 19:18
Copy link
Contributor

@dmitriy-sobolev dmitriy-sobolev left a comment

Choose a reason for hiding this comment

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

Should we forward declare everything what is used in that file?

For example, there are entities, which miss their declarations:

  • predicates/functors defined in a block starting with oneapi::dpl::__internal::__not_pred
  • zip_iterator, transform_iterator, permutation_iterator

@adamfidel
Copy link
Contributor Author

Should we forward declare everything what is used in that file?

That's a good question. I can certainly add forward declarations to all of the structs in this file, but I am not clear on the original design intent as it was introduced in #1394. I believe it was a design decision to only include some of the forward declarations in this file with the intent that the other structs will already be defined before including this header.

With that in mind, it might be better for the original author @MikeDvorskiy to answer that question.

@MikeDvorskiy
Copy link
Contributor

Why the PR is still draft?
I believe #include <oneapi/dpl/internal/binary_search_extension_defs.h> is not quite correct, should be a relative patch via ""
I think the forward declarations are required here just for the types which are not already defined.

@dmitriy-sobolev
Copy link
Contributor

dmitriy-sobolev commented Apr 12, 2024

I think the forward declarations are required here just for the types which are not already defined.

@MikeDvorskiy, do you confirm that it is everything besides what is declared in "binary_search_extension_defs.h" (a single include file here)? I just what to get an explicit answer to #1497 (review) regarding addition of the forward declarations listed there.

@danhoeflinger
Copy link
Contributor

danhoeflinger commented Apr 12, 2024

I really don't like the maintenance problem that #1394 presents. We discussed it back when #1394 was proposed and decided that it was the lesser of two evils to keep all these device_copyable definitions in one place rather than infect the rest of the code with device_copyable (SYCL specific) stuff.

However, the problems this has presented, and the need for all the forward declarations is making me reconsider that.

Would we be better off to just define the device copyable macro stuff in one place like this header or some other central header, and embed the _ONEDPL_DEVICE_COPYABLE( ... ); call in with the definition of the struct?

For non-dpcpp backends, the macro could be a no-op. It would reduce our maintenance burden by not having these duplicate declarations which need to be updated anytime something is changed. It will also make it more likely that when someone adds a similar functor or type to one which requires device copyable that they realize that they may need to add the new functor or type as _ONEDPL_DEVICE_COPYABLE() as well.

@danhoeflinger danhoeflinger self-requested a review April 12, 2024 13:56
@adamfidel adamfidel force-pushed the dev/adamfidel/device_copyable_namespace_kt branch from 24399e2 to 5094d6d Compare April 12, 2024 14:38
@adamfidel adamfidel changed the title Draft: add more forward declarations to sycl_traits.h Add more forward declarations to sycl_traits.h Apr 12, 2024
@adamfidel adamfidel marked this pull request as ready for review April 12, 2024 14:39
Base automatically changed from dev/adamfidel/device_copyable_namespace to main April 12, 2024 15:30
@adamfidel
Copy link
Contributor Author

Why the PR is still draft? I believe #include <oneapi/dpl/internal/binary_search_extension_defs.h> is not quite correct, should be a relative patch via "" I think the forward declarations are required here just for the types which are not already defined.

This PR was waiting on #1496 to be merged. It is no longer a draft now. I also removed the changes to binary search so there are no longer any additional includes.

@danhoeflinger
Copy link
Contributor

@adamfidel I think you need to rebase / resolve conflicts to fix the diff for this PR after merging #1496.

@adamfidel adamfidel force-pushed the dev/adamfidel/device_copyable_namespace_kt branch from 5094d6d to 79dede0 Compare April 12, 2024 15:49
@adamfidel adamfidel added this to the 2022.6.0 milestone Apr 15, 2024
@danhoeflinger
Copy link
Contributor

@adamfidel:

@MikeDvorskiy and I discussed a couple other issues we found with device copyable, and he is working on a PR which would likely supersede this PR by embedding the "device copyable" specializations with the types themselves, rather than having them in this sycl_traits.h.

I've created this issue #1505 to represent that, until a PR exists.

akukanov
akukanov previously approved these changes Apr 19, 2024
Copy link
Contributor

@akukanov akukanov left a comment

Choose a reason for hiding this comment

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

After all investigations and prototypes made, it seems the current approach is still preferable, despite its shortcomings. Yes it's bad at maintenance, but another possible solution is not much better in this aspect and quite worse in others, and a solution which would really be better either needs to be supported by the implementation of sycl::is_device_copyable or requires C++20 concepts.

Therefore I think for now it's best to proceed with this patch.

@danhoeflinger
Copy link
Contributor

danhoeflinger commented Apr 19, 2024

After all investigations and prototypes made, it seems the current approach is still preferable, despite its shortcomings. Yes it's bad at maintenance, but another possible solution is not much better in this aspect and quite worse in others, and a solution which would really be better either needs to be supported by the implementation of sycl::is_device_copyable or requires C++20 concepts.

Therefore I think for now it's best to proceed with this patch.

I need to catch up on the discussion of the other approach(es), but the version we were working on also addresses 2 additional issues which were not covered by this approach. If we continue with this approach, we still need more than this PR to address the issues. Where the specializations live is a related but separate decision. I'd hold on merging this until we have a plan for all the issues we currently face.

  1. Non-type template parameters (they do not match with a generic variadic template definition)
  2. Subset of template parameters (specifically avoiding execution policies, which are passed as template params and include a non-device copyable queue but go unused and don't change device copyability of the type)

@akukanov
Copy link
Contributor

akukanov commented Apr 19, 2024

Where the specializations live is a related but separate decision. I'd hold on merging this until we have a plan for all the issues we currently face.

That's simple - remove the macro, declare each specialization of sycl::is_device_copyable separately without any attempt to generalize. Or, if you prefer, keep using the macro where it works, otherwise do as suggested above.

@danhoeflinger
Copy link
Contributor

danhoeflinger commented Apr 19, 2024

@adamfidel I've created a PR targeting this PR #1520 to add some more missing fwd declarations. With those I think the list is complete. Please merge into this PR if you agree with that patch.

As mentioned in that PR, I think we still need to convert to the original proposal from #1513 (This commit), to allow a subset of types to be specified, and convert to that method at least for types which require a subset.

I've double checked the existing fwd declarations from this PR that they match the definition.

Signed-off-by: Dan Hoeflinger <[email protected]>
Copy link
Contributor

@danhoeflinger danhoeflinger left a comment

Choose a reason for hiding this comment

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

LGTM but please get a second approval since I added code here. (and wait for green CI)
I spoke with @MikeDvorskiy and we decided its best to merge this first then address the rest in a separate PR.

Copy link
Contributor

@MikeDvorskiy MikeDvorskiy left a comment

Choose a reason for hiding this comment

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

LGTM

@adamfidel adamfidel merged commit f371fb9 into main Apr 19, 2024
20 checks passed
@adamfidel adamfidel deleted the dev/adamfidel/device_copyable_namespace_kt branch April 19, 2024 15:26
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.

5 participants