lib.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. int
  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. type = va_arg (args, int);
  55. assert (type == expected->type);
  56. switch (type)
  57. {
  58. case STARPU_VALUE:
  59. {
  60. void *arg;
  61. size_t size;
  62. arg = va_arg (args, void *);
  63. size = va_arg (args, size_t);
  64. assert (size == expected->size);
  65. assert (arg != NULL);
  66. assert (!memcmp (arg, expected->pointer, size));
  67. break;
  68. }
  69. case STARPU_RW:
  70. case STARPU_R:
  71. case STARPU_W:
  72. assert (va_arg (args, void *) == expected->pointer);
  73. break;
  74. default:
  75. abort ();
  76. }
  77. }
  78. va_end (args);
  79. /* Make sure all the arguments were consumed. */
  80. assert (expected->type == 0);
  81. tasks_submitted++;
  82. return 0;
  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. starpu_data_handle
  107. starpu_data_lookup (const void *ptr)
  108. {
  109. return (starpu_data_handle) ptr;
  110. }
  111. void *
  112. starpu_handle_get_local_ptr (starpu_data_handle handle)
  113. {
  114. return handle;
  115. }