Lunderberg commented on PR #15577:
URL: https://github.com/apache/tvm/pull/15577#issuecomment-1708887108

   @Hzfengsy Thank you, and I do think the value should be a `tir.PrimExpr` and 
not just a `tir.Var` for a few reasons.
   
   * API consistency when applying `BindSymbolicVars`.  When a function is 
updated using `BindSymbolicVars`, the allowed values for each parameter are 
restricted, but the calling convention is otherwise kept identical.  For 
example, binding `{n: 16}` would reduce the set of allowed values for 
`R.Tensor([n, n])` (the set of all square tensors) to `R.Tensor([16, 16])` (the 
set of all tensors of shape `[16,16]`), and remains part of the function 
signature.  Similarly, a PrimValue parameter would be reduced from 
`R.Prim(dtype='int64', value=n)` (the set of all 64-bit integers) to 
`R.Prim(dtype='int64', value=16)` (the set containing only the integer 16), and 
remains part of the function signature.
   
     If `R.Prim` were instead restricted to a `tir.Var`, it wouldn't be 
possible to write `R.Prim(dtype='int64', value=16)`, and the parameter would 
need to be removed entirely.  As a result, the calling scope would need to be 
updated (e.g. from `my_func(tensor, 16)` to `my_func(tensor)`).
     
   * API consistency with `R.Shape`.  Similar to a `R.Prim`, a `R.Shape` can 
contain only static parameters.  However, for similar reasons, parameters of 
type `R.Shape([n, n])` are specialized to `R.Shape([16,16])` and retained in 
the function signature, even though they only have a single legal value of 
`ShapeTuple([16,16])`.
     
   * Usefulness as constituents in other StructInfo objects.  Currently, many 
types of StructInfo may internally contain a `PrimExpr` (e.g. 
`TensorStructInfo`, `ShapeStructInfo`), and so visitors that inspect the struct 
info for `PrimExpr` instances must handle each case independently, performing 
the handoff from `StructInfoFunctor` to `tir::ExprFunctor`.  If these were 
instead expressed in terms of `PrimStructInfo`, this would only need to occur 
in a single location.  Because `TensorStructInfo` and `ShapeStructInfo` may 
contain either static values or expressions in terms of other symbolic 
variables, this potential usage would require `PrimStructInfo` to also contain 
these values.
   


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to