multiformat_data_release.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2012 INRIA
  4. * Copyright (C) 2011, 2012 Centre National de la Recherche Scientifique
  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", __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, 0, 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)
  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, NULL},
  46. #endif
  47. #ifdef STARPU_USE_OPENCL
  48. .opencl_funcs = {opencl_func, NULL},
  49. #endif
  50. .nbuffers = 1
  51. };
  52. cl.where = where;
  53. struct starpu_task *task = starpu_task_create();
  54. task->cl = &cl;
  55. task->handles[0] = handle;
  56. /* We need to be sure the data has been copied to the GPU at the end
  57. * of this function */
  58. task->synchronous = 1;
  59. starpu_task_submit(task);
  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(void)
  103. {
  104. #ifdef STARPU_USE_CPU
  105. int ret;
  106. struct starpu_conf conf =
  107. {
  108. .ncpus = -1,
  109. .ncuda = 1,
  110. .nopencl = 1
  111. };
  112. memset(&global_stats, 0, sizeof(global_stats));
  113. ret = starpu_init(&conf);
  114. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  115. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  116. register_handle();
  117. int err = test();
  118. unregister_handle();
  119. starpu_shutdown();
  120. switch (err)
  121. {
  122. case -ENODEV:
  123. return STARPU_TEST_SKIPPED;
  124. case 0:
  125. return EXIT_SUCCESS;
  126. default:
  127. return EXIT_FAILURE;
  128. }
  129. #else /* ! STARPU_USE_CPU */
  130. /* Without the CPU, there is no point in using the multiformat
  131. * interface, so this test is pointless. */
  132. return STARPU_TEST_SKIPPED;
  133. #endif
  134. }