Should we use PureExtern for some TVM ops?

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

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.

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.

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

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

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

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

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

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?

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

HI Haichen,
can you help explain the difference between “pure intrinsic” and “pure extern” ?
Thank you

Halide doc provides the definition of “intrinsic” and “extern” functions:
https://halide-lang.org/docs/struct_halide_1_1_internal_1_1_call.html#a45d847325694df85e74150f770c1e393

“pure” just means that this function is side-effect-free.

1 Like