same_handle.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 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. /*
  20. * A single handle can be given twice to a given kernel. In this case, it
  21. * should only be converted once.
  22. */
  23. #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL) || defined(STARPU_USE_MIC)
  24. extern struct stats global_stats;
  25. static int vector[NX]; static starpu_data_handle_t handle;
  26. static struct starpu_codelet cl =
  27. {
  28. .modes = { STARPU_RW, STARPU_RW },
  29. #ifdef STARPU_USE_CUDA
  30. .cuda_funcs = { cuda_func },
  31. #endif
  32. #ifdef STARPU_USE_OPENCL
  33. .opencl_funcs = { opencl_func },
  34. #endif
  35. #ifdef STARPU_USE_MIC
  36. .mic_funcs = {mic_func},
  37. #endif
  38. .nbuffers = 2,
  39. };
  40. static void
  41. register_handle(void)
  42. {
  43. int i;
  44. for (i = 0; i < NX; i++)
  45. vector[i] = i;
  46. starpu_multiformat_data_register(&handle, STARPU_MAIN_RAM, vector, NX, &ops);
  47. }
  48. static void
  49. unregister_handle(void)
  50. {
  51. starpu_data_unregister(handle);
  52. }
  53. static int
  54. create_and_submit_tasks(void)
  55. {
  56. int ret;
  57. struct starpu_task *task;
  58. cl.where = 0;
  59. #ifdef STARPU_USE_CUDA
  60. cl.where |= STARPU_CUDA;
  61. #endif
  62. #ifdef STARPU_USE_OPENCL
  63. cl.where |= STARPU_OPENCL;
  64. #endif
  65. #ifdef STARPU_USE_MIC
  66. cl.where |= STARPU_MIC;
  67. #endif
  68. task = starpu_task_create();
  69. task->cl = &cl;
  70. task->handles[0] = handle;
  71. task->handles[1] = handle;
  72. ret = starpu_task_submit(task);
  73. if (ret == -ENODEV)
  74. {
  75. task->destroy = 0;
  76. starpu_task_destroy(task);
  77. return -ENODEV;
  78. }
  79. return 0;
  80. }
  81. #endif
  82. int
  83. main(int argc, char **argv)
  84. {
  85. #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL) || defined(STARPU_USE_MIC)
  86. int err;
  87. err = starpu_initialize(NULL, &argc, &argv);
  88. if (err == -ENODEV)
  89. goto enodev;
  90. reset_stats(&global_stats);
  91. register_handle();
  92. err = create_and_submit_tasks();
  93. unregister_handle();
  94. starpu_shutdown();
  95. if (err == -ENODEV)
  96. goto enodev;
  97. #if defined(STARPU_USE_CUDA)
  98. if (global_stats.cuda == 1)
  99. {
  100. if (global_stats.cpu_to_cuda == 1 &&
  101. global_stats.cuda_to_cpu == 1)
  102. return EXIT_SUCCESS;
  103. else
  104. return EXIT_FAILURE;
  105. }
  106. else
  107. #endif
  108. #if defined(STARPU_USE_OPENCL)
  109. if (global_stats.opencl == 1)
  110. {
  111. if (global_stats.cpu_to_opencl == 1 &&
  112. global_stats.opencl_to_cpu == 1)
  113. return EXIT_SUCCESS;
  114. else
  115. return EXIT_FAILURE;
  116. }
  117. else
  118. #endif
  119. #if defined(STARPU_USE_MIC)
  120. if (global_stats.mic == 1)
  121. {
  122. if (global_stats.cpu_to_mic == 1 &&
  123. global_stats.mic_to_cpu == 1)
  124. return EXIT_SUCCESS;
  125. else
  126. return EXIT_FAILURE;
  127. }
  128. else
  129. #endif
  130. {
  131. /* We should not get here */
  132. return EXIT_FAILURE;
  133. }
  134. enodev:
  135. #endif
  136. return STARPU_TEST_SKIPPED;
  137. }