Halide 22.0.0 Halide compiler and libraries

Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Functions | Variables
thread_pool_common.h File Reference

Go to the source code of this file.

## Classes
struct | Halide::Runtime::Internal::halide_cond_with_spinning
struct | Halide::Runtime::Internal::work
struct | Halide::Runtime::Internal::work_queue_t
struct | halide_semaphore_impl_t

## Namespaces
namespace | Halide
| This file defines the class FunctionDAG, which is our representation of a Halide pipeline, and contains methods to using Halide's bounds tools to query properties of it.
namespace | Halide::Runtime
namespace | Halide::Runtime::Internal

## Macros
#define | EXTENDED_DEBUG 0
#define | log_message(stuff) do { /*nothing*/ } while (0)
#define | print_job(job, indent, prefix) do { /*nothing*/ } while (0)
#define | dump_job_state() do { /*nothing*/ } while (0)

## Functions
ALWAYS_INLINE int | Halide::Runtime::Internal::clamp_num_threads (int threads)
WEAK int | Halide::Runtime::Internal::default_desired_num_threads ()
WEAK void | Halide::Runtime::Internal::worker_thread (void *)
WEAK void | Halide::Runtime::Internal::worker_thread_stall (work *owned_job)
WEAK void | Halide::Runtime::Internal::worker_thread_idle ()
WEAK void | Halide::Runtime::Internal::worker_thread_already_locked (work *owned_job)
WEAK void | Halide::Runtime::Internal::enqueue_work_already_locked (int num_jobs, work *jobs, work *task_parent)
WEAK int | halide_default_do_task (void *user_context, halide_task_t f, int idx, uint8_t *closure)
WEAK int | halide_default_do_loop_task (void *user_context, halide_loop_task_t f, int min, int extent, uint8_t *closure, void *task_parent)
WEAK int | halide_default_do_par_for (void *user_context, halide_task_t f, int min, int size, uint8_t *closure)
| The default versions of the parallel runtime functions.
WEAK int | halide_default_do_parallel_tasks (void *user_context, int num_tasks, struct halide_parallel_task_t *tasks, void *task_parent)
WEAK int | halide_set_num_threads (int n)
WEAK int | halide_get_num_threads ()
| Get or set the number of threads used by Halide's thread pool.
WEAK void | halide_shutdown_thread_pool ()
WEAK int | halide_default_semaphore_init (halide_semaphore_t *s, int n)
WEAK int | halide_default_semaphore_release (halide_semaphore_t *s, int n)
WEAK bool | halide_default_semaphore_try_acquire (halide_semaphore_t *s, int n)
WEAK halide_do_task_t | halide_set_custom_do_task (halide_do_task_t f)
WEAK halide_do_loop_task_t | halide_set_custom_do_loop_task (halide_do_loop_task_t f)
WEAK halide_do_par_for_t | halide_set_custom_do_par_for (halide_do_par_for_t f)
WEAK void | halide_set_custom_parallel_runtime (halide_do_par_for_t do_par_for, halide_do_task_t do_task, halide_do_loop_task_t do_loop_task, halide_do_parallel_tasks_t do_parallel_tasks, halide_semaphore_init_t semaphore_init, halide_semaphore_try_acquire_t semaphore_try_acquire, halide_semaphore_release_t semaphore_release)
WEAK int | halide_do_task (void *user_context, halide_task_t f, int idx, uint8_t *closure)
WEAK int | halide_do_par_for (void *user_context, halide_task_t f, int min, int size, uint8_t *closure)
WEAK int | halide_do_loop_task (void *user_context, halide_loop_task_t f, int min, int size, uint8_t *closure, void *task_parent)
WEAK int | halide_do_parallel_tasks (void *user_context, int num_tasks, struct halide_parallel_task_t *tasks, void *task_parent)
| Enqueue some number of the tasks described above and wait for them to complete.
WEAK int | halide_semaphore_init (struct halide_semaphore_t *sema, int count)
WEAK int | halide_semaphore_release (struct halide_semaphore_t *sema, int count)
WEAK bool | halide_semaphore_try_acquire (struct halide_semaphore_t *sema, int count)

