simple_deps.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012 Inria
  4. * Copyright (C) 2012,2013,2015,2017 CNRS
  5. * Copyright (C) 2014-2016,2019 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <unistd.h>
  19. #include <starpu.h>
  20. #include <starpu_scheduler.h>
  21. #include "../helper.h"
  22. /*
  23. * Task1 must be executed before task0, even if task0 is submitted first.
  24. * Applies to : all schedulers.
  25. */
  26. void dummy(void *buffers[], void *args)
  27. {
  28. (void) buffers;
  29. (void) args;
  30. usleep(10000);
  31. }
  32. static int
  33. run(struct starpu_sched_policy *policy)
  34. {
  35. int ret;
  36. struct starpu_conf conf;
  37. starpu_conf_init(&conf);
  38. conf.sched_policy = policy;
  39. ret = starpu_init(&conf);
  40. if (ret != 0)
  41. exit(STARPU_TEST_SKIPPED);
  42. starpu_profiling_status_set(1);
  43. struct starpu_codelet cl =
  44. {
  45. .cpu_funcs = {dummy},
  46. .cpu_funcs_name = {"dummy"},
  47. .opencl_funcs = {dummy},
  48. .cuda_funcs = {dummy},
  49. .nbuffers = 0
  50. };
  51. struct starpu_task *task0 = starpu_task_create();
  52. task0->cl = &cl;
  53. task0->destroy = 0;
  54. struct starpu_task *task1 = starpu_task_create();
  55. task1->cl = &cl;
  56. task1->destroy = 0;
  57. starpu_task_declare_deps_array(task0, 1, &task1);
  58. ret = starpu_task_submit(task0);
  59. if (ret == -ENODEV) goto enodev;
  60. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  61. ret = starpu_task_submit(task1);
  62. if (ret == -ENODEV) goto enodev;
  63. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  64. starpu_task_wait_for_all();
  65. double task1_end, task0_start;
  66. task1_end = starpu_timing_timespec_to_us(&task1->profiling_info->end_time);
  67. task0_start = starpu_timing_timespec_to_us(&task0->profiling_info->start_time);
  68. starpu_task_destroy(task0);
  69. starpu_task_destroy(task1);
  70. starpu_shutdown();
  71. return !!(task1_end > task0_start);
  72. enodev:
  73. starpu_shutdown();
  74. return -ENODEV;
  75. }
  76. int main(void)
  77. {
  78. struct starpu_sched_policy **policies;
  79. struct starpu_sched_policy **policy;
  80. char *sched = getenv("STARPU_SCHED");
  81. policies = starpu_sched_get_predefined_policies();
  82. for(policy=policies ; *policy!=NULL ; policy++)
  83. {
  84. int ret;
  85. if (sched && strcmp(sched, (*policy)->policy_name))
  86. /* Testing another specific scheduler, no need to run this */
  87. continue;
  88. FPRINTF(stderr, "Running with policy %s.\n", (*policy)->policy_name);
  89. ret = run(*policy);
  90. if (ret == -ENODEV)
  91. return STARPU_TEST_SKIPPED;
  92. if (ret == 1)
  93. return EXIT_FAILURE;
  94. }
  95. return EXIT_SUCCESS;
  96. }