declare_deps_in_callback.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. * Test that we can declare deps from the callback of the task
  22. */
  23. #ifdef STARPU_QUICK_CHECK
  24. #define NLOOPS 4
  25. #else
  26. #define NLOOPS 128
  27. #endif
  28. static void callback(void *arg)
  29. {
  30. struct starpu_task *taskA, *taskB;
  31. int ret;
  32. taskA = starpu_task_get_current();
  33. taskB = (struct starpu_task *) arg;
  34. starpu_task_declare_deps_array(taskB, 1, &taskA);
  35. ret = starpu_task_submit(taskB);
  36. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  37. }
  38. void dummy_func(void *descr[], void *arg)
  39. {
  40. (void)descr;
  41. (void)arg;
  42. }
  43. static struct starpu_codelet dummy_codelet =
  44. {
  45. .cpu_funcs = {dummy_func},
  46. .cuda_funcs = {dummy_func},
  47. .opencl_funcs = {dummy_func},
  48. .cpu_funcs_name = {"dummy_func"},
  49. .model = NULL,
  50. .nbuffers = 0
  51. };
  52. static struct starpu_task *create_dummy_task(void)
  53. {
  54. struct starpu_task *task = starpu_task_create();
  55. task->cl = &dummy_codelet;
  56. task->cl_arg = NULL;
  57. return task;
  58. }
  59. int main(int argc, char **argv)
  60. {
  61. int ret;
  62. unsigned loop;
  63. ret = starpu_initialize(NULL, &argc, &argv);
  64. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  65. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  66. struct starpu_task *taskA, *taskB;
  67. for (loop = 0; loop < NLOOPS; loop++)
  68. {
  69. taskA = create_dummy_task();
  70. taskB = create_dummy_task();
  71. taskA->callback_func = callback;
  72. taskA->callback_arg = taskB;
  73. ret = starpu_task_submit(taskA);
  74. if (ret == -ENODEV) goto enodev;
  75. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  76. }
  77. ret = starpu_task_wait_for_all();
  78. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  79. starpu_shutdown();
  80. return EXIT_SUCCESS;
  81. enodev:
  82. fprintf(stderr, "WARNING: No one can execute this task\n");
  83. /* yes, we do not perform the computation but we did detect that no one
  84. * could perform the kernel, so this is not an error from StarPU */
  85. starpu_shutdown();
  86. return STARPU_TEST_SKIPPED;
  87. }