tvm
c_backend_api.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 
28 #ifndef TVM_RUNTIME_C_BACKEND_API_H_
29 #define TVM_RUNTIME_C_BACKEND_API_H_
30 
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
49 typedef int (*TVMBackendPackedCFunc)(TVMValue* args, int* type_codes, int num_args,
50  TVMValue* out_ret_value, int* out_ret_tcode,
51  void* resource_handle);
52 
63 TVM_DLL int TVMBackendGetFuncFromEnv(void* mod_node, const char* func_name, TVMFunctionHandle* out);
64 
72 TVM_DLL int TVMBackendRegisterSystemLibSymbol(const char* name, void* ptr);
73 
88 TVM_DLL void* TVMBackendAllocWorkspace(int device_type, int device_id, uint64_t nbytes,
89  int dtype_code_hint, int dtype_bits_hint);
90 
101 TVM_DLL int TVMBackendFreeWorkspace(int device_type, int device_id, void* ptr);
102 
114 TVM_DLL int TVMBackendRegisterEnvCAPI(const char* name, void* ptr);
115 
119 typedef struct {
123  void* sync_handle;
125  int32_t num_task;
127 
134 typedef int (*FTVMParallelLambda)(int task_id, TVMParallelGroupEnv* penv, void* cdata);
135 
146 TVM_DLL int TVMBackendParallelLaunch(FTVMParallelLambda flambda, void* cdata, int num_task);
147 
154 TVM_DLL int TVMBackendParallelBarrier(int task_id, TVMParallelGroupEnv* penv);
155 
167 TVM_DLL int TVMBackendRunOnce(void** handle, int (*f)(void*), void* cdata, int nbytes);
168 
169 #ifdef __cplusplus
170 } // TVM_EXTERN_C
171 #endif
172 #endif // TVM_RUNTIME_C_BACKEND_API_H_
void * TVMBackendAllocWorkspace(int device_type, int device_id, uint64_t nbytes, int dtype_code_hint, int dtype_bits_hint)
Backend function to allocate temporal workspace.
int TVMBackendRegisterSystemLibSymbol(const char *name, void *ptr)
Backend function to register system-wide library symbol.
int TVMBackendRegisterEnvCAPI(const char *name, void *ptr)
Backend function to register execution environment(e.g. python) specific C APIs.
int TVMBackendParallelBarrier(int task_id, TVMParallelGroupEnv *penv)
BSP barrrier between parallel threads.
int TVMBackendFreeWorkspace(int device_type, int device_id, void *ptr)
Backend function to free temporal workspace.
int TVMBackendGetFuncFromEnv(void *mod_node, const char *func_name, TVMFunctionHandle *out)
Backend function for modules to get function from its environment mod_node (its imports and global fu...
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
int TVMBackendParallelLaunch(FTVMParallelLambda flambda, void *cdata, int num_task)
Backend function for running parallel jobs.
int(* FTVMParallelLambda)(int task_id, TVMParallelGroupEnv *penv, void *cdata)
The callback function to execute a parallel lambda.
Definition: c_backend_api.h:134
int TVMBackendRunOnce(void **handle, int(*f)(void *), void *cdata, int nbytes)
Simple static initialization function. Run f once and set handle to be not null. This function is mai...
void * TVMFunctionHandle
Handle to packed function handle.
Definition: c_runtime_api.h:229
constexpr const char * device_id
The allocation device for global malloc in host.
Definition: stmt.h:1416
constexpr const char * device_type
The device type.
Definition: stmt.h:1418
Environment for TVM parallel task.
Definition: c_backend_api.h:119
void * sync_handle
Auxiliary used for synchronization.
Definition: c_backend_api.h:123
int32_t num_task
total amount of task
Definition: c_backend_api.h:125
Union type of values being passed through API and function calls.
Definition: c_runtime_api.h:208