dummy_sched.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #include <pthread.h>
  17. #include <starpu.h>
  18. #define NTASKS 32000
  19. struct starpu_task_list sched_list;
  20. static pthread_cond_t sched_cond;
  21. static pthread_mutex_t sched_mutex;
  22. static void init_dummy_sched(struct starpu_machine_topology_s *topology,
  23. struct starpu_sched_policy_s *policy)
  24. {
  25. /* Create a linked-list of tasks and a condition variable to protect it */
  26. starpu_task_list_init(&sched_list);
  27. pthread_mutex_init(&sched_mutex, NULL);
  28. pthread_cond_init(&sched_cond, NULL);
  29. unsigned workerid;
  30. for (workerid = 0; workerid < topology->nworkers; workerid++)
  31. starpu_worker_set_sched_condition(workerid, &sched_cond, &sched_mutex);
  32. }
  33. static void deinit_dummy_sched(struct starpu_machine_topology_s *topology,
  34. struct starpu_sched_policy_s *policy)
  35. {
  36. STARPU_ASSERT(starpu_task_list_empty(&sched_list));
  37. pthread_cond_destroy(&sched_cond);
  38. pthread_mutex_destroy(&sched_mutex);
  39. }
  40. static int push_task_dummy(struct starpu_task *task)
  41. {
  42. pthread_mutex_lock(&sched_mutex);
  43. starpu_task_list_push_front(&sched_list, task);
  44. pthread_cond_signal(&sched_cond);
  45. pthread_mutex_unlock(&sched_mutex);
  46. }
  47. /* The mutex associated to the calling worker is already taken by StarPU */
  48. static struct starpu_task *pop_task_dummy(void)
  49. {
  50. /* NB: In this simplistic strategy, we assume that all workers are able
  51. * to execute all tasks, otherwise, it would have been necessary to go
  52. * through the entire list until we find a task that is executable from
  53. * the calling worker. So we just take the head of the list and give it
  54. * to the worker. */
  55. return starpu_task_list_pop_back(&sched_list);
  56. }
  57. static struct starpu_sched_policy_s dummy_sched_policy = {
  58. .init_sched = init_dummy_sched,
  59. .deinit_sched = deinit_dummy_sched,
  60. .push_task = push_task_dummy,
  61. .pop_task = pop_task_dummy,
  62. .pop_every_task = NULL,
  63. .policy_name = "dummy",
  64. .policy_description = "dummy scheduling strategy"
  65. };
  66. static struct starpu_conf conf = {
  67. .sched_policy_name = NULL,
  68. .sched_policy = &dummy_sched_policy,
  69. .ncpus = -1,
  70. .ncuda = -1,
  71. .nopencl = -1,
  72. .nspus = -1,
  73. .use_explicit_workers_bindid = 0,
  74. .use_explicit_workers_cuda_gpuid = 0,
  75. .use_explicit_workers_opencl_gpuid = 0,
  76. .calibrate = 0
  77. };
  78. static void dummy_func(void *descr[] __attribute__ ((unused)), void *arg __attribute__ ((unused)))
  79. {
  80. }
  81. static starpu_codelet dummy_codelet =
  82. {
  83. .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL,
  84. .cpu_func = dummy_func,
  85. .cuda_func = dummy_func,
  86. .opencl_func = dummy_func,
  87. .model = NULL,
  88. .nbuffers = 0
  89. };
  90. int main(int argc, char **argv)
  91. {
  92. starpu_init(&conf);
  93. unsigned i;
  94. for (i = 0; i < NTASKS; i++)
  95. {
  96. struct starpu_task *task = starpu_task_create();
  97. task->cl = &dummy_codelet;
  98. task->cl_arg = NULL;
  99. starpu_task_submit(task);
  100. }
  101. starpu_task_wait_for_all();
  102. starpu_shutdown();
  103. return 0;
  104. }