-
Notifications
You must be signed in to change notification settings - Fork 78
[Feat] Complete BasisAttr support in IntTupleBuilder (#574) #605
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
54148ed
[Feat] Complete BasisAttr support in IntTupleBuilder (#574)
jhinpan ae79fc1
Merge branch 'main' into feat-issue-574-basis-inttuplebuilder
jhinpan 7eab7d4
[Feat] Address PR #605 review on BasisAttr IntTupleBuilder support (#…
jhinpan 7255fff
[Fix] make_stride: raise instead of segfault on a non-stride object (…
jhinpan 72cf4e8
Merge branch 'main' into feat-issue-574-basis-inttuplebuilder
jhinpan b3c06cf
Merge branch 'main' into feat-issue-574-basis-inttuplebuilder
jhinpan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // Copyright (c) 2025 FlyDSL Project Contributors | ||
| // RUN: %fly-opt %s | FileCheck %s | ||
|
|
||
| // Tests for BasisAttr (scaled-basis / CuTe E<I>) stride leaves flowing through | ||
| // the IntTupleBuilder ops: division of a basis coefficient, and a full identity | ||
| // layout (1E0, 1E1, ...) through logical_divide. The inferred result types below | ||
| // are checked by fly-opt's type inference (a wrong type fails to parse). | ||
|
|
||
| // ----- | ||
|
|
||
| // div divides the scalar coefficient of each basis leaf, keeping its modes: | ||
| // (2E0, 8E1) / (2, 4) = (1E0, 2E1) | ||
| // CHECK-LABEL: @test_int_tuple_div_basis | ||
| func.func @test_int_tuple_div_basis() -> !fly.int_tuple<(1E0, 2E1)> { | ||
| %a = fly.static : !fly.int_tuple<(2E0, 8E1)> | ||
| %b = fly.static : !fly.int_tuple<(2, 4)> | ||
| // CHECK: fly.int_tuple_div(%{{.*}}, %{{.*}}) | ||
| %result = fly.int_tuple_div(%a, %b) : (!fly.int_tuple<(2E0, 8E1)>, !fly.int_tuple<(2, 4)>) -> !fly.int_tuple<(1E0, 2E1)> | ||
| return %result : !fly.int_tuple<(1E0, 2E1)> | ||
| } | ||
|
|
||
| // ----- | ||
|
|
||
| // logical_divide partitions a basis-strided identity layout; the algebra walks the | ||
| // basis strides (via complement/div) instead of asserting on a non-int leaf. | ||
| // CHECK-LABEL: @test_logical_divide_identity | ||
| func.func @test_logical_divide_identity() -> !fly.layout<((2, (2, 2)), 4) : ((1E0, (2E0, 1E1)), 2E1)> { | ||
| %s = fly.static : !fly.int_tuple<(4, 8)> | ||
| %id = fly.make_identity_layout(%s) : (!fly.int_tuple<(4, 8)>) -> !fly.layout<(4, 8) : (1E0, 1E1)> | ||
| %ds = fly.static : !fly.int_tuple<(2, 4)> | ||
| %dd = fly.static : !fly.int_tuple<(1, 2)> | ||
| %div = fly.make_layout(%ds, %dd) : (!fly.int_tuple<(2, 4)>, !fly.int_tuple<(1, 2)>) -> !fly.layout<(2, 4) : (1, 2)> | ||
| // CHECK: fly.logical_divide(%{{.*}}, %{{.*}}) | ||
| %result = fly.logical_divide(%id, %div) : (!fly.layout<(4, 8) : (1E0, 1E1)>, !fly.layout<(2, 4) : (1, 2)>) -> !fly.layout<((2, (2, 2)), 4) : ((1E0, (2E0, 1E1)), 2E1)> | ||
| return %result : !fly.layout<((2, (2, 2)), 4) : ((1E0, (2E0, 1E1)), 2E1)> | ||
| } | ||
|
|
||
| // ----- | ||
|
|
||
| // Rank-3 identity logical_divide with a valid (tiling) divisor walks the basis | ||
| // strides through complement/composition without crashing. A non-tiling divisor | ||
| // such as (2,4,2):(1,2,4) -- whose complement has a 0-extent mode -- is rejected | ||
| // by an assert in compositionImpl instead of dividing by zero (see issue #574). | ||
| // CHECK-LABEL: @test_logical_divide_identity_rank3 | ||
| func.func @test_logical_divide_identity_rank3() | ||
| -> !fly.layout<((2, (2, 2), 2), (2, 2)) : ((1E0, (2E0, 1E1), 2E1), (4E1, 1E2))> { | ||
| %s = fly.static : !fly.int_tuple<(4, 8, 2)> | ||
| %id = fly.make_identity_layout(%s) : (!fly.int_tuple<(4, 8, 2)>) -> !fly.layout<(4, 8, 2) : (1E0, 1E1, 1E2)> | ||
| %ds = fly.static : !fly.int_tuple<(2, 4, 2)> | ||
| %dd = fly.static : !fly.int_tuple<(1, 2, 8)> | ||
| %div = fly.make_layout(%ds, %dd) : (!fly.int_tuple<(2, 4, 2)>, !fly.int_tuple<(1, 2, 8)>) -> !fly.layout<(2, 4, 2) : (1, 2, 8)> | ||
| // CHECK: fly.logical_divide(%{{.*}}, %{{.*}}) | ||
| %result = fly.logical_divide(%id, %div) : (!fly.layout<(4, 8, 2) : (1E0, 1E1, 1E2)>, !fly.layout<(2, 4, 2) : (1, 2, 8)>) -> !fly.layout<((2, (2, 2), 2), (2, 2)) : ((1E0, (2E0, 1E1), 2E1), (4E1, 1E2))> | ||
| return %result : !fly.layout<((2, (2, 2), 2), (2, 2)) : ((1E0, (2E0, 1E1), 2E1), (4E1, 1E2))> | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
This still leaves a crash path for the falsy-marker case. With the current branch, a custom object that exposes
__fly_basis__ = Falseis no longer parsed as a basis leaf, but passing it throughfx.make_stride()segfaults the Python process instead of raising the normal invalid-argument error.Minimal repro against this PR head:
This exits with
SIGSEGV/139 in my local build. Since this code explicitly handles truthy-vs-falsy markers, the falsy marker should be covered by a regression and should fail safely, for example by explicitly rejecting it before the generic_CAPIPtrfallback or otherwise making that fallback safe for arbitrary Python objects.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.
Fixed in 7255fff. Root cause was in the generic fallback's error message: it called
nb::type_name(args), andnb_type_nameexpects a type object — it casts toPyTypeObject*and callsPyType_GetName/PyType_HasFeature. Passing an instance (yourFalsyMarker(), or any non-stride object) reinterprets it as a type and segfaults (on Python < 3.11 the__name__lookup on the instance also yields aNULLthat then feedsPyUnicode_FromFormat). Switched toPy_TYPE(args.ptr())->tp_name, which is always valid, so the fallback now fails safely for any object:It was pre-existing (any invalid stride element hit the same path — a bare
object()crashed identically), but the falsy-marker handling is what made it reachable, so good catch. Regression added intest_make_stride_rejects_non_stride_object, covering both the falsy marker and a bareobject().