Skip to content

Add SubView class - #1915

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

Add SubView class#1915
gberg617 wants to merge 34 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
@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
…pen interval [start, end) and added more checks for StridedSlice size
2. Replaced camp::array usage with std::array.
3. Fixed and simplified get_dim_stride and get_parent_dim_stride.
4. Replaced usage of IndexType with size_t where appropriate.
@gberg617
gberg617 force-pushed the feature/bergel1/subview branch from 2442033 to 41c7c1c Compare August 15, 2026 00:55
@@ -1,5 +1,5 @@
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Copyright (c) 2016-25, Lawrence Livermore National Security, LLC
// Copyright (c) 2016-26, Lawrence Livermore National Security, LLC

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.

@gberg617 we changed the copyright header in all RAJA files so when we update each year we only need to touch two files rather than the whole repo. Here is what you should have on all files you add or modify:
https://github.com/llnl/RAJA/blob/develop/test/unit/view-layout/test-indexlayout.cpp#L1

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

See comment about copyright header.

@gberg617

Copy link
Copy Markdown
Contributor Author

@MrBurmark @adayton1 I assume that SubViews can be 0D in certain cases where the slice(s) reduce the dimension to a scalar. This leads to compiler errors on Windows (see failing CI) because camp array stores a C-style array of size 0. My thoughts are to either disallow 0D SubViews or add a specialization of camp array for a 0-sized array. My preference is the latter because std::array can be zero-sized, so this addition would make camp::array be more consistent with std::array. Any thoughts?

@MrBurmark

Copy link
Copy Markdown
Member

@MrBurmark @adayton1 I assume that SubViews can be 0D in certain cases where the slice(s) reduce the dimension to a scalar. This leads to compiler errors on Windows (see failing CI) because camp array stores a C-style array of size 0. My thoughts are to either disallow 0D SubViews or add a specialization of camp array for a 0-sized array. My preference is the latter because std::array can be zero-sized, so this addition would make camp::array be more consistent with std::array. Any thoughts?

Adding a camp array specialization for 0-size makes a lot of sense.

@adayton1

Copy link
Copy Markdown
Member

@MrBurmark @adayton1 I assume that SubViews can be 0D in certain cases where the slice(s) reduce the dimension to a scalar. This leads to compiler errors on Windows (see failing CI) because camp array stores a C-style array of size 0. My thoughts are to either disallow 0D SubViews or add a specialization of camp array for a 0-sized array. My preference is the latter because std::array can be zero-sized, so this addition would make camp::array be more consistent with std::array. Any thoughts?

Adding a camp array specialization for 0-size makes a lot of sense.

I can't remember for sure, but I think that I disallowed the 0 size array because nvcc couldn't handle it (or maybe it was some other compiler). So just do plenty of testing.

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.

7 participants