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