Skip to content

Conversation

@CongMa13
Copy link
Collaborator

@CongMa13 CongMa13 commented Jan 19, 2026

Proposed changes

Refactor ck tile sequence_reverse_inclusive_scan from recursive to for-loop.

Tracking issue: #3575

This pull request introduces a new lightweight array type, trivial_array, and refactors the sequence utilities to use it for improved constexpr support and simplicity. The changes also include updates to the build system to add container-related tests.

Core Library Improvements:

  • Added a new header trivial_array.hpp that defines the trivial_array type, a constexpr-friendly array with basic accessors and no custom constructors.
  • Updated includes in core.hpp and sequence.hpp to import trivial_array. [1] [2]

Refactoring to Use trivial_array:

  • Refactored sequence utilities in sequence.hpp to use trivial_array instead of the previously forward-declared array type, including in histogram and array generation logic. [1] [2]
  • Rewrote the implementation of sequence_reverse_inclusive_scan to use trivial_array for intermediate storage, improving constexpr evaluation and clarity.

Build System and Testing:

  • Added a new test subdirectory for container tests and a GoogleTest executable for unit_sequence.cpp to the CMake build configuration. [1] [2]

@tenpercent
Copy link
Contributor

Thanks! Could you also measure the build metrics improvements, e.g. number of templates instantiated, or wall time improvement for some target?

template <index_t I, index_t... Is, typename Reduce, index_t Init>
struct sequence_reverse_inclusive_scan<sequence<I, Is...>, Reduce, Init>
template <index_t... Is, typename Reduce, index_t Init>
struct sequence_reverse_inclusive_scan_impl<sequence<Is...>, Reduce, Init>
Copy link
Contributor

Choose a reason for hiding this comment

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

re: implementation, would it help to have separate compile-time functions for sequence reversal (constexpr function with c-array initialized with variadic indices and then reverse using a for-loop logic) and scan (with a similar structure)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Refactor the code and added a reverse function

- Add trivial_array for template programming
- Add unit tests of sequence
@afagaj afagaj requested a review from Copilot January 20, 2026 22:09
Copy link
Contributor

Copilot AI left a comment

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 in the CK TILE library from a recursive template-based approach to an iterative for-loop implementation. The changes improve compilation efficiency by reducing template instantiation depth.

Changes:

  • Refactored sequence_reverse_inclusive_scan from recursive to iterative implementation using trivial_array
  • Added comprehensive unit tests for sequence operations
  • Introduced trivial_array container for constexpr operations

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
include/ck_tile/core/container/sequence.hpp Refactored sequence_reverse_inclusive_scan to use iterative approach with trivial_array, replaced array with trivial_array in utility functions
include/ck_tile/core/container/trivial_array.hpp New file introducing trivial_array container for constexpr aggregate initialization
include/ck_tile/core.hpp Added include for new trivial_array.hpp header
test/ck_tile/core/container/unit_sequence.cpp New comprehensive test suite covering sequence operations including scan, transform, reduce, and utility functions
test/ck_tile/core/container/CMakeLists.txt Build configuration for new sequence unit tests
test/ck_tile/core/CMakeLists.txt Added container subdirectory to test build

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

Comment on lines +5 to +7
if(result EQUAL 0)
target_link_libraries(ck_tile_unit_sequence PRIVATE utility)
endif()
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

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

The variable result is referenced but never defined. This condition will always fail. The add_gtest_executable macro likely needs to set a return value variable, or this check should reference a variable that the macro actually sets.

Suggested change
if(result EQUAL 0)
target_link_libraries(ck_tile_unit_sequence PRIVATE utility)
endif()
target_link_libraries(ck_tile_unit_sequence PRIVATE utility)

Copilot uses AI. Check for mistakes.
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.

3 participants