You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by "sdalvi-quic (via GitHub)" <gi...@apache.org> on 2024/02/15 19:27:46 UTC

[I] Possible issue with the "simplify pass" using the "propagate_knowns_to_simplify_expressions" flag [tvm]

sdalvi-quic opened a new issue, #16577:
URL: https://github.com/apache/tvm/issues/16577

   I was trying to understand the use of **T.assume** in the simplification of expressions and I came across this example in the "**test_tir_transform_simplify.py**" file named as "**TestSimplifyUsingPartiallyKnownBufferExpression**". Here, I tried to modify the test and saw that, it was failing while using the "**propagate_knowns_to_simplify_expressions**" flag and T.assume statements. I have attached the test below. 
   ```c++
   class TestSimplifyUsingPartiallyKnownBufferExpression(BaseBeforeAfter):
       """An assumption about buffer contents may apply to only part of a buffer
   
       Like TestSimplifyUsingPartiallyKnownBufferConditional, but the
       conditional is expressed as part of T.assume, instead of in the
       control flow.
       """
   
       # propagate_knowns_to_prove_conditional = True
       propagate_knowns_to_simplify_expressions = True
   
       def before(A: T.Buffer(16, "int32")):
           for i in T.serial(16):
               T.evaluate(T.assume(i < 14 or A[i] == 0))
   
           for i in T.serial(16):
               if i < 14:
                   if A[i] == 0:
                       A[i] = 42
   
       def expected(A: T.Buffer(16, "int32")):
           for i in T.serial(16):
               T.evaluate(T.assume(i < 14 or A[i] == 0))
   
           for i in T.serial(16):
               if i < 14:
                   if A[i] == 0:
                       A[i] = 42
   ``` 
   
   
   Here given the assumption statements `T.assume(i < 14 or A[i] == 0)`, A[i]  will have to be 0 if the range of `i >= 14` but A[i] may or may not be 0 if `i < 14`. So, we should see the expected code as **above** where no statement is eliminated. But the IR returned after the pass eliminates the condition `if A[i] == 0` and returns the IR as **below** : 
   ```c++
   def after(A: T.Buffer((16,), "int32")):
      T.func_attr({"global_symbol": "main"})
      for i in range(16):
          T.assume(i < 14 or A[i] == 0)
      for i in range(16):
         if i < 14:
              A[i] = 42
   ``` 
   
   I see that the two flags "**propagate_knowns_to_simplify_expressions**" and "**propagate_knowns_to_prove_conditional** " are internally calling the function **SimplifyInContext** which is simplifying using the line :
   ```c++
   expr = control_flow_block.known_at_block_start.SubstituteKnownBufferValues(
         std::move(expr), axis_var_lookup_, analyzer);
   ``` 
   
   Can you please help to fix the issue with the test or point what modification needs to be done?  
   
   According to my understanding there is either an issue with the control flow graph generated when T.assume statement are present or there needs to be slight changes in the **SimplifyInContext** function which is simplifying the expression, please correct me if I am wrong. 
   
   @Lunderberg, it will be helpful if you could help with this issue. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] Possible issue with the "simplify pass" using the "propagate_knowns_to_simplify_expressions" flag [tvm]

Posted by "sdalvi-quic (via GitHub)" <gi...@apache.org>.
sdalvi-quic commented on issue #16577:
URL: https://github.com/apache/tvm/issues/16577#issuecomment-1955530546

   Thank you eric for pointing to the location which might be causing issue. Yes, the additional predicate is not getting appended to the constraints. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] Possible issue with the "simplify pass" using the "propagate_knowns_to_simplify_expressions" flag [tvm]

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen closed issue #16577: [Bug] Possible issue with the "simplify pass" using the "propagate_knowns_to_simplify_expressions" flag
URL: https://github.com/apache/tvm/issues/16577


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] Possible issue with the "simplify pass" using the "propagate_knowns_to_simplify_expressions" flag [tvm]

Posted by "Lunderberg (via GitHub)" <gi...@apache.org>.
Lunderberg commented on issue #16577:
URL: https://github.com/apache/tvm/issues/16577#issuecomment-1948760352

   Thank you for the bug report, and that's definitely incorrect behavior.  I think the problem derives from [here](https://github.com/apache/tvm/blob/main/src/tir/analysis/control_flow_graph.cc#L314).  The `additional_predicate` isn't being appended to the buffer access, and so the `T.assume(i < 14 or A[i]==0)` is erroneously being treated as if it were `T.assume(A[i]==0)`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org