graph.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2016-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. #ifndef __GRAPH_H__
  17. #define __GRAPH_H__
  18. #include <common/list.h>
  19. #pragma GCC visibility push(hidden)
  20. /** @file */
  21. MULTILIST_CREATE_TYPE(_starpu_graph_node, all)
  22. MULTILIST_CREATE_TYPE(_starpu_graph_node, top)
  23. MULTILIST_CREATE_TYPE(_starpu_graph_node, bottom)
  24. MULTILIST_CREATE_TYPE(_starpu_graph_node, dropped)
  25. struct _starpu_graph_node
  26. {
  27. /** protects access to the job */
  28. starpu_pthread_mutex_t mutex;
  29. /** pointer to the job, if it is still alive, NULL otherwise */
  30. struct _starpu_job *job;
  31. /**
  32. * Fields for graph analysis for scheduling heuristics
  33. */
  34. /** Member of list of all jobs without incoming dependency */
  35. struct _starpu_graph_node_multilist_top top;
  36. /** Member of list of all jobs without outgoing dependency */
  37. struct _starpu_graph_node_multilist_bottom bottom;
  38. /** Member of list of all jobs */
  39. struct _starpu_graph_node_multilist_all all;
  40. /** Member of list of dropped jobs */
  41. struct _starpu_graph_node_multilist_dropped dropped;
  42. /** set of incoming dependencies */
  43. /** May contain NULLs for terminated jobs */
  44. struct _starpu_graph_node **incoming;
  45. /** Index within corresponding outgoing array */
  46. unsigned *incoming_slot;
  47. /** Number of slots used */
  48. unsigned n_incoming;
  49. /** Size of incoming */
  50. unsigned alloc_incoming;
  51. /** set of outgoing dependencies */
  52. struct _starpu_graph_node **outgoing;
  53. /** Index within corresponding incoming array */
  54. unsigned *outgoing_slot;
  55. /** Number of slots used */
  56. unsigned n_outgoing;
  57. /** Size of outgoing */
  58. unsigned alloc_outgoing;
  59. /** Rank from bottom, in number of jobs
  60. * Only available if _starpu_graph_compute_depths was called
  61. */
  62. unsigned depth;
  63. /** Number of children, grand-children, etc.
  64. * Only available if _starpu_graph_compute_descendants was called
  65. */
  66. unsigned descendants;
  67. /** Variable available for graph flow */
  68. int graph_n;
  69. };
  70. MULTILIST_CREATE_INLINES(struct _starpu_graph_node, _starpu_graph_node, all)
  71. MULTILIST_CREATE_INLINES(struct _starpu_graph_node, _starpu_graph_node, top)
  72. MULTILIST_CREATE_INLINES(struct _starpu_graph_node, _starpu_graph_node, bottom)
  73. MULTILIST_CREATE_INLINES(struct _starpu_graph_node, _starpu_graph_node, dropped)
  74. extern int _starpu_graph_record;
  75. void _starpu_graph_init(void);
  76. void _starpu_graph_wrlock(void);
  77. void _starpu_graph_rdlock(void);
  78. void _starpu_graph_wrunlock(void);
  79. void _starpu_graph_rdunlock(void);
  80. /** Add a job to the graph, called before any _starpu_graph_add_job_dep call */
  81. void _starpu_graph_add_job(struct _starpu_job *job);
  82. /** Add a dependency between jobs */
  83. void _starpu_graph_add_job_dep(struct _starpu_job *job, struct _starpu_job *prev_job);
  84. /** Remove a job from the graph */
  85. void _starpu_graph_drop_job(struct _starpu_job *job);
  86. /** Really drop the nodes from the graph now */
  87. void _starpu_graph_drop_dropped_nodes(void);
  88. /**
  89. * This make StarPU compute for each task the depth, i.e. the length
  90. * of the longest path to a task without outgoing dependencies.
  91. * This does not take job duration into account, just the number
  92. */
  93. void _starpu_graph_compute_depths(void);
  94. /** Compute the descendants of jobs in the graph */
  95. void _starpu_graph_compute_descendants(void);
  96. /**
  97. * This calls \e func for each node of the task graph, passing also \e
  98. * data as it
  99. * Apply func on each job of the graph
  100. */
  101. void _starpu_graph_foreach(void (*func)(void *data, struct _starpu_graph_node *node), void *data);
  102. #pragma GCC visibility pop
  103. #endif /* __GRAPH_H__ */