multiformat_data_release.c 4.1 KB

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