@@ -161,7 +161,7 @@ TVM_DLL const char *TVMGetLastError(void);
161161 * \param option_vals Additional option values to pass
162162 * \param num_options Number of options to be passed into it.
163163 * \param out_code 1: success, 0: already initialized
164- * \return Whether the function is successful.
164+ * \return 0 when success, -1 when failure happens
165165 */
166166TVM_DLL int TVMDeviceInit (int dev_mask ,
167167 const char * * option_keys ,
@@ -188,7 +188,7 @@ TVM_DLL int TVMContextEnabled(TVMContext ctx,
188188 * \param dtype The array data type.
189189 * \param ctx The ctx this array sits on.
190190 * \param out The output handle.
191- * \return Whether the function is successful.
191+ * \return 0 when success, -1 when failure happens
192192 */
193193TVM_DLL int TVMArrayAlloc (const tvm_index_t * shape ,
194194 tvm_index_t ndim ,
@@ -198,6 +198,7 @@ TVM_DLL int TVMArrayAlloc(const tvm_index_t* shape,
198198/*!
199199 * \brief Free the TVM Array.
200200 * \param handle The array handle to be freed.
201+ * \return 0 when success, -1 when failure happens
201202 */
202203TVM_DLL int TVMArrayFree (TVMArrayHandle handle );
203204
@@ -206,6 +207,7 @@ TVM_DLL int TVMArrayFree(TVMArrayHandle handle);
206207 * \param from The array to be copied from.
207208 * \param to The target space.
208209 * \param stream The stream where the copy happens, can be NULL.
210+ * \return 0 when success, -1 when failure happens
209211 */
210212TVM_DLL int TVMArrayCopyFromTo (TVMArrayHandle from ,
211213 TVMArrayHandle to ,
@@ -214,13 +216,14 @@ TVM_DLL int TVMArrayCopyFromTo(TVMArrayHandle from,
214216 * \brief Wait until all computations on stream completes.
215217 * \param ctx The ctx to be synchronized.
216218 * \param stream The stream to be synchronized.
219+ * \return 0 when success, -1 when failure happens
217220 */
218221TVM_DLL int TVMSynchronize (TVMContext ctx , TVMStreamHandle stream );
219222
220223/*!
221224 * \brief Free the function when it is no longer needed.
222225 * \param func The function handle
223- * \return whether
226+ * \return 0 when success, -1 when failure happens
224227 */
225228TVM_DLL int TVMFuncFree (TVMFunctionHandle func );
226229
@@ -239,6 +242,57 @@ TVM_DLL int TVMFuncCall(TVMFunctionHandle func,
239242 TVMValue * args ,
240243 int * type_codes ,
241244 int num_args );
245+
246+ /*!
247+ * \brief C type of packed function.
248+ *
249+ * \param args The arguments
250+ * \param type_codes The type codes of the arguments
251+ * \param num_args Number of arguments.
252+ * \param resource_handle The handle additional resouce handle from fron-end.
253+ */
254+ typedef void (* TVMPackedCFunc )(
255+ TVMValue * args , int * type_codes , int num_args , void * resource_handle );
256+
257+ /*!
258+ * \brief C callback to free the resource handle in C packed function.
259+ * \param resource_handle The handle additional resouce handle from fron-end.
260+ */
261+ typedef void (* TVMPackedCFuncFinalizer )(void * resource_handle );
262+
263+ /*!
264+ * \brief Wrap a TVMPackedCFunc to become a FunctionHandle.
265+ *
266+ * The resource_handle will be managed by TVM API, until the function is no longer used.
267+ *
268+ * \param func The packed C function.
269+ * \param resource_handle The resource handle from front-end, can be NULL.
270+ * \param fin The finalizer on resource handle when the FunctionHandle get freed, can be NULL
271+ * \param out the result function handle.
272+ * \return 0 when success, -1 when failure happens
273+ */
274+ TVM_DLL int TVMFuncCreateFromCFunc (TVMPackedCFunc func ,
275+ void * resource_handle ,
276+ TVMPackedCFuncFinalizer fin ,
277+ TVMFunctionHandle * out );
278+
279+ /*!
280+ * \brief Register the function to runtime's global table.
281+ *
282+ * The registered function then can be pulled by the backend by the name.
283+ *
284+ * \param name The name of the function.
285+ * \param f The function to be registered.
286+ */
287+ TVM_DLL int TVMFuncRegisterGlobal (const char * name , TVMFunctionHandle f );
288+
289+ /*!
290+ * \brief Get a global function.
291+ *
292+ * \param name The name of the function.
293+ * \param out the result function pointer.
294+ */
295+ TVM_DLL int TVMFuncGetGlobal (const char * name , TVMFunctionHandle * out );
242296} // TVM_EXTERN_C
243297
244298#endif // TVM_RUNTIME_C_RUNTIME_API_H_
0 commit comments