simple_deps.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. .fpga_funcs = {dummy},
  48. .nbuffers = 0
  49. };
  50. struct starpu_task *task0 = starpu_task_create();
  51. task0->cl = &cl;
  52. task0->destroy = 0;
  53. struct starpu_task *task1 = starpu_task_create();
  54. task1->cl = &cl;
  55. task1->destroy = 0;
  56. starpu_task_declare_deps_array(task0, 1, &task1);
  57. ret = starpu_task_submit(task0);
  58. if (ret == -ENODEV) goto enodev;
  59. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  60. ret = starpu_task_submit(task1);
  61. if (ret == -ENODEV) goto enodev;
  62. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  63. starpu_task_wait_for_all();
  64. double task1_end, task0_start;
  65. task1_end = starpu_timing_timespec_to_us(&task1->profiling_info->end_time);
  66. task0_start = starpu_timing_timespec_to_us(&task0->profiling_info->start_time);
  67. starpu_task_destroy(task0);
  68. starpu_task_destroy(task1);
  69. starpu_shutdown();
  70. return !!(task1_end > task0_start);
  71. enodev:
  72. starpu_shutdown();
  73. return -ENODEV;
  74. }
  75. int main(void)
  76. {
  77. struct starpu_sched_policy **policies;
  78. struct starpu_sched_policy **policy;
  79. char *sched = getenv("STARPU_SCHED");
  80. policies = starpu_sched_get_predefined_policies();
  81. for(policy=policies ; *policy!=NULL ; policy++)
  82. {
  83. int ret;
  84. if (sched && strcmp(sched, (*policy)->policy_name))
  85. /* Testing another specific scheduler, no need to run this */
  86. continue;
  87. FPRINTF(stderr, "Running with policy %s.\n", (*policy)->policy_name);
  88. ret = run(*policy);
  89. if (ret == -ENODEV)
  90. return STARPU_TEST_SKIPPED;
  91. if (ret == 1)
  92. return EXIT_FAILURE;
  93. }
  94. return EXIT_SUCCESS;
  95. }