18#ifndef __SCHED_CONTEXT_H__
19#define __SCHED_CONTEXT_H__
24#include <starpu_sched_ctx.h>
25#include <starpu_sched_ctx_hypervisor.h>
26#include <starpu_scheduler.h>
27#include <common/config.h>
35#ifdef STARPU_HAVE_HWLOC
39#pragma GCC visibility push(hidden)
45#define STARPU_GLOBAL_SCHED_CTX 0
46#define STARPU_NMAXSMS 13
86 struct starpu_task_list empty_ctx_tasks;
89 struct starpu_task_list waiting_tasks;
114 int min_priority_is_set;
115 int max_priority_is_set;
118#ifdef STARPU_HAVE_HWLOC
122#ifdef STARPU_USE_SC_HYPERVISOR
157 int sub_ctxs[STARPU_NMAXWORKERS];
167 starpu_pthread_rwlock_t rwlock;
168 starpu_pthread_t lock_write_owner;
175 int nworkers_to_notify;
176 int *workerids_to_notify;
177 int nworkers_to_change;
178 int *workerids_to_change;
188 int min_prio_set,
int min_prio,
189 int max_prio_set,
int max_prio,
unsigned awake_workers,
void (*sched_policy_callback)(
unsigned),
void *
user_data,
190 int nsub_ctxs,
int *sub_ctxs,
int nsms);
205void _starpu_increment_nsubmitted_tasks_of_sched_ctx(
unsigned sched_ctx_id);
206int _starpu_get_nsubmitted_tasks_of_sched_ctx(
unsigned sched_ctx_id);
207int _starpu_check_nsubmitted_tasks_of_sched_ctx(
unsigned sched_ctx_id);
209void _starpu_decrement_nready_tasks_of_sched_ctx(
unsigned sched_ctx_id,
double ready_flops);
210unsigned _starpu_increment_nready_tasks_of_sched_ctx(
unsigned sched_ctx_id,
double ready_flops,
struct starpu_task *task);
211int _starpu_wait_for_no_ready_of_sched_ctx(
unsigned sched_ctx_id);
239unsigned _starpu_sched_ctx_allow_hypervisor(
unsigned sched_ctx_id);
241struct starpu_perfmodel_arch * _starpu_sched_ctx_get_perf_archtype(
unsigned sched_ctx);
242#ifdef STARPU_USE_SC_HYPERVISOR
248void starpu_sched_ctx_add_combined_workers(
int *combined_workers_to_add,
unsigned n_combined_workers_to_add,
unsigned sched_ctx_id);
253#define _starpu_sched_ctx_get_sched_ctx_for_worker_and_job(w,j) \
254 (_starpu_get_nsched_ctxs() <= 1 ? _starpu_get_sched_ctx_struct(0) : __starpu_sched_ctx_get_sched_ctx_for_worker_and_job((w),(j)))
256static inline struct _starpu_sched_ctx *_starpu_get_sched_ctx_struct(
unsigned id);
258static inline int _starpu_sched_ctx_check_write_locked(
unsigned sched_ctx_id)
260 struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
261 return starpu_pthread_equal(sched_ctx->lock_write_owner, starpu_pthread_self());
263#define STARPU_SCHED_CTX_CHECK_LOCK(sched_ctx_id) STARPU_ASSERT(_starpu_sched_ctx_check_write_locked((sched_ctx_id)))
265static inline void _starpu_sched_ctx_lock_write(
unsigned sched_ctx_id)
267 STARPU_ASSERT(sched_ctx_id <= STARPU_NMAX_SCHED_CTXS);
268 struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
269 STARPU_HG_DISABLE_CHECKING(sched_ctx->lock_write_owner);
270 STARPU_ASSERT(!starpu_pthread_equal(sched_ctx->lock_write_owner, starpu_pthread_self()));
271 STARPU_HG_ENABLE_CHECKING(sched_ctx->lock_write_owner);
272 STARPU_PTHREAD_RWLOCK_WRLOCK(&sched_ctx->rwlock);
273 sched_ctx->lock_write_owner = starpu_pthread_self();
276static inline void _starpu_sched_ctx_unlock_write(
unsigned sched_ctx_id)
278 STARPU_ASSERT(sched_ctx_id <= STARPU_NMAX_SCHED_CTXS);
279 struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
280 STARPU_HG_DISABLE_CHECKING(sched_ctx->lock_write_owner);
281 STARPU_ASSERT(starpu_pthread_equal(sched_ctx->lock_write_owner, starpu_pthread_self()));
282 memset(&sched_ctx->lock_write_owner, 0,
sizeof(sched_ctx->lock_write_owner));
283 STARPU_HG_ENABLE_CHECKING(sched_ctx->lock_write_owner);
284 STARPU_PTHREAD_RWLOCK_UNLOCK(&sched_ctx->rwlock);
287static inline void _starpu_sched_ctx_lock_read(
unsigned sched_ctx_id)
289 STARPU_ASSERT(sched_ctx_id <= STARPU_NMAX_SCHED_CTXS);
290 struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
291 STARPU_HG_DISABLE_CHECKING(sched_ctx->lock_write_owner);
292 STARPU_ASSERT(!starpu_pthread_equal(sched_ctx->lock_write_owner, starpu_pthread_self()));
293 STARPU_HG_ENABLE_CHECKING(sched_ctx->lock_write_owner);
294 STARPU_PTHREAD_RWLOCK_RDLOCK(&sched_ctx->rwlock);
297static inline void _starpu_sched_ctx_unlock_read(
unsigned sched_ctx_id)
299 STARPU_ASSERT(sched_ctx_id <= STARPU_NMAX_SCHED_CTXS);
300 struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
301 STARPU_HG_DISABLE_CHECKING(sched_ctx->lock_write_owner);
302 STARPU_ASSERT(!starpu_pthread_equal(sched_ctx->lock_write_owner, starpu_pthread_self()));
303 STARPU_HG_ENABLE_CHECKING(sched_ctx->lock_write_owner);
304 STARPU_PTHREAD_RWLOCK_UNLOCK(&sched_ctx->rwlock);
307static inline unsigned _starpu_sched_ctx_worker_is_master_for_child_ctx(
unsigned sched_ctx_id,
unsigned workerid,
struct starpu_task *task)
309 unsigned child_sched_ctx = starpu_sched_ctx_worker_is_master_for_child_ctx(workerid, sched_ctx_id);
310 if(child_sched_ctx != STARPU_NMAX_SCHED_CTXS)
312 starpu_sched_ctx_move_task_to_ctx_locked(task, child_sched_ctx, 1);
313 starpu_sched_ctx_revert_task_counters_ctx_locked(sched_ctx_id, task->flops);
323#pragma GCC visibility pop
Definition barrier_counter.h:29
starpu_worker_archtype
Definition starpu_worker.h:66
Definition starpu_worker.h:113
#define struct
Definition list.h:175
unsigned _starpu_sched_ctx_get_current_context() STARPU_ATTRIBUTE_VISIBILITY_DEFAULT
int _starpu_workers_able_to_execute_task(struct starpu_task *task, struct _starpu_sched_ctx *sched_ctx)
void _starpu_init_all_sched_ctxs(struct _starpu_machine_config *config)
void _starpu_worker_apply_deferred_ctx_changes(void)
struct _starpu_sched_ctx * __starpu_sched_ctx_get_sched_ctx_for_worker_and_job(struct _starpu_worker *worker, struct _starpu_job *j)
int _starpu_wait_for_all_tasks_of_sched_ctx(unsigned sched_ctx_id)
struct _starpu_sched_ctx * _starpu_create_sched_ctx(struct starpu_sched_policy *policy, int *workerid, int nworkerids, unsigned is_init_sched, const char *sched_name, int min_prio_set, int min_prio, int max_prio_set, int max_prio, unsigned awake_workers, void(*sched_policy_callback)(unsigned), void *user_data, int nsub_ctxs, int *sub_ctxs, int nsms)
int _starpu_get_workers_of_sched_ctx(unsigned sched_ctx_id, int *pus, enum starpu_worker_archtype arch)
unsigned _starpu_worker_belongs_to_a_sched_ctx(int workerid, unsigned sched_ctx_id)
void _starpu_decrement_nsubmitted_tasks_of_sched_ctx(unsigned sched_ctx_id)
void _starpu_delete_all_sched_ctxs()
unsigned _starpu_sched_ctx_last_worker_awake(struct _starpu_worker *worker)
void _starpu_worker_gets_out_of_ctx(unsigned sched_ctx_id, struct _starpu_worker *worker)
void _starpu_sched_ctx_post_exec_task_cb(int workerid, struct starpu_task *task, size_t data_size, uint32_t footprint)
int _starpu_wait_for_n_submitted_tasks_of_sched_ctx(unsigned sched_ctx_id, unsigned n)
Definition sched_ctx.h:172
Definition sched_ctx.h:48
int max_ncpus
Definition sched_ctx.h:95
unsigned id
Definition sched_ctx.h:50
int min_priority
Definition sched_ctx.h:112
int main_master
Definition sched_ctx.h:137
unsigned awake_workers
Definition sched_ctx.h:152
struct _starpu_barrier_counter tasks_barrier
Definition sched_ctx.h:73
unsigned is_initial_sched
Definition sched_ctx.h:70
double ready_flops
Definition sched_ctx.h:79
unsigned parallel_view
Definition sched_ctx.h:147
long iterations[2]
Definition sched_ctx.h:82
int min_ngpus
Definition sched_ctx.h:98
int max_ngpus
Definition sched_ctx.h:101
unsigned finished_submit
Definition sched_ctx.h:108
unsigned do_schedule
Definition sched_ctx.h:53
struct starpu_perfmodel_arch perf_arch
Definition sched_ctx.h:143
unsigned nesting_sched_ctx
Definition sched_ctx.h:140
void(* close_callback)(unsigned sched_ctx_id, void *args)
Definition sched_ctx.h:128
hwloc_bitmap_t hwloc_workers_set
Definition sched_ctx.h:119
struct starpu_sched_policy * sched_policy
Definition sched_ctx.h:59
const char * name
Definition sched_ctx.h:56
void * policy_data
Definition sched_ctx.h:62
unsigned inheritor
Definition sched_ctx.h:104
struct starpu_sched_ctx_performance_counters * perf_counters
Definition sched_ctx.h:124
struct _starpu_barrier_counter ready_tasks_barrier
Definition sched_ctx.h:76
int min_ncpus
Definition sched_ctx.h:92
unsigned hierarchy_level
Definition sched_ctx.h:132
void * user_data
Definition sched_ctx.h:65
void(* callback_sched)(unsigned)
Definition sched_ctx.h:155
int nsms
Definition sched_ctx.h:161