graph.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2016 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 n_incoming; /* Number of slots used */
  40. unsigned alloc_incoming; /* Size of incoming */
  41. /* set of outgoing dependencies */
  42. struct _starpu_graph_node **outgoing;
  43. unsigned *outgoing_slot; /* Index within corresponding incoming array */
  44. unsigned n_outgoing; /* Number of slots used */
  45. unsigned alloc_outgoing; /* Size of outgoing */
  46. unsigned depth; /* Rank from bottom, in number of jobs */
  47. /* Only available if _starpu_graph_compute_depths was called */
  48. unsigned descendants; /* Number of children, grand-children, etc. */
  49. /* Only available if _starpu_graph_compute_descendants was called */
  50. int graph_n; /* Variable available for graph flow */
  51. };
  52. MULTILIST_CREATE_INLINES(struct _starpu_graph_node, _starpu_graph_node, all)
  53. MULTILIST_CREATE_INLINES(struct _starpu_graph_node, _starpu_graph_node, top)
  54. MULTILIST_CREATE_INLINES(struct _starpu_graph_node, _starpu_graph_node, bottom)
  55. MULTILIST_CREATE_INLINES(struct _starpu_graph_node, _starpu_graph_node, dropped)
  56. extern int _starpu_graph_record;
  57. void _starpu_graph_init(void);
  58. void _starpu_graph_wrlock(void);
  59. void _starpu_graph_rdlock(void);
  60. void _starpu_graph_wrunlock(void);
  61. void _starpu_graph_rdunlock(void);
  62. /* Add a job to the graph, called before any _starpu_graph_add_job_dep call */
  63. void _starpu_graph_add_job(struct _starpu_job *job);
  64. /* Add a dependency between jobs */
  65. void _starpu_graph_add_job_dep(struct _starpu_job *job, struct _starpu_job *prev_job);
  66. /* Remove a job from the graph */
  67. void _starpu_graph_drop_job(struct _starpu_job *job);
  68. /* This make StarPU compute for each task the depth, i.e. the length of the longest path to a task without outgoing dependencies. */
  69. /* This does not take job duration into account, just the number */
  70. void _starpu_graph_compute_depths(void);
  71. /* Compute the descendants of jobs in the graph */
  72. void _starpu_graph_compute_descendants(void);
  73. /* This calls \e func for each node of the task graph, passing also \e data as it */
  74. /* Apply func on each job of the graph */
  75. void _starpu_graph_foreach(void (*func)(void *data, struct _starpu_graph_node *node), void *data);
  76. #endif /* __GRAPH_H__ */