Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AOT] Introducing AOT in TVM #7785

Merged
merged 33 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Addressing comments - 11
Change-Id: Iad028144d7b394b2dd2fce41a35ca689d1680200
  • Loading branch information
Giuseppe Rossini committed May 4, 2021
commit 9a67b3f867d10c4a0a54eba8ebc126d9f49be4a0
25 changes: 0 additions & 25 deletions python/tvm/relay/build_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ def build(self, mod, target=None, target_host=None, params=None, executor="graph

Returns
-------
<<<<<<< HEAD
graph_json : str
The json string that can be accepted by graph executor.

Expand All @@ -125,10 +124,6 @@ def build(self, mod, target=None, target_host=None, params=None, executor="graph

params : dict
The parameters of the final graph.
=======
factory_module : tvm.relay.backend.executor_factory.ExecutorFactoryModule
The runtime factory for the TVM executor.
>>>>>>> f65012308... Addressing comments - 3
"""
target = _update_target(target)
target, target_host = Target.check_and_update_host_consist(
Expand Down Expand Up @@ -288,28 +283,8 @@ def build(ir_mod, target=None, target_host=None, params=None, mod_name="default"

Returns
-------
<<<<<<< HEAD
<<<<<<< HEAD
factory_module : tvm.relay.backend.executor_factory.ExecutorFactoryModule
The runtime factory for the TVM graph executor.
=======
internal_repr : str or tir.PrimFunc
The internal representation the executor uses to execute the
network. Can be a string representing the json graph (if we are
building for graph executor) or the PrimFunc representing the
AOT runner function
=======
executor_config : str
The internal configuration the executor uses to execute the
network.
>>>>>>> db667146e... addressing comments - 6

mod : tvm.Module
The module containing necessary libraries.

params : dict
The parameters of the final graph.
>>>>>>> f65012308... Addressing comments - 3
"""
# pylint: enable=line-too-long
# fmt: on
Expand Down
7 changes: 3 additions & 4 deletions src/relay/backend/aot_executor_codegen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
* \brief Graph runtime codegen
*/

#include <dmlc/any.h>
#include <tvm/ir/module.h>
#include <tvm/relay/expr_functor.h>
#include <tvm/runtime/device_api.h>
Expand Down Expand Up @@ -212,7 +211,7 @@ class AOTExecutorCodegen : public ExprVisitor {
*/
void CreateFuncCall(Call call, std::string func_name) {
tvm::Array<PrimExpr> args{tvm::tir::StringImm(func_name)};
std::vector<tir::Stmt> CreateFuncCall_stmts;
std::vector<tir::Stmt> create_func_call_stmts;

// Pack the inputs
for (Expr arg : call->args) {
Expand All @@ -228,9 +227,9 @@ class AOTExecutorCodegen : public ExprVisitor {
}

// Use tvm_call_packed to execute the function
CreateFuncCall_stmts.push_back(tir::Evaluate(
create_func_call_stmts.push_back(tir::Evaluate(
tvm::tir::Call(DataType::Int(32), tvm::tir::builtin::tvm_call_cpacked(), args)));
tir::Stmt body = tir::SeqStmt(CreateFuncCall_stmts);
tir::Stmt body = tir::SeqStmt(create_func_call_stmts);
stmts_.push_back(body);
}

Expand Down
35 changes: 18 additions & 17 deletions tests/crt/aot_memory_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ TEST(AOTMemory, Allocate) {
static uint8_t model_memory[96];
tvm_workspace_t tvm_runtime_workspace;

StackMemoryManager_Init(&tvm_runtime_workspace, model_memory, 96);
ASSERT_EQ(StackMemoryManager_Init(&tvm_runtime_workspace, model_memory, 96), kTvmErrorNoError);
void* block_one = NULL;
StackMemoryManager_Allocate(&tvm_runtime_workspace, 1, &block_one);
ASSERT_EQ(StackMemoryManager_Allocate(&tvm_runtime_workspace, 1, &block_one), kTvmErrorNoError);
ASSERT_EQ(block_one, &model_memory[0]);

void* block_two = NULL;
StackMemoryManager_Allocate(&tvm_runtime_workspace, 2, &block_two);
ASSERT_EQ(StackMemoryManager_Allocate(&tvm_runtime_workspace, 2, &block_two), kTvmErrorNoError);
ASSERT_EQ(block_two, &model_memory[16 + STACK_ALLOCATOR_TAG_SIZE_BYTES]);

void* two_blocks = NULL;
StackMemoryManager_Allocate(&tvm_runtime_workspace, 24, &two_blocks);
ASSERT_EQ(StackMemoryManager_Allocate(&tvm_runtime_workspace, 24, &two_blocks), kTvmErrorNoError);
ASSERT_EQ(two_blocks, &model_memory[32 + 2 * STACK_ALLOCATOR_TAG_SIZE_BYTES]);

void* block_three = NULL;
StackMemoryManager_Allocate(&tvm_runtime_workspace, 1, &block_three);
ASSERT_EQ(StackMemoryManager_Allocate(&tvm_runtime_workspace, 1, &block_three), kTvmErrorNoError);
ASSERT_EQ(block_three, &model_memory[64 + 3 * STACK_ALLOCATOR_TAG_SIZE_BYTES]);
}

Expand All @@ -51,24 +51,24 @@ TEST(AOTMemory, Allocate) {
TEST(AOTMemory, Free) {
static uint8_t model_memory[80];
tvm_workspace_t tvm_runtime_workspace;
StackMemoryManager_Init(&tvm_runtime_workspace, model_memory, 80);
ASSERT_EQ(StackMemoryManager_Init(&tvm_runtime_workspace, model_memory, 80), kTvmErrorNoError);

void* block_one = NULL;
StackMemoryManager_Allocate(&tvm_runtime_workspace, 1, &block_one);
ASSERT_EQ(StackMemoryManager_Allocate(&tvm_runtime_workspace, 1, &block_one), kTvmErrorNoError);
ASSERT_EQ(block_one, &model_memory[0]);

void* block_two = NULL;
StackMemoryManager_Allocate(&tvm_runtime_workspace, 1, &block_two);
ASSERT_EQ(StackMemoryManager_Allocate(&tvm_runtime_workspace, 1, &block_two), kTvmErrorNoError);
ASSERT_EQ(block_two, &model_memory[16 + STACK_ALLOCATOR_TAG_SIZE_BYTES]);
ASSERT_EQ(kTvmErrorNoError, StackMemoryManager_Free(&tvm_runtime_workspace, block_two));

void* two_blocks = NULL;
StackMemoryManager_Allocate(&tvm_runtime_workspace, 2, &two_blocks);
ASSERT_EQ(StackMemoryManager_Allocate(&tvm_runtime_workspace, 2, &two_blocks), kTvmErrorNoError);
ASSERT_EQ(two_blocks, &model_memory[16 + STACK_ALLOCATOR_TAG_SIZE_BYTES]);
ASSERT_EQ(kTvmErrorNoError, StackMemoryManager_Free(&tvm_runtime_workspace, two_blocks));

void* block_three = NULL;
StackMemoryManager_Allocate(&tvm_runtime_workspace, 1, &block_three);
ASSERT_EQ(StackMemoryManager_Allocate(&tvm_runtime_workspace, 1, &block_three), kTvmErrorNoError);
ASSERT_EQ(block_three, &model_memory[16 + STACK_ALLOCATOR_TAG_SIZE_BYTES]);
}

Expand All @@ -78,18 +78,19 @@ TEST(AOTMemory, Free) {
TEST(AOTMemory, OverAllocate) {
static uint8_t model_memory[72];
tvm_workspace_t tvm_runtime_workspace;
StackMemoryManager_Init(&tvm_runtime_workspace, model_memory, 80);
ASSERT_EQ(StackMemoryManager_Init(&tvm_runtime_workspace, model_memory, 80), kTvmErrorNoError);

void* block_one = NULL;
StackMemoryManager_Allocate(&tvm_runtime_workspace, 1, &block_one);
ASSERT_EQ(StackMemoryManager_Allocate(&tvm_runtime_workspace, 1, &block_one), kTvmErrorNoError);
ASSERT_EQ(block_one, &model_memory[0]);

void* block_two = NULL;
StackMemoryManager_Allocate(&tvm_runtime_workspace, 1, &block_two);
ASSERT_EQ(StackMemoryManager_Allocate(&tvm_runtime_workspace, 1, &block_two), kTvmErrorNoError);
ASSERT_EQ(block_two, &model_memory[16 + STACK_ALLOCATOR_TAG_SIZE_BYTES]);

void* two_blocks = NULL;
StackMemoryManager_Allocate(&tvm_runtime_workspace, 64, &two_blocks);
ASSERT_EQ(StackMemoryManager_Allocate(&tvm_runtime_workspace, 64, &two_blocks),
kTvmErrorPlatformNoMemory);
ASSERT_EQ(two_blocks, (void*)NULL);
}

Expand All @@ -99,14 +100,14 @@ TEST(AOTMemory, OverAllocate) {
TEST(AOTMemory, FreeOutOfOrder) {
static uint8_t model_memory[80];
tvm_workspace_t tvm_runtime_workspace;
StackMemoryManager_Init(&tvm_runtime_workspace, model_memory, 80);
ASSERT_EQ(StackMemoryManager_Init(&tvm_runtime_workspace, model_memory, 80), kTvmErrorNoError);

void* block_one = NULL;
StackMemoryManager_Allocate(&tvm_runtime_workspace, 1, &block_one);
ASSERT_EQ(StackMemoryManager_Allocate(&tvm_runtime_workspace, 1, &block_one), kTvmErrorNoError);
ASSERT_EQ(block_one, &model_memory[0]);

void* block_two = NULL;
StackMemoryManager_Allocate(&tvm_runtime_workspace, 1, &block_two);
ASSERT_EQ(StackMemoryManager_Allocate(&tvm_runtime_workspace, 1, &block_two), kTvmErrorNoError);
ASSERT_EQ(block_two, &model_memory[16 + STACK_ALLOCATOR_TAG_SIZE_BYTES]);

ASSERT_EXIT(StackMemoryManager_Free(&tvm_runtime_workspace, block_one),
Expand Down
4 changes: 2 additions & 2 deletions tests/python/relay/aot/aot_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ def create_main(test_name, input_list, output_list, output_path):
main_file.write("tvm_runtime_run(&network, inputs, outputs);")

for i in range(0, len(output_list)):
is_real_dtype = output_list[i].dtype == "float32"
is_float_dtype = output_list[i].dtype == "float32"
main_file.write("for (int i = 0; i<output_data%i_len; i++){\n" % i)
if is_real_dtype:
if is_float_dtype:
main_file.write(
'if (fabs(output_data%s[i]-expected_output_data%s[i]) > 0.001f){printf("ko\\n");return -1;}\n'
% (i, i)
Expand Down