declare_deps_after_submission_synchronous.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2016 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013, 2017 CNRS
  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 <stdio.h>
  18. #include <unistd.h>
  19. #include <starpu.h>
  20. #include "../helper.h"
  21. /*
  22. * Test that we can declare a dependency after submitting a non-auto-destroy synchronous task
  23. */
  24. #ifdef STARPU_QUICK_CHECK
  25. #define NLOOPS 4
  26. #else
  27. #define NLOOPS 128
  28. #endif
  29. void dummy_func(void *descr[], void *arg)
  30. {
  31. (void)descr;
  32. (void)arg;
  33. }
  34. static struct starpu_codelet dummy_codelet =
  35. {
  36. .cpu_funcs = {dummy_func},
  37. .cuda_funcs = {dummy_func},
  38. .opencl_funcs = {dummy_func},
  39. .cpu_funcs_name = {"dummy_func"},
  40. .model = NULL,
  41. .nbuffers = 0
  42. };
  43. static struct starpu_task *create_dummy_task(void)
  44. {
  45. struct starpu_task *task = starpu_task_create();
  46. task->cl = &dummy_codelet;
  47. task->cl_arg = NULL;
  48. return task;
  49. }
  50. int main(int argc, char **argv)
  51. {
  52. int ret;
  53. unsigned loop, nloops=NLOOPS;
  54. ret = starpu_initialize(NULL, &argc, &argv);
  55. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  56. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  57. struct starpu_task *taskA, *taskB;
  58. for (loop = 0; loop < nloops; loop++)
  59. {
  60. taskA = create_dummy_task();
  61. taskB = create_dummy_task();
  62. /* By default, dynamically allocated tasks are destroyed at
  63. * termination, we cannot declare a dependency on something
  64. * that does not exist anymore. */
  65. taskA->destroy = 0;
  66. taskA->synchronous = 1;
  67. ret = starpu_task_submit(taskA);
  68. if (ret == -ENODEV) goto enodev;
  69. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  70. starpu_task_declare_deps_array(taskB, 1, &taskA);
  71. taskB->synchronous = 1;
  72. ret = starpu_task_submit(taskB);
  73. if (ret == -ENODEV) goto enodev;
  74. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  75. starpu_task_destroy(taskA);
  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. }