Skip to content

Add generic device policies #2036

Open
artv3 wants to merge 10 commits into
developfrom
artv3/generic-device-policies
Open

Add generic device policies #2036
artv3 wants to merge 10 commits into
developfrom
artv3/generic-device-policies

Conversation

@artv3

@artv3 artv3 commented Jun 8, 2026

Copy link
Copy Markdown
Member

Summary

Link to new policy documentation: https://raja.readthedocs.io/en/artv3-generic-device-policies/sphinx/user_guide/feature/policies.html

@artv3 artv3 requested a review from a team June 8, 2026 23:51
@artv3 artv3 self-assigned this Jun 8, 2026
@artv3 artv3 added this to the July 2026 Release milestone Jun 9, 2026
Comment thread docs/sphinx/user_guide/tutorial/launch_basic.rst Outdated

// kernel (For) index mapping
template<int nx_threads>
using device_global_size_x_direct = RAJA::cuda_global_size_x_direct<nx_threads>;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are more policies than these. Check out the cuda or hip policy file where there are policies for the cartesian product of things like this.

  • (|flatten) x (global|block|thread) x (|size) x (x|y|z|xy|xz|yx|yz|zx|zy|xyz|xzy|yxz|yzx|zxy|zyx) x (direct_unchecked|direct|loop) x (|unchecked)
  • (global|block|thread) x (x|y|z|xy|xz|yx|yz|zx|zy|xyz|xzy|yxz|yzx|zxy|zyx) x (syncable_loop)

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.

Where should we draw the line in terms of providing device generics? I think it would be a little burdensome in terms of boilerplate to have using device_policy = .... for all possible cartesian products of policies.

We could probably automatically emit device generics with a .hpp.in + CMake file configure type interface, which would just cover all the cases in <backend>/policy.hpp, and error out if there isn't a backend specific implementation available. This is probably a bit cleaner and maintainable than manually generating a long list of aliases.

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.

Also--not sure if we can generate SYCL analogues to all of these cartesian product policies. However we could just leave the policies undefined in the case of SYCL

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think this pointing out that that SYCL is the forgotten backend, various policies such as unchecked, don't have a SYCL analogue. Is this the right place to introduce them or should we just have them throw an error?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The robot pointed out we are missing the following:

  Missing SYCL policy families
  - sycl_exec_async
  - sycl_launch_explicit_t
  - sycl_exec_grid*
  - sycl_exec_occ_*
  - sycl_exec_base*
  - sycl_exec_with_reduce*
  - sycl_work*
  - sycl_reduce_tuning
  - sycl_multi_reduce_*
  - sycl_warp_reduce
  - sycl_warp_direct
  - sycl_warp_loop
  - sycl_warp_masked_direct
  - sycl_warp_masked_loop
  - all sycl_*_direct_unchecked variants
  - all sycl_flatten_* variants
  - all sycl_*_nested_* aliases
  - the 2D/3D permutation families for sycl_thread_*, sycl_block_*, and sycl_global_*
  - the *_size_* variants for thread/block/global families

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this PR is the right place to add more sycl policies.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is why I suggested creating generic versions of all the policies that the current device backend supports. That way we don't have to worry about reconciling the differences yet. Then users can remove ifdefs for the cases that are portable across their use cases at least.

using device_global_thread_z = RAJA::cuda_global_thread_z;

// kernel (loop) index mapping
using device_thread_x_direct = RAJA::cuda_thread_x_direct;

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.

Would it make sense to rewrite some examples like launch_flatten using the generic names? It could simplify the examples


// kernel (For) index mapping
template<int nx_threads>
using device_global_size_x_direct = RAJA::cuda_global_size_x_direct<nx_threads>;

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.

Where should we draw the line in terms of providing device generics? I think it would be a little burdensome in terms of boilerplate to have using device_policy = .... for all possible cartesian products of policies.

We could probably automatically emit device generics with a .hpp.in + CMake file configure type interface, which would just cover all the cases in <backend>/policy.hpp, and error out if there isn't a backend specific implementation available. This is probably a bit cleaner and maintainable than manually generating a long list of aliases.

@johnbowen42

Copy link
Copy Markdown
Contributor

@artv3 @MrBurmark I pushed a commit containing an automatic CMake based file generation for device.hpp that will emit it directly into the build tree at config time. It emits a large roughly 6000 line file but it contains a relatively comprehensive list of policies. Let me know if you like this approach, if not we can revert the commit and keep the manually-maintained list

Comment thread docs/sphinx/user_guide/feature/policies.rst Outdated
Comment thread docs/sphinx/user_guide/feature/policies.rst Outdated
Comment thread examples/launch-device-policy-aliases.cpp Outdated

@rhornung67 rhornung67 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please see my comments.

Comment thread include/RAJA/policy/device.hpp.in Outdated
@artv3 artv3 force-pushed the artv3/generic-device-policies branch from 1994916 to d40be98 Compare June 22, 2026 17:36
@artv3

artv3 commented Jun 22, 2026

Copy link
Copy Markdown
Member Author

@llnl/raja-core , I pushed up additional support along with a table listing what we support and don't within device_* -- thank you all for the reviews

@artv3

artv3 commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

@rhornung67 I pushed up a change to the read the docs to adjust for browser width. If you have a chance can you let me know if this works?

@rhornung67

Copy link
Copy Markdown
Member

@rhornung67 I pushed up a change to the read the docs to adjust for browser width. If you have a chance can you let me know if this works?

That's great! I like it. 🥇

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.

4 participants