same_handle.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), 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)
  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. .nbuffers = 2,
  36. };
  37. static void
  38. register_handle(void)
  39. {
  40. int i;
  41. for (i = 0; i < NX; i++)
  42. vector[i] = i;
  43. starpu_multiformat_data_register(&handle, STARPU_MAIN_RAM, vector, NX, &ops);
  44. }
  45. static void
  46. unregister_handle(void)
  47. {
  48. starpu_data_unregister(handle);
  49. }
  50. static int
  51. create_and_submit_tasks(void)
  52. {
  53. int ret;
  54. struct starpu_task *task;
  55. cl.where = 0;
  56. #ifdef STARPU_USE_CUDA
  57. cl.where |= STARPU_CUDA;
  58. #endif
  59. #ifdef STARPU_USE_OPENCL
  60. cl.where |= STARPU_OPENCL;
  61. #endif
  62. task = starpu_task_create();
  63. task->cl = &cl;
  64. task->handles[0] = handle;
  65. task->handles[1] = handle;
  66. ret = starpu_task_submit(task);
  67. if (ret == -ENODEV)
  68. {
  69. task->destroy = 0;
  70. starpu_task_destroy(task);
  71. return -ENODEV;
  72. }
  73. return 0;
  74. }
  75. #endif
  76. int
  77. main(int argc, char **argv)
  78. {
  79. #if defined(STARPU_USE_CUDA) || defined(STARPU_USE_OPENCL)
  80. int err;
  81. err = starpu_initialize(NULL, &argc, &argv);
  82. if (err == -ENODEV)
  83. goto enodev;
  84. reset_stats(&global_stats);
  85. register_handle();
  86. err = create_and_submit_tasks();
  87. unregister_handle();
  88. starpu_shutdown();
  89. if (err == -ENODEV)
  90. goto enodev;
  91. #if defined(STARPU_USE_CUDA)
  92. if (global_stats.cuda == 1)
  93. {
  94. if (global_stats.cpu_to_cuda == 1 &&
  95. global_stats.cuda_to_cpu == 1)
  96. return EXIT_SUCCESS;
  97. else
  98. return EXIT_FAILURE;
  99. }
  100. else
  101. #endif
  102. #if defined(STARPU_USE_OPENCL)
  103. if (global_stats.opencl == 1)
  104. {
  105. if (global_stats.cpu_to_opencl == 1 &&
  106. global_stats.opencl_to_cpu == 1)
  107. return EXIT_SUCCESS;
  108. else
  109. return EXIT_FAILURE;
  110. }
  111. else
  112. #endif
  113. {
  114. /* We should not get here */
  115. return EXIT_FAILURE;
  116. }
  117. enodev:
  118. #endif
  119. return STARPU_TEST_SKIPPED;
  120. }