You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2020/03/20 18:59:59 UTC

[GitHub] [incubator-tvm] dpankratz opened a new pull request #5115: [Bugfix] Fixed bug where shifting by out-of-bounds RHS values results in LLVM …

dpankratz opened a new pull request #5115: [Bugfix] Fixed bug where shifting by out-of-bounds RHS values results in LLVM …
URL: https://github.com/apache/incubator-tvm/pull/5115
 
 
   ## Bug
   
   For operations `<<` and `>>` when the RHS is an IntImm with values that are negative or greater than or equal to the number of bits in the integer being shifted results in LLVM emitting no code for the `tvm.compute`. 
   
   ## Example
   
   ```
   a = te.var(name='a', dtype='int32')
   shape = (1,)
   c = te.compute(shape,lambda i: (4 * a) + (a >> 33))
   s = te.create_schedule([c.op])
   f = tvm.build(s,[a,c])
   print("default_function_compute" in f.get_source()) #prints False
   c_tvm= tvm.nd.array(np.zeros(shape,dtype='int32'))
   f(5,c_tvm) 
   print(c_tvm.asnumpy()[0]) #prints 0 instead of 20
   ```
   ## Fix
   
   Limit the RHS immediate values of `<<` and `>>` to be within a valid range. For example the new behaviour would be: 
   ```
   a = te.var(name='a', dtype='int64')
   a << 64 #raises TVMError
   a << -1 #raises TVMError
   a >> 31 #no error
   ```
   
   ## Explanation 
   
   LLVM constant folding silently replaces an out-of-bounds shift to an `undef` as seen [here](https://llvm.org/doxygen/ConstantFold_8cpp_source.html#l01232). Then any other parts of the expression are composed with the undef ( `(4 * a) + undef -> undef` in above example) and become undef as well. Therefore the `tvm.compute` is producing an `undef` which is optimized away by LLVM resulting in no compute code being generated at all.
   
   A review would be much appreciated!
   
   @tqchen 
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] tqchen commented on issue #5115: [Bugfix] Fixed bug where shifting by out-of-bounds value results in no compute code being emitted.

Posted by GitBox <gi...@apache.org>.
tqchen commented on issue #5115: [Bugfix] Fixed bug where shifting by out-of-bounds value results in no compute code being emitted.
URL: https://github.com/apache/incubator-tvm/pull/5115#issuecomment-602685970
 
 
   Thanks @dpankratz !

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] tqchen edited a comment on issue #5115: [Bugfix] Fixed bug where shifting by out-of-bounds value results in no compute code being emitted.

Posted by GitBox <gi...@apache.org>.
tqchen edited a comment on issue #5115: [Bugfix] Fixed bug where shifting by out-of-bounds value results in no compute code being emitted.
URL: https://github.com/apache/incubator-tvm/pull/5115#issuecomment-601936379
 
 
   cc @vinx13 @ZihengJiang @merrymercy @yzhliu please also help to take a look

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] tqchen commented on issue #5115: [Bugfix] Fixed bug where shifting by out-of-bounds value results in no compute code being emitted.

Posted by GitBox <gi...@apache.org>.
tqchen commented on issue #5115: [Bugfix] Fixed bug where shifting by out-of-bounds value results in no compute code being emitted.
URL: https://github.com/apache/incubator-tvm/pull/5115#issuecomment-601936379
 
 
   cc @vinx13 @ZihengJiang @merrymercy please also help to take a look

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-tvm] tqchen merged pull request #5115: [Bugfix] Fixed bug where shifting by out-of-bounds value results in no compute code being emitted.

Posted by GitBox <gi...@apache.org>.
tqchen merged pull request #5115: [Bugfix] Fixed bug where shifting by out-of-bounds value results in no compute code being emitted.
URL: https://github.com/apache/incubator-tvm/pull/5115
 
 
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services