memory_nodes.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2012,2014-2017 Université de Bordeaux
  4. * Copyright (C) 2012,2016,2017 Inria
  5. * Copyright (C) 2010,2011,2013,2015,2017 CNRS
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #ifndef __MEMORY_NODES_H__
  19. #define __MEMORY_NODES_H__
  20. #include <starpu.h>
  21. #include <common/config.h>
  22. #include <datawizard/coherency.h>
  23. #include <datawizard/memalloc.h>
  24. #include <common/utils.h>
  25. #include <core/workers.h>
  26. #ifdef STARPU_SIMGRID
  27. #include <core/simgrid.h>
  28. #endif
  29. #define _STARPU_MEMORY_NODE_TUPLE(node1,node2) (node1 | (node2 << 4))
  30. #define _STARPU_MEMORY_NODE_TUPLE_FIRST(tuple) (tuple & 0x0F)
  31. #define _STARPU_MEMORY_NODE_TUPLE_SECOND(tuple) (tuple & 0xF0)
  32. extern char _starpu_worker_drives_memory[STARPU_NMAXWORKERS][STARPU_MAXNODES];
  33. struct _starpu_cond_and_worker
  34. {
  35. starpu_pthread_cond_t *cond;
  36. struct _starpu_worker *worker;
  37. };
  38. struct _starpu_memory_node_descr
  39. {
  40. unsigned nnodes;
  41. enum starpu_node_kind nodes[STARPU_MAXNODES];
  42. /* Get the device id associated to this node, or -1 if not applicable */
  43. int devid[STARPU_MAXNODES];
  44. unsigned nworkers[STARPU_MAXNODES];
  45. #ifdef STARPU_SIMGRID
  46. msg_host_t host[STARPU_MAXNODES];
  47. #endif
  48. // TODO move this 2 lists outside struct _starpu_memory_node_descr
  49. /* Every worker is associated to a condition variable on which the
  50. * worker waits when there is task available. It is possible that
  51. * multiple worker share the same condition variable, so we maintain a
  52. * list of all these condition variables so that we can wake up all
  53. * worker attached to a memory node that are waiting on a task. */
  54. starpu_pthread_rwlock_t conditions_rwlock;
  55. struct _starpu_cond_and_worker conditions_attached_to_node[STARPU_MAXNODES][STARPU_NMAXWORKERS];
  56. struct _starpu_cond_and_worker conditions_all[STARPU_MAXNODES*STARPU_NMAXWORKERS];
  57. /* the number of queues attached to each node */
  58. unsigned total_condition_count;
  59. unsigned condition_count[STARPU_MAXNODES];
  60. };
  61. extern struct _starpu_memory_node_descr _starpu_descr;
  62. void _starpu_memory_nodes_init(void);
  63. void _starpu_memory_nodes_deinit(void);
  64. static inline unsigned _starpu_memory_node_get_local_key(void)
  65. {
  66. struct _starpu_worker *worker = _starpu_get_local_worker_key();
  67. if (!worker)
  68. return STARPU_MAIN_RAM;
  69. return worker->memory_node;
  70. }
  71. static inline void _starpu_memory_node_add_nworkers(unsigned node)
  72. {
  73. _starpu_descr.nworkers[node]++;
  74. }
  75. /* same utility as _starpu_memory_node_add_nworkers */
  76. void _starpu_worker_drives_memory_node(struct _starpu_worker *worker, unsigned memnode);
  77. static inline unsigned _starpu_memory_node_get_nworkers(unsigned node)
  78. {
  79. return _starpu_descr.nworkers[node];
  80. }
  81. #ifdef STARPU_SIMGRID
  82. static inline void _starpu_simgrid_memory_node_set_host(unsigned node, msg_host_t host)
  83. {
  84. _starpu_descr.host[node] = host;
  85. }
  86. static inline msg_host_t _starpu_simgrid_memory_node_get_host(unsigned node)
  87. {
  88. return _starpu_descr.host[node];
  89. }
  90. #endif
  91. unsigned _starpu_memory_node_register(enum starpu_node_kind kind, int devid);
  92. //void _starpu_memory_node_attach_queue(struct starpu_jobq_s *q, unsigned nodeid);
  93. void _starpu_memory_node_register_condition(struct _starpu_worker *worker, starpu_pthread_cond_t *cond, unsigned nodeid);
  94. static inline int _starpu_memory_node_get_devid(unsigned node)
  95. {
  96. return _starpu_descr.devid[node];
  97. }
  98. void _starpu_memory_node_get_name(unsigned node, char *name, int size);
  99. static inline struct _starpu_memory_node_descr *_starpu_memory_node_get_description(void)
  100. {
  101. return &_starpu_descr;
  102. }
  103. static inline enum starpu_node_kind _starpu_node_get_kind(unsigned node)
  104. {
  105. return _starpu_descr.nodes[node];
  106. }
  107. #define starpu_node_get_kind _starpu_node_get_kind
  108. static inline unsigned _starpu_memory_nodes_get_count(void)
  109. {
  110. return _starpu_descr.nnodes;
  111. }
  112. #define starpu_memory_nodes_get_count _starpu_memory_nodes_get_count
  113. static inline unsigned _starpu_worker_get_memory_node(unsigned workerid)
  114. {
  115. struct _starpu_machine_config *config = _starpu_get_machine_config();
  116. /* This workerid may either be a basic worker or a combined worker */
  117. unsigned nworkers = config->topology.nworkers;
  118. if (workerid < config->topology.nworkers)
  119. return config->workers[workerid].memory_node;
  120. /* We have a combined worker */
  121. unsigned ncombinedworkers STARPU_ATTRIBUTE_UNUSED = config->topology.ncombinedworkers;
  122. STARPU_ASSERT_MSG(workerid < ncombinedworkers + nworkers, "Bad workerid %u, maximum %u", workerid, ncombinedworkers + nworkers);
  123. return config->combined_workers[workerid - nworkers].memory_node;
  124. }
  125. #define starpu_worker_get_memory_node _starpu_worker_get_memory_node
  126. #endif // __MEMORY_NODES_H__