lib.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. /* Testing library, including stubs of StarPU functions. */
  14. #ifndef STARPU_GCC_PLUGIN
  15. # error barf!
  16. #endif
  17. #ifndef STARPU_USE_CPU
  18. # error damn it!
  19. #endif
  20. #undef NDEBUG
  21. #include <stdlib.h>
  22. #include <stdarg.h>
  23. #include <string.h>
  24. #include <assert.h>
  25. /* Stub used for testing purposes. */
  26. /* Number of tasks submitted. */
  27. static unsigned int tasks_submitted;
  28. struct insert_task_argument
  29. {
  30. int type; /* `STARPU_VALUE', etc. */
  31. void *pointer; /* Pointer to the expected value. */
  32. size_t size; /* Size in bytes of the data pointed to. */
  33. };
  34. /* Pointer to a zero-terminated array listing the expected
  35. `starpu_insert_task' arguments. */
  36. const struct insert_task_argument *expected_insert_task_arguments;
  37. void
  38. starpu_insert_task (starpu_codelet *cl, ...)
  39. {
  40. assert (cl->where == (STARPU_CPU | STARPU_OPENCL));
  41. /* TODO: Call `cpu_func' & co. and check whether they do the right
  42. thing. */
  43. assert (cl->cpu_func != NULL);
  44. assert (cl->opencl_func != NULL);
  45. assert (cl->cuda_func == NULL);
  46. va_list args;
  47. va_start (args, cl);
  48. const struct insert_task_argument *expected;
  49. for (expected = expected_insert_task_arguments;
  50. expected->type != 0;
  51. expected++)
  52. {
  53. int type;
  54. void *arg;
  55. size_t size;
  56. type = va_arg (args, int);
  57. arg = va_arg (args, void *);
  58. size = va_arg (args, size_t);
  59. assert (type == expected->type);
  60. assert (size == expected->size);
  61. assert (arg != NULL);
  62. assert (!memcmp (arg, expected->pointer, size));
  63. }
  64. va_end (args);
  65. /* Make sure all the arguments were consumed. */
  66. assert (expected->type == 0);
  67. tasks_submitted++;
  68. }
  69. /* Our own implementation of `starpu_unpack_cl_args', for debugging
  70. purposes. */
  71. void
  72. starpu_unpack_cl_args (void *cl_raw_arg, ...)
  73. {
  74. va_list args;
  75. size_t nargs, arg, offset, size;
  76. unsigned char *cl_arg;
  77. cl_arg = (unsigned char *) cl_raw_arg;
  78. nargs = *cl_arg;
  79. va_start (args, cl_raw_arg);
  80. for (arg = 0, offset = 1, size = 0;
  81. arg < nargs;
  82. arg++, offset += sizeof (size_t) + size)
  83. {
  84. void *argp;
  85. argp = va_arg (args, void *);
  86. size = *(size_t *) &cl_arg[size];
  87. memcpy (argp, &cl_arg[offset], size);
  88. }
  89. va_end (args);
  90. }