multiformat_data_release.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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)
  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. .nbuffers = 1
  50. };
  51. cl.where = where;
  52. struct starpu_task *task = starpu_task_create();
  53. task->cl = &cl;
  54. task->handles[0] = handle;
  55. /* We need to be sure the data has been copied to the GPU at the end
  56. * of this function */
  57. task->synchronous = 1;
  58. if (starpu_task_submit(task) == -ENODEV)
  59. exit(STARPU_TEST_SKIPPED);
  60. }
  61. #endif
  62. static int
  63. test(void)
  64. {
  65. struct stats expected_stats;
  66. memset(&expected_stats, 0, sizeof(expected_stats));
  67. #ifdef STARPU_USE_CUDA
  68. create_and_submit(STARPU_CUDA);
  69. starpu_data_acquire(handle, STARPU_RW);
  70. expected_stats.cuda = 1;
  71. expected_stats.cpu_to_cuda = 1;
  72. expected_stats.cuda_to_cpu = 1;
  73. starpu_data_release(handle);
  74. if (compare_stats(&global_stats, &expected_stats) != 0)
  75. {
  76. FPRINTF(stderr, "CUDA failed\n");
  77. print_stats(&global_stats);
  78. FPRINTF(stderr ,"\n");
  79. print_stats(&expected_stats);
  80. return -ENODEV;
  81. }
  82. #endif /* !STARPU_USE_CUDA */
  83. #ifdef STARPU_USE_OPENCL
  84. create_and_submit(STARPU_OPENCL);
  85. starpu_data_acquire(handle, STARPU_RW);
  86. expected_stats.opencl = 1;
  87. expected_stats.cpu_to_opencl = 1;
  88. expected_stats.opencl_to_cpu = 1;
  89. starpu_data_release(handle);
  90. if (compare_stats(&global_stats, &expected_stats) != 0)
  91. {
  92. FPRINTF(stderr, "OPENCL failed\n");
  93. print_stats(&global_stats);
  94. FPRINTF(stderr ,"\n");
  95. print_stats(&expected_stats);
  96. return -ENODEV;
  97. }
  98. #endif /* !STARPU_USE_OPENCL */
  99. return 0;
  100. }
  101. int
  102. main(int argc, char **argv)
  103. {
  104. #ifdef STARPU_USE_CPU
  105. int ret;
  106. struct starpu_conf conf;
  107. starpu_conf_init(&conf);
  108. conf.ncuda = 1;
  109. conf.nopencl = 1;
  110. memset(&global_stats, 0, sizeof(global_stats));
  111. ret = starpu_initialize(&conf, &argc, &argv);
  112. if (ret == -ENODEV || starpu_cpu_worker_get_count() == 0) return STARPU_TEST_SKIPPED;
  113. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  114. register_handle();
  115. int err = test();
  116. unregister_handle();
  117. starpu_shutdown();
  118. switch (err)
  119. {
  120. case -ENODEV:
  121. return STARPU_TEST_SKIPPED;
  122. case 0:
  123. return EXIT_SUCCESS;
  124. default:
  125. return EXIT_FAILURE;
  126. }
  127. #else /* ! STARPU_USE_CPU */
  128. /* Without the CPU, there is no point in using the multiformat
  129. * interface, so this test is pointless. */
  130. return STARPU_TEST_SKIPPED;
  131. #endif
  132. }