tvm
func_registry.h
Go to the documentation of this file.
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 
24 #ifndef TVM_RUNTIME_CRT_FUNC_REGISTRY_H_
25 #define TVM_RUNTIME_CRT_FUNC_REGISTRY_H_
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
33 
34 typedef uint16_t tvm_function_index_t;
35 
36 typedef uint16_t tvm_module_index_t;
37 
41 typedef struct TVMFuncRegistry {
47  const char* names;
48 
52 
63 tvm_crt_error_t TVMFuncRegistry_Lookup(const TVMFuncRegistry* reg, const char* name,
64  tvm_function_index_t* function_index);
65 
76 tvm_crt_error_t TVMFuncRegistry_GetByIndex(const TVMFuncRegistry* reg, tvm_function_index_t index,
77  TVMBackendPackedCFunc* out_func);
78 
82 typedef struct TVMMutableFuncRegistry {
84 
86  size_t max_functions;
88 
89 // Defined to work around compiler limitations.
90 #define TVM_AVERAGE_FUNCTION_NAME_STRLEN_BYTES 10
91 
97 static const size_t kTvmAverageFunctionNameStrlenBytes = TVM_AVERAGE_FUNCTION_NAME_STRLEN_BYTES;
98 
104 static const size_t kTvmAverageFuncEntrySizeBytes =
105  TVM_AVERAGE_FUNCTION_NAME_STRLEN_BYTES + 1 + sizeof(void*);
106 
117  size_t buffer_size_bytes);
118 
131  TVMBackendPackedCFunc func, int override);
132 
133 #ifdef __cplusplus
134 }
135 #endif
136 
137 #endif // TVM_RUNTIME_CRT_FUNC_REGISTRY_H_
TVMFuncRegistry registry
Definition: func_registry.h:83
#define TVM_AVERAGE_FUNCTION_NAME_STRLEN_BYTES
Definition: func_registry.h:90
const TVMBackendPackedCFunc * funcs
Function pointers, in the same order as their names in names.
Definition: func_registry.h:50
A data structure that facilitates function lookup by C-string name.
Definition: func_registry.h:41
struct TVMMutableFuncRegistry TVMMutableFuncRegistry
A TVMFuncRegistry that supports adding and changing the functions.
tvm_crt_error_t TVMFuncRegistry_Lookup(const TVMFuncRegistry *reg, const char *name, tvm_function_index_t *function_index)
Get packed function from registry by name.
tvm_crt_error_t TVMFuncRegistry_GetByIndex(const TVMFuncRegistry *reg, tvm_function_index_t index, TVMBackendPackedCFunc *out_func)
Fetch TVMBackendPackedCFunc given a function index.
Defines integral error codes returned by the CRT.
tvm_crt_error_t
Definition: error_codes.h:50
uint16_t tvm_function_index_t
Definition: func_registry.h:34
uint16_t tvm_module_index_t
Definition: func_registry.h:36
tvm_crt_error_t TVMMutableFuncRegistry_Set(TVMMutableFuncRegistry *reg, const char *name, TVMBackendPackedCFunc func, int override)
Add or set a function in the registry.
A TVMFuncRegistry that supports adding and changing the functions.
Definition: func_registry.h:82
size_t max_functions
maximum number of functions in this registry.
Definition: func_registry.h:86
TVM runtime backend API.
int(* TVMBackendPackedCFunc)(TVMValue *args, int *type_codes, int num_args, TVMValue *out_ret_value, int *out_ret_tcode, void *resource_handle)
Signature for backend functions exported as DLL.
Definition: c_backend_api.h:49
tvm_crt_error_t TVMMutableFuncRegistry_Create(TVMMutableFuncRegistry *reg, uint8_t *buffer, size_t buffer_size_bytes)
Create a new mutable function registry from a block of memory.
const char * names
Names of registered functions, concatenated together and separated by \0. An additional \0 is present...
Definition: func_registry.h:47
struct TVMFuncRegistry TVMFuncRegistry
A data structure that facilitates function lookup by C-string name.