Repository navigation
[LinalgExt] fix arg_compare op with region and start index - #21106
Conversation
3e2d53f to
2f8212f
Compare
Signed-off-by: Bangtian Liu <[email protected]>
MaheshRavishankar
left a comment
There was a problem hiding this comment.
I think the op needs to be renamed to arg_compare?
Ian pointed it out as well, I think you need some better verifiers in the region?. You essentially want to check that this is a binary comparator operator, i.e. its a (T a, T b) -> T c.
Actually working through this a bit more, I think we need this to be (T a, index a_index, Tb, index b_index) -> (T, index) . Reason is you need to compute the argmax or argmin. The current region will not let you do this.
Easy way to verify that you have what is needed is to implement the lowering of this operation to loops. If you can lower this to loops, then we should be able to do tiling etc. on it.
Signed-off-by: Bangtian Liu <[email protected]>
Thanks for the feedback. I just sent out a commit that improves the verifier based on Ian's earlier comment. Regarding your suggestion here, I agree this requires further refinement to properly support argmax/argmin semantics (and also |
|
@MaheshRavishankar One question about the proposed region type |
My understanding was that it would be equivalent to this pseudo-code: # `elems` represents the input tensor.
# `pred` represents the region as a predicate that takes the current val and the current max val.
def argMax(elems, pred):
maxVal = elems[0]
maxIdx = 0
for i, elem in enumerate(elems):
if pred(elem, maxVal):
maxVal = elem
maxIdx = i
return maxVal, maxIdx |
|
Can you clarify what the yield is supposed to mean? What is the Boolean supposed to indicate? EDIT : I see from @IanWood1 s explanation what it is. Ok, this makes sense then |
Signed-off-by: Bangtian Liu <[email protected]>
|
Just sent the commit about op renaming. I will add the implementation of lowering to loops next. |
…ng test Signed-off-by: Bangtian Liu <[email protected]>
MaheshRavishankar
left a comment
There was a problem hiding this comment.
This looks fine, but it will be clear after the loop implementation if we missed something.
Signed-off-by: Bangtian Liu <[email protected]>
Signed-off-by: Bangtian Liu <[email protected]>
On top of #21106. This PR Adds `generateScalarImplementation` for ArgCompareOp, defining the scalar behavior within the innermost loop during loop lowering. The lowering performs the following: - Loads the current best value and corresponding index (accumulator) from the output tensor. - Loads the candidate value at the current loop indices. - Invokes the provided comparator region (T a, T b) -> i1 to compare values. - Selects the new best value and index based on the comparison result. - Supports an optional index_base operand, which is added to the computed index before storing. Next, will add tiling support. --------- Signed-off-by: Bangtian Liu <[email protected]>
This is a follow-up PR to address feedback on the previously landed PR for the argmax op #21021 according to comments in #21021 (comment): - Adds support for a comparator region in the argmax op - Introduces an optional index_base operand to specify the starting index offset. --------- Signed-off-by: Bangtian Liu <[email protected]>
On top of #21106. This PR Adds `generateScalarImplementation` for ArgCompareOp, defining the scalar behavior within the innermost loop during loop lowering. The lowering performs the following: - Loads the current best value and corresponding index (accumulator) from the output tensor. - Loads the candidate value at the current loop indices. - Invokes the provided comparator region (T a, T b) -> i1 to compare values. - Selects the new best value and index based on the comparison result. - Supports an optional index_base operand, which is added to the computed index before storing. Next, will add tiling support. --------- Signed-off-by: Bangtian Liu <[email protected]>
This is a follow-up PR to address feedback on the previously landed PR for the argmax op #21021 according to comments in #21021 (comment):