comaniac commented on a change in pull request #4644: [WIP] Relay op strategy
URL: https://github.com/apache/incubator-tvm/pull/4644#discussion_r372636908
##########
File path: python/tvm/relay/backend/compile_engine.py
##########
@@ -63,6 +83,316 @@ def _get_cache_key(source_func, target):
return source_func
+def get_shape(shape):
+ """Convert the shape to correct dtype and vars."""
+ ret = []
+ for dim in shape:
+ if isinstance(dim, tvm.expr.IntImm):
+ val = int(dim)
+ assert val <= np.iinfo(np.int32).max
+ ret.append(tvm.expr.IntImm("int32", val))
+ elif isinstance(dim, tvm.expr.Any):
+ ret.append(tvm.var("any_dim", "int32"))
+ else:
+ ret.append(dim)
+ return ret
+
+
+def get_valid_implements(op, attrs, inputs, out_type, target):
+ """Get all valid implementations from the op strategy.
+
+ Note that this function doesn't support op that has symbolic input shapes.
+
+ Parameters
+ ----------
+ op : relay.op.Op
+ Relay operator.
+
+ attrs : object
+ The op attribute.
+
+ inputs : list of tvm.Tensor
+ Input tensors to the op.
+
+ out_type : relay.Type
+ The output type.
+
+ target : tvm.Target
+ The target to compile the op.
+
+ Returns
+ -------
+ ret : list of relay.op.OpImplement
+ The list of op implementations.
+ """
+ fstrategy = op.get_attr("FTVMStrategy")
+ assert fstrategy is not None, "%s doesn't have FTVMStrategy registered" %
op.name
+ with target:
+ strategy = fstrategy(attrs, inputs, out_type, target)
+ ret = []
+ for spec in strategy.specializations:
+ if spec.condition:
+ flag = True
+ for clause in spec.condition.clauses:
+ clause = tvm.ir_pass.Simplify(clause)
+ if isinstance(clause, tvm.expr.IntImm) and clause.value:
Review comment:
Could you add comments to this statement, or use a better name for `flag`?
I don't quite understand the logic here.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services