I added a new ‘mytarget’ to target list and add dense strategy registration in python/tvm/op/strategy/mytarget.py as below (__init__.py has been updated appropriately to include this newly added target file):
However, when tvm tries to select_implementations() in python/tvm/relay/backend/compile_engine.py. It always goes to the generic version of dense_strategy defined in python/tvm/op/strategy/generic.py:
@override_native_generic_func("dense_strategy")
def dense_strategy(attrs, inputs, out_type, target):
"""dense generic strategy"""
logger.warning("dense is not optimized for this platform.")
strategy = _op.OpStrategy()
strategy.add_implementation(wrap_compute_dense(topi.nn.dense),
wrap_topi_schedule(topi.generic.schedule_dense),
name="dense.generic")
return strategy
Can anyone give me some hint why my registration doesnt work? Thanks.
This is where the problem lies. You need to give the target context by relay.build with the target argument.
But there is no requirement to do this in TVM for flexibility. In some tutorials, compute graph is not build by using op strategy but directly using the wrap function(cfunc&sfunc).
For example, one can build an nms graph by cfunc and sfunc without target context. And then give the target context in building stage.
out = topi.vision.nms.non_max_suppression(data, valid_count, iou_threshold=iou_threshold,
force_suppress=force_suppress, top_k=top_k)
s = topi.generic.schedule_nms(out)
print(tvm.lower(s,[data,valid_count,out]))
f = tvm.build(s, [data, valid_count, out], "llvm")
I finally figured it out. It was because I didn’t specify “keys” when I create the new ‘mytarget’. Once I add ‘mytarget’ as the key, the dense_strategy registration works like a charm…
It is really appreciated there’ll be a tutorial/docs on how to add a new target,