multiformat_worker.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. task->destroy = 0;
  94. starpu_task_destroy(task);
  95. return -ENODEV;
  96. }
  97. return starpu_task_submit(task);
  98. }
  99. #endif
  100. int
  101. main(int argc, char **argv)
  102. {
  103. #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL) || defined(STARPU_USE_MIC)
  104. int err;
  105. err = starpu_initialize(NULL, &argc, &argv);
  106. if (err == -ENODEV)
  107. goto enodev;
  108. #ifdef STARPU_USE_CUDA
  109. ncuda = starpu_worker_get_ids_by_type(STARPU_CUDA_WORKER,
  110. &cuda_worker, 1);
  111. if (ncuda < 0)
  112. ncuda = 1;
  113. #endif
  114. #ifdef STARPU_USE_OPENCL
  115. nopencl = starpu_worker_get_ids_by_type(STARPU_OPENCL_WORKER,
  116. &opencl_worker, 1);
  117. if (nopencl < 0)
  118. nopencl = 1;
  119. #endif
  120. #ifdef STARPU_USE_MIC
  121. nmic = starpu_worker_get_ids_by_type(STARPU_MIC_WORKER,
  122. &mic_worker, 1);
  123. if(nmic < 0)
  124. nmic = 1;
  125. #endif
  126. reset_stats(&global_stats);
  127. register_handle();
  128. err = create_and_submit_tasks();
  129. unregister_handle();
  130. starpu_shutdown();
  131. if (err == -ENODEV)
  132. goto enodev;
  133. #if defined(STARPU_USE_CUDA)
  134. if (global_stats.cuda == 1)
  135. {
  136. if (global_stats.cpu_to_cuda == 1 &&
  137. global_stats.cuda_to_cpu == 1)
  138. return EXIT_SUCCESS;
  139. else
  140. return EXIT_FAILURE;
  141. }
  142. #endif /* !STARPU_USE_CUDA */
  143. #if defined(STARPU_USE_OPENCL)
  144. if (global_stats.opencl == 1)
  145. {
  146. if (global_stats.cpu_to_opencl == 1 &&
  147. global_stats.opencl_to_cpu == 1)
  148. return EXIT_SUCCESS;
  149. else
  150. return EXIT_FAILURE;
  151. }
  152. #endif /* !STARPU_USE_OPENCL */
  153. #ifdef STARPU_USE_MIC
  154. if (global_stats.mic == 1)
  155. {
  156. if (global_stats.cpu_to_mic == 1 &&
  157. global_stats.mic_to_cpu == 1)
  158. return EXIT_SUCCESS;
  159. else
  160. return EXIT_FAILURE;
  161. }
  162. #endif
  163. /* We should not get here */
  164. return EXIT_FAILURE;
  165. enodev:
  166. #endif
  167. return STARPU_TEST_SKIPPED;
  168. }