simple_deps.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012-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 <unistd.h>
  17. #include <starpu.h>
  18. #include <starpu_scheduler.h>
  19. #include "../helper.h"
  20. /*
  21. * Task1 must be executed before task0, even if task0 is submitted first.
  22. * Applies to : all schedulers.
  23. */
  24. void dummy(void *buffers[], void *args)
  25. {
  26. (void) buffers;
  27. (void) args;
  28. usleep(10000);
  29. }
  30. static int
  31. run(struct starpu_sched_policy *policy)
  32. {
  33. int ret;
  34. struct starpu_conf conf;
  35. starpu_conf_init(&conf);
  36. conf.sched_policy = policy;
  37. ret = starpu_init(&conf);
  38. if (ret != 0)
  39. exit(STARPU_TEST_SKIPPED);
  40. starpu_profiling_status_set(1);
  41. struct starpu_codelet cl =
  42. {
  43. .cpu_funcs = {dummy},
  44. .cpu_funcs_name = {"dummy"},
  45. .opencl_funcs = {dummy},
  46. .cuda_funcs = {dummy},
  47. .nbuffers = 0
  48. };
  49. struct starpu_task *task0 = starpu_task_create();
  50. task0->cl = &cl;
  51. task0->destroy = 0;
  52. struct starpu_task *task1 = starpu_task_create();
  53. task1->cl = &cl;
  54. task1->destroy = 0;
  55. starpu_task_declare_deps_array(task0, 1, &task1);
  56. ret = starpu_task_submit(task0);
  57. if (ret == -ENODEV) goto enodev;
  58. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  59. ret = starpu_task_submit(task1);
  60. if (ret == -ENODEV) goto enodev;
  61. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  62. starpu_task_wait_for_all();
  63. double task1_end, task0_start;
  64. task1_end = starpu_timing_timespec_to_us(&task1->profiling_info->end_time);
  65. task0_start = starpu_timing_timespec_to_us(&task0->profiling_info->start_time);
  66. starpu_task_destroy(task0);
  67. starpu_task_destroy(task1);
  68. starpu_shutdown();
  69. return !!(task1_end > task0_start);
  70. enodev:
  71. starpu_shutdown();
  72. return -ENODEV;
  73. }
  74. int main(void)
  75. {
  76. struct starpu_sched_policy **policies;
  77. struct starpu_sched_policy **policy;
  78. char *sched = getenv("STARPU_SCHED");
  79. policies = starpu_sched_get_predefined_policies();
  80. for(policy=policies ; *policy!=NULL ; policy++)
  81. {
  82. int ret;
  83. if (sched && strcmp(sched, (*policy)->policy_name))
  84. /* Testing another specific scheduler, no need to run this */
  85. continue;
  86. FPRINTF(stderr, "Running with policy %s.\n", (*policy)->policy_name);
  87. ret = run(*policy);
  88. if (ret == -ENODEV)
  89. return STARPU_TEST_SKIPPED;
  90. if (ret == 1)
  91. return EXIT_FAILURE;
  92. }
  93. return EXIT_SUCCESS;
  94. }