get_current_task.c 3.4 KB

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