multiformat_worker.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012,2013 Inria
  4. * Copyright (C) 2012,2013,2016,2017 CNRS
  5. * Copyright (C) 2013,2014 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu.h>
  19. #include "generic.h"
  20. #include "../../../../helper.h"
  21. #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL) || defined(STARPU_USE_MIC)
  22. extern struct stats global_stats;
  23. static int vector[NX]; static starpu_data_handle_t handle;
  24. #endif
  25. #ifdef STARPU_USE_CUDA
  26. static int ncuda;
  27. static int cuda_worker;
  28. #endif
  29. #ifdef STARPU_USE_OPENCL
  30. static int nopencl;
  31. static int opencl_worker;
  32. #endif
  33. #ifdef STARPU_USE_MIC
  34. static int nmic;
  35. static int mic_worker;
  36. #endif
  37. #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL) || defined(STARPU_USE_MIC)
  38. static struct starpu_codelet cl =
  39. {
  40. .modes = { STARPU_RW },
  41. #ifdef STARPU_USE_CUDA
  42. .cuda_funcs = { cuda_func },
  43. #endif
  44. #ifdef STARPU_USE_OPENCL
  45. .opencl_funcs = { opencl_func },
  46. #endif
  47. #ifdef STARPU_USE_MIC
  48. .mic_funcs = {mic_func},
  49. #endif
  50. .nbuffers = 1,
  51. };
  52. static void
  53. register_handle(void)
  54. {
  55. int i;
  56. for (i = 0; i < NX; i++)
  57. vector[i] = i;
  58. starpu_multiformat_data_register(&handle, STARPU_MAIN_RAM, vector, NX, &ops);
  59. }
  60. static void
  61. unregister_handle(void)
  62. {
  63. starpu_data_unregister(handle);
  64. }
  65. static int
  66. create_and_submit_tasks(void)
  67. {
  68. struct starpu_task *task;
  69. task = starpu_task_create();
  70. task->cl = &cl;
  71. task->handles[0] = handle;
  72. task->execute_on_a_specific_worker = 1;
  73. #ifdef STARPU_USE_CUDA
  74. if (ncuda > 0)
  75. {
  76. task->workerid = cuda_worker;
  77. }
  78. else
  79. #endif
  80. #ifdef STARPU_USE_OPENCL
  81. if (nopencl > 0)
  82. {
  83. task->workerid = opencl_worker;
  84. }
  85. else
  86. #endif
  87. #ifdef STARPU_USE_MIC
  88. if (nmic > 0)
  89. {
  90. task->workerid = mic_worker;
  91. }
  92. else
  93. #endif
  94. {
  95. task->destroy = 0;
  96. starpu_task_destroy(task);
  97. return -ENODEV;
  98. }
  99. return starpu_task_submit(task);
  100. }
  101. #endif
  102. int
  103. main(int argc, char **argv)
  104. {
  105. #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL) || defined(STARPU_USE_MIC)
  106. int err;
  107. err = starpu_initialize(NULL, &argc, &argv);
  108. if (err == -ENODEV)
  109. goto enodev;
  110. #ifdef STARPU_USE_CUDA
  111. ncuda = starpu_worker_get_ids_by_type(STARPU_CUDA_WORKER,
  112. &cuda_worker, 1);
  113. if (ncuda < 0)
  114. ncuda = 1;
  115. #endif
  116. #ifdef STARPU_USE_OPENCL
  117. nopencl = starpu_worker_get_ids_by_type(STARPU_OPENCL_WORKER,
  118. &opencl_worker, 1);
  119. if (nopencl < 0)
  120. nopencl = 1;
  121. #endif
  122. #ifdef STARPU_USE_MIC
  123. nmic = starpu_worker_get_ids_by_type(STARPU_MIC_WORKER,
  124. &mic_worker, 1);
  125. if(nmic < 0)
  126. nmic = 1;
  127. #endif
  128. reset_stats(&global_stats);
  129. register_handle();
  130. err = create_and_submit_tasks();
  131. unregister_handle();
  132. starpu_shutdown();
  133. if (err == -ENODEV)
  134. goto enodev;
  135. #if defined(STARPU_USE_CUDA)
  136. if (global_stats.cuda == 1)
  137. {
  138. if (global_stats.cpu_to_cuda == 1 &&
  139. global_stats.cuda_to_cpu == 1)
  140. return EXIT_SUCCESS;
  141. else
  142. return EXIT_FAILURE;
  143. }
  144. #endif /* !STARPU_USE_CUDA */
  145. #if defined(STARPU_USE_OPENCL)
  146. if (global_stats.opencl == 1)
  147. {
  148. if (global_stats.cpu_to_opencl == 1 &&
  149. global_stats.opencl_to_cpu == 1)
  150. return EXIT_SUCCESS;
  151. else
  152. return EXIT_FAILURE;
  153. }
  154. #endif /* !STARPU_USE_OPENCL */
  155. #ifdef STARPU_USE_MIC
  156. if (global_stats.mic == 1)
  157. {
  158. if (global_stats.cpu_to_mic == 1 &&
  159. global_stats.mic_to_cpu == 1)
  160. return EXIT_SUCCESS;
  161. else
  162. return EXIT_FAILURE;
  163. }
  164. #endif
  165. /* We should not get here */
  166. return EXIT_FAILURE;
  167. enodev:
  168. #endif
  169. return STARPU_TEST_SKIPPED;
  170. }