Skip to content
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

[Bugfix] Fixed: Bitwise ops on floats causing wrong code generation and crashes. #4892

Merged
merged 1 commit into from
Feb 18, 2020
Merged

Conversation

dpankratz
Copy link
Contributor

@dpankratz dpankratz commented Feb 15, 2020

Bitwise Ops on Floats

I encountered a few bugs involving using bitwise operators on floating point types. The first bug is that the << and >> operators are essentially no-ops when applied to floats which can be misleading. For example:

shape = (1,1)
c = tvm.compute(shape,lambda i,j: tvm.const(10) << 2.0)
s = tvm.create_schedule([c.op])
f = tvm.build(s,[c])
c_tvm= tvm.nd.array(numpy.zeros(shape,dtype='float32'))
f(c_tvm)
print(c_tvm) #Prints [[10.]] not expected [[40.]]

The other bitwise operators |, &, ^, and ~ throw an error in the LLVM backend when applied to floats. For reference I tested using LLVM-8.

This bug is fixed by adding checks to filter out floats for the |, &, ^, ~, <<, and >> operators.

TypeError Crashes

I also encountered a few more cases where operators failed to promote python types to tvm ExprOps which causes a python TypeError.

a = tvm.var()
10 % a #crashes
10 << a #crashes
10 >> a #crashes

This bug is fixed by adding the missing operators to expr.py

This pull request also includes a regression test for both in test_lang_basic.py

@tqchen @ZihengJiang

…t type expressions. Further crash when using ops <<, >>, %. Finally added regression tests for both types of bug.
@tqchen tqchen merged commit 976c08a into apache:master Feb 18, 2020
@tqchen
Copy link
Member

tqchen commented Feb 18, 2020

Thanks @dpankratz !

alexwong pushed a commit to alexwong/tvm that referenced this pull request Feb 26, 2020
…t type expressions. Further crash when using ops <<, >>, %. Finally added regression tests for both types of bug. (apache#4892)
alexwong pushed a commit to alexwong/tvm that referenced this pull request Feb 28, 2020
…t type expressions. Further crash when using ops <<, >>, %. Finally added regression tests for both types of bug. (apache#4892)
zhiics pushed a commit to neo-ai/tvm that referenced this pull request Mar 2, 2020
…t type expressions. Further crash when using ops <<, >>, %. Finally added regression tests for both types of bug. (apache#4892)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants