|
| 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 include/tvm/runtime/crt/aot/tvm_backend.h |
| 22 | + * \brief Backend functions for the AOT executor |
| 23 | + * |
| 24 | + * These are not designed to user-facing and may change without warning |
| 25 | + */ |
| 26 | + |
| 27 | +#ifndef TVM_RUNTIME_CRT_AOT_TVM_BACKEND_H_ |
| 28 | +#define TVM_RUNTIME_CRT_AOT_TVM_BACKEND_H_ |
| 29 | + |
| 30 | +#include <stddef.h> |
| 31 | +#include <stdint.h> |
| 32 | + |
| 33 | +#include "tvm_error.h" |
| 34 | + |
| 35 | +#ifdef __cplusplus |
| 36 | +extern "C" { |
| 37 | +#endif |
| 38 | + |
| 39 | +/*! Memory alignment for allocator */ |
| 40 | +#ifndef TVM_RUNTIME_ALLOC_ALIGNMENT |
| 41 | +#define TVM_RUNTIME_ALLOC_ALIGNMENT 16 |
| 42 | +#endif |
| 43 | + |
| 44 | +/*! The AOT runtime links staticly */ |
| 45 | +#define TVM_DLL |
| 46 | + |
| 47 | +/*! |
| 48 | + * \brief Minimal TVMValue |
| 49 | + */ |
| 50 | +typedef union { |
| 51 | + int64_t v_int64; /** Currently used for parameter lookup */ |
| 52 | + void* v_handle; /** Pointer to other values */ |
| 53 | +} TVMValue; |
| 54 | + |
| 55 | +/*! |
| 56 | + * \brief Packed function signature definition |
| 57 | + */ |
| 58 | +typedef int32_t(tvm_function_t)(void* args, void* arg_type_ids, int32_t num_args, |
| 59 | + void* out_ret_value, void* out_ret_tcode, void* resource_handle); |
| 60 | + |
| 61 | +/*! |
| 62 | + * \brief Workspace memory structure |
| 63 | + */ |
| 64 | +typedef struct { |
| 65 | + uint8_t* next_alloc; /** Pointer to the next block of bytes to allocate */ |
| 66 | + uint8_t* workspace; /** Pointer to start of the workspace */ |
| 67 | + size_t workspace_size; /** Total number of bytes in the workspace */ |
| 68 | +} tvm_workspace_t; |
| 69 | + |
| 70 | +/** |
| 71 | + * \brief Backend function to allocate temporal workspace. |
| 72 | + * |
| 73 | + * \note The result allocated space is ensured to be aligned to TVM_RUNTIME_ALLOC_ALIGNMENT. |
| 74 | + * \note Currently matches CRT runtime signature but this will change in future to accommodate |
| 75 | + * memory planning |
| 76 | + * |
| 77 | + * \param device_type Ignored |
| 78 | + * \param device_id Ignored |
| 79 | + * \param nbytes The size of the space requested. |
| 80 | + * \param dtype_code_hint Ignored |
| 81 | + * \param dtype_bits_hint Ignored |
| 82 | + * \return void* NULL on error, a valid pointer on success |
| 83 | + */ |
| 84 | +void* TVMBackendAllocWorkspace(int device_type, int device_id, uint64_t nbytes, int dtype_code_hint, |
| 85 | + int dtype_bits_hint); |
| 86 | + |
| 87 | +/*! |
| 88 | + * \brief Backend function to free temporal workspace. |
| 89 | + * |
| 90 | + * \note Currently matches CRT runtime signature but this will change in future to accomodate memory |
| 91 | + * planning |
| 92 | + * |
| 93 | + * \param ptr The result allocated space pointer. |
| 94 | + * \param device_type Ignored |
| 95 | + * \param device_id Ignored |
| 96 | + * \return tvm_crt_error_t Containing any error statuses |
| 97 | + */ |
| 98 | +tvm_crt_error_t TVMBackendFreeWorkspace(int device_type, int device_id, void* ptr); |
| 99 | + |
| 100 | +#ifdef __cplusplus |
| 101 | +} // extern "C" |
| 102 | +#endif |
| 103 | + |
| 104 | +#endif // TVM_RUNTIME_CRT_AOT_TVM_BACKEND_H_ |
0 commit comments