Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/tir/transforms/arg_binder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ void ArgBinder::BindDLTensor(const Buffer& buffer, const PrimExpr& device_type,
def_handle_dtype_.Set(v_shape, make_const(tvm_shape_type, 0));
init_nest_.emplace_back(
LetStmt(buf_shape->data, TVMArrayGet(DataType::Handle(), handle, builtin::kArrShape), nop));
init_nest_.emplace_back(DeclBuffer(buf_shape, nop));
for (size_t k = 0; k < buffer->shape.size(); ++k) {
if (buffer->dtype == DataType::Int(4) || buffer->dtype == DataType::UInt(4) ||
buffer->dtype == DataType::Int(1)) {
Expand All @@ -221,6 +222,7 @@ void ArgBinder::BindDLTensor(const Buffer& buffer, const PrimExpr& device_type,
def_handle_dtype_.Set(buf_strides->data, tir::TypeAnnotation(tvm_shape_type));
init_nest_.emplace_back(LetStmt(
buf_strides->data, TVMArrayGet(DataType::Handle(), handle, builtin::kArrStrides), nop));
init_nest_.emplace_back(DeclBuffer(buf_strides, nop));
PrimExpr v_strides_is_null = Call(DataType::Bool(1), builtin::isnullptr(), {buf_strides->data});
if (buffer->strides.size() == 0) {
// Assert the buffer is compact
Expand Down
11 changes: 8 additions & 3 deletions src/tir/transforms/make_packed_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,12 @@ PrimFunc MakePackedAPI(PrimFunc func) {
Integer device_type(target_device_type);
// seq_init gives sequence of initialization
// seq_check gives sequence of later checks after init
std::vector<Stmt> seq_init, seq_check;
std::vector<Stmt> seq_init, seq_check, arg_buffer_declarations;
std::unordered_map<const VarNode*, PrimExpr> vmap;
ArgBinder binder(&vmap);

seq_init.emplace_back(DeclBuffer(buf_packed_arg_type_ids, nop));

// ---------------------------
// local function definitions
// load i-th argument as type t
Expand Down Expand Up @@ -331,6 +334,7 @@ PrimFunc MakePackedAPI(PrimFunc func) {
for (const auto& kv : buffer_def) {
binder.BindDLTensor(kv.second, device_type, device_id, kv.first,
name_hint + "." + kv.first->name_hint);
arg_buffer_declarations.push_back(DeclBuffer(kv.second, nop));
}

func = WithAttrs(std::move(func), {{tvm::attr::kCallingConv, Integer(CallingConv::kCPackedFunc)},
Expand Down Expand Up @@ -360,8 +364,9 @@ PrimFunc MakePackedAPI(PrimFunc func) {
std::ostringstream num_args_error;
num_args_error << name_hint << ": num_args should be " << num_args;
std::vector<Stmt> arg_assert = {MakeAssertEQ(v_num_packed_args, num_args, num_args_error.str())};
body = MergeNest({arg_assert, seq_init, binder.init_nest(), seq_check, binder.asserts()}, body);

body = MergeNest({arg_assert, seq_init, binder.init_nest(), seq_check, binder.asserts(),
arg_buffer_declarations},
body);
func_ptr->body = body;
func_ptr->params = args;

Expand Down