graph.h 4.0 KB

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