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, 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 <stdio.h>
  19. #include <unistd.h>
  20. #include <starpu.h>
  21. #include "../helper.h"
  22. #ifdef STARPU_QUICK_CHECK
  23. static unsigned ntasks = 64;
  24. #else
  25. static unsigned ntasks = 65536;
  26. #endif
  27. void check_task_func(void *descr[], void *arg)
  28. {
  29. }
  30. static void check_task_callback(void *arg)
  31. {
  32. /* We check that the returned task is valid from the callback */
  33. struct starpu_task *task = (struct starpu_task *) arg;
  34. STARPU_ASSERT(task == starpu_task_get_current());
  35. }
  36. static struct starpu_codelet dummy_cl =
  37. {
  38. .cuda_funcs = {check_task_func, NULL},
  39. .cpu_funcs = {check_task_func, NULL},
  40. .opencl_funcs = {check_task_func, NULL},
  41. .cpu_funcs_name = {"check_task_func", NULL},
  42. .model = NULL,
  43. .nbuffers = 0
  44. };
  45. int main(int argc, char **argv)
  46. {
  47. int ret;
  48. ret = starpu_initialize(NULL, &argc, &argv);
  49. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  50. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  51. FPRINTF(stderr, "#tasks : %u\n", ntasks);
  52. unsigned 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->cl_arg_size = sizeof(task);
  61. task->callback_func = check_task_callback;
  62. task->callback_arg = task;
  63. ret = starpu_task_submit(task);
  64. if (ret == -ENODEV) goto enodev;
  65. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  66. }
  67. ret = starpu_task_wait_for_all();
  68. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  69. FPRINTF(stderr, "#empty tasks : %u\n", ntasks);
  70. /* We repeat the same experiment with null codelets */
  71. for (i = 0; i < ntasks; i++)
  72. {
  73. struct starpu_task *task = starpu_task_create();
  74. task->cl = NULL;
  75. /* We check if the function is valid from the callback */
  76. task->callback_func = check_task_callback;
  77. task->callback_arg = task;
  78. ret = starpu_task_submit(task);
  79. if (ret == -ENODEV) goto enodev;
  80. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  81. }
  82. ret = starpu_task_wait_for_all();
  83. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  84. starpu_shutdown();
  85. return EXIT_SUCCESS;
  86. enodev:
  87. fprintf(stderr, "WARNING: No one can execute this task\n");
  88. /* yes, we do not perform the computation but we did detect that no one
  89. * could perform the kernel, so this is not an error from StarPU */
  90. starpu_shutdown();
  91. return STARPU_TEST_SKIPPED;
  92. }