Halide
Halide::JITHandlers Struct Reference

A set of custom overrides of runtime functions. More...

#include <JITModule.h>

Public Attributes

void(* custom_print )(JITUserContext *, const char *)
 Set the function called to print messages from the runtime. More...
 
void *(* custom_malloc )(JITUserContext *, size_t)
 A custom malloc and free for halide to use. More...
 
void(* custom_free )(JITUserContext *, void *)
 
int(* custom_do_task )(JITUserContext *, int(*)(JITUserContext *, int, uint8_t *), int, uint8_t *)
 A custom task handler to be called by the parallel for loop. More...
 
int(* custom_do_par_for )(JITUserContext *, int(*)(JITUserContext *, int, uint8_t *), int, int, uint8_t *)
 A custom parallel for loop launcher. More...
 
void(* custom_error )(JITUserContext *, const char *)
 The error handler function that be called in the case of runtime errors during halide pipelines. More...
 
int32_t(* custom_trace )(JITUserContext *, const halide_trace_event_t *)
 A custom routine to call when tracing is enabled. More...
 
void *(* custom_get_symbol )(const char *name)
 A method to use for Halide to resolve symbol names dynamically in the calling process or library from within the Halide runtime. More...
 
void *(* custom_load_library )(const char *name)
 A method to use for Halide to dynamically load libraries from within the runtime. More...
 
void *(* custom_get_library_symbol )(void *lib, const char *name)
 A method to use for Halide to dynamically find a symbol within an opened library. More...
 
int32_t(* custom_cuda_acquire_context )(JITUserContext *user_context, void **cuda_context_ptr, bool create)
 A custom method for the Halide runtime acquire a cuda context. More...
 
int32_t(* custom_cuda_release_context )(JITUserContext *user_context)
 The Halide runtime calls this when it is done with a cuda context. More...
 
int32_t(* custom_cuda_get_stream )(JITUserContext *user_context, void *cuda_context, void **stream_ptr)
 A custom method for the Halide runtime to acquire a cuda stream to use. More...
 

Detailed Description

A set of custom overrides of runtime functions.

These only apply when JIT-compiling code. If you are doing AOT compilation, see HalideRuntime.h for instructions on how to replace runtime functions.

Definition at line 35 of file JITModule.h.

Member Data Documentation

◆ custom_print

void(* Halide::JITHandlers::custom_print) (JITUserContext *, const char *)
inline

Set the function called to print messages from the runtime.

Definition at line 37 of file JITModule.h.

◆ custom_malloc

void*(* Halide::JITHandlers::custom_malloc) (JITUserContext *, size_t)
inline

A custom malloc and free for halide to use.

Malloc should return 32-byte aligned chunks of memory, and it should be safe for Halide to read slightly out of bounds (up to 8 bytes before the start or beyond the end).

Definition at line 44 of file JITModule.h.

◆ custom_free

void(* Halide::JITHandlers::custom_free) (JITUserContext *, void *)
inline

Definition at line 45 of file JITModule.h.

◆ custom_do_task

int(* Halide::JITHandlers::custom_do_task) (JITUserContext *, int(*)(JITUserContext *, int, uint8_t *), int, uint8_t *)
inline

A custom task handler to be called by the parallel for loop.

It is useful to set this if you want to do some additional bookkeeping at the granularity of parallel tasks. The default implementation does this:

extern "C" int halide_do_task(JITUserContext *user_context,
int (*f)(void *, int, uint8_t *),
int idx, uint8_t *state) {
return f(user_context, idx, state);
}

If you're trying to use a custom parallel runtime, you probably don't want to call this. See instead custom_do_par_for.

Definition at line 63 of file JITModule.h.

◆ custom_do_par_for

int(* Halide::JITHandlers::custom_do_par_for) (JITUserContext *, int(*)(JITUserContext *, int, uint8_t *), int, int, uint8_t *)
inline

A custom parallel for loop launcher.

Useful if your app already manages a thread pool. The default implementation is equivalent to this:

extern "C" int halide_do_par_for(JITUserContext *user_context,
int (*f)(void *, int, uint8_t *),
int min, int extent, uint8_t *state) {
int exit_status = 0;
parallel for (int idx = min; idx < min+extent; idx++) {
int job_status = halide_do_task(user_context, f, idx, state);
if (job_status) exit_status = job_status;
}
return exit_status;
}

However, notwithstanding the above example code, if one task fails, we may skip over other tasks, and if two tasks return different error codes, we may select one arbitrarily to return.

Definition at line 85 of file JITModule.h.

◆ custom_error

void(* Halide::JITHandlers::custom_error) (JITUserContext *, const char *)
inline

The error handler function that be called in the case of runtime errors during halide pipelines.

Definition at line 89 of file JITModule.h.

◆ custom_trace

int32_t(* Halide::JITHandlers::custom_trace) (JITUserContext *, const halide_trace_event_t *)
inline

A custom routine to call when tracing is enabled.

Call this on the output Func of your pipeline. This then sets custom routines for the entire pipeline, not just calls to this Func.

Definition at line 95 of file JITModule.h.

◆ custom_get_symbol

void*(* Halide::JITHandlers::custom_get_symbol) (const char *name)
inline

A method to use for Halide to resolve symbol names dynamically in the calling process or library from within the Halide runtime.

Equivalent to dlsym with a null first argument.

Definition at line 100 of file JITModule.h.

◆ custom_load_library

void*(* Halide::JITHandlers::custom_load_library) (const char *name)
inline

A method to use for Halide to dynamically load libraries from within the runtime.

Equivalent to dlopen. Returns a handle to the opened library.

Definition at line 105 of file JITModule.h.

◆ custom_get_library_symbol

void*(* Halide::JITHandlers::custom_get_library_symbol) (void *lib, const char *name)
inline

A method to use for Halide to dynamically find a symbol within an opened library.

Equivalent to dlsym. Takes a handle returned by custom_load_library as the first argument.

Definition at line 110 of file JITModule.h.

◆ custom_cuda_acquire_context

int32_t(* Halide::JITHandlers::custom_cuda_acquire_context) (JITUserContext *user_context, void **cuda_context_ptr, bool create)
inline

A custom method for the Halide runtime acquire a cuda context.

The cuda context is treated as a void * to avoid a dependence on the cuda headers. If the create argument is set to true, a context should be created if one does not already exist.

Definition at line 117 of file JITModule.h.

◆ custom_cuda_release_context

int32_t(* Halide::JITHandlers::custom_cuda_release_context) (JITUserContext *user_context)
inline

The Halide runtime calls this when it is done with a cuda context.

The default implementation does nothing.

Definition at line 121 of file JITModule.h.

◆ custom_cuda_get_stream

int32_t(* Halide::JITHandlers::custom_cuda_get_stream) (JITUserContext *user_context, void *cuda_context, void **stream_ptr)
inline

A custom method for the Halide runtime to acquire a cuda stream to use.

The cuda context and stream are both modelled as a void *, to avoid a dependence on the cuda headers.

Definition at line 126 of file JITModule.h.


The documentation for this struct was generated from the following file:
uint8_t
unsigned __INT8_TYPE__ uint8_t
Definition: runtime_internal.h:29
Halide::min
Expr min(const FuncRef &a, const FuncRef &b)
Explicit overloads of min and max for FuncRef.
Definition: Func.h:584
halide_do_par_for
int halide_do_par_for(void *user_context, halide_task_t task, int min, int size, uint8_t *closure)
Definition: thread_pool_common.h:799
halide_do_task
int halide_do_task(void *user_context, halide_task_t f, int idx, uint8_t *closure)
Definition: thread_pool_common.h:794