Skip to content

[CK] Refactor container array and function sequence_reverse_inclusive_scan - #3612

Closed
CongMa13 wants to merge 2 commits into
developfrom
congma13/ck_tile/inclusive_scan_sequence_ck
Closed

CongMa13 wants to merge 2 commits into
developfrom
congma13/ck_tile/inclusive_scan_sequence_ck

Conversation

@CongMa13

Copy link
Copy Markdown
Collaborator

Refactor cd sequence_reverse_inclusive_scan from recursive template to constexpr for-loop.

This pull request improves the utility array functionality and its integration with sequence utilities, as well as adds comprehensive unit tests for the Array class. The main changes include refactoring the implementation of reverse inclusive scan for sequences, updating header dependencies, optimizing the Array assignment operator, and introducing a full test suite for Array.

Array and Sequence Utility Improvements:

  • Refactored the implementation of sequence_reverse_inclusive_scan in sequence.hpp to use a more efficient, array-based approach, encapsulated in a new impl namespace. This change simplifies the logic and should improve compile-time performance.
  • Updated header dependencies in both array.hpp and sequence.hpp to remove unused includes and ensure correct dependency order, notably including array.hpp in sequence.hpp to support the new scan implementation. [1] [2]
  • Optimized the assignment operator in the Array struct by replacing the static_for loop with a standard for-loop and adding a pragma for potential unrolling, improving both readability and performance.

Testing Enhancements:

  • Added a new unit test file unit_array.cpp with comprehensive tests covering construction, element access, assignment, iterators, the make_array helper, and different data types for the Array class.
  • Updated the CMakeLists.txt to build and link the new unit_array test executable.

Tracking issue: #3575

Comment thread include/ck/utility/array.hpp Outdated
Comment on lines +34 to +38
#pragma unroll
for(int i = 0; i < NSize; i++)
{
mData[i] = a[i];
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed the dependency on static_for. Hence, only need to include type.hpp.

And the code is easier to read.

@afagaj
afagaj requested a review from Copilot January 20, 2026 22:09

Copilot AI left a comment

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.

Pull request overview

This PR refactors the sequence_reverse_inclusive_scan implementation from a recursive template-based approach to a more efficient constexpr for-loop using the Array utility class. The changes improve compile-time performance and simplify the logic.

Changes:

  • Refactored sequence_reverse_inclusive_scan to use an array-based iterative approach instead of recursive templates
  • Updated header dependencies to remove circular includes and optimize dependencies
  • Optimized Array::operator= by replacing static_for with a standard for-loop with unroll pragma
  • Added comprehensive unit tests for the Array class

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
include/ck/utility/sequence.hpp Refactored sequence_reverse_inclusive_scan from recursive templates to constexpr array-based implementation
include/ck/utility/array.hpp Updated header dependencies and optimized assignment operator with standard for-loop
test/util/unit_array.cpp Added comprehensive unit tests covering Array construction, access, assignment, iterators, and edge cases
test/util/CMakeLists.txt Added build configuration for new unit_array test executable

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/util/unit_array.cpp Outdated

using namespace ck;

// Test basic Sequence construction and properties

Copilot AI Jan 20, 2026

Copy link

Choose a reason for hiding this comment

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

Comment mentions 'Sequence' but should refer to 'Array' since this test is for the Array class.

Suggested change
// Test basic Sequence construction and properties
// Test basic Array construction and properties

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This comment should be updated.

Comment thread include/ck/utility/array.hpp Outdated

static_for<0, Size(), 1>{}([&](auto i) { operator()(i) = a[i]; });
#pragma unroll
for(int i = 0; i < NSize; i++)

Copilot AI Jan 20, 2026

Copy link

Choose a reason for hiding this comment

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

The loop variable uses int type while NSize is of type index_t (typically size_t or similar). For consistency and to avoid potential type conversion issues, use index_t i = 0 instead of int i = 0.

Suggested change
for(int i = 0; i < NSize; i++)
for(index_t i = 0; i < NSize; i++)

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes, let's use index_t for consistency.

Comment thread include/ck/utility/array.hpp Outdated

static_for<0, Size(), 1>{}([&](auto i) { operator()(i) = a[i]; });
#pragma unroll
for(int i = 0; i < NSize; i++)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We don't need pragma unroll here. The compiler should optimize correctly.

Comment thread include/ck/utility/sequence.hpp
Comment thread include/ck/utility/sequence.hpp Outdated
}
else
{
constexpr Array<index_t, size> arr = []() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It might be slightly faster to replace this lambda with a named constexpr function helper.

Comment thread include/ck/utility/sequence.hpp
shumway
shumway previously approved these changes Jan 21, 2026

@shumway shumway left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks great. I just have a few small comments.

I think we may need unit tests for the reverse inclusive scan.

@illsilin

Copy link
Copy Markdown
Collaborator

Hey @CongMa13, please resolve conflicts for the headers, and make sure ci tests pass.

@CongMa13
CongMa13 force-pushed the congma13/ck_tile/inclusive_scan_sequence_ck branch from bf61492 to 0995ef9 Compare January 28, 2026 23:29
@CongMa13
CongMa13 force-pushed the congma13/ck_tile/inclusive_scan_sequence_ck branch from 0995ef9 to 897f8d2 Compare January 28, 2026 23:38
shumway
shumway previously approved these changes Jan 29, 2026
@ammallya

ammallya commented Feb 3, 2026

Copy link
Copy Markdown

Imported to ROCm/rocm-libraries

@ammallya ammallya closed this Feb 3, 2026
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