Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
1f076ad
Generate AOT Metadata when targeting C runtime and packed API.
areusch Mar 9, 2022
92aad23
Also copy metadata.h and metadata_base.h to standalone_crt.
areusch Mar 9, 2022
8d5b266
add support for get_input_index as well as setting up get_input_info …
alanmacd Mar 10, 2022
5425e46
add support for tvm.aot_executor.create in C runtime
alanmacd Mar 17, 2022
6ddb5c2
changes in-progress to unit tests
alanmacd Mar 17, 2022
a7e05a5
Include get_c_metadata in emitted function list
areusch Apr 4, 2022
fd8fc0d
make CRT error codes generic for graph or AoT executor, fix AoT lib l…
alanmacd Apr 5, 2022
3bad0f9
add AoT executor creation and initializaion, as well as support for g…
alanmacd Apr 6, 2022
db82d35
add allocation of inputs, outputs, and pools; add get_input(), but sh…
alanmacd Apr 8, 2022
9786e6b
add support to test_aot_executor for get_input()
alanmacd Apr 8, 2022
75a2e28
fix numpy array shape so that get_input() works properly
alanmacd Apr 8, 2022
90f3152
implement run(), get_output(), get_num_inputs(), and get_num_outputs(…
alanmacd Apr 9, 2022
c8e9964
fix up some issues from rebase with main
alanmacd Apr 15, 2022
6f389bb
clean up logging and test_graph_executor()
alanmacd Apr 15, 2022
ae73fa6
Merge branch 'main' into host-driven-aot-executor-merge-main
alanmacd Apr 16, 2022
2c16c63
lint clean-up
alanmacd Apr 18, 2022
2f54090
more lint clean-up
alanmacd Apr 18, 2022
94294d3
fix i386 build errors
alanmacd Apr 20, 2022
4e2978f
Merge branch 'main' into host-driven-aot-executor
alanmacd Apr 20, 2022
f11400e
first set of changes addressing PR feedback
alanmacd Apr 21, 2022
0723196
more PR feedback: device pass-by-value, docstring entries, return var…
alanmacd Apr 21, 2022
a7c07e4
add mangling of get_c_metadata() name to avoid function name collisions
alanmacd Apr 26, 2022
797f9a0
only mangle get_c_metadata() when using C runtime
alanmacd Apr 27, 2022
57ad55c
add static specifier to all kTvmgenMetadata variables to avoid namesp…
alanmacd Apr 27, 2022
31014d0
Merge branch 'main' into host-driven-aot-executor
alanmacd Apr 28, 2022
ae79dc6
use TVM_IS_CPP_RUNTIME preprocessor define to deteremine whether or n…
alanmacd Apr 29, 2022
c40e6ad
add TVM_IS_CPP_RUNTIME define for cpptest
alanmacd Apr 29, 2022
2290e55
add TVM_IS_CPP_RUNTIME to apps/bundle_deploy
alanmacd Apr 29, 2022
fcdbb6d
add TVM_IS_CPP_RUNTIME web/Makefile
alanmacd Apr 29, 2022
1d9545b
update number of expected generated C files for AoT source files
alanmacd May 2, 2022
9b152f1
break out metadata data structures into separate metadata_types.h hea…
alanmacd May 3, 2022
8185074
remove TVM_IS_CPP_RUNTIME from web makefile
alanmacd May 3, 2022
8ff68f3
fix metadata.h include-order lint issue
alanmacd May 3, 2022
b68bd3a
correct error mask bits
alanmacd May 3, 2022
370c272
address PR feedback
alanmacd May 4, 2022
ab30758
Merge branch 'main' into host-driven-aot-executor
alanmacd May 4, 2022
d3dae0f
Merge branch 'main' into host-driven-aot-executor
alanmacd May 5, 2022
778ec49
Merge branch 'main' into host-driven-aot-executor
alanmacd May 6, 2022
49b4f15
trigger build
alanmacd May 7, 2022
f22f274
trigger build
alanmacd May 8, 2022
bdc02d1
trigger build
alanmacd May 8, 2022
7b744a4
trigger build
alanmacd May 9, 2022
e7f5080
add alternate name for test_graph_executor() too see if it runs in CI
alanmacd May 9, 2022
d566feb
fix lint
alanmacd May 9, 2022
98eed70
revert alternate test code
alanmacd May 9, 2022
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
3 changes: 3 additions & 0 deletions cmake/modules/StandaloneCrt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ if(USE_MICRO)
"3rdparty/dlpack/include *.h -> include"
"3rdparty/dmlc-core/include *.h -> include"
"include/tvm/runtime c_*_api.h -> include/tvm/runtime"
"include/tvm/runtime metadata*.h -> include/tvm/runtime"
"include/tvm/runtime/crt *.h -> include/tvm/runtime/crt"
"src/runtime/crt Makefile -> ."
"src/runtime/crt/include *.h -> include"
"src/runtime/crt/aot_executor *.c -> src/runtime/crt/aot_executor"
"src/runtime/crt/aot_executor_module *.c -> src/runtime/crt/aot_executor_module"
"src/runtime/crt/common *.c -> src/runtime/crt/common"
"src/runtime/crt/graph_executor *.c -> src/runtime/crt/graph_executor"
"src/runtime/crt/graph_executor_module *.c -> src/runtime/crt/graph_executor_module"
Expand Down
4 changes: 2 additions & 2 deletions include/tvm/runtime/c_runtime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ TVM_DLL int TVMCbArgToReturn(TVMValue* value, int* code);
* \param type_codes The type codes of the arguments
* \param num_args Number of arguments.
* \param ret The return value handle.
* \param resource_handle The handle additional resouce handle from fron-end.
* \param resource_handle The handle additional resouce handle from front-end.
* \return 0 if success, -1 if failure happens, set error via TVMAPISetLastError.
* \sa TVMCFuncSetReturn
*/
Expand All @@ -307,7 +307,7 @@ typedef int (*TVMPackedCFunc)(TVMValue* args, int* type_codes, int num_args, TVM

/*!
* \brief C callback to free the resource handle in C packed function.
* \param resource_handle The handle additional resouce handle from fron-end.
* \param resource_handle The handle additional resouce handle from front-end.
*/
typedef void (*TVMPackedCFuncFinalizer)(void* resource_handle);

Expand Down
74 changes: 74 additions & 0 deletions include/tvm/runtime/crt/aot_executor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/*!
* \file aot_executor.h
* \brief AoT Executor
*/
#ifndef TVM_RUNTIME_CRT_AOT_EXECUTOR_H_
#define TVM_RUNTIME_CRT_AOT_EXECUTOR_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <dlpack/dlpack.h>
#include <tvm/runtime/crt/internal/common/ndarray.h>
#include <tvm/runtime/metadata.h>

typedef struct TVMMetadata TVMMetadata;

typedef struct TVMAotExecutor {
/*! \brief The top-level metadata structure */
TVMMetadata* metadata;
/*! \brief The code module that contains both host and device code */
TVMModuleHandle module_handle;
/*! \brief The device type */
DLDevice device;
/*! \brief List of allocated arguments, input(s), output(s), and pool(s)*/
TVMNDArray* args;
int64_t num_args;
} TVMAotExecutor;

/*!
* \brief Allocate a new AotExecutor with TVMPlatformMemoryAllocate and initialize it.
*
* \param module_handle TVM Module that exposes the functions to call.
* \param devices runtime execution device.
* \param executor Pointer which receives a pointer to the newly-created instance.
* \return 0 if successful.
*/
int TVMAotExecutor_Create(TVMModuleHandle module_handle, const DLDevice* devices,
TVMAotExecutor** executor);

int TVMAotExecutor_Release(TVMAotExecutor* executor, const DLDevice device);

int TVMAotExecutor_GetNumInputs(TVMAotExecutor* executor);

int TVMAotExecutor_GetNumOutputs(TVMAotExecutor* executor);

int TVMAotExecutor_GetInputIndex(TVMAotExecutor* executor, const char* name);

int TVMAotExecutor_Run(TVMAotExecutor* executor);

#ifdef __cplusplus
} // extern "C"
#endif

#endif // TVM_RUNTIME_CRT_AOT_EXECUTOR_H_
42 changes: 42 additions & 0 deletions include/tvm/runtime/crt/aot_executor_module.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/*!
* \file graph_executor.h
* \brief Tiny AoT executor
*/
#ifndef TVM_RUNTIME_CRT_AOT_EXECUTOR_MODULE_H_
#define TVM_RUNTIME_CRT_AOT_EXECUTOR_MODULE_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <tvm/runtime/crt/error_codes.h>

/*!
* \brief Register the "tvm.aot_executor.create" constructor PackedFunc.
*/
tvm_crt_error_t TVMAotExecutorModule_Register();

#ifdef __cplusplus
} // extern "C"
#endif

