cg.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2012-2013 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2013 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #ifndef __CG_H__
  18. #define __CG_H__
  19. #include <starpu.h>
  20. #include <common/config.h>
  21. /* we do not necessarily want to allocate room for 256 dependencies, but we
  22. want to handle the few situation where there are a lot of dependencies as
  23. well */
  24. #define STARPU_DYNAMIC_DEPS_SIZE 1
  25. /* randomly choosen ! */
  26. #ifndef STARPU_DYNAMIC_DEPS_SIZE
  27. #define STARPU_NMAXDEPS 256
  28. #endif
  29. struct _starpu_job;
  30. /* Completion Group list, records both the number of expected notifications
  31. * before the completion can start, and the list of successors when the
  32. * completion is finished. */
  33. struct _starpu_cg_list
  34. {
  35. /* Protects atomicity of the list and the terminated flag */
  36. struct _starpu_spinlock lock;
  37. /* Number of notifications to be waited for */
  38. unsigned ndeps; /* how many deps ? */
  39. unsigned ndeps_completed; /* how many deps are done ? */
  40. /* Whether the completion is finished.
  41. * For restartable/restarted tasks, only the first iteration is taken into account here.
  42. */
  43. unsigned terminated;
  44. /* List of successors */
  45. unsigned nsuccs; /* how many successors ? */
  46. #ifdef STARPU_DYNAMIC_DEPS_SIZE
  47. unsigned succ_list_size; /* How many allocated items in succ */
  48. struct _starpu_cg **succ;
  49. #else
  50. struct _starpu_cg *succ[STARPU_NMAXDEPS];
  51. #endif
  52. };
  53. enum _starpu_cg_type
  54. {
  55. STARPU_CG_APPS=(1<<0),
  56. STARPU_CG_TAG=(1<<1),
  57. STARPU_CG_TASK=(1<<2)
  58. };
  59. /* Completion Group */
  60. struct _starpu_cg
  61. {
  62. unsigned ntags; /* number of tags depended on */
  63. unsigned remaining; /* number of remaining tags */
  64. enum _starpu_cg_type cg_type;
  65. union
  66. {
  67. /* STARPU_CG_TAG */
  68. struct _starpu_tag *tag;
  69. /* STARPU_CG_TASK */
  70. struct _starpu_job *job;
  71. /* STARPU_CG_APPS */
  72. /* in case this completion group is related to an application,
  73. * we have to explicitely wake the waiting thread instead of
  74. * reschedule the corresponding task */
  75. struct
  76. {
  77. unsigned completed;
  78. starpu_pthread_mutex_t cg_mutex;
  79. starpu_pthread_cond_t cg_cond;
  80. } succ_apps;
  81. } succ;
  82. };
  83. void _starpu_cg_list_init(struct _starpu_cg_list *list);
  84. void _starpu_cg_list_deinit(struct _starpu_cg_list *list);
  85. int _starpu_add_successor_to_cg_list(struct _starpu_cg_list *successors, struct _starpu_cg *cg);
  86. void _starpu_notify_cg(struct _starpu_cg *cg);
  87. void _starpu_notify_cg_list(struct _starpu_cg_list *successors);
  88. void _starpu_notify_task_dependencies(struct _starpu_job *j);
  89. #endif // __CG_H__