multiformat_data_release.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2012 Inria
  4. * Copyright (C) 2011, 2012, 2013 CNRS
  5. * Copyright (C) 2017 Inria
  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. static int vector[NX];
  22. static starpu_data_handle_t handle;
  23. #define ENTER() do { FPRINTF(stderr, "Entering %s\n", __starpu_func__); } while (0)
  24. extern struct stats global_stats;
  25. static void
  26. register_handle(void)
  27. {
  28. int i;
  29. for (i = 0; i < NX; i++)
  30. vector[i] = i;
  31. starpu_multiformat_data_register(&handle, STARPU_MAIN_RAM, vector, NX, &ops);
  32. }
  33. static void
  34. unregister_handle(void)
  35. {
  36. starpu_data_unregister(handle);
  37. }
  38. #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL) || defined(STARPU_USE_MIC)
  39. static void
  40. create_and_submit(int where)
  41. {
  42. static struct starpu_codelet cl =
  43. {
  44. .modes = { STARPU_RW },
  45. #ifdef STARPU_USE_CUDA
  46. .cuda_funcs = {cuda_func},
  47. #endif
  48. #ifdef STARPU_USE_OPENCL
  49. .opencl_funcs = {opencl_func},
  50. #endif
  51. #ifdef STARPU_USE_MIC
  52. .mic_funcs = {mic_func},
  53. #endif
  54. .nbuffers = 1
  55. };
  56. cl.where = where;
  57. struct starpu_task *task = starpu_task_create();
  58. task->cl = &cl;
  59. task->handles[0] = handle;
  60. /* We need to be sure the data has been copied to the GPU at the end
  61. * of this function */
  62. task->synchronous = 1;
  63. if (starpu_task_submit(task) == -ENODEV)
  64. exit(STARPU_TEST_SKIPPED);
  65. }
  66. #endif
  67. static int
  68. test(void)
  69. {
  70. struct stats expected_stats;
  71. memset(&expected_stats, 0, sizeof(expected_stats));
  72. #ifdef STARPU_USE_CUDA
  73. create_and_submit(STARPU_CUDA);
  74. starpu_data_acquire(handle, STARPU_RW);
  75. expected_stats.cuda = 1;
  76. expected_stats.cpu_to_cuda = 1;
  77. expected_stats.cuda_to_cpu = 1;
  78. starpu_data_release(handle);
  79. if (compare_stats(&global_stats, &expected_stats) != 0)
  80. {
  81. FPRINTF(stderr, "CUDA failed\n");
  82. print_stats(&global_stats);
  83. FPRINTF(stderr ,"\n");
  84. print_stats(&expected_stats);
  85. return -ENODEV;
  86. }
  87. #endif /* !STARPU_USE_CUDA */
  88. #ifdef STARPU_USE_OPENCL
  89. create_and_submit(STARPU_OPENCL);
  90. starpu_data_acquire(handle, STARPU_RW);
  91. expected_stats.opencl = 1;
  92. expected_stats.cpu_to_opencl = 1;
  93. expected_stats.opencl_to_cpu = 1;
  94. starpu_data_release(handle);
  95. if (compare_stats(&global_stats, &expected_stats) != 0)
  96. {
  97. FPRINTF(stderr, "OPENCL failed\n");
  98. print_stats(&global_stats);
  99. FPRINTF(stderr ,"\n");
  100. print_stats(&expected_stats);
  101. return -ENODEV;
  102. }
  103. #endif /* !STARPU_USE_OPENCL */
  104. #ifdef STARPU_USE_MIC
  105. create_and_submit(STARPU_MIC);
  106. starpu_data_acquire(handle, STARPU_RW);
  107. expected_stats.mic = 1;
  108. expected_stats.cpu_to_mic = 1;
  109. expected_stats.mic_to_cpu = 1;
  110. starpu_data_release(handle);
  111. if (compare_stats(&global_stats, &expected_stats) != 0)
  112. {
  113. FPRINTF(stderr, "MIC failed\n");
  114. print_stats(&global_stats);
  115. FPRINTF(stderr ,"\n");
  116. print_stats(&expected_stats);
  117. return -ENODEV;
  118. }
  119. #endif /* !STARPU_USE_CUDA */
  120. return 0;
  121. }
  122. int
  123. main(int argc, char **argv)
  124. {
  125. #ifdef STARPU_USE_CPU
  126. int ret;
  127. struct starpu_conf conf;
  128. starpu_conf_init(&conf);
  129. conf.ncuda = 1;
  130. conf.nopencl = 1;
  131. conf.nmic = 1;
  132. memset(&global_stats, 0, sizeof(global_stats));
  133. ret = starpu_initialize(&conf, &argc, &argv);
  134. if (ret == -ENODEV || starpu_cpu_worker_get_count() == 0) return STARPU_TEST_SKIPPED;
  135. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  136. register_handle();
  137. int err = test();
  138. unregister_handle();
  139. starpu_shutdown();
  140. switch (err)
  141. {
  142. case -ENODEV:
  143. return STARPU_TEST_SKIPPED;
  144. case 0:
  145. return EXIT_SUCCESS;
  146. default:
  147. return EXIT_FAILURE;
  148. }
  149. #else /* ! STARPU_USE_CPU */
  150. /* Without the CPU, there is no point in using the multiformat
  151. * interface, so this test is pointless. */
  152. return STARPU_TEST_SKIPPED;
  153. #endif
  154. }