get_current_task.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <config.h>
  18. #if STARPU_HAVE_VALGRIND_H
  19. #include <valgrind/valgrind.h>
  20. #endif
  21. #include <sys/time.h>
  22. #include <stdio.h>
  23. #include <unistd.h>
  24. #include <starpu.h>
  25. #include "../helper.h"
  26. static unsigned ntasks = 65536;
  27. static void check_task_func(void *descr[], void *arg)
  28. {
  29. STARPU_SKIP_IF_VALGRIND;
  30. /* We check that the returned task is valid from the codelet */
  31. struct starpu_task *task = (struct starpu_task *) arg;
  32. STARPU_ASSERT(task == starpu_task_get_current());
  33. }
  34. static void check_task_callback(void *arg)
  35. {
  36. /* We check that the returned task is valid from the callback */
  37. struct starpu_task *task = (struct starpu_task *) arg;
  38. STARPU_ASSERT(task == starpu_task_get_current());
  39. }
  40. static struct starpu_codelet dummy_cl =
  41. {
  42. .where = STARPU_CUDA|STARPU_CPU,
  43. .cuda_funcs = {check_task_func, NULL},
  44. .cpu_funcs = {check_task_func, NULL},
  45. .model = NULL,
  46. .nbuffers = 0
  47. };
  48. int main(int argc, char **argv)
  49. {
  50. int ret;
  51. ret = starpu_init(NULL);
  52. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  53. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  54. #ifdef STARPU_SLOW_MACHINE
  55. ntasks /= 10;
  56. #endif
  57. FPRINTF(stderr, "#tasks : %u\n", ntasks);
  58. int i;
  59. for (i = 0; i < ntasks; i++)
  60. {
  61. struct starpu_task *task = starpu_task_create();
  62. /* We check if the function is valid from the codelet or from
  63. * the callback */
  64. task->cl = &dummy_cl;
  65. task->cl_arg = task;
  66. task->callback_func = check_task_callback;
  67. task->callback_arg = task;
  68. ret = starpu_task_submit(task);
  69. if (ret == -ENODEV) goto enodev;
  70. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  71. }
  72. ret = starpu_task_wait_for_all();
  73. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  74. FPRINTF(stderr, "#empty tasks : %u\n", ntasks);
  75. /* We repeat the same experiment with null codelets */
  76. for (i = 0; i < ntasks; i++)
  77. {
  78. struct starpu_task *task = starpu_task_create();
  79. task->cl = NULL;
  80. /* We check if the function is valid from the callback */
  81. task->callback_func = check_task_callback;
  82. task->callback_arg = task;
  83. int ret = starpu_task_submit(task);
  84. if (ret == -ENODEV) goto enodev;
  85. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  86. }
  87. ret = starpu_task_wait_for_all();
  88. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  89. starpu_shutdown();
  90. return EXIT_SUCCESS;
  91. enodev:
  92. fprintf(stderr, "WARNING: No one can execute this task\n");
  93. /* yes, we do not perform the computation but we did detect that no one
  94. * could perform the kernel, so this is not an error from StarPU */
  95. starpu_shutdown();
  96. return STARPU_TEST_SKIPPED;
  97. }