cornell-zhang/heterocl

Support declarative programming APIs in HeteroCL module

Closed this issue · 1 comments

HeteroCL does not have complete support for declarative programming API in HeteroCl module function definitions. Using declarative APIs in HeteroCL module will result in errors in Storage Flatten IR pass (i.e. it failed to find the correct buffers for function argument tensors):

heterocl.tvm._ffi.base.TVMError: [19:50:35] src/pass/storage_flatten.cc:413: Check failed: buf_map_.count(key) Cannot find buffer of placeholder(k.A, 0x562ffd06c000) value=0

Stack trace returned 10 entries:
[bt] (0) heterocl/tvm/lib/libhcl.so(dmlc::StackTrace()+0x40) [0x7f346fcedb30]
[bt] (1) heterocl/tvm/lib/libhcl.so(dmlc::LogMessageFatal::~LogMessageFatal()+0x2b) [0x7f346fcee2bb]
[bt] (2) heterocl/tvm/lib/libhcl.so(TVM::ir::StorageFlattener::HandleBufferBindScope(Halide::Internal::AttrStmt const*)+0x3d7) [0x7f346fdf7cd7]
[bt] (3) heterocl/tvm/lib/libhcl.so(TVM::ir::StorageFlattener::Mutate_(Halide::Internal::AttrStmt const*, Halide::Internal::Stmt const&)+0x926) [0x7f346fdfc046]
[bt] (4) heterocl/tvm/lib/libhcl.so(+0x945bf0) [0x7f346fd93bf0]
[bt] (5) heterocl/tvm/lib/libhcl.so(std::_Function_handler<Halide::Internal::Stmt (TVM::NodeRef const&, Halide::Internal::Stmt const&, TVM::ir::IRMutator*), TVM::IRFunctor<Halide::Internal::Stmt (TVM::NodeRef const&, Halide::Internal::Stmt const&, TVM::ir::IRMutator*)>::set_dispatch<Halide::Internal::AttrStmt>(std::function<Halide::Internal::Stmt (Halide::Internal::AttrStmt const*, Halide::Internal::Stmt const&, TVM::ir::IRMutator*)>)::{lambda(TVM::NodeRef const&, Halide::Internal::Stmt const&, TVM::ir::IRMutator*)#1}>::_M_invoke(std::_Any_data const&, TVM::NodeRef const&, Halide::Internal::Stmt const&, TVM::ir::IRMutator*&&)+0x30) [0x7f346fd9e590]
[bt] (6) heterocl/tvm/lib/libhcl.so(TVM::IRFunctor<Halide::Internal::Stmt (TVM::NodeRef const&, Halide::Internal::Stmt const&, TVM::ir::IRMutator*)>::operator()(TVM::NodeRef const&, Halide::Internal::Stmt const&, TVM::ir::IRMutator*) const+0x123) [0x7f346fcee7f3]
[bt] (7) heterocl/tvm/lib/libhcl.so(TVM::ir::IRMutator::Mutate(Halide::Internal::Stmt)+0x49) [0x7f346fcee8e9]
[bt] (8) heterocl/tvm/lib/libhcl.so(TVM::ir::StorageFlattener::Mutate_(Halide::Internal::Realize const*, Halide::Internal::Stmt const&)+0x947) [0x7f346fdf9dd7]
[bt] (9) heterocl/tvm/lib/libhcl.so(+0x945e10) [0x7f346fd93e10]

A simple example to reproduce the error:

    hcl.init()
    A = hcl.placeholder((10,10))
    B = hcl.placeholder((10,10))

    def kernel(A, B):
       @hcl.def_([(10,10), (10,10)])
       def k(A, B):
           hcl.update(B, lambda y, x: A[y, x] + 1)
       k(A, B)

    s = hcl.create_schedule([A, B], kernel)
    f = hcl.build(s)

Should be solved by #166.