get_current_task.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 "../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 dummy_cl =
  36. {
  37. .where = STARPU_CUDA|STARPU_CPU,
  38. .cuda_funcs = {check_task_func, NULL},
  39. .cpu_funcs = {check_task_func, NULL},
  40. .model = NULL,
  41. .nbuffers = 0
  42. };
  43. int main(int argc, char **argv)
  44. {
  45. int ret;
  46. ret = starpu_init(NULL);
  47. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  48. #ifdef STARPU_SLOW_MACHINE
  49. ntasks /= 10;
  50. #endif
  51. FPRINTF(stderr, "#tasks : %u\n", ntasks);
  52. int i;
  53. for (i = 0; i < ntasks; i++)
  54. {
  55. struct starpu_task *task = starpu_task_create();
  56. /* We check if the function is valid from the codelet or from
  57. * the callback */
  58. task->cl = &dummy_cl;
  59. task->cl_arg = task;
  60. task->callback_func = check_task_callback;
  61. task->callback_arg = task;
  62. ret = starpu_task_submit(task);
  63. if (ret == -ENODEV) goto enodev;
  64. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  65. }
  66. ret = starpu_task_wait_for_all();
  67. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  68. FPRINTF(stderr, "#empty tasks : %u\n", ntasks);
  69. /* We repeat the same experiment with null codelets */
  70. for (i = 0; i < ntasks; i++)
  71. {
  72. struct starpu_task *task = starpu_task_create();
  73. task->cl = NULL;
  74. /* We check if the function is valid from the callback */
  75. task->callback_func = check_task_callback;
  76. task->callback_arg = task;
  77. int ret = starpu_task_submit(task);
  78. if (ret == -ENODEV) goto enodev;
  79. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  80. }
  81. ret = starpu_task_wait_for_all();
  82. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  83. starpu_shutdown();
  84. return EXIT_SUCCESS;
  85. enodev:
  86. fprintf(stderr, "WARNING: No one can execute this task\n");
  87. /* yes, we do not perform the computation but we did detect that no one
  88. * could perform the kernel, so this is not an error from StarPU */
  89. starpu_shutdown();
  90. return STARPU_TEST_SKIPPED;
  91. }