28 #include <common/config.h>
41 #ifdef STARPU_HAVE_HWLOC
53 #ifdef STARPU_USE_MPI_MASTER_SLAVE
63 #define STARPU_MAX_PIPELINE 4
65 enum initialization { UNINITIALIZED = 0, CHANGING, INITIALIZED };
67 struct _starpu_ctx_change_list;
72 starpu_pthread_mutex_t mutex;
73 enum starpu_worker_archtype arch;
75 struct starpu_perfmodel_arch perf_arch;
95 #ifdef STARPU_SPINLOCK_CHECK
96 const char *relax_on_file;
98 const char *relax_on_func;
99 const char *relax_off_file;
101 const char *relax_off_func;
120 starpu_pthread_t thread_changing_ctx;
128 struct _starpu_ctx_change_list ctx_change_list;
129 struct starpu_task_list local_tasks;
135 struct starpu_task *current_tasks[STARPU_MAX_PIPELINE];
136 #ifdef STARPU_SIMGRID
137 starpu_pthread_wait_t wait;
140 struct timespec cl_start;
141 struct timespec cl_end;
147 unsigned worker_is_running;
148 unsigned worker_is_initialized;
163 unsigned removed_from_ctx[STARPU_NMAX_SCHED_CTXS+1];
175 unsigned shares_tasks_lists[STARPU_NMAX_SCHED_CTXS+1];
177 unsigned poped_in_ctx[STARPU_NMAX_SCHED_CTXS+1];
183 unsigned reverse_phase[2];
193 #ifdef STARPU_HAVE_HWLOC
194 hwloc_bitmap_t hwloc_cpu_set;
195 hwloc_obj_t hwloc_obj;
199 char padding[STARPU_CACHELINE_SIZE];
208 int combined_workerid[STARPU_NMAXWORKERS];
211 starpu_pthread_mutex_t count_mutex;
217 #ifdef STARPU_HAVE_HWLOC
218 hwloc_bitmap_t hwloc_cpu_set;
232 starpu_pthread_mutex_t mutex;
239 unsigned set_is_initialized;
242 #ifdef STARPU_USE_MPI_MASTER_SLAVE
254 unsigned nsched_ctxs;
256 #ifdef STARPU_HAVE_HWLOC
293 unsigned nworkerpercuda;
294 int cuda_th_per_stream;
302 unsigned nhwmpidevices;
305 unsigned nmpicores[STARPU_MAXMPIDEVS];
310 unsigned nmicdevices;
313 unsigned nmiccores[STARPU_MAXMICDEVS];
355 #ifdef STARPU_HAVE_HWLOC
362 char currently_bound[STARPU_NMAXWORKERS];
363 char currently_shared[STARPU_NMAXWORKERS];
399 starpu_pthread_mutex_t submitted_mutex;
418 struct starpu_conf
conf;
438 extern int _starpu_worker_parallel_blocks;
441 extern int _starpu_keys_initialized STARPU_ATTRIBUTE_INTERNAL;
442 extern starpu_pthread_key_t _starpu_worker_key STARPU_ATTRIBUTE_INTERNAL;
443 extern starpu_pthread_key_t _starpu_worker_set_key STARPU_ATTRIBUTE_INTERNAL;
446 void _starpu_set_argc_argv(
int *argc,
char ***argv);
447 int *_starpu_get_argc();
448 char ***_starpu_get_argv();
451 void _starpu_conf_check_environment(
struct starpu_conf *
conf);
454 void _starpu_may_pause(
void);
457 static inline unsigned _starpu_machine_is_running(
void)
463 ANNOTATE_HAPPENS_AFTER(&_starpu_config.running);
464 ret = _starpu_config.running;
465 ANNOTATE_HAPPENS_BEFORE(&_starpu_config.running);
474 uint32_t _starpu_worker_exists(
struct starpu_task *);
477 uint32_t _starpu_can_submit_cuda_task(
void);
480 uint32_t _starpu_can_submit_cpu_task(
void);
483 uint32_t _starpu_can_submit_opencl_task(
void);
487 unsigned _starpu_worker_can_block(
unsigned memnode,
struct _starpu_worker *worker);
492 void _starpu_block_worker(
int workerid, starpu_pthread_cond_t *cond, starpu_pthread_mutex_t *mutex);
495 void _starpu_driver_start(
struct _starpu_worker *worker,
unsigned fut_key,
unsigned sync);
497 void _starpu_worker_start(
struct _starpu_worker *worker,
unsigned fut_key,
unsigned sync);
499 static inline unsigned _starpu_worker_get_count(
void)
501 return _starpu_config.topology.nworkers;
503 #define starpu_worker_get_count _starpu_worker_get_count
508 static inline void _starpu_set_local_worker_key(
struct _starpu_worker *worker)
510 STARPU_ASSERT(_starpu_keys_initialized);
511 STARPU_PTHREAD_SETSPECIFIC(_starpu_worker_key, worker);
516 static inline struct _starpu_worker *_starpu_get_local_worker_key(
void)
518 if (!_starpu_keys_initialized)
520 return (
struct _starpu_worker *) STARPU_PTHREAD_GETSPECIFIC(_starpu_worker_key);
526 static inline void _starpu_set_local_worker_set_key(
struct _starpu_worker_set *worker)
528 STARPU_ASSERT(_starpu_keys_initialized);
529 STARPU_PTHREAD_SETSPECIFIC(_starpu_worker_set_key, worker);
536 if (!_starpu_keys_initialized)
538 return (
struct _starpu_worker_set *) STARPU_PTHREAD_GETSPECIFIC(_starpu_worker_set_key);
543 static inline struct _starpu_worker *_starpu_get_worker_struct(
unsigned id)
545 STARPU_ASSERT(
id < starpu_worker_get_count());
546 return &_starpu_config.workers[id];
551 static inline struct _starpu_sched_ctx *_starpu_get_sched_ctx_struct(
unsigned id)
553 return (
id > STARPU_NMAX_SCHED_CTXS) ? NULL : &_starpu_config.sched_ctxs[
id];
562 return &_starpu_config;
566 static inline int _starpu_get_disable_kernels(
void)
568 return _starpu_config.disable_kernels;
574 return _starpu_config.workers[workerid].status;
581 _starpu_config.workers[workerid].status = status;
587 return &_starpu_config.sched_ctxs[STARPU_GLOBAL_SCHED_CTX];
590 int starpu_worker_get_nids_by_type(
enum starpu_worker_archtype type,
int *workerids,
int maxsize);
594 int starpu_worker_get_nids_ctx_free_by_type(
enum starpu_worker_archtype type,
int *workerids,
int maxsize);
596 static inline unsigned _starpu_worker_mutex_is_sched_mutex(
int workerid, starpu_pthread_mutex_t *mutex)
602 static inline int _starpu_worker_get_nsched_ctxs(
int workerid)
604 return _starpu_config.workers[
workerid].nsched_ctxs;
608 static inline unsigned _starpu_get_nsched_ctxs(
void)
612 return _starpu_config.topology.nsched_ctxs;
616 static inline int _starpu_worker_get_id(
void)
620 worker = _starpu_get_local_worker_key();
632 #define starpu_worker_get_id _starpu_worker_get_id
636 static inline unsigned __starpu_worker_get_id_check(
const char *f,
int l)
640 int id = starpu_worker_get_id();
641 STARPU_ASSERT_MSG(
id>=0,
"%s:%d Cannot be called from outside a worker\n", f, l);
644 #define _starpu_worker_get_id_check(f,l) __starpu_worker_get_id_check(f,l)
646 enum starpu_node_kind _starpu_worker_get_node_kind(
enum starpu_worker_archtype type);
650 struct _starpu_sched_ctx* _starpu_worker_get_ctx_stream(
unsigned stream_workerid);
657 static inline void _starpu_worker_request_blocking_in_parallel(
struct _starpu_worker *
const worker)
659 _starpu_worker_parallel_blocks = 1;
680 STARPU_PTHREAD_COND_BROADCAST(&worker->
sched_cond);
681 #ifdef STARPU_SIMGRID
682 starpu_pthread_queue_broadcast(&_starpu_simgrid_task_queue[worker->
workerid]);
698 STARPU_PTHREAD_COND_BROADCAST(&worker->
sched_cond);
706 static inline void _starpu_worker_request_unblocking_in_parallel(
struct _starpu_worker *
const worker)
727 STARPU_PTHREAD_COND_BROADCAST(&worker->
sched_cond);
741 STARPU_PTHREAD_COND_BROADCAST(&worker->
sched_cond);
755 static inline void _starpu_worker_process_block_in_parallel_requests(
struct _starpu_worker *
const worker)
770 STARPU_PTHREAD_COND_BROADCAST(&worker->
sched_cond);
787 STARPU_PTHREAD_COND_BROADCAST(&worker->
sched_cond);
807 #ifdef STARPU_SPINLOCK_CHECK
808 static inline void __starpu_worker_enter_sched_op(
struct _starpu_worker *
const worker,
const char*file,
int line,
const char* func)
810 static inline void _starpu_worker_enter_sched_op(
struct _starpu_worker *
const worker)
817 _starpu_worker_process_block_in_parallel_requests(worker);
824 _starpu_worker_process_block_in_parallel_requests(worker);
846 #ifdef STARPU_SPINLOCK_CHECK
847 worker->relax_on_file = file;
848 worker->relax_on_line = line;
849 worker->relax_on_func = func;
852 #ifdef STARPU_SPINLOCK_CHECK
853 #define _starpu_worker_enter_sched_op(worker) __starpu_worker_enter_sched_op((worker), __FILE__, __LINE__, __starpu_func__)
861 #ifdef STARPU_SPINLOCK_CHECK
862 static inline void __starpu_worker_leave_sched_op(
struct _starpu_worker *
const worker,
const char*file,
int line,
const char* func)
864 static inline void _starpu_worker_leave_sched_op(
struct _starpu_worker *
const worker)
869 #ifdef STARPU_SPINLOCK_CHECK
870 worker->relax_off_file = file;
871 worker->relax_off_line = line;
872 worker->relax_off_func = func;
875 STARPU_PTHREAD_COND_BROADCAST(&worker->
sched_cond);
878 #ifdef STARPU_SPINLOCK_CHECK
879 #define _starpu_worker_leave_sched_op(worker) __starpu_worker_leave_sched_op((worker), __FILE__, __LINE__, __starpu_func__)
882 static inline int _starpu_worker_sched_op_pending(
void)
884 int workerid = starpu_worker_get_id();
888 STARPU_ASSERT(worker != NULL);
901 static inline void _starpu_worker_enter_changing_ctx_op(
struct _starpu_worker *
const worker)
924 STARPU_PTHREAD_COND_BROADCAST(&worker->
sched_cond);
925 #ifdef STARPU_SIMGRID
926 starpu_pthread_queue_broadcast(&_starpu_simgrid_task_queue[worker->
workerid]);
943 static inline void _starpu_worker_leave_changing_ctx_op(
struct _starpu_worker *
const worker)
947 STARPU_PTHREAD_COND_BROADCAST(&worker->
sched_cond);
952 #ifdef STARPU_SPINLOCK_CHECK
953 static inline void __starpu_worker_relax_on(
const char*file,
int line,
const char* func)
955 static inline void _starpu_worker_relax_on(
void)
963 STARPU_PTHREAD_MUTEX_LOCK_SCHED(&worker->
sched_mutex);
964 #ifdef STARPU_SPINLOCK_CHECK
965 STARPU_ASSERT_MSG(worker->
state_relax_refcnt<UINT_MAX,
"relax last turn on in %s (%s:%d)\n", worker->relax_on_func, worker->relax_on_file, worker->relax_on_line);
970 #ifdef STARPU_SPINLOCK_CHECK
971 worker->relax_on_file = file;
972 worker->relax_on_line = line;
973 worker->relax_on_func = func;
975 STARPU_PTHREAD_COND_BROADCAST(&worker->
sched_cond);
976 STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&worker->
sched_mutex);
978 #ifdef STARPU_SPINLOCK_CHECK
979 #define _starpu_worker_relax_on() __starpu_worker_relax_on(__FILE__, __LINE__, __starpu_func__)
981 #define starpu_worker_relax_on _starpu_worker_relax_on
984 #ifdef STARPU_SPINLOCK_CHECK
985 static inline void __starpu_worker_relax_on_locked(
struct _starpu_worker *worker,
const char*file,
int line,
const char* func)
987 static inline void _starpu_worker_relax_on_locked(
struct _starpu_worker *worker)
992 #ifdef STARPU_SPINLOCK_CHECK
993 STARPU_ASSERT_MSG(worker->
state_relax_refcnt<UINT_MAX,
"relax last turn on in %s (%s:%d)\n", worker->relax_on_func, worker->relax_on_file, worker->relax_on_line);
998 #ifdef STARPU_SPINLOCK_CHECK
999 worker->relax_on_file = file;
1000 worker->relax_on_line = line;
1001 worker->relax_on_func = func;
1003 STARPU_PTHREAD_COND_BROADCAST(&worker->
sched_cond);
1005 #ifdef STARPU_SPINLOCK_CHECK
1006 #define _starpu_worker_relax_on_locked(worker) __starpu_worker_relax_on_locked(worker,__FILE__, __LINE__, __starpu_func__)
1009 #ifdef STARPU_SPINLOCK_CHECK
1010 static inline void __starpu_worker_relax_off(
const char*file,
int line,
const char* func)
1012 static inline void _starpu_worker_relax_off(
void)
1015 int workerid = starpu_worker_get_id();
1019 STARPU_ASSERT(worker != NULL);
1022 STARPU_PTHREAD_MUTEX_LOCK_SCHED(&worker->
sched_mutex);
1023 #ifdef STARPU_SPINLOCK_CHECK
1024 STARPU_ASSERT_MSG(worker->
state_relax_refcnt>0,
"relax last turn off in %s (%s:%d)\n", worker->relax_on_func, worker->relax_on_file, worker->relax_on_line);
1029 #ifdef STARPU_SPINLOCK_CHECK
1030 worker->relax_off_file = file;
1031 worker->relax_off_line = line;
1032 worker->relax_off_func = func;
1034 STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&worker->
sched_mutex);
1036 #ifdef STARPU_SPINLOCK_CHECK
1037 #define _starpu_worker_relax_off() __starpu_worker_relax_off(__FILE__, __LINE__, __starpu_func__)
1039 #define starpu_worker_relax_off _starpu_worker_relax_off
1041 #ifdef STARPU_SPINLOCK_CHECK
1042 static inline void __starpu_worker_relax_off_locked(
const char*file,
int line,
const char* func)
1044 static inline void _starpu_worker_relax_off_locked(
void)
1047 int workerid = starpu_worker_get_id();
1051 STARPU_ASSERT(worker != NULL);
1054 #ifdef STARPU_SPINLOCK_CHECK
1055 STARPU_ASSERT_MSG(worker->
state_relax_refcnt>0,
"relax last turn off in %s (%s:%d)\n", worker->relax_on_func, worker->relax_on_file, worker->relax_on_line);
1060 #ifdef STARPU_SPINLOCK_CHECK
1061 worker->relax_off_file = file;
1062 worker->relax_off_line = line;
1063 worker->relax_off_func = func;
1066 #ifdef STARPU_SPINLOCK_CHECK
1067 #define _starpu_worker_relax_off_locked() __starpu_worker_relax_off_locked(__FILE__, __LINE__, __starpu_func__)
1070 static inline int _starpu_worker_get_relax_state(
void)
1072 int workerid = starpu_worker_get_id();
1076 STARPU_ASSERT(worker != NULL);
1079 #define starpu_worker_get_relax_state _starpu_worker_get_relax_state
1085 static inline void _starpu_worker_lock(
int workerid)
1088 STARPU_ASSERT(worker != NULL);
1089 int cur_workerid = starpu_worker_get_id();
1092 starpu_worker_relax_on();
1094 STARPU_PTHREAD_MUTEX_LOCK_SCHED(&worker->
sched_mutex);
1102 STARPU_PTHREAD_MUTEX_LOCK_SCHED(&worker->
sched_mutex);
1106 static inline int _starpu_worker_trylock(
int workerid)
1108 struct _starpu_worker *cur_worker = _starpu_get_local_worker_key();
1109 int cur_workerid = cur_worker->
workerid;
1111 STARPU_ASSERT(worker != NULL);
1114 int ret = STARPU_PTHREAD_MUTEX_TRYLOCK_SCHED(&cur_worker->
sched_mutex);
1122 ret = STARPU_PTHREAD_MUTEX_TRYLOCK_SCHED(&worker->
sched_mutex);
1128 STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&worker->
sched_mutex);
1131 _starpu_worker_relax_on_locked(cur_worker);
1132 STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&cur_worker->
sched_mutex);
1136 static inline void _starpu_worker_unlock(
int workerid)
1139 STARPU_ASSERT(worker != NULL);
1140 STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&worker->
sched_mutex);
1141 int cur_workerid = starpu_worker_get_id();
1144 starpu_worker_relax_off();
1148 static inline void _starpu_worker_lock_self(
void)
1150 int workerid = starpu_worker_get_id_check();
1152 STARPU_ASSERT(worker != NULL);
1153 STARPU_PTHREAD_MUTEX_LOCK_SCHED(&worker->
sched_mutex);
1156 static inline void _starpu_worker_unlock_self(
void)
1158 int workerid = starpu_worker_get_id_check();
1160 STARPU_ASSERT(worker != NULL);
1161 STARPU_PTHREAD_MUTEX_UNLOCK_SCHED(&worker->
sched_mutex);
1164 static inline int _starpu_wake_worker_relax(
int workerid)
1167 int ret = starpu_wake_worker_locked(
workerid);
1172 int starpu_wake_worker_relax_light(
int workerid);
1178 void _starpu_worker_refuse_task(
struct _starpu_worker *worker,
struct starpu_task *task);
Definition: barrier_counter.h:27
_starpu_worker_status
Definition: errorcheck.h:26
void _starpu_worker_apply_deferred_ctx_changes(void)
Definition: sched_ctx_list.h:25
Definition: workers.h:203
char padding[STARPU_CACHELINE_SIZE]
Definition: workers.h:223
unsigned memory_node
Definition: workers.h:207
struct starpu_perfmodel_arch perf_arch
Definition: workers.h:204
uint32_t worker_mask
Definition: workers.h:205
Definition: workers.h:352
int mpi_nodeid
Definition: workers.h:386
struct _starpu_combined_worker combined_workers[STARPU_NMAX_COMBINEDWORKERS]
Definition: workers.h:397
int opencl_nodeid
Definition: workers.h:382
unsigned running
Definition: workers.h:421
int current_cuda_gpuid
Definition: workers.h:366
unsigned nbindid
Definition: workers.h:410
int pause_depth
Definition: workers.h:427
int current_opencl_gpuid
Definition: workers.h:369
int cpus_nodeid
Definition: workers.h:378
int mic_nodeid
Definition: workers.h:384
struct _starpu_machine_config::@4 * bindid_workers
struct _starpu_sched_ctx sched_ctxs[STARPU_NMAX_SCHED_CTXS+1]
Definition: workers.h:430
int current_bindid
Definition: workers.h:361
struct _starpu_worker workers[STARPU_NMAXWORKERS]
Definition: workers.h:393
uint32_t worker_mask
Definition: workers.h:415
int current_mic_deviceid
Definition: workers.h:372
int cuda_nodeid
Definition: workers.h:380
char padding2[STARPU_CACHELINE_SIZE]
Definition: workers.h:402
unsigned submitting
Definition: workers.h:433
char padding1[STARPU_CACHELINE_SIZE]
Definition: workers.h:389
int current_mpi_deviceid
Definition: workers.h:375
struct starpu_conf conf
Definition: workers.h:418
Definition: workers.h:247
struct starpu_tree * tree
Definition: workers.h:261
unsigned nmpidevices
Definition: workers.h:301
unsigned nhwmicdevices
Definition: workers.h:309
hwloc_topology_t hwtopology
Definition: workers.h:258
unsigned workers_mpi_ms_deviceid[STARPU_NMAXWORKERS]
Definition: workers.h:348
unsigned workers_cuda_gpuid[STARPU_NMAXWORKERS]
Definition: workers.h:330
unsigned nhwopenclgpus
Definition: workers.h:281
unsigned workers_opencl_gpuid[STARPU_NMAXWORKERS]
Definition: workers.h:338
unsigned nworkers
Definition: workers.h:249
unsigned ncudagpus
Definition: workers.h:292
unsigned nhwmpi
Definition: workers.h:286
unsigned ncpus
Definition: workers.h:289
unsigned ncombinedworkers
Definition: workers.h:252
unsigned nhwcudagpus
Definition: workers.h:276
unsigned nopenclgpus
Definition: workers.h:298
unsigned nhwmpicores[STARPU_MAXMPIDEVS]
Definition: workers.h:304
unsigned nhwpus
Definition: workers.h:271
unsigned workers_bindid[STARPU_NMAXWORKERS]
Definition: workers.h:322
unsigned nhwmiccores[STARPU_MAXMICDEVS]
Definition: workers.h:312
unsigned nhwcpus
Definition: workers.h:266
Definition: sched_ctx.h:46
unsigned id
Definition: sched_ctx.h:48
Definition: workers.h:231
unsigned started
Definition: workers.h:235
starpu_pthread_t worker_thread
Definition: workers.h:233
starpu_pthread_cond_t ready_cond
Definition: workers.h:238
unsigned state_blocked_in_parallel_observed
Definition: workers.h:107
struct starpu_task * current_task
Definition: workers.h:134
unsigned state_block_in_parallel_ack
Definition: workers.h:109
unsigned state_relax_refcnt
Definition: workers.h:94
struct starpu_task * task_transferring
Definition: workers.h:169
unsigned state_changing_ctx_waiting
Definition: workers.h:104
unsigned subworkerid
Definition: workers.h:78
unsigned devid
Definition: workers.h:77
starpu_pthread_t thread_changing_ctx
Definition: workers.h:120
int current_rank
Definition: workers.h:82
unsigned state_unblock_in_parallel_req
Definition: workers.h:110
unsigned nb_buffers_transferred
Definition: workers.h:167
starpu_pthread_t worker_thread
Definition: workers.h:76
starpu_pthread_cond_t ready_cond
Definition: workers.h:85
unsigned memory_node
Definition: workers.h:86
int workerid
Definition: workers.h:80
unsigned nb_buffers_totransfer
Definition: workers.h:168
unsigned state_keep_awake
Definition: workers.h:150
struct _starpu_worker_set * set
Definition: workers.h:146
int worker_size
Definition: workers.h:83
unsigned pop_ctx_priority
Definition: workers.h:185
unsigned state_unblock_in_parallel_ack
Definition: workers.h:111
unsigned numa_memory_node
Definition: workers.h:87
unsigned char pipeline_stuck
Definition: workers.h:145
unsigned char pipeline_length
Definition: workers.h:144
unsigned nsched_ctxs
Definition: workers.h:158
unsigned spinning_backoff
Definition: workers.h:165
unsigned state_blocked_in_parallel
Definition: workers.h:106
unsigned current_ordered_task_order
Definition: workers.h:133
starpu_pthread_cond_t started_cond
Definition: workers.h:84
starpu_pthread_mutex_t sched_mutex
Definition: workers.h:93
unsigned run_by_starpu
Definition: workers.h:153
unsigned local_ordered_tasks_size
Definition: workers.h:131
struct starpu_task ** local_ordered_tasks
Definition: workers.h:130
unsigned is_slave_somewhere
Definition: workers.h:186
starpu_pthread_cond_t sched_cond
Definition: workers.h:92
unsigned has_prev_init
Definition: workers.h:161
unsigned char ntasks
Definition: workers.h:143
int bindid
Definition: workers.h:79
unsigned state_block_in_parallel_req
Definition: workers.h:108
unsigned state_changing_ctx_notice
Definition: workers.h:105
unsigned state_sched_op_pending
Definition: workers.h:103
int combined_workerid
Definition: workers.h:81
unsigned char first_task
Definition: workers.h:142
unsigned current_ordered_task
Definition: workers.h:132
unsigned block_in_parallel_ref_count
Definition: workers.h:119