explicit_combined_worker.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 <starpu.h>
  17. #include <limits.h>
  18. #define N 1000
  19. #define VECTORSIZE 1024
  20. static pthread_mutex_t mutex;
  21. static pthread_cond_t cond;
  22. static unsigned finished = 0;
  23. static unsigned cnt;
  24. starpu_data_handle v_handle;
  25. static unsigned *v;
  26. static void codelet_null(void *descr[], __attribute__ ((unused)) void *_args)
  27. {
  28. int worker_size = starpu_combined_worker_get_size();
  29. assert(worker_size > 0);
  30. usleep(1000/worker_size);
  31. #if 0
  32. int id = starpu_worker_get_id();
  33. int combined_id = starpu_combined_worker_get_id();
  34. fprintf(stderr, "worker id %d - combined id %d - worker size %d\n", id, combined_id, worker_size);
  35. #endif
  36. }
  37. static starpu_codelet cl = {
  38. .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL,
  39. .type = STARPU_FORKJOIN,
  40. .max_parallelism = INT_MAX,
  41. .cpu_func = codelet_null,
  42. .cuda_func = codelet_null,
  43. .opencl_func = codelet_null,
  44. .nbuffers = 1
  45. };
  46. int main(int argc, char **argv)
  47. {
  48. struct starpu_conf conf = {
  49. .sched_policy_name = "pheft",
  50. .ncpus = -1,
  51. .ncuda = -1,
  52. .nopencl = -1,
  53. .nspus = -1,
  54. .use_explicit_workers_bindid = 0,
  55. .use_explicit_workers_cuda_gpuid = 0,
  56. .use_explicit_workers_opencl_gpuid = 0,
  57. .calibrate = -1
  58. };
  59. starpu_init(NULL);
  60. starpu_data_malloc_pinned_if_possible((void **)&v, VECTORSIZE*sizeof(unsigned));
  61. starpu_vector_data_register(&v_handle, 0, (uintptr_t)v, VECTORSIZE, sizeof(unsigned));
  62. unsigned nworker = starpu_worker_get_count() + starpu_combined_worker_get_count();
  63. cnt = nworker*N;
  64. unsigned iter, worker;
  65. for (iter = 0; iter < N; iter++)
  66. {
  67. for (worker = 0; worker < nworker; worker++)
  68. {
  69. /* execute a task on that worker */
  70. struct starpu_task *task = starpu_task_create();
  71. task->cl = &cl;
  72. task->buffers[0].handle = v_handle;
  73. task->buffers[0].mode = STARPU_R;
  74. task->execute_on_a_specific_worker = 1;
  75. task->workerid = worker;
  76. int ret = starpu_task_submit(task);
  77. if (ret == -ENODEV)
  78. goto enodev;
  79. }
  80. }
  81. starpu_task_wait_for_all();
  82. starpu_shutdown();
  83. return 0;
  84. enodev:
  85. fprintf(stderr, "WARNING: No one can execute this task\n");
  86. /* yes, we do not perform the computation but we did detect that no one
  87. * could perform the kernel, so this is not an error from StarPU */
  88. return 0;
  89. }