## Variables
WEAK work_queue_t | Halide::Runtime::Internal::work_queue = {}
WEAK halide_do_task_t | Halide::Runtime::Internal::custom_do_task = halide_default_do_task
WEAK halide_do_loop_task_t | Halide::Runtime::Internal::custom_do_loop_task = halide_default_do_loop_task
WEAK halide_do_par_for_t | Halide::Runtime::Internal::custom_do_par_for = halide_default_do_par_for
WEAK halide_do_parallel_tasks_t | Halide::Runtime::Internal::custom_do_parallel_tasks = halide_default_do_parallel_tasks
WEAK halide_semaphore_init_t | Halide::Runtime::Internal::custom_semaphore_init = halide_default_semaphore_init
WEAK halide_semaphore_try_acquire_t | Halide::Runtime::Internal::custom_semaphore_try_acquire = halide_default_semaphore_try_acquire
WEAK halide_semaphore_release_t | Halide::Runtime::Internal::custom_semaphore_release = halide_default_semaphore_release

## Macro Definition Documentation

## ◆ EXTENDED_DEBUG

#define EXTENDED_DEBUG 0

Definition at line 1 of file thread_pool_common.h.

## ◆ log_message

#define log_message | ( |  | stuff | ) | do { /*nothing*/ } while (0)

Definition at line 24 of file thread_pool_common.h.

## ◆ print_job

#define print_job | ( |  | job,
|  |  | indent,
|  |  | prefix
| ) |  | do { /*nothing*/ } while (0)

Definition at line 248 of file thread_pool_common.h.

## ◆ dump_job_state

#define dump_job_state | ( |  | ) | do { /*nothing*/ } while (0)

Definition at line 249 of file thread_pool_common.h.

## Function Documentation

## ◆ halide_default_do_task()

WEAK int halide_default_do_task | ( | void * | user_context,
|  | halide_task_t | f,
|  | int | idx,
|  | uint8_t * | closure
| ) |  |

Definition at line 641 of file thread_pool_common.h.

References user_context.

## ◆ halide_default_do_loop_task()

WEAK int halide_default_do_loop_task | ( | void * | user_context,
|  | halide_loop_task_t | f,
|  | int | min,
|  | int | extent,
|  | uint8_t * | closure,
|  | void * | task_parent
| ) |  |

Definition at line 646 of file thread_pool_common.h.

References user_context.

## ◆ halide_default_do_par_for()

WEAK int halide_default_do_par_for | ( | void * | user_context,
|  | halide_task_t | f,
|  | int | min,
|  | int | size,
|  | uint8_t * | closure
| ) |  |

The default versions of the parallel runtime functions.

Definition at line 652 of file thread_pool_common.h.

References Halide::Runtime::Internal::work::active_workers, halide_parallel_task_t::closure, Halide::Runtime::Internal::enqueue_work_already_locked(), Halide::Runtime::Internal::work::exit_status, halide_parallel_task_t::extent, halide_parallel_task_t::fn, halide_error_code_success, halide_mutex_lock(), halide_mutex_unlock(), halide_parallel_task_t::min, halide_parallel_task_t::min_threads, Halide::Runtime::Internal::work_queue_t::mutex, halide_parallel_task_t::name, Halide::Runtime::Internal::work::next_semaphore, halide_parallel_task_t::num_semaphores, Halide::Runtime::Internal::work::owner_is_sleeping, Halide::Runtime::Internal::work::parent_job, halide_parallel_task_t::semaphores, halide_parallel_task_t::serial, Halide::Runtime::Internal::work::sibling_count, Halide::Runtime::Internal::work::siblings, Halide::Runtime::Internal::work::task, Halide::Runtime::Internal::work::task_fn, Halide::Runtime::Internal::work::user_context, user_context, Halide::Runtime::Internal::work_queue, and Halide::Runtime::Internal::worker_thread_already_locked().

## ◆ halide_default_do_parallel_tasks()

WEAK int halide_default_do_parallel_tasks | ( | void * | user_context,
|  | int | num_tasks,
|  | struct halide_parallel_task_t * | tasks,
|  | void * | task_parent
| ) |  |

Definition at line 684 of file thread_pool_common.h.

