forked from apache/tvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[microTVM] Add support for host-driven AoT Executor (apache#11044)
* Generate AOT Metadata when targeting C runtime and packed API. * Also copy metadata.h and metadata_base.h to standalone_crt. * add support for get_input_index as well as setting up get_input_info as unsupported * add support for tvm.aot_executor.create in C runtime * changes in-progress to unit tests * Include get_c_metadata in emitted function list * make CRT error codes generic for graph or AoT executor, fix AoT lib link order * add AoT executor creation and initializaion, as well as support for get_input_index() * add allocation of inputs, outputs, and pools; add get_input(), but shape encoded in metadata appears to be incorrect; * add support to test_aot_executor for get_input() * fix numpy array shape so that get_input() works properly * implement run(), get_output(), get_num_inputs(), and get_num_outputs(); test_aot_executor() is now passing; * fix up some issues from rebase with main * clean up logging and test_graph_executor() * lint clean-up * more lint clean-up * fix i386 build errors * first set of changes addressing PR feedback * more PR feedback: device pass-by-value, docstring entries, return variable name * add mangling of get_c_metadata() name to avoid function name collisions * only mangle get_c_metadata() when using C runtime * add static specifier to all kTvmgenMetadata variables to avoid namespace collisions * use TVM_IS_CPP_RUNTIME preprocessor define to deteremine whether or not to include metadata.h c++ code * add TVM_IS_CPP_RUNTIME define for cpptest * add TVM_IS_CPP_RUNTIME to apps/bundle_deploy * add TVM_IS_CPP_RUNTIME web/Makefile * update number of expected generated C files for AoT source files * break out metadata data structures into separate metadata_types.h header to avoid c/c++ issues and remove the need for the TVM_IS_CPP_RUNTIME define * remove TVM_IS_CPP_RUNTIME from web makefile * fix metadata.h include-order lint issue * correct error mask bits * address PR feedback * trigger build * trigger build * trigger build * trigger build * add alternate name for test_graph_executor() too see if it runs in CI * fix lint * revert alternate test code Co-authored-by: Andrew Reusch <[email protected]>
- Loading branch information
1 parent
6603d1a
commit a382c68
Showing
23 changed files
with
905 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* 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_types.h> | ||
|
||
typedef struct TVMMetadata TVMMetadata; | ||
|
||
typedef struct TVMAotExecutor { | ||
/*! \brief The top-level metadata structure supplied by the generated code */ | ||
const TVMMetadata* metadata; | ||
/*! \brief The code module that contains the compiled model */ | ||
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 device Runtime execution device, only supports device type kDLCPU, index 0. | ||
* \param executor Pointer which receives a pointer to the newly-created instance. | ||
* \param module_name TVM Module name prefix, typically "default". | ||
* \return 0 if successful. | ||
*/ | ||
int TVMAotExecutor_Create(TVMModuleHandle module_handle, const DLDevice device, | ||
TVMAotExecutor** executor, const char* module_name); | ||
|
||
/*! | ||
* \brief Release the AoT executor created by TVMAotExecutor_Create(). | ||
* | ||
* \param executor Pointer to executor instance, created by TVMAotExecutor_Create(). | ||
* \param device Runtime execution device, only supports device type kDLCPU, index 0. | ||
* \return 0 if successful. | ||
*/ | ||
int TVMAotExecutor_Release(TVMAotExecutor* executor, const DLDevice device); | ||
|
||
/*! | ||
* \brief Return the number of inputs. | ||
* | ||
* \param executor Pointer to executor instance, created by TVMAotExecutor_Create(). | ||
* \return Number of inputs. | ||
*/ | ||
int TVMAotExecutor_GetNumInputs(TVMAotExecutor* executor); | ||
|
||
/*! | ||
* \brief Return the number of outputs. | ||
* | ||
* \param executor Pointer to executor instance, created by TVMAotExecutor_Create(). | ||
* \return Number of outputs. | ||
*/ | ||
int TVMAotExecutor_GetNumOutputs(TVMAotExecutor* executor); | ||
|
||
/*! | ||
* \brief Return the input index of the specified input name | ||
* | ||
* \param executor Pointer to executor instance, created by TVMAotExecutor_Create(). | ||
* \param name Input name for retrieving index. | ||
* \return Input index. | ||
*/ | ||
int TVMAotExecutor_GetInputIndex(TVMAotExecutor* executor, const char* name); | ||
|
||
/*! | ||
* \brief Run the generated program. | ||
* | ||
* \param executor Pointer to executor instance, created by TVMAotExecutor_Create(). | ||
* \return 0 if successful. | ||
*/ | ||
int TVMAotExecutor_Run(TVMAotExecutor* executor); | ||
|
||
#ifdef __cplusplus | ||
} // extern "C" | ||
#endif | ||
|
||
#endif // TVM_RUNTIME_CRT_AOT_EXECUTOR_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.