I think option B puts too much limitation that it might be only good for asserting non-neg property. But I can imagine that we need more properties on shapes to perform other optimization. At that time, we will be back on this discussion again whether we add another intrinsic or we will add property to var. For example, people may want to add likely property to a var that expresses the likely size of a shape as a hint to AutoTVM. Allowing var to have properties will benefit in long term, IMO.
I agree with @kparzysz that having such builtin_condition or other helper function for developers to easily add properties to var is good for usability.
Let me try to summarize the point. Seems we are converging to a common ground.
I think currently the closest thing possible would be add an assert_expr that assets the non-negative condition to the expression as well as other conditions(chained by and). Alternatively, we can go for the assert_lower_bound, which is more specialized.
assert_expr(x, x>=0)
@haichen would you like to volunteer to summarize, send a formal RFC and land this feature? It would be relevant to dynamic shapes
Another requirement is we may need a reduction infor in Variable, since weāve seen we need to identify if axes are reduce or not in passes. Also orignal Halide has reduce domain infor, we may just need a boolean flag.
Thinking about the problem a bit more during the holiday. Now that we have a flexible Object system whichi supports runtime dynamic checks, one variant of Option A might start to become interesting.
Option A+
class IterVarNode : public Variable {
public:
Range dom;
static constexpr const char* _type_key = "IterVar";
}
Instead of directly enforcing the variable types on the Variable, we could build extension of Var that contains additional information. In order for the visitor/functor to work for this types, we just need to set the default dispatching strategy to
So all the visitors that are based on the functor will work out of the box.
This will allow us to introduce a few variants of Vars that can add additional information, while not having to change the rest part of the codebase to accomodate them(things will fallback to normal var) and perhaps it could be complementary to option B
Iām know Iām quite late to this discussion, but is there a way to embed bound information on variables now.
I know that we have tvm.tir.SizeVar which defines a bound of >= 0, but couldnāt find a way to directly embed bound information on variables without writing a pass through TIR.
OK. So can you give an example about using assert_stmt to embed bound infomation? And can this infomation be propagated to simplfy codegen? Thank you so much