#endif // TVM_RUNTIME_CRT_AOT_EXECUTOR_MODULE_H_
10 changes: 5 additions & 5 deletions include/tvm/runtime/crt/error_codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ typedef enum {
kTvmErrorCategorySession = 4,
kTvmErrorCategoryPlatform = 5,
kTvmErrorCategoryGenerated = 6,
kTvmErrorCategoryGraphExecutor = 7,
kTvmErrorCategoryExecutor = 7,
kTvmErrorCategoryFunctionCall = 8,
kTvmErrorCategoryTimeEvaluator = 9,
} tvm_crt_error_category_t;
Expand Down Expand Up @@ -84,10 +84,10 @@ typedef enum {
// Common error codes returned from generated functions.
kTvmErrorGeneratedInvalidStorageId = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryGenerated, 0),

// Graph executor
kTvmErrorGraphModuleAlreadyCreated = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryGraphExecutor, 0),
kTvmErrorGraphModuleBadContext = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryGraphExecutor, 1),
kTvmErrorGraphModuleNoSuchInput = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryGraphExecutor, 2),
// Graph or AoT executor
kTvmErrorExecutorModuleAlreadyCreated = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryExecutor, 0),
kTvmErrorExecutorModuleBadContext = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryExecutor, 1),
kTvmErrorExecutorModuleNoSuchInput = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryExecutor, 2),

