Hi, im going to implement HashTableLookUp in tvm
As a external OP, String as new a type working progress has already been done, i add a object-type in dlpack and store tvm String ObjectRef in data, every thing works fine in HashBucketStrong, AsString which already implemented.
But HashTableLookUp has a little difference, I have to replace HashTable to a fake op, and prepare inputs and args as Attributes in the fake op
here is some code
HashTableOp gen in tensorflow_ops.py
def _hashtablefind():
def _impl(inputs, attr, params, mod):
dt = attr["T"].name
def make_expr(name):
value = attr[name]
np_value = tf.make_ndarray(value)
nd_value = tvm.runtime.array(
np_value.astype('|S') if np_value.dtype ==
np.object else np_value)
p_name = attr["_node_name"] + "/" + name
params[p_name] = nd_value
return _expr.var(p_name,
shape=params[p_name].shape,
dtype=nd_value.dtype)
key = make_expr("key") # store key in params
value = make_expr("value") # store value in params
default_value = make_expr("default_value")
return _op.hash_table_find(inputs[0], key, value, default_value, dt)
return _impl
Expr MakeHashTableFind(Expr x, Expr key, Expr value, Expr default_value, String dt) {
auto attrs = make_object<HashTableFindAttrs>();
attrs->dt = dt;
static const Op& op = Op::Get("hash_table_find");
return Call(op, {x, key, value, default_value}, Attrs(attrs), {});
}
def hash_table_find(x, key, value, dvalue, dt):
return te.extern(
x.shape, [x, key, value, dvalue],
lambda ins, outs: tvm.tir.call_packed("tvm.topi.hash_table_find", ins[
0], ins[1], ins[2], ins[3], outs[0], dt),
name="hash_table_find",
dtype=dt)
but got err in Lower, and i have no idea
3: tvm::tir::StmtFunctor<tvm::tir::Stmt (tvm::tir::Stmt const&)>::InitVTable()::{lambda(tvm::runtime::ObjectRef const&, tvm::tir::StmtFunctor<tvm::tir::Stmt (tvm::tir::Stmt const&)>*)#2}::_FUN(tvm::runtime::ObjectRef const&, tvm::tir::StmtFunctor<tvm::tir::Stmt (tvm::tir::Stmt const&)>*)
at /workspace/tvm/include/tvm/tir/stmt_functor.h:111
2: tvm::tir::StmtFunctor<tvm::tir::Stmt (tvm::tir::Stmt const&)>::InitVTable()::{lambda(tvm::runtime::ObjectRef const&, tvm::tir::StmtFunctor<tvm::tir::Stmt (tvm::tir::Stmt const&)>*)#2}::operator()(tvm::runtime::ObjectRef const&, tvm::tir::StmtFunctor<tvm::tir::Stmt (tvm::tir::Stmt const&)>*) const
at /workspace/tvm/include/tvm/tir/stmt_functor.h:111
1: tvm::tir::BufferShapeLegalize::VisitStmt_(tvm::tir::AttrStmtNode const*)
at /workspace/tvm/src/tir/transforms/storage_flatten.cc:222
0: tvm::tir::BufferShapeLegalize::HandleBufferBindScope(tvm::tir::AttrStmtNode const*)
at /workspace/tvm/src/tir/transforms/storage_flatten.cc:254
File "/workspace/tvm/src/tir/transforms/storage_flatten.cc", line 254
TVMError:
---------------------------------------------------------------
An error occurred during the execution of TVM.
For more information, please see: https://tvm.apache.org/docs/errors.html
---------------------------------------------------------------
Check failed: (it != buf_map_.end()) is false: attr::buffer_bind_scope target buffer(compile_engine_const, 0xc1a2f00) not in scope. op:[buffer(compile_engine_const, 0xc4b76e0), buffer(compile_engine_const, 0xc1a2f00)] buffer:buffer(compile_engine_const, 0xc4b76e0) buffer_map:buffer(placeholder, 0xb2db490),buffer(placeholder, 0xb6758b0),buffer(T_take, 0xbe40fc0),buffer(placeholder, 0xaeadb80),buffer(placeholder, 0xbe40e70),buffer(placeholder, 0xbe40bd0),buffer(hash_table_find, 0xc1a2e10),buffer(placeholder, 0xc0cd1c0),buffer(placeholder, 0xb8e7d60),
Any help will be appreciated