get_current_task.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011 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 <sys/time.h>
  18. #include <stdio.h>
  19. #include <unistd.h>
  20. #include <starpu.h>
  21. #include "../common/helper.h"
  22. static unsigned ntasks = 65536;
  23. static void check_task_func(void *descr[], void *arg)
  24. {
  25. /* We check that the returned task is valid from the codelet */
  26. struct starpu_task *task = (struct starpu_task *) arg;
  27. STARPU_ASSERT(task == starpu_get_current_task());
  28. }
  29. static void check_task_callback(void *arg)
  30. {
  31. /* We check that the returned task is valid from the callback */
  32. struct starpu_task *task = (struct starpu_task *) arg;
  33. STARPU_ASSERT(task == starpu_get_current_task());
  34. }
  35. static struct starpu_codelet_t dummy_cl = {
  36. .where = STARPU_CUDA|STARPU_CPU,
  37. .cuda_func = check_task_func,
  38. .cpu_func = check_task_func,
  39. .model = NULL,
  40. .nbuffers = 0
  41. };
  42. int main(int argc, char **argv)
  43. {
  44. int ret;
  45. ret = starpu_init(NULL);
  46. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  47. #ifdef STARPU_SLOW_MACHINE
  48. ntasks /= 10;
  49. #endif
  50. FPRINTF(stderr, "#tasks : %u\n", ntasks);
  51. int i;
  52. for (i = 0; i < ntasks; i++)
  53. {
  54. struct starpu_task *task = starpu_task_create();
  55. /* We check if the function is valid from the codelet or from
  56. * the callback */
  57. task->cl = &dummy_cl;
  58. task->cl_arg = task;
  59. task->callback_func = check_task_callback;
  60. task->callback_arg = task;
  61. ret = starpu_task_submit(task);
  62. if (ret == -ENODEV) goto enodev;
  63. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  64. }
  65. ret = starpu_task_wait_for_all();
  66. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  67. FPRINTF(stderr, "#empty tasks : %u\n", ntasks);
  68. /* We repeat the same experiment with null codelets */
  69. for (i = 0; i < ntasks; i++)
  70. {
  71. struct starpu_task *task = starpu_task_create();
  72. task->cl = NULL;
  73. /* We check if the function is valid from the callback */
  74. task->callback_func = check_task_callback;
  75. task->callback_arg = task;
  76. int ret = starpu_task_submit(task);
  77. if (ret == -ENODEV) goto enodev;
  78. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  79. }
  80. ret = starpu_task_wait_for_all();
  81. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  82. starpu_shutdown();
  83. return EXIT_SUCCESS;
  84. enodev:
  85. fprintf(stderr, "WARNING: No one can execute this task\n");
  86. /* yes, we do not perform the computation but we did detect that no one
  87. * could perform the kernel, so this is not an error from StarPU */
  88. starpu_shutdown();
  89. return 77;
  90. }