// Function Calls - common problems encountered calling functions.
kTvmErrorFunctionCallNumArguments = DEFINE_TVM_CRT_ERROR(kTvmErrorCategoryFunctionCall, 0),
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/runtime/crt/graph_executor_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*!
* \file graph_executor.h
* \file graph_executor_module.h
* \brief Tiny graph executor that can run graph containing only tvm PackedFunc.
*/
#ifndef TVM_RUNTIME_CRT_GRAPH_EXECUTOR_MODULE_H_
Expand Down
6 changes: 3 additions & 3 deletions src/relay/backend/build_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,9 @@ class RelayBuildModule : public runtime::ModuleNode {
}

auto ext_mods = executor_codegen_->GetExternalModules();
ret_.mod =
tvm::codegen::CreateMetadataModule(ret_.params, ret_.mod, ext_mods, host_target, runtime_,
executor_codegen_->GetExecutorCodegenMetadata());
ret_.mod = tvm::codegen::CreateMetadataModule(ret_.params, ret_.mod, ext_mods, host_target,
runtime_, executor_,
executor_codegen_->GetExecutorCodegenMetadata());
// Remove external params which were stored in metadata module.
for (tvm::runtime::Module mod : ext_mods) {
auto pf_var = mod.GetFunction("get_const_vars");
Expand Down
7 changes: 4 additions & 3 deletions src/relay/backend/vm/compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1155,9 +1155,10 @@ void VMCompiler::Codegen() {
lib = tvm::TIRToRuntime(per_tvm_target_modules, config_->host_target);
}

lib = codegen::CreateMetadataModule(params_, lib, ext_mods, config_->host_target,
Runtime::Create("cpp"),
relay::backend::ExecutorCodegenMetadata());
lib =
codegen::CreateMetadataModule(params_, lib, ext_mods, config_->host_target,
Runtime::Create("cpp"), Executor::Create("graph"), // DNS HACK
relay::backend::ExecutorCodegenMetadata());
exec_->SetLib(lib);
}

Expand Down
2 changes: 2 additions & 0 deletions src/runtime/crt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ $(notdir $(1)): $${BUILD_DIR}/lib$(notdir $(1)).a
endef

LIBS = \
src/runtime/crt/aot_executor \
src/runtime/crt/aot_executor_module \
src/runtime/crt/common \
src/runtime/crt/graph_executor \
src/runtime/crt/graph_executor_module \
Expand Down
Loading