ibsidorenko commented on code in PR #15057: URL: https://github.com/apache/tvm/pull/15057#discussion_r1223925498
########## python/tvm/topi/hexagon/utils.py: ########## @@ -24,10 +24,30 @@ from typing import Dict, Tuple, Union import tvm -from tvm import IRModule, te +from tvm import IRModule, te, tir from tvm.tir import IndexMap, PrimFunc +def is_scalar(expr): + if isinstance(expr, te.Tensor): + return expr.ndim == 0 and (isinstance(expr.op.body[0], (tir.FloatImm, tir.IntImm))) + return isinstance(expr, (tir.FloatImm, tir.IntImm)) + + +def get_const_int_value(expr): + if isinstance(expr, te.Tensor): + assert isinstance(expr.op.body[0], tir.IntImm) + return expr.op.body[0].value + return get_const_int(expr) + + +def get_const_float_value(expr): + if isinstance(expr, te.Tensor): + assert isinstance(expr.op.body[0], tir.FloatImm) + return expr.op.body[0].value + return get_const_float(expr) + + Review Comment: `is_scalar/get_const_int_value/get_const_float_value` - it looks like code duplication with `python/tvm/topi/hexagon/qnn/nn.py` (except for Relax const support). Agree, `utils.py` is a better place for that. Can we add support for Relax constants here and remove it from `nn.py`? -- 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]