References Halide::Runtime::Internal::work::active_workers, Halide::Runtime::Internal::enqueue_work_already_locked(), Halide::Runtime::Internal::work::exit_status, halide_parallel_task_t::extent, halide_error_code_success, halide_mutex_lock(), halide_mutex_unlock(), Halide::Runtime::Internal::work_queue_t::mutex, Halide::Runtime::Internal::work::next_semaphore, Halide::Runtime::Internal::work::owner_is_sleeping, Halide::Runtime::Internal::work::parent_job, Halide::Runtime::Internal::work::task, Halide::Runtime::Internal::work::task_fn, Halide::Runtime::Internal::work::user_context, user_context, Halide::Runtime::Internal::work_queue, and Halide::Runtime::Internal::worker_thread_already_locked().

## ◆ halide_set_num_threads()

WEAK int halide_set_num_threads | ( | int | n | ) |

Definition at line 724 of file thread_pool_common.h.

References Halide::Runtime::Internal::clamp_num_threads(), Halide::Runtime::Internal::default_desired_num_threads(), Halide::Runtime::Internal::work_queue_t::desired_threads_working, halide_error(), halide_mutex_lock(), halide_mutex_unlock(), Halide::Runtime::Internal::work_queue_t::mutex, and Halide::Runtime::Internal::work_queue.

## ◆ halide_get_num_threads()

WEAK int halide_get_num_threads | ( |  | ) |

Get or set the number of threads used by Halide's thread pool.

Set returns the old number.

n < 0 : error condition n == 0 : use a reasonable system default (typically, number of cpus online). n == 1 : use exactly one thread; this will always enforce serial execution n > 1 : use a pool of exactly n threads.

(Note that this is only guaranteed when using the default implementations of halide_do_par_for(); custom implementations may completely ignore values passed to halide_set_num_threads().)

Definition at line 741 of file thread_pool_common.h.

References Halide::Runtime::Internal::work_queue_t::desired_threads_working, halide_mutex_lock(), halide_mutex_unlock(), Halide::Runtime::Internal::work_queue_t::mutex, and Halide::Runtime::Internal::work_queue.

## ◆ halide_shutdown_thread_pool()

WEAK void halide_shutdown_thread_pool | ( | void |  | ) |

Definition at line 748 of file thread_pool_common.h.

References Halide::Runtime::Internal::halide_cond_with_spinning::broadcast(), halide_join_thread(), halide_mutex_lock(), halide_mutex_unlock(), Halide::Runtime::Internal::work_queue_t::initialized, Halide::Runtime::Internal::work_queue_t::mutex, Halide::Runtime::Internal::work_queue_t::reset(), Halide::Runtime::Internal::work_queue_t::shutdown, Halide::Runtime::Internal::work_queue_t::threads, Halide::Runtime::Internal::work_queue_t::threads_created, Halide::Runtime::Internal::work_queue_t::wake_a_team, Halide::Runtime::Internal::work_queue_t::wake_b_team, Halide::Runtime::Internal::work_queue_t::wake_owners, and Halide::Runtime::Internal::work_queue.

## ◆ halide_default_semaphore_init()

WEAK int halide_default_semaphore_init | ( | halide_semaphore_t * | s,
|  | int | n
| ) |  |

Definition at line 774 of file thread_pool_common.h.

References halide_semaphore_impl_t::value.

## ◆ halide_default_semaphore_release()

WEAK int halide_default_semaphore_release | ( | halide_semaphore_t * | s,
|  | int | n
| ) |  |

Definition at line 780 of file thread_pool_common.h.

References Halide::Runtime::Internal::halide_cond_with_spinning::broadcast(), halide_mutex_lock(), halide_mutex_unlock(), Halide::Runtime::Internal::work_queue_t::mutex, halide_semaphore_impl_t::value, Halide::Runtime::Internal::work_queue_t::wake_a_team, Halide::Runtime::Internal::work_queue_t::wake_owners, and Halide::Runtime::Internal::work_queue.

## ◆ halide_default_semaphore_try_acquire()

WEAK bool halide_default_semaphore_try_acquire | ( | halide_semaphore_t * | s,
|  | int | n
| ) |  |

Definition at line 794 of file thread_pool_common.h.

References halide_semaphore_impl_t::value.

Referenced by Halide::Runtime::Internal::work::make_runnable().

## ◆ halide_set_custom_do_task()

WEAK halide_do_task_t halide_set_custom_do_task | ( | halide_do_task_t | f | ) |

Definition at line 810 of file thread_pool_common.h.

References Halide::Runtime::Internal::custom_do_task.

