get_current_task.c 3.2 KB

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