StarPU Internal Handbook
memory_nodes.h
Go to the documentation of this file.
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 
17 #ifndef __MEMORY_NODES_H__
18 #define __MEMORY_NODES_H__
19 
22 #include <starpu.h>
23 #include <common/config.h>
24 #include <datawizard/coherency.h>
25 #include <datawizard/memalloc.h>
26 #include <datawizard/node_ops.h>
27 #include <common/utils.h>
28 #include <core/workers.h>
29 
30 #ifdef STARPU_SIMGRID
31 #include <core/simgrid.h>
32 #endif
33 
34 extern char _starpu_worker_drives_memory[STARPU_NMAXWORKERS][STARPU_MAXNODES];
35 
37 {
38  starpu_pthread_cond_t *cond;
39  struct _starpu_worker *worker;
40 };
41 
43 {
44  unsigned nnodes;
45  enum starpu_node_kind nodes[STARPU_MAXNODES];
46  struct _starpu_node_ops *node_ops[STARPU_MAXNODES];
47 
48  /* Get the device id associated to this node, or -1 if not applicable */
49  int devid[STARPU_MAXNODES];
50 
51  unsigned nworkers[STARPU_MAXNODES];
52 
53 #ifdef STARPU_SIMGRID
54  starpu_sg_host_t host[STARPU_MAXNODES];
55 #endif
56 
57  // TODO move this 2 lists outside struct _starpu_memory_node_descr
58  /* Every worker is associated to a condition variable on which the
59  * worker waits when there is task available. It is possible that
60  * multiple worker share the same condition variable, so we maintain a
61  * list of all these condition variables so that we can wake up all
62  * worker attached to a memory node that are waiting on a task. */
63  starpu_pthread_rwlock_t conditions_rwlock;
64  struct _starpu_cond_and_worker conditions_attached_to_node[STARPU_MAXNODES][STARPU_NMAXWORKERS];
65  struct _starpu_cond_and_worker conditions_all[STARPU_MAXNODES*STARPU_NMAXWORKERS];
66  /* the number of queues attached to each node */
67  unsigned total_condition_count;
68  unsigned condition_count[STARPU_MAXNODES];
69 };
70 
71 extern struct _starpu_memory_node_descr _starpu_descr;
72 
73 void _starpu_memory_nodes_init(void);
74 void _starpu_memory_nodes_deinit(void);
75 
76 static inline void _starpu_memory_node_add_nworkers(unsigned node)
77 {
78  _starpu_descr.nworkers[node]++;
79 }
80 
82 void _starpu_worker_drives_memory_node(struct _starpu_worker *worker, unsigned memnode);
83 
84 static inline struct _starpu_node_ops *_starpu_memory_node_get_node_ops(unsigned node)
85 {
86  return _starpu_descr.node_ops[node];
87 }
88 
89 static inline unsigned _starpu_memory_node_get_nworkers(unsigned node)
90 {
91  return _starpu_descr.nworkers[node];
92 }
93 
94 #ifdef STARPU_SIMGRID
95 static inline void _starpu_simgrid_memory_node_set_host(unsigned node, starpu_sg_host_t host)
96 {
97  _starpu_descr.host[node] = host;
98 }
99 
100 static inline starpu_sg_host_t _starpu_simgrid_memory_node_get_host(unsigned node)
101 {
102  return _starpu_descr.host[node];
103 }
104 #endif
105 unsigned _starpu_memory_node_register(enum starpu_node_kind kind, int devid, struct _starpu_node_ops *node_ops);
106 //void _starpu_memory_node_attach_queue(struct starpu_jobq_s *q, unsigned nodeid);
107 void _starpu_memory_node_register_condition(struct _starpu_worker *worker, starpu_pthread_cond_t *cond, unsigned nodeid);
108 
109 static inline struct _starpu_memory_node_descr *_starpu_memory_node_get_description(void)
110 {
111  return &_starpu_descr;
112 }
113 
114 static inline enum starpu_node_kind _starpu_node_get_kind(unsigned node)
115 {
116  return _starpu_descr.nodes[node];
117 }
118 #define starpu_node_get_kind _starpu_node_get_kind
119 
120 static inline unsigned _starpu_memory_nodes_get_count(void)
121 {
122  return _starpu_descr.nnodes;
123 }
124 #define starpu_memory_nodes_get_count _starpu_memory_nodes_get_count
125 
126 static inline unsigned _starpu_worker_get_memory_node(unsigned workerid)
127 {
128  struct _starpu_machine_config *config = _starpu_get_machine_config();
129 
131  unsigned nworkers = config->topology.nworkers;
132 
133  if (workerid < config->topology.nworkers)
134  return config->workers[workerid].memory_node;
135 
137  unsigned ncombinedworkers STARPU_ATTRIBUTE_UNUSED = config->topology.ncombinedworkers;
138  STARPU_ASSERT_MSG(workerid < ncombinedworkers + nworkers, "Bad workerid %u, maximum %u", workerid, ncombinedworkers + nworkers);
139  return config->combined_workers[workerid - nworkers].memory_node;
140 
141 }
142 #define starpu_worker_get_memory_node _starpu_worker_get_memory_node
143 
144 #endif // __MEMORY_NODES_H__
_starpu_machine_config::workers
struct _starpu_worker workers[STARPU_NMAXWORKERS]
Definition: workers.h:394
memalloc.h
_starpu_combined_worker::memory_node
unsigned memory_node
Definition: workers.h:208
node_ops.h
coherency.h
_starpu_machine_topology::ncombinedworkers
unsigned ncombinedworkers
Definition: workers.h:253
_starpu_cond_and_worker
Definition: memory_nodes.h:37
_starpu_worker::memory_node
unsigned memory_node
Definition: workers.h:86
_starpu_worker
Definition: workers.h:70
_starpu_machine_topology::nworkers
unsigned nworkers
Definition: workers.h:250
utils.h
_starpu_machine_config::combined_workers
struct _starpu_combined_worker combined_workers[STARPU_NMAX_COMBINEDWORKERS]
Definition: workers.h:398
_starpu_worker_get_memory_node
static unsigned _starpu_worker_get_memory_node(unsigned workerid)
Definition: memory_nodes.h:126
_starpu_machine_config
Definition: workers.h:353
_starpu_memory_node_descr
Definition: memory_nodes.h:43
_starpu_worker_drives_memory_node
void _starpu_worker_drives_memory_node(struct _starpu_worker *worker, unsigned memnode)
simgrid.h
_starpu_node_ops
Definition: node_ops.h:48