Data type error while using tensorize

hello! I am trying to use tensorize on my declared conv2d operator. here is my code.import numpy as np

import tvm

from tvm import te from tvm import autotvm from tvm import topi from zte.enviroment import get_env from zte.intrin import gemm

data = tvm.te.placeholder((1, 64, 112, 112), dtype=“int16”, name=“data”) kernel = tvm.te.placeholder((64, 64, 3, 3), dtype=“int16”, name=“kernel”)

out_w = 110 out_h = 110 out_dtype = “int32” oshape = (1, 64, 110, 110)

define the conv2d operator over the padded data

c = te.reduce_axis((0, 64), name=“c”) k_h = te.reduce_axis((0, 3), name=“k_h”) k_w = te.reduce_axis((0, 3), name=“k_w”) hstride, wstride = 1, 1 res = te.compute( oshape, lambda n, o, h, w: te.sum( data[n, c, h * hstride + k_h, w * wstride + k_w].astype(out_dtype) * kernel[o, c, k_h, k_w].astype(out_dtype), axis=[c, k_h, k_w], ), name=“res”, tag=“conv2d_dense”, )

s = tvm.te.create_schedule(res.op)

env = get_env()

n_o, o_o, h_o, w_o = s[res].op.axis c_in, h_1, w_1 = s[res].op.reduce_axis

h_w_data = s[res].fuse(h_o, w_o) h_w_kernel = s[res].fuse(k_h, k_w) s[res].reorder(n_o, h_w_kernel, h_w_data, o_o, c_in)

xo, yo, xi, yi = s[res].tile(o_o, c_in, x_factor=16, y_factor=16) x_y_fuse = s[res].fuse(xo, yo) data_out, data_in = s[res].split(h_w_data, 256)

s[res].tensorize(h_w_kernel, gemm(env, 0, 16, 16, 16))

code = tvm.lower(s, [data, kernel, res], simple_mode=True) print(code)

And I got this after I run this program.

Traceback (most recent call last):
  File "/home/tonywu/Documents/tvm/zte/test_con2d.py", line 53, in <module>
    s[res].tensorize(h_w_kernel, gemm(env, 0, 16, 16, 16))
  File "/home/tonywu/Documents/tvm/zte/intrin.py", line 60, in gemm
    wgt_layout = tvm.tir.decl_buffer(
  File "/home/tonywu/Documents/tvm/python/tvm/tir/buffer.py", line 254, in decl_buffer
    return _ffi_api.Buffer(
  File "/home/tonywu/Documents/tvm/python/tvm/_ffi/_ctypes/packed_func.py", line 237, in __call__
    raise get_last_ffi_error()
tvm._ffi.base.TVMError: Traceback (most recent call last):
  3: TVMFuncCall
  2: _ZNSt17_Function_handlerIFvN3
  1: tvm::tir::{lambda(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)#3}::operator()(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*) const [clone .isra.0]
  0: tvm::runtime::TVMPODValue_::operator int() const
  File "/home/tonywu/Documents/tvm/include/tvm/runtime/packed_func.h", line 513
TVMError: ---------------------------------------------------------------
An internal invariant was violated during the execution of TVM.
Please read TVM's error reporting guidelines.
More details can be found here: https://discuss.tvm.ai/t/error-reporting/7793.
---------------------------------------------------------------

  Check failed: type_code_ == kDLInt: expected int but got float

Process finished with exit code 1

I’d appreciate it if you could help me solve this problem. Thank you!

I guess you declared elem_offset as a floating number, let’s say 1.0 but not 1. :slight_smile:

1 Like

where to set elem_offset?

I see, the bug is fixed, thanks!