output-pointer.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* GCC-StarPU
  2. Copyright (C) 2011, 2012 Institut National de Recherche en Informatique et Automatique
  3. GCC-StarPU is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. GCC-StarPU is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with GCC-StarPU. If not, see <http://www.gnu.org/licenses/>. */
  13. #undef NDEBUG
  14. #include <mocks.h>
  15. #define __output __attribute__ ((output))
  16. /* The tasks under test. */
  17. static void my_pointer_task (size_t size, __output int *x)
  18. __attribute__ ((task));
  19. static void my_pointer_task_cpu (size_t size, __output int *x)
  20. __attribute__ ((task_implementation ("cpu", my_pointer_task)));
  21. static void my_pointer_task_opencl (size_t size, __output int *x)
  22. __attribute__ ((task_implementation ("opencl", my_pointer_task)));
  23. static void
  24. my_pointer_task_cpu (size_t size, __output int *x)
  25. {
  26. printf ("%s: x = %p, size = %zi\n", __func__, x, size);
  27. }
  28. static void
  29. my_pointer_task_opencl (size_t size, int *x)
  30. {
  31. printf ("%s: x = %p, size = %zi\n", __func__, x, size);
  32. }
  33. static void my_array_task (size_t size, __output int x[size])
  34. __attribute__ ((task));
  35. static void my_array_task_cpu (size_t size, __output int x[size])
  36. __attribute__ ((task_implementation ("cpu", my_array_task)));
  37. static void my_array_task_opencl (size_t size, __output int x[size])
  38. __attribute__ ((task_implementation ("opencl", my_array_task)));
  39. static void
  40. my_array_task_cpu (size_t size, __output int x[size])
  41. {
  42. printf ("%s: x = %p, size = %zi\n", __func__, x, size);
  43. }
  44. static void
  45. my_array_task_opencl (size_t size, __output int x[size])
  46. {
  47. printf ("%s: x = %p, size = %zi\n", __func__, x, size);
  48. }
  49. int
  50. main (int argc, char *argv[])
  51. {
  52. #pragma starpu initialize
  53. size_t size = 42;
  54. int x[size];
  55. /* Register X (don't use the pragma, to avoid mixing concerns in this
  56. test.) */
  57. starpu_data_handle_t handle;
  58. expected_register_arguments.pointer = x;
  59. expected_register_arguments.elements = 42;
  60. expected_register_arguments.element_size = sizeof x[0];
  61. starpu_vector_data_register (&handle, 0, (uintptr_t) x, 42, sizeof x[0]);
  62. struct insert_task_argument expected[] =
  63. {
  64. { STARPU_VALUE, &size, sizeof size },
  65. { STARPU_W, x },
  66. { 0, 0, 0 }
  67. };
  68. expected_insert_task_arguments = expected;
  69. /* Invoke the task, which makes sure it gets called with EXPECTED. */
  70. my_pointer_task (size, x);
  71. assert (tasks_submitted == 1);
  72. /* Again. */
  73. my_array_task (size, x);
  74. assert (tasks_submitted == 2);
  75. return EXIT_SUCCESS;
  76. }