Should we use PureExtern for some TVM ops?


#1

I found that some TVM ops such as exp, floor, ceil, etc., are defined as pure intrinsic ops. For example,


However, in HalideIR, these ops are defined as pure extern ops, see

Should we change them to pure extern ops to be consistent with HalideIR? Further, this will also be compatible with HalideIR simplification pass (though we need to add TVM op signature for them).

@tqchen


#2

These operators will get lowered in compiler into different extern functions. So we want to keep them as intrinsics as opposed to extern.

In terms of simplification i feel we should not do the simplification for floating pt ops anyway, mainly because LLVM will do them when necessary and we mainly need simplification for integer indices.


#3

One problem I have now is that when I want to compute the shape of arange op, storage rewrite fails because it cannot simplify the expr due to ceil op.


#4

Should we use pure integer arithmetics to implement ceil division instead?


#5

But arange can take in float value for start, stop, and step.


#6

I see what you mean. Perhaps we could overload ceil floor op to eagerly simplify float arithmetics. As in our current eager simplification of integer ones


#7

as in https://github.com/dmlc/tvm/blob/master/src/lang/ir_operator.cc#L133


#8

Thanks Tianqi. I can work on a PR to simplify ceil and floor.


#9

hmm. I found that float division/add/sub are not eagerly simplified either. Therefore, operand to ceil is still an expr instead of FloatImm. But I feel that eagar simplication for all float expression might not be desired. So what should we do here? Should I change the HalideIR simplify and match intrinsic ceil op defined in TVM?


#10

Let us simply make the add sub div arithmetic eager simplify for float. I think it is not a bad choice anyway