yongwww commented on code in PR #14394:
URL: https://github.com/apache/tvm/pull/14394#discussion_r1155053362
##########
python/tvm/relax/analysis/analysis.py:
##########
@@ -276,6 +276,34 @@ def has_reshape_pattern(func: tir.PrimFunc) -> bool:
return _ffi_api.has_reshape_pattern(func) # type: ignore
+def contains_impure_call(expr: Expr, own_name: Optional[Union[Var, GlobalVar]]
= None) -> bool:
+ """
+ Check if the given expression (likely a function body) contains any
impure calls.
Review Comment:
remove 4 spaces to maintain that indentation aligns with the rest of the
code.
##########
src/relax/op/op.cc:
##########
@@ -177,7 +227,9 @@ TVM_REGISTER_OP("relax.call_builtin_with_ctx")
.set_num_inputs(4)
Review Comment:
just noticed this should be 2, it is not related to your change...
##########
src/relax/op/tensor/manipulate.cc:
##########
@@ -1357,7 +1370,8 @@ TVM_REGISTER_OP("relax.cumsum")
.set_attrs_type<CumsumAttrs>()
.set_num_inputs(1)
.add_argument("data", "Tensor", "The input tensor.")
- .set_attr<FInferStructInfo>("FInferStructInfo", InferStructInfoCumsum);
+ .set_attr<FInferStructInfo>("FInferStructInfo", InferStructInfoCumsum)
+ .set_attr<Bool>("FPurity", Bool(true));
Review Comment:
will we run into issue if FPurity is not specified explicitly?
##########
src/relax/op/op.cc:
##########
@@ -177,7 +227,9 @@ TVM_REGISTER_OP("relax.call_builtin_with_ctx")
.set_num_inputs(4)
.add_argument("func", "Expr", "The builtin packed func.")
.add_argument("args", "Tuple", "The input arguments.")
- .set_attr<FInferStructInfo>("FInferStructInfo",
InferStructInfoCallBuiltinWithCtx);
+ .set_attr<FInferStructInfo>("FInferStructInfo",
InferStructInfoCallBuiltinWithCtx)
+ // TODO(relax-team): Please verify if these are normally impure or not
Review Comment:
seems the existing builtin packedfuncs are pure
##########
python/tvm/script/parser/relax/parser.py:
##########
@@ -220,7 +220,31 @@ def visit_tvm_declare_function(self: Parser, node:
doc.FunctionDef) -> GlobalVar
param_sinfo = eval_struct_info(self, arg.annotation, eval_str=True)
params.append(relax.Var(arg.arg, param_sinfo))
- func_signature = relax.Function.create_empty(params, ret_sinfo)
+ # find a call to R.func_attr to see if purity should be indicated
+ # namely, find a call to R.func_attr({..., "IsPure": val, ...})
+ # (we don't need any other attributes at the function declaration stage)
+ attrs = None
+ for item in node.body:
+ if (
+ isinstance(item, doc.Expr)
+ and isinstance(item.value, doc.Call)
+ and isinstance(item.value.func, doc.Attribute)
+ and item.value.func.attr == "func_attr"
+ and len(item.value.args) == 1
+ and isinstance(item.value.args[0], doc.Dict)
Review Comment:
consider move this to a func like `get_func_attrs`
--
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]