Skip to content

Add SubView class#1915

Open
gberg617 wants to merge 28 commits into
developfrom
feature/bergel1/subview
Open

Add SubView class#1915
gberg617 wants to merge 28 commits into
developfrom
feature/bergel1/subview

Conversation

@gberg617

@gberg617 gberg617 commented Sep 19, 2025

Copy link
Copy Markdown
Contributor

Summary

  • This WIP PR adds the SubView class. This class stores a view-type object and a tuple of slices that indicate how to access the view's underlying data. The following slice types are supported:
    • range slice: Indexes a subset of the original dimension's extents. Does not reduce dimensionality.
    • fixed slice: Indexes along a fixed value of a given dimension. Reduces dimensionality.
    • no slice: Indexes according to the original view's layout along the given dimension. Does not reduce dimensionality.

A few simple examples are provided below:

    View<Index_type, Layout<2>> view(&my_data[0][0], Layout<2>(3,3));

    // "sv1 = View[1:3,:]"
    auto sv1 = SubView(view, RangeSlice{1,3}, NoSlice{});

    // "sv2 = View[1:3,1]"
    auto sv2 = SubView(view, RangeSlice{1,3}, FixedSlice{1});

Here, sv1 and sv2 are subviews of dimensions (2,3) and (2) respectively.

Future tasks:

  • Add Slices whose extents are determined at compile time
  • Add Slice types that use non-affine mappings (e.g. index lists)
  • Add ability to collapse nested sub-layouts into a single sub-layout for slices that have affine mappings
  • Add ability to distinguish between projected dimension and an empty slice (e.g. RangeSlice{2,2})

@gberg617 gberg617 marked this pull request as draft September 19, 2025 21:12
@gberg617

Copy link
Copy Markdown
Contributor Author

This PR is still a WIP!

@gberg617 gberg617 self-assigned this Sep 19, 2025
Comment thread include/RAJA/util/SubView.hpp Outdated
Comment thread include/RAJA/util/SubView.hpp Outdated
Comment thread include/RAJA/util/SubView.hpp Outdated
Comment thread include/RAJA/util/SubView.hpp Outdated
@gberg617 gberg617 force-pushed the feature/bergel1/subview branch from 804abcd to 5ba920d Compare September 30, 2025 01:08
Comment thread test/unit/view-layout/test-subview.cpp Outdated

}

// void test_subviewGPU() {

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.

To Do: Fix GPU tests.

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.

Perhaps remove GPU tests?

@gberg617 gberg617 changed the title Feature/bergel1/subview Add SubView class Sep 30, 2025
Comment thread include/RAJA/util/SubView.hpp Outdated
Comment thread include/RAJA/util/SubView.hpp Outdated
Comment thread include/RAJA/util/SubView.hpp Outdated
Comment thread include/RAJA/util/SubView.hpp Outdated
Comment thread include/RAJA/util/SubView.hpp Outdated
Comment thread include/RAJA/util/SubView.hpp Outdated
Comment thread include/RAJA/util/SubView.hpp Outdated
Comment thread test/unit/view-layout/test-subview.cpp
@gberg617

Copy link
Copy Markdown
Contributor Author

I'm considering separating the SubView holding the view from the slices that are used to access the view, somewhat analogous to the approach of having layouts and Views be separate classes. Any thoughts on this?

Comment thread include/RAJA/util/SubView.hpp Outdated
Comment thread include/RAJA/util/SubView.hpp Outdated
Comment thread include/RAJA/util/SubView.hpp Outdated
Comment thread include/RAJA/util/SubView.hpp Outdated
Comment thread include/RAJA/util/SubView.hpp Outdated
Comment thread include/RAJA/util/for_each.hpp Outdated
Comment thread include/RAJA/util/for_each.hpp Outdated
Comment thread include/RAJA/util/SubView.hpp Outdated
RAJA_INLINE RAJA_HOST_DEVICE constexpr auto operator()(Idxs... idxs) const {
static_assert(sizeof...(idxs) == n_dims, "Wrong number of indices");

std::array<IndexType, n_dims> arr{idxs...};

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.

@MrBurmark Did we decide to go with std::array, or switch back to camp::array here?

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.

Let's use camp array, we haven't asked users to add the cuda flag that would enable this yet.

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.

OK, I added back camp::array. This means that we first need to push the following camp PR:
llnl/camp#194

@gberg617 gberg617 force-pushed the feature/bergel1/subview branch from be6df15 to ea02c47 Compare May 22, 2026 22:24
@gberg617 gberg617 marked this pull request as ready for review May 22, 2026 22: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.

6 participants