-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: main
Are you sure you want to change the base?
Conversation
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
|
This PR simplifies and replaces #21 and makes the additional reduction operator contribution optional/independent/extensible. |
- 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.
|
|
||
| """ | ||
| ReduceIdentity | ||
| IdentityOp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to submit this comment yesterday:
It's not really an IdentityOp, is it? The
Opmakes me think this is an Tile IR operation, while we're simply dealing with values here AFAIU.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. I had alternative name. I can't recollect it now. For now does IdentityValue or IdentityVal sounds good to you ?
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: