Instructions
Example
The following example shows how to concatenate the preceding APIs. It implements a simple operator that supports the float16 type to obtain an absolute value.
import te.lang.cce from te import tvm import topi shape = (28,28) dtype = "float16" # Define input. data = tvm.placeholder(shape, name="data", dtype=dtype) # Describe the computation process of the operator. res = te.lang.cce.vabs(data) with tvm.target.cce(): # Generate a schedule object. sch = topi.generic.auto_schedule(res) # Define build parameters. config = {"print_ir" : True, "need_build" : True, "name" : "abs_28_28_float16", "tensor_list" : [data,res]} # Build operator te.lang.cce.cce_build_code(sch, config)
Exception Handling
If an exception occurs when an API is executed, the error is usually caused by incorrect input parameters. The following example shows the error information when tensor_list is incomplete.
Code example:
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)
The following error information is displayed:
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)
The problem is solved after the parameter is modified as follows:
"tensor_list" : [data, res]