icemelon9 commented on a change in pull request #4644: [Relay][AutoTVM] Relay
op strategy
URL: https://github.com/apache/incubator-tvm/pull/4644#discussion_r381029964
##########
File path: python/tvm/relay/backend/compile_engine.py
##########
@@ -63,6 +75,191 @@ 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 with 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)
+ analyzer = tvm.arith.Analyzer()
+ ret = []
+ for spec in strategy.specializations:
+ if spec.condition:
+ # check if all the clauses in the specialized condition are true
+ flag = True
+ for clause in spec.condition.clauses:
+ clause = analyzer.canonical_simplify(clause)
+ if isinstance(clause, tvm.expr.IntImm) and clause.value:
+ continue
+ flag = False
+ break
+ if flag:
+ for impl in spec.implements:
+ ret.append(impl)
+ else:
+ for impl in spec.implements:
+ ret.append(impl)
+ return ret
+
+
+def select_implement(op, attrs, inputs, out_type, target, use_autotvm=True):
Review comment:
changed to implementation
----------------------------------------------------------------
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