same_handle.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2013 Inria
  4. * Copyright (C) 2011,2012,2017 CNRS
  5. * Copyright (C) 2013,2014,2016 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu.h>
  19. #include "generic.h"
  20. #include "../../../../helper.h"
  21. /*
  22. * A single handle can be given twice to a given kernel. In this case, it
  23. * should only be converted once.
  24. */
  25. #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL) || defined(STARPU_USE_MIC)
  26. extern struct stats global_stats;
  27. static int vector[NX]; static starpu_data_handle_t handle;
  28. static struct starpu_codelet cl =
  29. {
  30. .modes = { STARPU_RW, STARPU_RW },
  31. #ifdef STARPU_USE_CUDA
  32. .cuda_funcs = { cuda_func },
  33. #endif
  34. #ifdef STARPU_USE_OPENCL
  35. .opencl_funcs = { opencl_func },
  36. #endif
  37. #ifdef STARPU_USE_MIC
  38. .mic_funcs = {mic_func},
  39. #endif
  40. .nbuffers = 2,
  41. };
  42. static void
  43. register_handle(void)
  44. {
  45. int i;
  46. for (i = 0; i < NX; i++)
  47. vector[i] = i;
  48. starpu_multiformat_data_register(&handle, STARPU_MAIN_RAM, vector, NX, &ops);
  49. }
  50. static void
  51. unregister_handle(void)
  52. {
  53. starpu_data_unregister(handle);
  54. }
  55. static int
  56. create_and_submit_tasks(void)
  57. {
  58. int ret;
  59. struct starpu_task *task;
  60. cl.where = 0;
  61. #ifdef STARPU_USE_CUDA
  62. cl.where |= STARPU_CUDA;
  63. #endif
  64. #ifdef STARPU_USE_OPENCL
  65. cl.where |= STARPU_OPENCL;
  66. #endif
  67. #ifdef STARPU_USE_MIC
  68. cl.where |= STARPU_MIC;
  69. #endif
  70. task = starpu_task_create();
  71. task->cl = &cl;
  72. task->handles[0] = handle;
  73. task->handles[1] = handle;
  74. ret = starpu_task_submit(task);
  75. if (ret == -ENODEV)
  76. {
  77. task->destroy = 0;
  78. starpu_task_destroy(task);
  79. return -ENODEV;
  80. }
  81. return 0;
  82. }
  83. #endif
  84. int
  85. main(int argc, char **argv)
  86. {
  87. #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL) || defined(STARPU_USE_MIC)
  88. int err;
  89. err = starpu_initialize(NULL, &argc, &argv);
  90. if (err == -ENODEV)
  91. goto enodev;
  92. reset_stats(&global_stats);
  93. register_handle();
  94. err = create_and_submit_tasks();
  95. unregister_handle();
  96. starpu_shutdown();
  97. if (err == -ENODEV)
  98. goto enodev;
  99. #if defined(STARPU_USE_CUDA)
  100. if (global_stats.cuda == 1)
  101. {
  102. if (global_stats.cpu_to_cuda == 1 &&
  103. global_stats.cuda_to_cpu == 1)
  104. return EXIT_SUCCESS;
  105. else
  106. return EXIT_FAILURE;
  107. }
  108. else
  109. #endif
  110. #if defined(STARPU_USE_OPENCL)
  111. if (global_stats.opencl == 1)
  112. {
  113. if (global_stats.cpu_to_opencl == 1 &&
  114. global_stats.opencl_to_cpu == 1)
  115. return EXIT_SUCCESS;
  116. else
  117. return EXIT_FAILURE;
  118. }
  119. else
  120. #endif
  121. #if defined(STARPU_USE_MIC)
  122. if (global_stats.mic == 1)
  123. {
  124. if (global_stats.cpu_to_mic == 1 &&
  125. global_stats.mic_to_cpu == 1)
  126. return EXIT_SUCCESS;
  127. else
  128. return EXIT_FAILURE;
  129. }
  130. else
  131. #endif
  132. {
  133. /* We should not get here */
  134. return EXIT_FAILURE;
  135. }
  136. enodev:
  137. #endif
  138. return STARPU_TEST_SKIPPED;
  139. }