starpu_scheduler.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * StarPU
  3. * Copyright (C) Université Bordeaux 1, CNRS 2008-2010 (see AUTHORS file)
  4. *
  5. * This program 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. * This program 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_SCHEDULER_H__
  17. #define __STARPU_SCHEDULER_H__
  18. #include <starpu.h>
  19. #include <starpu_config.h>
  20. #include <pthread.h>
  21. #ifdef STARPU_HAVE_HWLOC
  22. #include <hwloc.h>
  23. #endif
  24. struct starpu_task;
  25. struct starpu_machine_topology_s {
  26. unsigned nworkers;
  27. #ifdef STARPU_HAVE_HWLOC
  28. hwloc_topology_t hwtopology;
  29. #else
  30. /* We maintain ABI compatibility with and without hwloc */
  31. void *dummy;
  32. #endif
  33. unsigned nhwcpus;
  34. unsigned nhwcudagpus;
  35. unsigned nhwopenclgpus;
  36. unsigned ncpus;
  37. unsigned ncudagpus;
  38. unsigned nopenclgpus;
  39. unsigned ngordon_spus;
  40. /* Where to bind workers ? */
  41. unsigned workers_bindid[STARPU_NMAXWORKERS];
  42. /* Which GPU(s) do we use for CUDA ? */
  43. unsigned workers_cuda_gpuid[STARPU_NMAXWORKERS];
  44. /* Which GPU(s) do we use for OpenCL ? */
  45. unsigned workers_opencl_gpuid[STARPU_NMAXWORKERS];
  46. };
  47. /* This structure contains all the methods that implement a scheduling policy.
  48. * An application may specify which scheduling strategy in the "sched_policy"
  49. * field of the starpu_conf structure passed to the starpu_init function. */
  50. struct starpu_sched_policy_s {
  51. /* Initialize the scheduling policy. */
  52. void (*init_sched)(struct starpu_machine_topology_s *, struct starpu_sched_policy_s *);
  53. /* Cleanup the scheduling policy. */
  54. void (*deinit_sched)(struct starpu_machine_topology_s *, struct starpu_sched_policy_s *);
  55. /* Insert a task into the scheduler. */
  56. int (*push_task)(struct starpu_task *);
  57. /* Insert a priority task into the scheduler. */
  58. int (*push_prio_task)(struct starpu_task *);
  59. /* Get a task from the scheduler. The mutex associated to the worker is
  60. * already taken when this method is called. */
  61. struct starpu_task *(*pop_task)(void);
  62. /* Remove all available tasks from the scheduler (tasks are chained by
  63. * the means of the prev and next fields of the starpu_task
  64. * structure). The mutex associated to the worker is already taken
  65. * when this method is called. */
  66. struct starpu_task *(*pop_every_task)(void);
  67. /* This method is called every time a task has been executed. (optionnal) */
  68. void (*post_exec_hook)(struct starpu_task *);
  69. /* Name of the policy (optionnal) */
  70. const char *policy_name;
  71. /* Description of the policy (optionnal) */
  72. const char *policy_description;
  73. };
  74. /* When there is no available task for a worker, StarPU blocks this worker on a
  75. condition variable. This function specifies which condition variable (and the
  76. associated mutex) should be used to block (and to wake up) a worker. Note that
  77. multiple workers may use the same condition variable. For instance, in the case
  78. of a scheduling strategy with a single task queue, the same condition variable
  79. would be used to block and wake up all workers. The initialization method of a
  80. scheduling strategy (init_sched) must call this function once per worker. */
  81. void starpu_worker_set_sched_condition(int workerid, pthread_cond_t *sched_cond, pthread_mutex_t *sched_mutex);
  82. /* Provided for legacy reasons */
  83. #define STARPU_MIN_PRIO (starpu_sched_get_min_priority())
  84. #define STARPU_MAX_PRIO (starpu_sched_get_max_priority())
  85. /* By convention, the default priority level should be 0 so that we can
  86. * statically allocate tasks with a default priority. */
  87. #define STARPU_DEFAULT_PRIO 0
  88. int starpu_sched_get_min_priority(void);
  89. int starpu_sched_get_max_priority(void);
  90. void starpu_sched_set_min_priority(int min_prio);
  91. void starpu_sched_set_max_priority(int max_prio);
  92. #endif // __STARPU_SCHEDULER_H__