|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +/*! |
| 21 | + * \file aot_executor.h |
| 22 | + * \brief AoT Executor |
| 23 | + */ |
| 24 | +#ifndef TVM_RUNTIME_CRT_AOT_EXECUTOR_H_ |
| 25 | +#define TVM_RUNTIME_CRT_AOT_EXECUTOR_H_ |
| 26 | + |
| 27 | +#ifdef __cplusplus |
| 28 | +extern "C" { |
| 29 | +#endif |
| 30 | + |
| 31 | +#include <dlpack/dlpack.h> |
| 32 | +#include <tvm/runtime/crt/internal/common/ndarray.h> |
| 33 | +#include <tvm/runtime/metadata_types.h> |
| 34 | + |
| 35 | +typedef struct TVMMetadata TVMMetadata; |
| 36 | + |
| 37 | +typedef struct TVMAotExecutor { |
| 38 | + /*! \brief The top-level metadata structure supplied by the generated code */ |
| 39 | + const TVMMetadata* metadata; |
| 40 | + /*! \brief The code module that contains the compiled model */ |
| 41 | + TVMModuleHandle module_handle; |
| 42 | + /*! \brief The device type */ |
| 43 | + DLDevice device; |
| 44 | + /*! \brief List of allocated arguments, input(s), output(s), and pool(s)*/ |
| 45 | + TVMNDArray* args; |
| 46 | + int64_t num_args; |
| 47 | +} TVMAotExecutor; |
| 48 | + |
| 49 | +/*! |
| 50 | + * \brief Allocate a new AotExecutor with TVMPlatformMemoryAllocate and initialize it. |
| 51 | + * |
| 52 | + * \param module_handle TVM Module that exposes the functions to call. |
| 53 | + * \param device Runtime execution device, only supports device type kDLCPU, index 0. |
| 54 | + * \param executor Pointer which receives a pointer to the newly-created instance. |
| 55 | + * \param module_name TVM Module name prefix, typically "default". |
| 56 | + * \return 0 if successful. |
| 57 | + */ |
| 58 | +int TVMAotExecutor_Create(TVMModuleHandle module_handle, const DLDevice device, |
| 59 | + TVMAotExecutor** executor, const char* module_name); |
| 60 | + |
| 61 | +/*! |
| 62 | + * \brief Release the AoT executor created by TVMAotExecutor_Create(). |
| 63 | + * |
| 64 | + * \param executor Pointer to executor instance, created by TVMAotExecutor_Create(). |
| 65 | + * \param device Runtime execution device, only supports device type kDLCPU, index 0. |
| 66 | + * \return 0 if successful. |
| 67 | + */ |
| 68 | +int TVMAotExecutor_Release(TVMAotExecutor* executor, const DLDevice device); |
| 69 | + |
| 70 | +/*! |
| 71 | + * \brief Return the number of inputs. |
| 72 | + * |
| 73 | + * \param executor Pointer to executor instance, created by TVMAotExecutor_Create(). |
| 74 | + * \return Number of inputs. |
| 75 | + */ |
| 76 | +int TVMAotExecutor_GetNumInputs(TVMAotExecutor* executor); |
| 77 | + |
| 78 | +/*! |
| 79 | + * \brief Return the number of outputs. |
| 80 | + * |
| 81 | + * \param executor Pointer to executor instance, created by TVMAotExecutor_Create(). |
| 82 | + * \return Number of outputs. |
| 83 | + */ |
| 84 | +int TVMAotExecutor_GetNumOutputs(TVMAotExecutor* executor); |
| 85 | + |
| 86 | +/*! |
| 87 | + * \brief Return the input index of the specified input name |
| 88 | + * |
| 89 | + * \param executor Pointer to executor instance, created by TVMAotExecutor_Create(). |
| 90 | + * \param name Input name for retrieving index. |
| 91 | + * \return Input index. |
| 92 | + */ |
| 93 | +int TVMAotExecutor_GetInputIndex(TVMAotExecutor* executor, const char* name); |
| 94 | + |
| 95 | +/*! |
| 96 | + * \brief Run the generated program. |
| 97 | + * |
| 98 | + * \param executor Pointer to executor instance, created by TVMAotExecutor_Create(). |
| 99 | + * \return 0 if successful. |
| 100 | + */ |
| 101 | +int TVMAotExecutor_Run(TVMAotExecutor* executor); |
| 102 | + |
| 103 | +#ifdef __cplusplus |
| 104 | +} // extern "C" |
| 105 | +#endif |
| 106 | + |
| 107 | +#endif // TVM_RUNTIME_CRT_AOT_EXECUTOR_H_ |
0 commit comments