tvm
packed_func.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_PACKED_FUNC_H_
25 #define TVM_RUNTIME_CRT_PACKED_FUNC_H_
26 
27 #include <assert.h>
28 #include <stdio.h>
29 #include <stdlib.h>
31 #include <tvm/runtime/crt/module.h>
33 
34 #include "crt_config.h"
35 
36 DLDataType String2DLDataType(const char* s);
37 
38 typedef struct TVMArgs {
39  TVMValue values[TVM_CRT_MAX_ARGS];
40  int tcodes[TVM_CRT_MAX_ARGS]; /* Data type should be identical to type_codes in TVMPackedCFunc */
41  uint32_t values_count;
43 
44 TVMArgs TVMArgs_Create(TVMValue* values, uint32_t* tcodes, uint32_t values_count);
45 
46 typedef struct TVMPackedFunc {
47  char name[200];
51  int (*Call)(struct TVMPackedFunc* pf);
52  void (*SetArgs)(struct TVMPackedFunc* pf, const struct TVMArgs* args);
54 
55 int TVMPackedFunc_InitGlobalFunc(TVMPackedFunc* pf, const char* name, const TVMArgs* args);
57  const TVMArgs* args);
58 
60 
62 
63 inline TVMModuleHandle TVMArgs_AsModuleHandle(const TVMArgs* args, size_t index) {
64  if (index >= args->values_count) {
66  }
67 
68  if (args->tcodes[index] != kTVMModuleHandle) {
70  }
71 
72  return args->values[index].v_handle;
73 }
74 
75 extern TVMPackedFunc* g_fexecs;
76 extern uint32_t g_fexecs_count;
77 
78 #endif // TVM_RUNTIME_CRT_PACKED_FUNC_H_
@ kTVMModuleHandle
Definition: c_runtime_api.h:183
void * TVMModuleHandle
Handle to TVM runtime modules.
Definition: c_runtime_api.h:227
void * TVMFunctionHandle
Handle to packed function handle.
Definition: c_runtime_api.h:229
DLDataType String2DLDataType(const char *s)
struct TVMPackedFunc TVMPackedFunc
int TVMPackedFunc_InitModuleFunc(TVMPackedFunc *pf, TVMModuleHandle module, const char *name, const TVMArgs *args)
struct TVMArgs TVMArgs
TVMPackedFunc * g_fexecs
uint32_t g_fexecs_count
TVMModuleHandle TVMArgs_AsModuleHandle(const TVMArgs *args, size_t index)
Definition: packed_func.h:63
int TVMPackedFunc_Call(TVMPackedFunc *pf)
int TVMPackedFunc_InitGlobalFunc(TVMPackedFunc *pf, const char *name, const TVMArgs *args)
void TVMPackedFunc_SetArgs(TVMPackedFunc *pf, const TVMArgs *args)
TVMArgs TVMArgs_Create(TVMValue *values, uint32_t *tcodes, uint32_t values_count)
tvm_crt_error_t
Definition: error_codes.h:50
The virtual memory manager for micro-controllers.
void TVMPlatformAbort(tvm_crt_error_t code)
Called when an internal error occurs and execution cannot continue.
Runtime container of the functions.
Definition: packed_func.h:38
int tcodes[TVM_CRT_MAX_ARGS]
Definition: packed_func.h:40
TVMValue values[TVM_CRT_MAX_ARGS]
Definition: packed_func.h:39
uint32_t values_count
Definition: packed_func.h:41
Definition: packed_func.h:46
void(* SetArgs)(struct TVMPackedFunc *pf, const struct TVMArgs *args)
Definition: packed_func.h:52
char name[200]
Definition: packed_func.h:47
TVMFunctionHandle fexec
Definition: packed_func.h:48
int(* Call)(struct TVMPackedFunc *pf)
Definition: packed_func.h:51
TVMArgs ret_value
Definition: packed_func.h:50
TVMArgs args
Definition: packed_func.h:49
Union type of values being passed through API and function calls.
Definition: c_runtime_api.h:208
void * v_handle
Definition: c_runtime_api.h:211