memory_nodes.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-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 __MEMORY_NODES_H__
  17. #define __MEMORY_NODES_H__
  18. /** @file */
  19. #include <starpu.h>
  20. #include <common/config.h>
  21. #include <datawizard/coherency.h>
  22. #include <datawizard/memalloc.h>
  23. #include <datawizard/node_ops.h>
  24. #include <common/utils.h>
  25. #include <core/workers.h>
  26. #ifdef STARPU_SIMGRID
  27. #include <core/simgrid.h>
  28. #endif
  29. extern char _starpu_worker_drives_memory[STARPU_NMAXWORKERS][STARPU_MAXNODES];
  30. struct _starpu_cond_and_worker
  31. {
  32. starpu_pthread_cond_t *cond;
  33. struct _starpu_worker *worker;
  34. };
  35. struct _starpu_memory_node_descr
  36. {
  37. unsigned nnodes;
  38. enum starpu_node_kind nodes[STARPU_MAXNODES];
  39. struct _starpu_node_ops *node_ops[STARPU_MAXNODES];
  40. /** Get the device id associated to this node, or -1 if not applicable */
  41. int devid[STARPU_MAXNODES];
  42. unsigned nworkers[STARPU_MAXNODES];
  43. #ifdef STARPU_SIMGRID
  44. starpu_sg_host_t host[STARPU_MAXNODES];
  45. #endif
  46. // TODO move this 2 lists outside struct _starpu_memory_node_descr
  47. /** Every worker is associated to a condition variable on which the
  48. * worker waits when there is task available. It is possible that
  49. * multiple worker share the same condition variable, so we maintain a
  50. * list of all these condition variables so that we can wake up all
  51. * worker attached to a memory node that are waiting on a task. */
  52. starpu_pthread_rwlock_t conditions_rwlock;
  53. struct _starpu_cond_and_worker conditions_attached_to_node[STARPU_MAXNODES][STARPU_NMAXWORKERS];
  54. struct _starpu_cond_and_worker conditions_all[STARPU_MAXNODES*STARPU_NMAXWORKERS];
  55. /** the number of queues attached to each node */
  56. unsigned total_condition_count;
  57. unsigned condition_count[STARPU_MAXNODES];
  58. };
  59. extern struct _starpu_memory_node_descr _starpu_descr;
  60. void _starpu_memory_nodes_init(void);
  61. void _starpu_memory_nodes_deinit(void);
  62. static inline void _starpu_memory_node_add_nworkers(unsigned node)
  63. {
  64. _starpu_descr.nworkers[node]++;
  65. }
  66. /** same utility as _starpu_memory_node_add_nworkers */
  67. void _starpu_worker_drives_memory_node(struct _starpu_worker *worker, unsigned memnode);
  68. static inline struct _starpu_node_ops *_starpu_memory_node_get_node_ops(unsigned node)
  69. {
  70. return _starpu_descr.node_ops[node];
  71. }
  72. static inline unsigned _starpu_memory_node_get_nworkers(unsigned node)
  73. {
  74. return _starpu_descr.nworkers[node];
  75. }
  76. #ifdef STARPU_SIMGRID
  77. static inline void _starpu_simgrid_memory_node_set_host(unsigned node, starpu_sg_host_t host)
  78. {
  79. _starpu_descr.host[node] = host;
  80. }
  81. static inline starpu_sg_host_t _starpu_simgrid_memory_node_get_host(unsigned node)
  82. {
  83. return _starpu_descr.host[node];
  84. }
  85. #endif
  86. unsigned _starpu_memory_node_register(enum starpu_node_kind kind, int devid, struct _starpu_node_ops *node_ops);
  87. //void _starpu_memory_node_attach_queue(struct starpu_jobq_s *q, unsigned nodeid);
  88. void _starpu_memory_node_register_condition(struct _starpu_worker *worker, starpu_pthread_cond_t *cond, unsigned nodeid);
  89. static inline struct _starpu_memory_node_descr *_starpu_memory_node_get_description(void)
  90. {
  91. return &_starpu_descr;
  92. }
  93. static inline enum starpu_node_kind _starpu_node_get_kind(unsigned node)
  94. {
  95. return _starpu_descr.nodes[node];
  96. }
  97. #define starpu_node_get_kind _starpu_node_get_kind
  98. static inline unsigned _starpu_memory_nodes_get_count(void)
  99. {
  100. return _starpu_descr.nnodes;
  101. }
  102. #define starpu_memory_nodes_get_count _starpu_memory_nodes_get_count
  103. static inline unsigned _starpu_worker_get_memory_node(unsigned workerid)
  104. {
  105. struct _starpu_machine_config *config = _starpu_get_machine_config();
  106. /** This workerid may either be a basic worker or a combined worker */
  107. unsigned nworkers = config->topology.nworkers;
  108. if (workerid < config->topology.nworkers)
  109. return config->workers[workerid].memory_node;
  110. /** We have a combined worker */
  111. unsigned ncombinedworkers STARPU_ATTRIBUTE_UNUSED = config->topology.ncombinedworkers;
  112. STARPU_ASSERT_MSG(workerid < ncombinedworkers + nworkers, "Bad workerid %u, maximum %u", workerid, ncombinedworkers + nworkers);
  113. return config->combined_workers[workerid - nworkers].memory_node;
  114. }
  115. #define starpu_worker_get_memory_node _starpu_worker_get_memory_node
  116. #endif // __MEMORY_NODES_H__