Cannot quantize hcl tensors for Vitis
Closed this issue · 1 comments
chhzh123 commented
I want to quantize hcl tensors for the Vitis target, but it seems the current codegen for Vitis (CodeGenXOCLHost
) cannot support quantization. An example and generated errors are shown below.
qtype = hcl.Fixed(16,12)
A = hcl.placeholder((10,), "A", dtype=qtype)
def kernel(A):
return hcl.compute((10,), lambda x: A[x] + 1, "B", dtype=qtype)
s = hcl.create_schedule(A, kernel)
target = hcl.platform.aws_f1
# target.config(compile="vivado_hls", mode="csim")
target.config(compile="vitis", mode="hw_sim", backend="vhls")
f = hcl.build(s, target=target)
Traceback (most recent call last):
File "add2.py", line 14, in <module>
f = hcl.build(s, target=target)
File "/home/chz/heterocl/python/heterocl/api.py", line 319, in build
return _build(schedule.sch, new_inputs, target=target, name=name, stmt=stmt, schedule_name=schedule.name)
File "/home/chz/heterocl/python/heterocl/tvm/build_module.py", line 565, in build
return build_fpga_kernel(sch, args, target, name=name, schedule_name=schedule_name)
File "/home/chz/heterocl/python/heterocl/tvm/build_module.py", line 509, in build_fpga_kernel
f = builder(fdevice, keys, vals)
File "/home/chz/heterocl/python/heterocl/tvm/_ffi/function.py", line 280, in my_api_func
return flocal(*args)
File "/home/chz/heterocl/python/heterocl/tvm/_ffi/_ctypes/function.py", line 183, in __call__
ctypes.byref(ret_val), ctypes.byref(ret_tcode)))
File "/home/chz/heterocl/python/heterocl/tvm/_ffi/base.py", line 66, in check_call
raise TVMError(py_str(_LIB.TVMGetLastError()))
heterocl.tvm._ffi.base.TVMError: [10:51:37] src/codegen/codegen_c.cc:446: Cannot convert type fixed16_12 to C type
Stack trace returned 10 entries:
[bt] (0) /home/chz/heterocl/tvm/lib/libhcl.so(dmlc::StackTrace[abi:cxx11]()+0x53) [0x7f61530276b3]
[bt] (1) /home/chz/heterocl/tvm/lib/libhcl.so(dmlc::LogMessageFatal::~LogMessageFatal()+0x39) [0x7f6153027ef9]
[bt] (2) /home/chz/heterocl/tvm/lib/libhcl.so(TVM::codegen::CodeGenC::PrintType(Halide::Type, std::ostream&)+0x14b) [0x7f61532908db]
[bt] (3) /home/chz/heterocl/tvm/lib/libhcl.so(TVM::codegen::CodeGenC::AddFunction(TVM::LoweredFunc, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, Halide::Type>, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, Halide::Type> > > >)+0x532) [0x7f61532930d2]
[bt] (4) /home/chz/heterocl/tvm/lib/libhcl.so(TVM::codegen::CodeGenXOCLHost::AddFunction(TVM::LoweredFunc, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, Halide::Type>, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, Halide::Type> > > >)+0xa4) [0x7f615332cc74]
[bt] (5) /home/chz/heterocl/tvm/lib/libhcl.so(TVM::runtime::Module TVM::codegen::BuildSimModule<TVM::codegen::CodeGenXOCLHost, TVM::codegen::CodeGenVivadoHLS>(TVM::Array<TVM::LoweredFunc, void>, TVM::Array<Halide::Expr, void>, TVM::Array<Halide::Expr, void>)+0x480) [0x7f615326f0a0]
[bt] (6) /home/chz/heterocl/tvm/lib/libhcl.so(+0x46f82c) [0x7f615326782c]
[bt] (7) /home/chz/heterocl/tvm/lib/libhcl.so(+0x46fc64) [0x7f6153267c64]
[bt] (8) /home/chz/heterocl/tvm/lib/libhcl.so(TVMFuncCall+0x62) [0x7f61534e1a42]
[bt] (9) /home/chz/anaconda3/lib/python3.6/lib-dynload/../../libffi.so.6(ffi_call_unix64+0x4c) [0x7f61d0dc5ec0]
However, it works well for other targets like vivado_hls.
hecmay commented
Issue fixed. test cases added here: https://github.com/cornell-zhang/heterocl/blob/heteroflow/tests/issues/test_issue_260.py