multiformat_data_release.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2012 INRIA
  4. * Copyright (C) 2011, 2012, 2013 CNRS
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. #include "generic.h"
  19. #include "../../../../helper.h"
  20. static int vector[NX];
  21. static starpu_data_handle_t handle;
  22. #define ENTER() do { FPRINTF(stderr, "Entering %s\n", __starpu_func__); } while (0)
  23. extern struct stats global_stats;
  24. static void
  25. register_handle(void)
  26. {
  27. int i;
  28. for (i = 0; i < NX; i++)
  29. vector[i] = i;
  30. starpu_multiformat_data_register(&handle, STARPU_MAIN_RAM, vector, NX, &ops);
  31. }
  32. static void
  33. unregister_handle(void)
  34. {
  35. starpu_data_unregister(handle);
  36. }
  37. #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL) || defined(STARPU_USE_MIC)
  38. static void
  39. create_and_submit(int where)
  40. {
  41. static struct starpu_codelet cl =
  42. {
  43. .modes = { STARPU_RW },
  44. #ifdef STARPU_USE_CUDA
  45. .cuda_funcs = {cuda_func},
  46. #endif
  47. #ifdef STARPU_USE_OPENCL
  48. .opencl_funcs = {opencl_func},
  49. #endif
  50. #ifdef STARPU_USE_MIC
  51. .mic_funcs = {mic_func},
  52. #endif
  53. .nbuffers = 1
  54. };
  55. cl.where = where;
  56. struct starpu_task *task = starpu_task_create();
  57. task->cl = &cl;
  58. task->handles[0] = handle;
  59. /* We need to be sure the data has been copied to the GPU at the end
  60. * of this function */
  61. task->synchronous = 1;
  62. if (starpu_task_submit(task) == -ENODEV)
  63. exit(STARPU_TEST_SKIPPED);
  64. }
  65. #endif
  66. static int
  67. test(void)
  68. {
  69. struct stats expected_stats;
  70. memset(&expected_stats, 0, sizeof(expected_stats));
  71. #ifdef STARPU_USE_CUDA
  72. create_and_submit(STARPU_CUDA);
  73. starpu_data_acquire(handle, STARPU_RW);
  74. expected_stats.cuda = 1;
  75. expected_stats.cpu_to_cuda = 1;
  76. expected_stats.cuda_to_cpu = 1;
  77. starpu_data_release(handle);
  78. if (compare_stats(&global_stats, &expected_stats) != 0)
  79. {
  80. FPRINTF(stderr, "CUDA failed\n");
  81. print_stats(&global_stats);
  82. FPRINTF(stderr ,"\n");
  83. print_stats(&expected_stats);
  84. return -ENODEV;
  85. }
  86. #endif /* !STARPU_USE_CUDA */
  87. #ifdef STARPU_USE_OPENCL
  88. create_and_submit(STARPU_OPENCL);
  89. starpu_data_acquire(handle, STARPU_RW);
  90. expected_stats.opencl = 1;
  91. expected_stats.cpu_to_opencl = 1;
  92. expected_stats.opencl_to_cpu = 1;
  93. starpu_data_release(handle);
  94. if (compare_stats(&global_stats, &expected_stats) != 0)
  95. {
  96. FPRINTF(stderr, "OPENCL failed\n");
  97. print_stats(&global_stats);
  98. FPRINTF(stderr ,"\n");
  99. print_stats(&expected_stats);
  100. return -ENODEV;
  101. }
  102. #endif /* !STARPU_USE_OPENCL */
  103. #ifdef STARPU_USE_MIC
  104. create_and_submit(STARPU_MIC);
  105. starpu_data_acquire(handle, STARPU_RW);
  106. expected_stats.mic = 1;
  107. expected_stats.cpu_to_mic = 1;
  108. expected_stats.mic_to_cpu = 1;
  109. starpu_data_release(handle);
  110. if (compare_stats(&global_stats, &expected_stats) != 0)
  111. {
  112. FPRINTF(stderr, "MIC failed\n");
  113. print_stats(&global_stats);
  114. FPRINTF(stderr ,"\n");
  115. print_stats(&expected_stats);
  116. return -ENODEV;
  117. }
  118. #endif /* !STARPU_USE_CUDA */
  119. return 0;
  120. }
  121. int
  122. main(int argc, char **argv)
  123. {
  124. #ifdef STARPU_USE_CPU
  125. int ret;
  126. struct starpu_conf conf;
  127. starpu_conf_init(&conf);
  128. conf.ncuda = 1;
  129. conf.nopencl = 1;
  130. conf.nmic = 1;
  131. memset(&global_stats, 0, sizeof(global_stats));
  132. ret = starpu_initialize(&conf, &argc, &argv);
  133. if (ret == -ENODEV || starpu_cpu_worker_get_count() == 0) return STARPU_TEST_SKIPPED;
  134. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  135. register_handle();
  136. int err = test();
  137. unregister_handle();
  138. starpu_shutdown();
  139. switch (err)
  140. {
  141. case -ENODEV:
  142. return STARPU_TEST_SKIPPED;
  143. case 0:
  144. return EXIT_SUCCESS;
  145. default:
  146. return EXIT_FAILURE;
  147. }
  148. #else /* ! STARPU_USE_CPU */
  149. /* Without the CPU, there is no point in using the multiformat
  150. * interface, so this test is pointless. */
  151. return STARPU_TEST_SKIPPED;
  152. #endif
  153. }