## ◆ halide_set_custom_do_loop_task()

WEAK halide_do_loop_task_t halide_set_custom_do_loop_task | ( | halide_do_loop_task_t | f | ) |

Definition at line 816 of file thread_pool_common.h.

References Halide::Runtime::Internal::custom_do_loop_task.

## ◆ halide_set_custom_do_par_for()

WEAK halide_do_par_for_t halide_set_custom_do_par_for | ( | halide_do_par_for_t | f | ) |

Definition at line 822 of file thread_pool_common.h.

References Halide::Runtime::Internal::custom_do_par_for.

## ◆ halide_set_custom_parallel_runtime()

WEAK void halide_set_custom_parallel_runtime | ( | halide_do_par_for_t | do_par_for,
|  | halide_do_task_t | do_task,
|  | halide_do_loop_task_t | do_loop_task,
|  | halide_do_parallel_tasks_t | do_parallel_tasks,
|  | halide_semaphore_init_t | semaphore_init,
|  | halide_semaphore_try_acquire_t | semaphore_try_acquire,
|  | halide_semaphore_release_t | semaphore_release
| ) |  |

Definition at line 828 of file thread_pool_common.h.

References Halide::Runtime::Internal::custom_do_loop_task, Halide::Runtime::Internal::custom_do_par_for, Halide::Runtime::Internal::custom_do_parallel_tasks, Halide::Runtime::Internal::custom_do_task, Halide::Runtime::Internal::custom_semaphore_init, Halide::Runtime::Internal::custom_semaphore_release, and Halide::Runtime::Internal::custom_semaphore_try_acquire.

## ◆ halide_do_task()

WEAK int halide_do_task | ( | void * | user_context,
|  | halide_task_t | f,
|  | int | idx,
|  | uint8_t * | closure
| ) |  |

Definition at line 846 of file thread_pool_common.h.

References Halide::Runtime::Internal::custom_do_task, and user_context.

Referenced by Halide::Runtime::Internal::worker_thread_already_locked().

## ◆ halide_do_par_for()

WEAK int halide_do_par_for | ( | void * | user_context,
|  | halide_task_t | f,
|  | int | min,
|  | int | size,
|  | uint8_t * | closure
| ) |  |

Definition at line 851 of file thread_pool_common.h.

References Halide::Runtime::Internal::custom_do_par_for, and user_context.

## ◆ halide_do_loop_task()

WEAK int halide_do_loop_task | ( | void * | user_context,
|  | halide_loop_task_t | f,
|  | int | min,
|  | int | size,
|  | uint8_t * | closure,
|  | void * | task_parent
| ) |  |

Definition at line 856 of file thread_pool_common.h.

References Halide::Runtime::Internal::custom_do_loop_task, and user_context.

Referenced by Halide::Runtime::Internal::worker_thread_already_locked().

## ◆ halide_do_parallel_tasks()

WEAK int halide_do_parallel_tasks | ( | void * | user_context,
|  | int | num_tasks,
|  | struct halide_parallel_task_t * | tasks,
|  | void * | task_parent
| ) |  |

Enqueue some number of the tasks described above and wait for them to complete.

While waiting, the calling threads assists with either the tasks enqueued, or other non-blocking tasks in the task system. Note that task_parent should be NULL for top-level calls and the pass through argument if this call is being made from another task.

Definition at line 861 of file thread_pool_common.h.

References Halide::Runtime::Internal::custom_do_parallel_tasks, and user_context.

## ◆ halide_semaphore_init()

WEAK int halide_semaphore_init | ( | struct halide_semaphore_t * | sema,
|  | int | count
| ) |  |

Definition at line 867 of file thread_pool_common.h.

References Halide::Runtime::Internal::custom_semaphore_init.

## ◆ halide_semaphore_release()

WEAK int halide_semaphore_release | ( | struct halide_semaphore_t * | sema,
|  | int | count
| ) |  |

Definition at line 871 of file thread_pool_common.h.

References Halide::Runtime::Internal::custom_semaphore_release.

## ◆ halide_semaphore_try_acquire()

WEAK bool halide_semaphore_try_acquire | ( | struct halide_semaphore_t * | sema,
|  | int | count
| ) |  |

Definition at line 875 of file thread_pool_common.h.

References Halide::Runtime::Internal::custom_semaphore_try_acquire.