base.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* GCC-StarPU
  2. Copyright (C) 2011 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 <stdlib.h>
  15. #include <stdarg.h>
  16. #include <string.h>
  17. #include <assert.h>
  18. #ifndef STARPU_GCC_PLUGIN
  19. # error barf!
  20. #endif
  21. #ifndef STARPU_USE_CPU
  22. # error damn it!
  23. #endif
  24. /* The task under test. */
  25. static void my_scalar_task (int x, int y) __attribute__ ((task));
  26. static void my_scalar_task_cpu (int, int)
  27. __attribute__ ((task_implementation ("cpu", my_scalar_task)));
  28. static void my_scalar_task_opencl (int, int)
  29. __attribute__ ((task_implementation ("opencl", my_scalar_task)));
  30. static void
  31. my_scalar_task_cpu (int x, int y)
  32. {
  33. printf ("%s: x = %i, y = %i\n", __func__, x, y);
  34. }
  35. static void
  36. my_scalar_task_opencl (int x, int y)
  37. {
  38. printf ("%s: x = %i, y = %i\n", __func__, x, y);
  39. }
  40. /* Stub used for testing purposes. */
  41. /* Number of tasks submitted. */
  42. static unsigned int tasks_submitted;
  43. struct insert_task_argument
  44. {
  45. int type; /* `STARPU_VALUE', etc. */
  46. void *pointer; /* Pointer to the expected value. */
  47. size_t size; /* Size in bytes of the data pointed to. */
  48. };
  49. /* Pointer to a zero-terminated array listing the expected
  50. `starpu_insert_task' arguments. */
  51. const struct insert_task_argument *expected_insert_task_arguments;
  52. void
  53. starpu_insert_task (starpu_codelet *cl, ...)
  54. {
  55. assert (cl->where == (STARPU_CPU | STARPU_OPENCL));
  56. /* TODO: Call `cpu_func' & co. and check whether they do the right
  57. thing. */
  58. assert (cl->cpu_func != NULL);
  59. assert (cl->opencl_func != NULL);
  60. assert (cl->cuda_func == NULL);
  61. va_list args;
  62. va_start (args, cl);
  63. const struct insert_task_argument *expected;
  64. for (expected = expected_insert_task_arguments;
  65. expected->type != 0;
  66. expected++)
  67. {
  68. int type;
  69. void *arg;
  70. size_t size;
  71. type = va_arg (args, int);
  72. arg = va_arg (args, void *);
  73. size = va_arg (args, size_t);
  74. assert (type == expected->type);
  75. assert (size == expected->size);
  76. assert (arg != NULL);
  77. assert (!memcmp (arg, expected->pointer, size));
  78. }
  79. va_end (args);
  80. /* Make sure all the arguments were consumed. */
  81. assert (expected->type == 0);
  82. tasks_submitted++;
  83. }
  84. /* Our own implementation of `starpu_unpack_cl_args', for debugging
  85. purposes. */
  86. void
  87. starpu_unpack_cl_args (void *cl_raw_arg, ...)
  88. {
  89. va_list args;
  90. size_t nargs, arg, offset, size;
  91. unsigned char *cl_arg;
  92. cl_arg = (unsigned char *) cl_raw_arg;
  93. nargs = *cl_arg;
  94. va_start (args, cl_raw_arg);
  95. for (arg = 0, offset = 1, size = 0;
  96. arg < nargs;
  97. arg++, offset += sizeof (size_t) + size)
  98. {
  99. void *argp;
  100. argp = va_arg (args, void *);
  101. size = *(size_t *) &cl_arg[size];
  102. memcpy (argp, &cl_arg[offset], size);
  103. }
  104. va_end (args);
  105. }
  106. int
  107. main (int argc, char *argv[])
  108. {
  109. #pragma starpu hello
  110. int x = 42, y = 77;
  111. struct insert_task_argument expected[] =
  112. {
  113. { STARPU_VALUE, &x, sizeof (int) },
  114. { STARPU_VALUE, &y, sizeof (int) },
  115. { 0, 0, 0 }
  116. };
  117. expected_insert_task_arguments = expected;
  118. /* Invoke the task, which should make sure it gets called with
  119. EXPECTED. */
  120. my_scalar_task (x, y);
  121. assert (tasks_submitted == 1);
  122. return EXIT_SUCCESS;
  123. }