workers.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2016 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2016 CNRS
  5. * Copyright (C) 2011 INRIA
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #ifndef __WORKERS_H__
  19. #define __WORKERS_H__
  20. #include <starpu.h>
  21. #include <common/config.h>
  22. #include <common/timing.h>
  23. #include <common/fxt.h>
  24. #include <common/thread.h>
  25. #include <core/jobs.h>
  26. #include <core/perfmodel/perfmodel.h>
  27. #include <core/sched_policy.h>
  28. #include <core/topology.h>
  29. #include <core/errorcheck.h>
  30. #include <core/sched_ctx.h>
  31. #include <core/sched_ctx_list.h>
  32. #ifdef STARPU_HAVE_HWLOC
  33. #include <hwloc.h>
  34. #endif
  35. #include <drivers/cuda/driver_cuda.h>
  36. #include <drivers/opencl/driver_opencl.h>
  37. #ifdef STARPU_USE_MIC
  38. #include <drivers/mic/driver_mic_source.h>
  39. #endif /* STARPU_USE_MIC */
  40. #ifdef STARPU_USE_SCC
  41. #include <drivers/scc/driver_scc_source.h>
  42. #endif
  43. #include <drivers/cpu/driver_cpu.h>
  44. #include <datawizard/datawizard.h>
  45. #include <starpu_parameters.h>
  46. #define STARPU_MAX_PIPELINE 4
  47. /* This is initialized from in _starpu_worker_init */
  48. LIST_TYPE(_starpu_worker,
  49. struct _starpu_machine_config *config;
  50. starpu_pthread_mutex_t mutex;
  51. enum starpu_worker_archtype arch; /* what is the type of worker ? */
  52. uint32_t worker_mask; /* what is the type of worker ? */
  53. struct starpu_perfmodel_arch perf_arch; /* in case there are different models of the same arch */
  54. starpu_pthread_t worker_thread; /* the thread which runs the worker */
  55. unsigned devid; /* which cpu/gpu/etc is controlled by the worker ? */
  56. unsigned subworkerid; /* which sub-worker this one is for the cpu/gpu */
  57. int bindid; /* which cpu is the driver bound to ? (logical index) */
  58. int workerid; /* uniquely identify the worker among all processing units types */
  59. int combined_workerid; /* combined worker currently using this worker */
  60. int current_rank; /* current rank in case the worker is used in a parallel fashion */
  61. int worker_size; /* size of the worker in case we use a combined worker */
  62. starpu_pthread_cond_t started_cond; /* indicate when the worker is ready */
  63. starpu_pthread_cond_t ready_cond; /* indicate when the worker is ready */
  64. unsigned memory_node; /* which memory node is the worker associated with ? */
  65. starpu_pthread_cond_t sched_cond; /* condition variable used when the worker waits for tasks. */
  66. starpu_pthread_mutex_t sched_mutex; /* mutex protecting sched_cond */
  67. struct starpu_task_list local_tasks; /* this queue contains tasks that have been explicitely submitted to that queue */
  68. struct starpu_task **local_ordered_tasks; /* this queue contains tasks that have been explicitely submitted to that queue with an explicit order */
  69. unsigned local_ordered_tasks_size; /* this records the size of local_ordered_tasks */
  70. unsigned current_ordered_task; /* this records the index (within local_ordered_tasks) of the next ordered task to be executed */
  71. unsigned current_ordered_task_order; /* this records the order of the next ordered task to be executed */
  72. struct starpu_task *current_task; /* task currently executed by this worker (non-pipelined version) */
  73. struct starpu_task *current_tasks[STARPU_MAX_PIPELINE]; /* tasks currently executed by this worker (pipelined version) */
  74. #ifdef STARPU_SIMGRID
  75. starpu_pthread_wait_t wait;
  76. #endif
  77. unsigned char first_task; /* Index of first task in the pipeline */
  78. unsigned char ntasks; /* number of tasks in the pipeline */
  79. unsigned char pipeline_length; /* number of tasks to be put in the pipeline */
  80. unsigned char pipeline_stuck; /* whether a task prevents us from pipelining */
  81. struct _starpu_worker_set *set; /* in case this worker belongs to a set */
  82. unsigned worker_is_running;
  83. unsigned worker_is_initialized;
  84. enum _starpu_worker_status status; /* what is the worker doing now ? (eg. CALLBACK) */
  85. char name[64];
  86. char short_name[10];
  87. unsigned run_by_starpu; /* Is this run by StarPU or directly by the application ? */
  88. struct _starpu_sched_ctx_list *sched_ctx_list;
  89. int tmp_sched_ctx;
  90. unsigned nsched_ctxs; /* the no of contexts a worker belongs to*/
  91. struct _starpu_barrier_counter tasks_barrier; /* wait for the tasks submitted */
  92. unsigned has_prev_init; /* had already been inited in another ctx */
  93. unsigned removed_from_ctx[STARPU_NMAX_SCHED_CTXS+1];
  94. unsigned spinning_backoff ; /* number of cycles to pause when spinning */
  95. /* indicate whether the workers shares tasks lists with other workers*/
  96. /* in this case when removing him from a context it disapears instantly */
  97. unsigned shares_tasks_lists[STARPU_NMAX_SCHED_CTXS+1];
  98. /* boolean to chose the next ctx a worker will pop into */
  99. unsigned poped_in_ctx[STARPU_NMAX_SCHED_CTXS+1];
  100. /* boolean indicating at which moment we checked all ctxs and change phase for the booleab poped_in_ctx*/
  101. /* one for each of the 2 priorities*/
  102. unsigned reverse_phase[2];
  103. /* indicate which priority of ctx is currently active: the values are 0 or 1*/
  104. unsigned pop_ctx_priority;
  105. /* flag to know if sched_mutex is locked or not */
  106. unsigned sched_mutex_locked;
  107. /* bool to indicate if the worker is blocked in a ctx */
  108. unsigned blocked;
  109. /* bool to indicate if the worker is slave in a ctx */
  110. unsigned is_slave_somewhere;
  111. #ifdef __GLIBC__
  112. cpu_set_t cpu_set;
  113. #endif /* __GLIBC__ */
  114. #ifdef STARPU_HAVE_HWLOC
  115. hwloc_bitmap_t hwloc_cpu_set;
  116. #endif
  117. );
  118. struct _starpu_combined_worker
  119. {
  120. struct starpu_perfmodel_arch perf_arch; /* in case there are different models of the same arch */
  121. uint32_t worker_mask; /* what is the type of workers ? */
  122. int worker_size;
  123. unsigned memory_node; /* which memory node is associated that worker to ? */
  124. int combined_workerid[STARPU_NMAXWORKERS];
  125. #ifdef STARPU_USE_MP
  126. int count;
  127. starpu_pthread_mutex_t count_mutex;
  128. #endif
  129. #ifdef __GLIBC__
  130. cpu_set_t cpu_set;
  131. #endif /* __GLIBC__ */
  132. #ifdef STARPU_HAVE_HWLOC
  133. hwloc_bitmap_t hwloc_cpu_set;
  134. #endif
  135. };
  136. /* in case a single CPU worker may control multiple
  137. * accelerators (eg. Gordon for n SPUs) */
  138. struct _starpu_worker_set
  139. {
  140. starpu_pthread_mutex_t mutex;
  141. starpu_pthread_t worker_thread; /* the thread which runs the worker */
  142. unsigned nworkers;
  143. unsigned started; /* Only one thread for the whole set */
  144. void *retval;
  145. struct _starpu_worker *workers;
  146. starpu_pthread_cond_t ready_cond; /* indicate when the set is ready */
  147. unsigned set_is_initialized;
  148. };
  149. struct _starpu_machine_topology
  150. {
  151. /* Total number of workers. */
  152. unsigned nworkers;
  153. /* Total number of combined workers. */
  154. unsigned ncombinedworkers;
  155. unsigned nsched_ctxs;
  156. #ifdef STARPU_HAVE_HWLOC
  157. /* Topology as detected by hwloc. */
  158. hwloc_topology_t hwtopology;
  159. #endif
  160. /* custom hwloc tree*/
  161. struct starpu_tree *tree;
  162. /* Total number of CPUs, as detected by the topology code. May
  163. * be different from the actual number of CPU workers.
  164. */
  165. unsigned nhwcpus;
  166. /* Total number of PUs, as detected by the topology code. May
  167. * be different from the actual number of PU workers.
  168. */
  169. unsigned nhwpus;
  170. /* Total number of CUDA devices, as detected. May be different
  171. * from the actual number of CUDA workers.
  172. */
  173. unsigned nhwcudagpus;
  174. /* Total number of OpenCL devices, as detected. May be
  175. * different from the actual number of OpenCL workers.
  176. */
  177. unsigned nhwopenclgpus;
  178. /* Total number of SCC cores, as detected. May be different
  179. * from the actual number of core workers.
  180. */
  181. unsigned nhwscc;
  182. /* Actual number of CPU workers used by StarPU. */
  183. unsigned ncpus;
  184. /* Actual number of CUDA workers used by StarPU. */
  185. unsigned ncudagpus;
  186. /* Actual number of OpenCL workers used by StarPU. */
  187. unsigned nopenclgpus;
  188. /* Actual number of SCC workers used by StarPU. */
  189. unsigned nsccdevices;
  190. /* Topology of MP nodes (mainly MIC and SCC) as well as necessary
  191. * objects to communicate with them. */
  192. unsigned nhwmicdevices;
  193. unsigned nmicdevices;
  194. unsigned nhwmiccores[STARPU_MAXMICDEVS]; // Each MIC node has its set of cores.
  195. unsigned nmiccores[STARPU_MAXMICDEVS];
  196. /* Indicates the successive logical PU identifier that should be used
  197. * to bind the workers. It is either filled according to the
  198. * user's explicit parameters (from starpu_conf) or according
  199. * to the STARPU_WORKERS_CPUID env. variable. Otherwise, a
  200. * round-robin policy is used to distributed the workers over
  201. * the cores.
  202. */
  203. unsigned workers_bindid[STARPU_NMAXWORKERS];
  204. /* Indicates the successive CUDA identifier that should be
  205. * used by the CUDA driver. It is either filled according to
  206. * the user's explicit parameters (from starpu_conf) or
  207. * according to the STARPU_WORKERS_CUDAID env. variable.
  208. * Otherwise, they are taken in ID order.
  209. */
  210. unsigned workers_cuda_gpuid[STARPU_NMAXWORKERS];
  211. /* Indicates the successive OpenCL identifier that should be
  212. * used by the OpenCL driver. It is either filled according
  213. * to the user's explicit parameters (from starpu_conf) or
  214. * according to the STARPU_WORKERS_OPENCLID env. variable.
  215. * Otherwise, they are taken in ID order.
  216. */
  217. unsigned workers_opencl_gpuid[STARPU_NMAXWORKERS];
  218. /** Indicates the successive MIC devices that should be used
  219. * by the MIC driver. It is either filled according to the
  220. * user's explicit parameters (from starpu_conf) or according
  221. * to the STARPU_WORKERS_MICID env. variable. Otherwise, they
  222. * are taken in ID order. */
  223. /* TODO */
  224. /* unsigned workers_mic_deviceid[STARPU_NMAXWORKERS]; */
  225. /* Which SCC(s) do we use ? */
  226. /* Indicates the successive SCC devices that should be used by
  227. * the SCC driver. It is either filled according to the
  228. * user's explicit parameters (from starpu_conf) or according
  229. * to the STARPU_WORKERS_SCCID env. variable. Otherwise, they
  230. * are taken in ID order.
  231. */
  232. unsigned workers_scc_deviceid[STARPU_NMAXWORKERS];
  233. };
  234. struct _starpu_machine_config
  235. {
  236. struct _starpu_machine_topology topology;
  237. #ifdef STARPU_HAVE_HWLOC
  238. int cpu_depth;
  239. int pu_depth;
  240. #endif
  241. /* Where to bind workers ? */
  242. int current_bindid;
  243. /* Which GPU(s) do we use for CUDA ? */
  244. int current_cuda_gpuid;
  245. /* Which GPU(s) do we use for OpenCL ? */
  246. int current_opencl_gpuid;
  247. /* Which MIC do we use? */
  248. int current_mic_deviceid;
  249. /* Which SCC do we use? */
  250. int current_scc_deviceid;
  251. /* Memory node for cpus, if only one */
  252. int cpus_nodeid;
  253. /* Memory node for CUDA, if only one */
  254. int cuda_nodeid;
  255. /* Memory node for OpenCL, if only one */
  256. int opencl_nodeid;
  257. /* Memory node for MIC, if only one */
  258. int mic_nodeid;
  259. /* Memory node for SCC, if only one */
  260. int scc_nodeid;
  261. /* Basic workers : each of this worker is running its own driver and
  262. * can be combined with other basic workers. */
  263. struct _starpu_worker workers[STARPU_NMAXWORKERS];
  264. /* Combined workers: these worker are a combination of basic workers
  265. * that can run parallel tasks together. */
  266. struct _starpu_combined_worker combined_workers[STARPU_NMAX_COMBINEDWORKERS];
  267. /* Translation table from bindid to worker IDs */
  268. struct {
  269. int *workerids;
  270. unsigned nworkers; /* size of workerids */
  271. } *bindid_workers;
  272. unsigned nbindid; /* size of bindid_workers */
  273. /* This bitmask indicates which kinds of worker are available. For
  274. * instance it is possible to test if there is a CUDA worker with
  275. * the result of (worker_mask & STARPU_CUDA). */
  276. uint32_t worker_mask;
  277. /* either the user given configuration passed to starpu_init or a default configuration */
  278. struct starpu_conf conf;
  279. /* this flag is set until the runtime is stopped */
  280. unsigned running;
  281. int disable_kernels;
  282. /* Number of calls to starpu_pause() - calls to starpu_resume(). When >0,
  283. * StarPU should pause. */
  284. int pause_depth;
  285. /* all the sched ctx of the current instance of starpu */
  286. struct _starpu_sched_ctx sched_ctxs[STARPU_NMAX_SCHED_CTXS+1];
  287. /* this flag is set until the application is finished submitting tasks */
  288. unsigned submitting;
  289. int watchdog_ok;
  290. starpu_pthread_mutex_t submitted_mutex;
  291. };
  292. extern struct _starpu_machine_config _starpu_config STARPU_ATTRIBUTE_INTERNAL;
  293. extern int _starpu_keys_initialized STARPU_ATTRIBUTE_INTERNAL;
  294. extern starpu_pthread_key_t _starpu_worker_key STARPU_ATTRIBUTE_INTERNAL;
  295. extern starpu_pthread_key_t _starpu_worker_set_key STARPU_ATTRIBUTE_INTERNAL;
  296. /* Three functions to manage argv, argc */
  297. void _starpu_set_argc_argv(int *argc, char ***argv);
  298. int *_starpu_get_argc();
  299. char ***_starpu_get_argv();
  300. /* Fill conf with environment variables */
  301. void _starpu_conf_check_environment(struct starpu_conf *conf);
  302. /* Called by the driver when it is ready to pause */
  303. void _starpu_may_pause(void);
  304. /* Has starpu_shutdown already been called ? */
  305. static inline unsigned _starpu_machine_is_running(void)
  306. {
  307. unsigned ret;
  308. /* running is just protected by a memory barrier */
  309. STARPU_RMB();
  310. ANNOTATE_HAPPENS_AFTER(&_starpu_config.running);
  311. ret = _starpu_config.running;
  312. ANNOTATE_HAPPENS_BEFORE(&_starpu_config.running);
  313. return ret;
  314. }
  315. /* Check if there is a worker that may execute the task. */
  316. uint32_t _starpu_worker_exists(struct starpu_task *);
  317. /* Is there a worker that can execute CUDA code ? */
  318. uint32_t _starpu_can_submit_cuda_task(void);
  319. /* Is there a worker that can execute CPU code ? */
  320. uint32_t _starpu_can_submit_cpu_task(void);
  321. /* Is there a worker that can execute OpenCL code ? */
  322. uint32_t _starpu_can_submit_opencl_task(void);
  323. /* Is there a worker that can execute OpenCL code ? */
  324. uint32_t _starpu_can_submit_scc_task(void);
  325. /* Check whether there is anything that the worker should do instead of
  326. * sleeping (waiting on something to happen). */
  327. unsigned _starpu_worker_can_block(unsigned memnode, struct _starpu_worker *worker);
  328. /* This function must be called to block a worker. It puts the worker in a
  329. * sleeping state until there is some event that forces the worker to wake up.
  330. * */
  331. void _starpu_block_worker(int workerid, starpu_pthread_cond_t *cond, starpu_pthread_mutex_t *mutex);
  332. /* This function initializes the current driver for the given worker */
  333. void _starpu_driver_start(struct _starpu_worker *worker, unsigned fut_key, unsigned sync);
  334. /* This function initializes the current thread for the given worker */
  335. void _starpu_worker_start(struct _starpu_worker *worker, unsigned fut_key, unsigned sync);
  336. static inline unsigned _starpu_worker_get_count(void)
  337. {
  338. return _starpu_config.topology.nworkers;
  339. }
  340. #define starpu_worker_get_count _starpu_worker_get_count
  341. /* The _starpu_worker structure describes all the state of a StarPU worker.
  342. * This function sets the pthread key which stores a pointer to this structure.
  343. * */
  344. static inline void _starpu_set_local_worker_key(struct _starpu_worker *worker)
  345. {
  346. STARPU_ASSERT(_starpu_keys_initialized);
  347. STARPU_PTHREAD_SETSPECIFIC(_starpu_worker_key, worker);
  348. }
  349. /* Returns the _starpu_worker structure that describes the state of the
  350. * current worker. */
  351. static inline struct _starpu_worker *_starpu_get_local_worker_key(void)
  352. {
  353. if (!_starpu_keys_initialized)
  354. return NULL;
  355. return (struct _starpu_worker *) STARPU_PTHREAD_GETSPECIFIC(_starpu_worker_key);
  356. }
  357. /* The _starpu_worker_set structure describes all the state of a StarPU worker_set.
  358. * This function sets the pthread key which stores a pointer to this structure.
  359. * */
  360. static inline void _starpu_set_local_worker_set_key(struct _starpu_worker_set *worker)
  361. {
  362. STARPU_ASSERT(_starpu_keys_initialized);
  363. STARPU_PTHREAD_SETSPECIFIC(_starpu_worker_set_key, worker);
  364. }
  365. /* Returns the _starpu_worker_set structure that describes the state of the
  366. * current worker_set. */
  367. static inline struct _starpu_worker_set *_starpu_get_local_worker_set_key(void)
  368. {
  369. if (!_starpu_keys_initialized)
  370. return NULL;
  371. return (struct _starpu_worker_set *) STARPU_PTHREAD_GETSPECIFIC(_starpu_worker_set_key);
  372. }
  373. /* Returns the _starpu_worker structure that describes the state of the
  374. * specified worker. */
  375. static inline struct _starpu_worker *_starpu_get_worker_struct(unsigned id)
  376. {
  377. STARPU_ASSERT(id < starpu_worker_get_count());
  378. return &_starpu_config.workers[id];
  379. }
  380. /* Returns the starpu_sched_ctx structure that descriebes the state of the
  381. * specified ctx */
  382. static inline struct _starpu_sched_ctx *_starpu_get_sched_ctx_struct(unsigned id)
  383. {
  384. if(id == STARPU_NMAX_SCHED_CTXS) return NULL;
  385. return &_starpu_config.sched_ctxs[id];
  386. }
  387. struct _starpu_combined_worker *_starpu_get_combined_worker_struct(unsigned id);
  388. int _starpu_is_initialized(void);
  389. /* Returns the structure that describes the overall machine configuration (eg.
  390. * all workers and topology). */
  391. static inline struct _starpu_machine_config *_starpu_get_machine_config(void)
  392. {
  393. return &_starpu_config;
  394. }
  395. /* Return whether kernels should be run (<=0) or not (>0) */
  396. static inline int _starpu_get_disable_kernels(void)
  397. {
  398. return _starpu_config.disable_kernels;
  399. }
  400. /* Retrieve the status which indicates what the worker is currently doing. */
  401. static inline enum _starpu_worker_status _starpu_worker_get_status(int workerid)
  402. {
  403. return _starpu_config.workers[workerid].status;
  404. }
  405. /* Change the status of the worker which indicates what the worker is currently
  406. * doing (eg. executing a callback). */
  407. static inline void _starpu_worker_set_status(int workerid, enum _starpu_worker_status status)
  408. {
  409. _starpu_config.workers[workerid].status = status;
  410. }
  411. /* We keep an initial sched ctx which might be used in case no other ctx is available */
  412. static inline struct _starpu_sched_ctx* _starpu_get_initial_sched_ctx(void)
  413. {
  414. return &_starpu_config.sched_ctxs[STARPU_GLOBAL_SCHED_CTX];
  415. }
  416. int starpu_worker_get_nids_by_type(enum starpu_worker_archtype type, int *workerids, int maxsize);
  417. /* returns workers not belonging to any context, be careful no mutex is used,
  418. the list might not be updated */
  419. int starpu_worker_get_nids_ctx_free_by_type(enum starpu_worker_archtype type, int *workerids, int maxsize);
  420. /* if the current worker has the lock release it */
  421. void _starpu_unlock_mutex_if_prev_locked();
  422. /* if we prev released the lock relock it */
  423. void _starpu_relock_mutex_if_prev_locked();
  424. static inline void _starpu_worker_set_flag_sched_mutex_locked(int workerid, unsigned flag)
  425. {
  426. struct _starpu_worker *w = _starpu_get_worker_struct(workerid);
  427. w->sched_mutex_locked = flag;
  428. }
  429. static inline unsigned _starpu_worker_mutex_is_sched_mutex(int workerid, starpu_pthread_mutex_t *mutex)
  430. {
  431. struct _starpu_worker *w = _starpu_get_worker_struct(workerid);
  432. return &w->sched_mutex == mutex;
  433. }
  434. static inline int _starpu_worker_get_nsched_ctxs(int workerid)
  435. {
  436. return _starpu_config.workers[workerid].nsched_ctxs;
  437. }
  438. /* Get the total number of sched_ctxs created till now */
  439. static inline unsigned _starpu_get_nsched_ctxs(void)
  440. {
  441. return _starpu_config.topology.nsched_ctxs;
  442. }
  443. /* Inlined version when building the core. */
  444. static inline int _starpu_worker_get_id(void)
  445. {
  446. struct _starpu_worker * worker;
  447. worker = _starpu_get_local_worker_key();
  448. if (worker)
  449. {
  450. return worker->workerid;
  451. }
  452. else
  453. {
  454. /* there is no worker associated to that thread, perhaps it is
  455. * a thread from the application or this is some SPU worker */
  456. return -1;
  457. }
  458. }
  459. #define starpu_worker_get_id _starpu_worker_get_id
  460. /* Similar behaviour to starpu_worker_get_id() but fails when called from outside a worker */
  461. static inline unsigned __starpu_worker_get_id_check(const char *f, int l)
  462. {
  463. int id = starpu_worker_get_id();
  464. STARPU_ASSERT_MSG(id>=0, "%s:%u Cannot be called from outside a worker\n", f, l);
  465. return id;
  466. }
  467. #define _starpu_worker_get_id_check(f,l) __starpu_worker_get_id_check(f,l)
  468. #endif // __WORKERS_H__