dummy_sched.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <pthread.h>
  18. #include <starpu.h>
  19. #define NTASKS 32000
  20. struct starpu_task_list sched_list;
  21. static pthread_cond_t sched_cond;
  22. static pthread_mutex_t sched_mutex;
  23. static void init_dummy_sched(struct starpu_machine_topology_s *topology,
  24. struct starpu_sched_policy_s *policy)
  25. {
  26. /* Create a linked-list of tasks and a condition variable to protect it */
  27. starpu_task_list_init(&sched_list);
  28. pthread_mutex_init(&sched_mutex, NULL);
  29. pthread_cond_init(&sched_cond, NULL);
  30. unsigned workerid;
  31. for (workerid = 0; workerid < topology->nworkers; workerid++)
  32. starpu_worker_set_sched_condition(workerid, &sched_cond, &sched_mutex);
  33. fprintf(stderr, "Initialising Dummy scheduler\n");
  34. }
  35. static void deinit_dummy_sched(struct starpu_machine_topology_s *topology,
  36. struct starpu_sched_policy_s *policy)
  37. {
  38. STARPU_ASSERT(starpu_task_list_empty(&sched_list));
  39. pthread_cond_destroy(&sched_cond);
  40. pthread_mutex_destroy(&sched_mutex);
  41. fprintf(stderr, "Destroying Dummy scheduler\n");
  42. }
  43. static int push_task_dummy(struct starpu_task *task)
  44. {
  45. pthread_mutex_lock(&sched_mutex);
  46. starpu_task_list_push_front(&sched_list, task);
  47. pthread_cond_signal(&sched_cond);
  48. pthread_mutex_unlock(&sched_mutex);
  49. return 0;
  50. }
  51. /* The mutex associated to the calling worker is already taken by StarPU */
  52. static struct starpu_task *pop_task_dummy(void)
  53. {
  54. /* NB: In this simplistic strategy, we assume that all workers are able
  55. * to execute all tasks, otherwise, it would have been necessary to go
  56. * through the entire list until we find a task that is executable from
  57. * the calling worker. So we just take the head of the list and give it
  58. * to the worker. */
  59. return starpu_task_list_pop_back(&sched_list);
  60. }
  61. static struct starpu_sched_policy_s dummy_sched_policy = {
  62. .init_sched = init_dummy_sched,
  63. .deinit_sched = deinit_dummy_sched,
  64. .push_task = push_task_dummy,
  65. .push_prio_task = NULL,
  66. .pop_task = pop_task_dummy,
  67. .post_exec_hook = NULL,
  68. .pop_every_task = NULL,
  69. .policy_name = "dummy",
  70. .policy_description = "dummy scheduling strategy"
  71. };
  72. static struct starpu_conf conf = {
  73. .sched_policy_name = NULL,
  74. .sched_policy = &dummy_sched_policy,
  75. .ncpus = -1,
  76. .ncuda = -1,
  77. .nopencl = -1,
  78. .nspus = -1,
  79. .use_explicit_workers_bindid = 0,
  80. .use_explicit_workers_cuda_gpuid = 0,
  81. .use_explicit_workers_opencl_gpuid = 0,
  82. .calibrate = 0
  83. };
  84. static void dummy_func(void *descr[] __attribute__ ((unused)), void *arg __attribute__ ((unused)))
  85. {
  86. }
  87. static starpu_codelet dummy_codelet =
  88. {
  89. .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL,
  90. .cpu_func = dummy_func,
  91. .cuda_func = dummy_func,
  92. .opencl_func = dummy_func,
  93. .model = NULL,
  94. .nbuffers = 0
  95. };
  96. int main(int argc, char **argv)
  97. {
  98. starpu_init(&conf);
  99. unsigned i;
  100. for (i = 0; i < NTASKS; i++)
  101. {
  102. struct starpu_task *task = starpu_task_create();
  103. task->cl = &dummy_codelet;
  104. task->cl_arg = NULL;
  105. starpu_task_submit(task);
  106. }
  107. starpu_task_wait_for_all();
  108. starpu_shutdown();
  109. return 0;
  110. }