graph.h 3.9 KB

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