使用方式
使用示例
下面通过一个简单的示例,将上面的接口串起来。该示例是实现一个简单的支持float16数据类型的求绝对值的算子。
import te.lang.cce from te import tvm import topi shape = (28,28) dtype = "float16" # 定义输入 data = tvm.placeholder(shape, name="data", dtype=dtype) # 描述算子计算过程 res = te.lang.cce.vabs(data) with tvm.target.cce(): # 生成schedule对象 sch = topi.generic.auto_schedule(res) # 定义build配置参数 config = {"print_ir" : True, "need_build" : True, "name" : "abs_28_28_float16", "tensor_list" : [data,res]} # build算子 te.lang.cce.cce_build_code(sch, config)
异常处理
接口如果执行异常,一般都是由于错误的入参引起的。下边例子给出了tensor_list不全给出的错误信息。
代码片段
data = tvm.placeholder(shape, name="data", dtype=inp_dtype) with tvm.target.cce(): res = te.lang.cce.vabs(data) sch = generic.auto_schedule(res) config = {"print_ir": need_print, "need_build": need_build, "name": kernel_name, "tensor_list": [res]} te.lang.cce.cce_build_code(sch, config)
执行会发生如下错误:
Traceback (most recent call last): File "llt/tensor_engine/ut/testcase_python/tf_abs/test_tf_abs_cce.py", line 71, in test_cce_tf_abs_99991_fp16 tf_abs_cce((99991,), dtype = "Float16", need_build = False, need_print = False, kernel_name = "cce_tf_abs") File "/home1/repotvm/tensor_engine/topi/python/topi/cce/tf_abs.py", line 68, in tf_abs_cce te.lang.cce.cce_build_code(sch, config) File "/home1/repotvm/tensor_engine/python/te/lang/cce/te_schedule/cce_schedule.py", line 381, in cce_build_code _build(sch, tensor_list, local_config_map["name"]) File "/home1/repotvm/tensor_engine/python/te/lang/cce/te_schedule/cce_schedule.py", line 338, in _build mod = tvm.build(sch, tensor_list, device, name=name) File "/home1/repotvm/tensor_engine/python/te/tvm/build_module.py", line 432, in build binds=binds) File "/home1/repotvm/tensor_engine/python/te/tvm/build_module.py", line 353, in lower stmt = ir_pass.StorageFlatten(stmt, binds, 64) File "/home1/repotvm/tensor_engine/python/te/tvm/_ffi/function.py", line 280, in my_api_func return flocal(*args) File "/home1/repotvm/tensor_engine/python/te/tvm/_ffi/_ctypes/function.py", line 183, in __call__ ctypes.byref(ret_val), ctypes.byref(ret_tcode))) File "/home1/repotvm/tensor_engine/python/te/tvm/_ffi/base.py", line 66, in check_call raise TVMError(py_str(_LIB.TVMGetLastError())) TVMError: [17:12:02] /home1/repotvm/tensor_engine/src/pass/storage_flatten.cc:249: Check failed: it != buf_map_.end() Cannot find allocated buffer for placeholder(data, 0x27d7290)
参数更正为如下情况后,问题得到解决。
"tensor_list" : [data, res]