starpu_sched_ctx.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010 - 2012 INRIA
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #ifndef __STARPU_SCHED_CTX_H__
  17. #define __STARPU_SCHED_CTX_H__
  18. #include <starpu.h>
  19. #ifdef __cplusplus
  20. extern "C"
  21. {
  22. #endif
  23. #ifdef STARPU_DEVEL
  24. # warning rename all objects to start with starpu_sched_ctx
  25. #endif
  26. /* generic structure used by the scheduling contexts to iterate the workers */
  27. struct starpu_sched_ctx_worker_collection
  28. {
  29. /* hidden data structure used to memorize the workers */
  30. void *workerids;
  31. /* the number of workers in the collection */
  32. unsigned nworkers;
  33. /* the current cursor of the collection*/
  34. pthread_key_t cursor_key;
  35. /* the type of structure (WORKER_LIST,...) */
  36. int type;
  37. /* checks if there is another element in collection */
  38. unsigned (*has_next)(struct starpu_sched_ctx_worker_collection *workers);
  39. /* return the next element in the collection */
  40. int (*get_next)(struct starpu_sched_ctx_worker_collection *workers);
  41. /* add a new element in the collection */
  42. int (*add)(struct starpu_sched_ctx_worker_collection *workers, int worker);
  43. /* remove an element from the collection */
  44. int (*remove)(struct starpu_sched_ctx_worker_collection *workers, int worker);
  45. /* initialize the structure */
  46. void* (*init)(struct starpu_sched_ctx_worker_collection *workers);
  47. /* free the structure */
  48. void (*deinit)(struct starpu_sched_ctx_worker_collection *workers);
  49. /* initialize the cursor if there is one */
  50. void (*init_cursor)(struct starpu_sched_ctx_worker_collection *workers);
  51. /* free the cursor if there is one */
  52. void (*deinit_cursor)(struct starpu_sched_ctx_worker_collection *workers);
  53. };
  54. /* types of structures the worker collection can implement */
  55. #define WORKER_LIST 0
  56. struct starpu_performance_counters
  57. {
  58. void (*notify_idle_cycle)(unsigned sched_ctx, int worker, double idle_time);
  59. void (*notify_idle_end)(unsigned sched_ctx, int worker);
  60. void (*notify_pushed_task)(unsigned sched_ctx, int worker);
  61. void (*notify_poped_task)(unsigned sched_ctx, int worker, double flops);
  62. void (*notify_post_exec_hook)(unsigned sched_ctx, int taskid);
  63. void (*notify_submitted_job)(struct starpu_task *task, uint32_t footprint);
  64. };
  65. #ifdef STARPU_USE_SCHED_CTX_HYPERVISOR
  66. void starpu_set_perf_counters(unsigned sched_ctx_id, struct starpu_performance_counters *perf_counters);
  67. void starpu_call_poped_task_cb(int workerid, unsigned sched_ctx_id, double flops);
  68. void starpu_call_pushed_task_cb(int workerid, unsigned sched_ctx_id);
  69. #endif //STARPU_USE_SCHED_CTX_HYPERVISOR
  70. unsigned starpu_sched_ctx_create(const char *policy_name, int *workerids_ctx, int nworkers_ctx, const char *sched_ctx_name);
  71. unsigned starpu_sched_ctx_create_inside_interval(const char *policy_name, const char *sched_name,
  72. int min_ncpus, int max_ncpus, int min_ngpus, int max_ngpus,
  73. unsigned allow_overlap);
  74. void starpu_sched_ctx_delete(unsigned sched_ctx_id, unsigned inheritor_sched_ctx_id);
  75. void starpu_sched_ctx_add_workers(int *workerids_ctx, int nworkers_ctx, unsigned sched_ctx);
  76. void starpu_sched_ctx_remove_workers(int *workerids_ctx, int nworkers_ctx, unsigned sched_ctx);
  77. void starpu_sched_ctx_set_policy_data(unsigned sched_ctx_id, void *policy_data);
  78. void* starpu_sched_ctx_get_policy_data(unsigned sched_ctx);
  79. /* When there is no available task for a worker, StarPU blocks this worker on a
  80. condition variable. This function specifies which condition variable (and the
  81. associated mutex) should be used to block (and to wake up) a worker. Note that
  82. multiple workers may use the same condition variable. For instance, in the case
  83. of a scheduling strategy with a single task queue, the same condition variable
  84. would be used to block and wake up all workers. The initialization method of a
  85. scheduling strategy (init_sched) must call this function once per worker. */
  86. #if !defined(_MSC_VER) && !defined(STARPU_SIMGRID)
  87. #ifdef STARPU_DEVEL
  88. #warning do we really need both starpu_sched_ctx_set_worker_mutex_and_cond and starpu_sched_ctx_init_worker_mutex_and_cond functions
  89. #endif
  90. void starpu_sched_ctx_set_worker_mutex_and_cond(unsigned sched_ctx_id, int workerid, pthread_mutex_t *sched_mutex, pthread_cond_t *sched_cond);
  91. void starpu_sched_ctx_get_worker_mutex_and_cond(unsigned sched_ctx_id, int workerid, pthread_mutex_t **sched_mutex, pthread_cond_t **sched_cond);
  92. #endif
  93. void starpu_sched_ctx_init_worker_mutex_and_cond(unsigned sched_ctx_id, int workerid);
  94. void starpu_sched_ctx_deinit_worker_mutex_and_cond(unsigned sched_ctx_id, int workerid);
  95. struct starpu_sched_ctx_worker_collection* starpu_sched_ctx_create_worker_collection(unsigned sched_ctx_id, int type);
  96. void starpu_sched_ctx_delete_worker_collection(unsigned sched_ctx_id);
  97. struct starpu_sched_ctx_worker_collection* starpu_sched_ctx_get_worker_collection(unsigned sched_ctx_id);
  98. #if !defined(_MSC_VER) && !defined(STARPU_SIMGRID)
  99. pthread_mutex_t* starpu_get_changing_ctx_mutex(unsigned sched_ctx_id);
  100. #endif
  101. void starpu_set_sched_ctx(unsigned *sched_ctx);
  102. unsigned starpu_get_sched_ctx(void);
  103. void starpu_notify_hypervisor_exists(void);
  104. unsigned starpu_check_if_hypervisor_exists(void);
  105. unsigned starpu_sched_ctx_get_nworkers(unsigned sched_ctx);
  106. unsigned starpu_sched_ctx_get_nshared_workers(unsigned sched_ctx_id, unsigned sched_ctx_id2);
  107. unsigned starpu_sched_ctx_contains_worker(int workerid, unsigned sched_ctx_id);
  108. unsigned starpu_sched_ctx_overlapping_ctxs_on_worker(int workerid);
  109. unsigned starpu_is_ctxs_turn(int workerid, unsigned sched_ctx_id);
  110. void starpu_set_turn_to_other_ctx(int workerid, unsigned sched_ctx_id);
  111. double starpu_get_max_time_worker_on_ctx(void);
  112. void starpu_stop_task_submission(void);
  113. void starpu_sched_ctx_set_inheritor(unsigned sched_ctx, unsigned inheritor);
  114. void starpu_sched_ctx_finished_submit(unsigned sched_ctx_id);
  115. #ifdef __cplusplus
  116. }
  117. #endif
  118. #endif /* __STARPU_SCHED_CTX_H__ */