task_deps.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2013 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012, 2013 Centre National de la Recherche Scientifique
  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 <starpu.h>
  18. #include <common/config.h>
  19. #include <common/utils.h>
  20. #include <core/dependencies/tags.h>
  21. #include <core/jobs.h>
  22. #include <core/task.h>
  23. #include <core/sched_policy.h>
  24. #include <core/dependencies/data_concurrency.h>
  25. #include <profiling/bound.h>
  26. #include <core/debug.h>
  27. static struct _starpu_cg *create_cg_task(unsigned ntags, struct _starpu_job *j)
  28. {
  29. struct _starpu_cg *cg = (struct _starpu_cg *) malloc(sizeof(struct _starpu_cg));
  30. STARPU_ASSERT(cg);
  31. cg->ntags = ntags;
  32. cg->remaining = ntags;
  33. cg->cg_type = STARPU_CG_TASK;
  34. cg->succ.job = j;
  35. j->job_successors.ndeps++;
  36. return cg;
  37. }
  38. static void _starpu_task_add_succ(struct _starpu_job *j, struct _starpu_cg *cg)
  39. {
  40. STARPU_ASSERT(j);
  41. if (_starpu_add_successor_to_cg_list(&j->job_successors, cg))
  42. /* the task was already completed sooner */
  43. _starpu_notify_cg(cg);
  44. }
  45. void _starpu_notify_task_dependencies(struct _starpu_job *j)
  46. {
  47. _starpu_notify_cg_list(&j->job_successors);
  48. }
  49. /* task depends on the tasks in task array */
  50. void _starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[], int check)
  51. {
  52. if (ndeps == 0)
  53. return;
  54. struct _starpu_job *job;
  55. job = _starpu_get_job_associated_to_task(task);
  56. STARPU_PTHREAD_MUTEX_LOCK(&job->sync_mutex);
  57. if (check)
  58. STARPU_ASSERT_MSG(!job->submitted || !task->destroy || task->detach, "Task dependencies have to be set before submission (submitted %u destroy %d detach %d)", job->submitted, task->destroy, task->detach);
  59. else
  60. STARPU_ASSERT_MSG(job->terminated <= 1, "Task dependencies have to be set before termination (terminated %u)", job->terminated);
  61. struct _starpu_cg *cg = create_cg_task(ndeps, job);
  62. STARPU_PTHREAD_MUTEX_UNLOCK(&job->sync_mutex);
  63. unsigned i;
  64. for (i = 0; i < ndeps; i++)
  65. {
  66. struct starpu_task *dep_task = task_array[i];
  67. struct _starpu_job *dep_job;
  68. dep_job = _starpu_get_job_associated_to_task(dep_task);
  69. STARPU_ASSERT_MSG(dep_job != job, "A task must not depend on itself.");
  70. STARPU_PTHREAD_MUTEX_LOCK(&dep_job->sync_mutex);
  71. if (check)
  72. {
  73. STARPU_ASSERT_MSG(!dep_job->submitted || !dep_job->task->destroy || dep_job->task->detach, "Unless it is not to be destroyed automatically, a task dependencies have to be set before submission");
  74. STARPU_ASSERT_MSG(dep_job->submitted != 2, "For resubmited tasks, dependencies have to be set before first re-submission");
  75. STARPU_ASSERT_MSG(!dep_job->submitted || !dep_job->task->regenerate, "For regenerated tasks, dependencies have to be set before first submission");
  76. } else
  77. STARPU_ASSERT_MSG(dep_job->terminated <= 1, "Task dependencies have to be set before termination (terminated %u)", dep_job->terminated);
  78. STARPU_PTHREAD_MUTEX_UNLOCK(&dep_job->sync_mutex);
  79. _STARPU_TRACE_TASK_DEPS(dep_job, job);
  80. _starpu_bound_task_dep(job, dep_job);
  81. #ifdef HAVE_AYUDAME_H
  82. if (AYU_event && check)
  83. {
  84. uintptr_t AYU_data[3] = {dep_job->job_id, 0, 0};
  85. AYU_event(AYU_ADDDEPENDENCY, job->job_id, AYU_data);
  86. }
  87. #endif
  88. _starpu_task_add_succ(dep_job, cg);
  89. }
  90. }
  91. void starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[])
  92. {
  93. _starpu_task_declare_deps_array(task, ndeps, task_array, 1);
  94. }