multiformat_data_release.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. 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, NULL},
  45. #endif
  46. #ifdef STARPU_USE_OPENCL
  47. .opencl_funcs = {opencl_func, NULL},
  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. starpu_task_submit(task);
  59. }
  60. static int
  61. test(void)
  62. {
  63. struct stats expected_stats;
  64. memset(&expected_stats, 0, sizeof(expected_stats));
  65. #ifdef STARPU_USE_CUDA
  66. create_and_submit(STARPU_CUDA);
  67. starpu_data_acquire(handle, STARPU_RW);
  68. expected_stats.cuda = 1;
  69. expected_stats.cpu_to_cuda = 1;
  70. expected_stats.cuda_to_cpu = 1;
  71. starpu_data_release(handle);
  72. if (compare_stats(&global_stats, &expected_stats) != 0)
  73. {
  74. FPRINTF(stderr, "CUDA failed\n");
  75. print_stats(&global_stats);
  76. FPRINTF(stderr ,"\n");
  77. print_stats(&expected_stats);
  78. return -ENODEV;
  79. }
  80. #endif /* !STARPU_USE_CUDA */
  81. #ifdef STARPU_USE_OPENCL
  82. create_and_submit(STARPU_OPENCL);
  83. starpu_data_acquire(handle, STARPU_RW);
  84. expected_stats.opencl = 1;
  85. expected_stats.cpu_to_opencl = 1;
  86. expected_stats.opencl_to_cpu = 1;
  87. starpu_data_release(handle);
  88. if (compare_stats(&global_stats, &expected_stats) != 0)
  89. {
  90. FPRINTF(stderr, "OPENCL failed\n");
  91. print_stats(&global_stats);
  92. FPRINTF(stderr ,"\n");
  93. print_stats(&expected_stats);
  94. return -ENODEV;
  95. }
  96. #endif /* !STARPU_USE_OPENCL */
  97. return 0;
  98. }
  99. int
  100. main(void)
  101. {
  102. #ifdef STARPU_USE_CPU
  103. int ret;
  104. struct starpu_conf conf =
  105. {
  106. .ncpus = -1,
  107. .ncuda = 1,
  108. .nopencl = 1
  109. };
  110. memset(&global_stats, 0, sizeof(global_stats));
  111. ret = starpu_init(&conf);
  112. if (ret == -ENODEV) 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. }