-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Add integer reduction support for reduce ops #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
Author
|
This PR simplifies and replaces #21 and makes the additional reduction operator contribution optional/independent/extensible. |
maleadt
reviewed
Jan 19, 2026
maleadt
reviewed
Jan 20, 2026
Contributor
Author
|
after #31 tests fail. But it has nothing to do with this PR. Tests might error from second argument, where tests walk through each reduce op. |
eb6bd51 to
1ab7d5b
Compare
Member
|
Passes test after rebase (i.e. after #46). |
maleadt
reviewed
Jan 30, 2026
This commit enables reduce_sum and reduce_max operations on all numeric types, extending beyond the previous float-only support. ## Infrastructure Changes ### Bytecode Layer - Added IntegerIdentityOp struct with signed/unsigned handling - Added encode_tagged_int! for integer identity encoding - Added mask_to_width function with zigzag encoding for signed types - Added encode_identity! dispatch for FloatIdentityOp and IntegerIdentityOp - Refactored ReduceIdentity → IdentityOp for extensibility ### Compiler Layer - Refactored emit_reduce! to use dispatch-based approach - Added operation_identity dispatch for add/max operations - Added encode_reduce_body dispatch for float and integer operations - Removed T <: AbstractFloat constraints from intrinsics ### Language Layer - Removed type constraints from reduce_sum and reduce_max in operations.jl ## Test Coverage ### Codegen Tests - Added FileCheck tests for Int32/UInt32 reduce_sum and reduce_max - Verifies correct IR generation (addi, maxi instructions) ### Execution Tests - Factory pattern for easy extension (makeReduceKernel, cpu_reduce) - Tests 10 types: Int8, Int16, Int32, Int64, UInt16, UInt32, UInt64, Float16, Float32, Float64 - Tests 2 operations: reduce_sum, reduce_max - CPU verification for all test cases - Type-appropriate input ranges to prevent overflow ## Files Changed - src/bytecode/encodings.jl: Fix IdentityOp type annotation - src/bytecode/writer.jl: Integer identity infrastructure - src/compiler/intrinsics.jl: Import identity types - src/compiler/intrinsics/core.jl: Dispatch-based reduce implementation - src/cuTile.jl: Export identity types - src/language/operations.jl: Remove type constraints - test/codegen.jl: Add integer reduction codegen tests - test/execution.jl: Add extendable execution tests ## Extensibility The infrastructure is designed for easy extension: - Add new reduce operations by defining operation_identity and encode_reduce_body methods - Add new types by adding to TEST_TYPES array and appropriate data generation
- Constrain T <: Number in reduce_sum/reduce_max signatures for type safety - Ensures only numeric types can be used with reduction operations
- IntegerIdentityOp no longer stores signed::Bool field - signedness inferred from dtype (T <: Signed) - mask_to_width simplified to use T <: Signed for zigzag encoding - All call sites updated
- Zigzag encoding now handled entirely in mask_to_width - Single encode_varint! call regardless of signedness
Single-use functionality doesn't benefit from dispatch-based selection.
The original name `IdentityOp` could be misleading representation for TileIR Op. New name better represent that its rather a value. - IdentityOp -> IdentityVal
1ab7d5b to
f37fc6e
Compare
maleadt
approved these changes
Jan 30, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit enables reduce_sum and reduce_max operations on all numeric types, extending beyond the previous float-only support.
Infrastructure Changes
Bytecode Layer
Compiler Layer
Language Layer
Test Coverage
Codegen Tests
Execution Tests
Files Changed
Extensibility
The infrastructure is designed for easy extension: