get_current_task.c 3.3 KB

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