Loading...
Searching...
No Matches
sched_ctx.h
Go to the documentation of this file.
/* StarPU --- Runtime system for heterogeneous multicore architectures.
*
* Copyright (C) 2011-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
* Copyright (C) 2016 Uppsala University
*
* StarPU is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at
* your option) any later version.
*
* StarPU is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU Lesser General Public License in COPYING.LGPL for more details.
*/
#ifndef __SCHED_CONTEXT_H__
#define __SCHED_CONTEXT_H__
#include <starpu.h>
#include <starpu_sched_ctx.h>
#include <starpu_sched_ctx_hypervisor.h>
#include <starpu_scheduler.h>
#include <common/config.h>
#include <common/barrier_counter.h>
#include <common/utils.h>
#include <profiling/profiling.h>
#include <semaphore.h>
#include <core/task.h>
#include "sched_ctx_list.h"
#ifdef STARPU_HAVE_HWLOC
#include <hwloc.h>
#endif
#define NO_RESIZE -1
#define REQ_RESIZE 0
#define DO_RESIZE 1
#define STARPU_GLOBAL_SCHED_CTX 0
#define STARPU_NMAXSMS 13
struct _starpu_sched_ctx
{
unsigned id;
unsigned do_schedule;
const char *name;
struct starpu_sched_policy *sched_policy;
void *policy_data;
void *user_data;
struct starpu_worker_collection *workers;
unsigned is_initial_sched;
struct _starpu_barrier_counter tasks_barrier;
struct _starpu_barrier_counter ready_tasks_barrier;
double ready_flops;
long iterations[2];
int iteration_level;
/*ready tasks that couldn't be pushed because the ctx has no workers*/
struct starpu_task_list empty_ctx_tasks;
/*ready tasks that couldn't be pushed because the the window of tasks was already full*/
struct starpu_task_list waiting_tasks;
int min_ncpus;
int max_ncpus;
int min_ngpus;
int max_ngpus;
unsigned inheritor;
unsigned finished_submit;
int min_priority;
int max_priority;
int min_priority_is_set;
int max_priority_is_set;
#ifdef STARPU_HAVE_HWLOC
hwloc_bitmap_t hwloc_workers_set;
#endif
#ifdef STARPU_USE_SC_HYPERVISOR
struct starpu_sched_ctx_performance_counters *perf_counters;
#endif //STARPU_USE_SC_HYPERVISOR
void (*close_callback)(unsigned sched_ctx_id, void* args);
void *close_args;
unsigned hierarchy_level;
int main_master;
unsigned nesting_sched_ctx;
struct starpu_perfmodel_arch perf_arch;
unsigned parallel_view;
unsigned awake_workers;
void (*init_sched)(unsigned);
int sub_ctxs[STARPU_NMAXWORKERS];
int nsub_ctxs;
int nsms;
int sms_start_idx;
int sms_end_idx;
int stream_worker;
starpu_pthread_rwlock_t rwlock;
starpu_pthread_t lock_write_owner;
};
LIST_TYPE(_starpu_ctx_change,
int sched_ctx_id;
int op;
int nworkers_to_notify;
int *workerids_to_notify;
int nworkers_to_change;
int *workerids_to_change;
);
struct _starpu_machine_config;
void _starpu_init_all_sched_ctxs(struct _starpu_machine_config *config);
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_init)(unsigned), void *user_data,
int nsub_ctxs, int *sub_ctxs, int nsms);
void _starpu_delete_all_sched_ctxs();
int _starpu_wait_for_all_tasks_of_sched_ctx(unsigned sched_ctx_id);
int _starpu_wait_for_n_submitted_tasks_of_sched_ctx(unsigned sched_ctx_id, unsigned n);
void _starpu_decrement_nsubmitted_tasks_of_sched_ctx(unsigned sched_ctx_id);
void _starpu_increment_nsubmitted_tasks_of_sched_ctx(unsigned sched_ctx_id);
int _starpu_get_nsubmitted_tasks_of_sched_ctx(unsigned sched_ctx_id);
int _starpu_check_nsubmitted_tasks_of_sched_ctx(unsigned sched_ctx_id);
void _starpu_decrement_nready_tasks_of_sched_ctx(unsigned sched_ctx_id, double ready_flops);
unsigned _starpu_increment_nready_tasks_of_sched_ctx(unsigned sched_ctx_id, double ready_flops, struct starpu_task *task);
int _starpu_wait_for_no_ready_of_sched_ctx(unsigned sched_ctx_id);
int _starpu_get_index_in_ctx_of_workerid(unsigned sched_ctx, unsigned workerid);
starpu_pthread_mutex_t *_starpu_get_sched_mutex(struct _starpu_sched_ctx *sched_ctx, int worker);
int _starpu_get_workers_of_sched_ctx(unsigned sched_ctx_id, int *pus, enum starpu_worker_archtype arch);
void _starpu_worker_gets_out_of_ctx(unsigned sched_ctx_id, struct _starpu_worker *worker);
unsigned _starpu_worker_belongs_to_a_sched_ctx(int workerid, unsigned sched_ctx_id);
unsigned _starpu_sched_ctx_last_worker_awake(struct _starpu_worker *worker);
unsigned _starpu_sched_ctx_get_current_context();
int _starpu_workers_able_to_execute_task(struct starpu_task *task, struct _starpu_sched_ctx *sched_ctx);
void _starpu_fetch_tasks_from_empty_ctx_list(struct _starpu_sched_ctx *sched_ctx);
unsigned _starpu_sched_ctx_allow_hypervisor(unsigned sched_ctx_id);
struct starpu_perfmodel_arch * _starpu_sched_ctx_get_perf_archtype(unsigned sched_ctx);
#ifdef STARPU_USE_SC_HYPERVISOR
void _starpu_sched_ctx_post_exec_task_cb(int workerid, struct starpu_task *task, size_t data_size, uint32_t footprint);
#endif //STARPU_USE_SC_HYPERVISOR
void starpu_sched_ctx_add_combined_workers(int *combined_workers_to_add, unsigned n_combined_workers_to_add, unsigned sched_ctx_id);
struct _starpu_sched_ctx *__starpu_sched_ctx_get_sched_ctx_for_worker_and_job(struct _starpu_worker *worker, struct _starpu_job *j);
#define _starpu_sched_ctx_get_sched_ctx_for_worker_and_job(w,j) \
(_starpu_get_nsched_ctxs() <= 1 ? _starpu_get_sched_ctx_struct(0) : __starpu_sched_ctx_get_sched_ctx_for_worker_and_job((w),(j)))
static inline struct _starpu_sched_ctx *_starpu_get_sched_ctx_struct(unsigned id);
static inline int _starpu_sched_ctx_check_write_locked(unsigned sched_ctx_id)
{
struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
return starpu_pthread_equal(sched_ctx->lock_write_owner, starpu_pthread_self());
}
#define STARPU_SCHED_CTX_CHECK_LOCK(sched_ctx_id) STARPU_ASSERT(_starpu_sched_ctx_check_write_locked((sched_ctx_id)))
static inline void _starpu_sched_ctx_lock_write(unsigned sched_ctx_id)
{
struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
STARPU_HG_DISABLE_CHECKING(sched_ctx->lock_write_owner);
STARPU_ASSERT(!starpu_pthread_equal(sched_ctx->lock_write_owner, starpu_pthread_self()));
STARPU_HG_ENABLE_CHECKING(sched_ctx->lock_write_owner);
STARPU_PTHREAD_RWLOCK_WRLOCK(&sched_ctx->rwlock);
sched_ctx->lock_write_owner = starpu_pthread_self();
}
static inline void _starpu_sched_ctx_unlock_write(unsigned sched_ctx_id)
{
struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
STARPU_HG_DISABLE_CHECKING(sched_ctx->lock_write_owner);
STARPU_ASSERT(starpu_pthread_equal(sched_ctx->lock_write_owner, starpu_pthread_self()));
memset(&sched_ctx->lock_write_owner, 0, sizeof(sched_ctx->lock_write_owner));
STARPU_HG_ENABLE_CHECKING(sched_ctx->lock_write_owner);
STARPU_PTHREAD_RWLOCK_UNLOCK(&sched_ctx->rwlock);
}
static inline void _starpu_sched_ctx_lock_read(unsigned sched_ctx_id)
{
struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
STARPU_HG_DISABLE_CHECKING(sched_ctx->lock_write_owner);
STARPU_ASSERT(!starpu_pthread_equal(sched_ctx->lock_write_owner, starpu_pthread_self()));
STARPU_HG_ENABLE_CHECKING(sched_ctx->lock_write_owner);
STARPU_PTHREAD_RWLOCK_RDLOCK(&sched_ctx->rwlock);
}
static inline void _starpu_sched_ctx_unlock_read(unsigned sched_ctx_id)
{
struct _starpu_sched_ctx *sched_ctx = _starpu_get_sched_ctx_struct(sched_ctx_id);
STARPU_HG_DISABLE_CHECKING(sched_ctx->lock_write_owner);
STARPU_ASSERT(!starpu_pthread_equal(sched_ctx->lock_write_owner, starpu_pthread_self()));
STARPU_HG_ENABLE_CHECKING(sched_ctx->lock_write_owner);
STARPU_PTHREAD_RWLOCK_UNLOCK(&sched_ctx->rwlock);
}
static inline unsigned _starpu_sched_ctx_worker_is_master_for_child_ctx(unsigned sched_ctx_id, unsigned workerid, struct starpu_task *task)
{
unsigned child_sched_ctx = starpu_sched_ctx_worker_is_master_for_child_ctx(workerid, sched_ctx_id);
if(child_sched_ctx != STARPU_NMAX_SCHED_CTXS)
{
starpu_sched_ctx_move_task_to_ctx_locked(task, child_sched_ctx, 1);
starpu_sched_ctx_revert_task_counters_ctx_locked(sched_ctx_id, task->flops);
return 1;
}
return 0;
}
void _starpu_worker_apply_deferred_ctx_changes(void);
#endif // __SCHED_CONTEXT_H__
barrier_counter.h
_starpu_barrier_counter
Definition barrier_counter.h:27
profiling.h
_starpu_get_sched_mutex
starpu_pthread_mutex_t * _starpu_get_sched_mutex(struct _starpu_sched_ctx *sched_ctx, int worker)
_starpu_workers_able_to_execute_task
int _starpu_workers_able_to_execute_task(struct starpu_task *task, struct _starpu_sched_ctx *sched_ctx)
_starpu_init_all_sched_ctxs
void _starpu_init_all_sched_ctxs(struct _starpu_machine_config *config)
_starpu_worker_apply_deferred_ctx_changes
void _starpu_worker_apply_deferred_ctx_changes(void)
__starpu_sched_ctx_get_sched_ctx_for_worker_and_job
struct _starpu_sched_ctx * __starpu_sched_ctx_get_sched_ctx_for_worker_and_job(struct _starpu_worker *worker, struct _starpu_job *j)
_starpu_sched_ctx_get_current_context
unsigned _starpu_sched_ctx_get_current_context()
_starpu_wait_for_all_tasks_of_sched_ctx
int _starpu_wait_for_all_tasks_of_sched_ctx(unsigned sched_ctx_id)
_starpu_create_sched_ctx
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_init)(unsigned), void *user_data, int nsub_ctxs, int *sub_ctxs, int nsms)
_starpu_get_workers_of_sched_ctx
int _starpu_get_workers_of_sched_ctx(unsigned sched_ctx_id, int *pus, enum starpu_worker_archtype arch)
_starpu_worker_belongs_to_a_sched_ctx
unsigned _starpu_worker_belongs_to_a_sched_ctx(int workerid, unsigned sched_ctx_id)
_starpu_decrement_nsubmitted_tasks_of_sched_ctx
void _starpu_decrement_nsubmitted_tasks_of_sched_ctx(unsigned sched_ctx_id)
_starpu_delete_all_sched_ctxs
void _starpu_delete_all_sched_ctxs()
_starpu_sched_ctx_last_worker_awake
unsigned _starpu_sched_ctx_last_worker_awake(struct _starpu_worker *worker)
_starpu_worker_gets_out_of_ctx
void _starpu_worker_gets_out_of_ctx(unsigned sched_ctx_id, struct _starpu_worker *worker)
_starpu_sched_ctx_post_exec_task_cb
void _starpu_sched_ctx_post_exec_task_cb(int workerid, struct starpu_task *task, size_t data_size, uint32_t footprint)
_starpu_wait_for_n_submitted_tasks_of_sched_ctx
int _starpu_wait_for_n_submitted_tasks_of_sched_ctx(unsigned sched_ctx_id, unsigned n)
_starpu_get_index_in_ctx_of_workerid
int _starpu_get_index_in_ctx_of_workerid(unsigned sched_ctx, unsigned workerid)
_starpu_ctx_change
Definition sched_ctx.h:170
sched_ctx_list.h
_starpu_job
Definition jobs.h:79
_starpu_machine_config
Definition workers.h:359
_starpu_sched_ctx
Definition sched_ctx.h:46
_starpu_sched_ctx::max_ncpus
int max_ncpus
Definition sched_ctx.h:93
_starpu_sched_ctx::id
unsigned id
Definition sched_ctx.h:48
_starpu_sched_ctx::min_priority
int min_priority
Definition sched_ctx.h:110
_starpu_sched_ctx::init_sched
void(* init_sched)(unsigned)
Definition sched_ctx.h:153
_starpu_sched_ctx::main_master
int main_master
Definition sched_ctx.h:135
_starpu_sched_ctx::awake_workers
unsigned awake_workers
Definition sched_ctx.h:150
_starpu_sched_ctx::tasks_barrier
struct _starpu_barrier_counter tasks_barrier
Definition sched_ctx.h:71
_starpu_sched_ctx::is_initial_sched
unsigned is_initial_sched
Definition sched_ctx.h:68
_starpu_sched_ctx::ready_flops
double ready_flops
Definition sched_ctx.h:77
_starpu_sched_ctx::parallel_view
unsigned parallel_view
Definition sched_ctx.h:145
_starpu_sched_ctx::iterations
long iterations[2]
Definition sched_ctx.h:80
_starpu_sched_ctx::min_ngpus
int min_ngpus
Definition sched_ctx.h:96
_starpu_sched_ctx::max_ngpus
int max_ngpus
Definition sched_ctx.h:99
_starpu_sched_ctx::finished_submit
unsigned finished_submit
Definition sched_ctx.h:106
_starpu_sched_ctx::do_schedule
unsigned do_schedule
Definition sched_ctx.h:51
_starpu_sched_ctx::perf_arch
struct starpu_perfmodel_arch perf_arch
Definition sched_ctx.h:141
_starpu_sched_ctx::nesting_sched_ctx
unsigned nesting_sched_ctx
Definition sched_ctx.h:138
_starpu_sched_ctx::close_callback
void(* close_callback)(unsigned sched_ctx_id, void *args)
Definition sched_ctx.h:126
_starpu_sched_ctx::hwloc_workers_set
hwloc_bitmap_t hwloc_workers_set
Definition sched_ctx.h:117
_starpu_sched_ctx::sched_policy
struct starpu_sched_policy * sched_policy
Definition sched_ctx.h:57
_starpu_sched_ctx::name
const char * name
Definition sched_ctx.h:54
_starpu_sched_ctx::policy_data
void * policy_data
Definition sched_ctx.h:60
_starpu_sched_ctx::inheritor
unsigned inheritor
Definition sched_ctx.h:102
_starpu_sched_ctx::perf_counters
struct starpu_sched_ctx_performance_counters * perf_counters
Definition sched_ctx.h:122
_starpu_sched_ctx::ready_tasks_barrier
struct _starpu_barrier_counter ready_tasks_barrier
Definition sched_ctx.h:74
_starpu_sched_ctx::min_ncpus
int min_ncpus
Definition sched_ctx.h:90
_starpu_sched_ctx::hierarchy_level
unsigned hierarchy_level
Definition sched_ctx.h:130
_starpu_sched_ctx::user_data
void * user_data
Definition sched_ctx.h:63
_starpu_sched_ctx::nsms
int nsms
Definition sched_ctx.h:159
_starpu_worker
Definition workers.h:70
task.h
utils.h