graph.h 4.0 KB

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