multiformat_worker.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012 INRIA
  4. *
  5. * StarPU 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. * StarPU 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 "generic.h"
  18. #include "../../../../helper.h"
  19. #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL) || defined(STARPU_USE_MIC)
  20. extern struct stats global_stats;
  21. static int vector[NX]; static starpu_data_handle_t handle;
  22. #endif
  23. #ifdef STARPU_USE_CUDA
  24. static int ncuda;
  25. static int cuda_worker;
  26. #endif
  27. #ifdef STARPU_USE_OPENCL
  28. static int nopencl;
  29. static int opencl_worker;
  30. #endif
  31. #ifdef STARPU_USE_MIC
  32. static int nmic;
  33. static int mic_worker;
  34. #endif
  35. #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL) || defined(STARPU_USE_MIC)
  36. static struct starpu_codelet cl =
  37. {
  38. .modes = { STARPU_RW },
  39. #ifdef STARPU_USE_CUDA
  40. .cuda_funcs = { cuda_func },
  41. #endif
  42. #ifdef STARPU_USE_OPENCL
  43. .opencl_funcs = { opencl_func },
  44. #endif
  45. #ifdef STARPU_USE_MIC
  46. .mic_funcs = {mic_func},
  47. #endif
  48. .nbuffers = 1,
  49. };
  50. static void
  51. register_handle(void)
  52. {
  53. int i;
  54. for (i = 0; i < NX; i++)
  55. vector[i] = i;
  56. starpu_multiformat_data_register(&handle, STARPU_MAIN_RAM, vector, NX, &ops);
  57. }
  58. static void
  59. unregister_handle(void)
  60. {
  61. starpu_data_unregister(handle);
  62. }
  63. static int
  64. create_and_submit_tasks(void)
  65. {
  66. struct starpu_task *task;
  67. task = starpu_task_create();
  68. task->cl = &cl;
  69. task->handles[0] = handle;
  70. task->execute_on_a_specific_worker = 1;
  71. #ifdef STARPU_USE_CUDA
  72. if (ncuda > 0)
  73. {
  74. task->workerid = cuda_worker;
  75. }
  76. else
  77. #endif
  78. #ifdef STARPU_USE_OPENCL
  79. if (nopencl > 0)
  80. {
  81. task->workerid = opencl_worker;
  82. }
  83. else
  84. #endif
  85. #ifdef STARPU_USE_MIC
  86. if (nmic > 0)
  87. {
  88. task->workerid = mic_worker;
  89. }
  90. else
  91. #endif
  92. {
  93. return -ENODEV;
  94. }
  95. return starpu_task_submit(task);
  96. }
  97. #endif
  98. int
  99. main(int argc, char **argv)
  100. {
  101. #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL) || defined(STARPU_USE_MIC)
  102. int err;
  103. err = starpu_initialize(NULL, &argc, &argv);
  104. if (err == -ENODEV)
  105. goto enodev;
  106. #ifdef STARPU_USE_CUDA
  107. ncuda = starpu_worker_get_ids_by_type(STARPU_CUDA_WORKER,
  108. &cuda_worker, 1);
  109. if (ncuda < 0)
  110. ncuda = 1;
  111. #endif
  112. #ifdef STARPU_USE_OPENCL
  113. nopencl = starpu_worker_get_ids_by_type(STARPU_OPENCL_WORKER,
  114. &opencl_worker, 1);
  115. if (nopencl < 0)
  116. nopencl = 1;
  117. #endif
  118. #ifdef STARPU_USE_MIC
  119. nmic = starpu_worker_get_ids_by_type(STARPU_MIC_WORKER,
  120. &mic_worker, 1);
  121. if(nmic < 0)
  122. nmic = 1;
  123. #endif
  124. reset_stats(&global_stats);
  125. register_handle();
  126. err = create_and_submit_tasks();
  127. unregister_handle();
  128. starpu_shutdown();
  129. if (err == -ENODEV)
  130. goto enodev;
  131. #if defined(STARPU_USE_CUDA)
  132. if (global_stats.cuda == 1)
  133. {
  134. if (global_stats.cpu_to_cuda == 1 &&
  135. global_stats.cuda_to_cpu == 1)
  136. return EXIT_SUCCESS;
  137. else
  138. return EXIT_FAILURE;
  139. }
  140. #endif /* !STARPU_USE_CUDA */
  141. #if defined(STARPU_USE_OPENCL)
  142. if (global_stats.opencl == 1)
  143. {
  144. if (global_stats.cpu_to_opencl == 1 &&
  145. global_stats.opencl_to_cpu == 1)
  146. return EXIT_SUCCESS;
  147. else
  148. return EXIT_FAILURE;
  149. }
  150. #endif /* !STARPU_USE_OPENCL */
  151. #ifdef STARPU_USE_MIC
  152. if (global_stats.mic == 1)
  153. {
  154. if (global_stats.cpu_to_mic == 1 &&
  155. global_stats.mic_to_cpu == 1)
  156. return EXIT_SUCCESS;
  157. else
  158. return EXIT_FAILURE;
  159. }
  160. #endif
  161. /* We should not get here */
  162. return EXIT_FAILURE;
  163. enodev:
  164. #endif
  165. return STARPU_TEST_SKIPPED;
  166. }