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-2022 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 #pragma GCC visibility push(hidden)
35 
36 extern char _starpu_worker_drives_memory[STARPU_NMAXWORKERS][STARPU_MAXNODES];
37 
39 {
40  starpu_pthread_cond_t *cond;
41  struct _starpu_worker *worker;
42 };
43 
44 // TODO: split out all these arrays into struct _starpu_node
46 {
47  unsigned nnodes;
49  const struct _starpu_node_ops *node_ops[STARPU_MAXNODES];
50 
53 
54  unsigned nworkers[STARPU_MAXNODES];
55 
56 #ifdef STARPU_SIMGRID
57  starpu_sg_host_t host[STARPU_MAXNODES];
58 #endif
59 
60  // TODO move this 2 lists outside struct _starpu_memory_node_descr
66  starpu_pthread_rwlock_t conditions_rwlock;
67  struct _starpu_cond_and_worker conditions_attached_to_node[STARPU_MAXNODES][STARPU_NMAXWORKERS];
71  unsigned condition_count[STARPU_MAXNODES];
72  unsigned mapped[STARPU_MAXNODES];
73 };
74 
75 extern struct _starpu_memory_node_descr _starpu_descr;
76 
77 void _starpu_memory_nodes_init(void);
78 void _starpu_memory_nodes_deinit(void);
79 
80 static inline void _starpu_memory_node_add_nworkers(unsigned node)
81 {
82  _starpu_descr.nworkers[node]++;
83 }
84 
86 void _starpu_worker_drives_memory_node(struct _starpu_worker *worker, unsigned memnode);
87 
88 static inline const struct _starpu_node_ops *_starpu_memory_node_get_node_ops(unsigned node)
89 {
90  return _starpu_descr.node_ops[node];
91 }
92 
93 static inline unsigned _starpu_memory_node_get_nworkers(unsigned node)
94 {
95  return _starpu_descr.nworkers[node];
96 }
97 
98 #ifdef STARPU_SIMGRID
99 static inline void _starpu_simgrid_memory_node_set_host(unsigned node, starpu_sg_host_t host)
100 {
101  _starpu_descr.host[node] = host;
102 }
103 
104 static inline starpu_sg_host_t _starpu_simgrid_memory_node_get_host(unsigned node)
105 {
106  return _starpu_descr.host[node];
107 }
108 #endif
109 
110 void _starpu_memory_node_set_mapped(unsigned node);
111 unsigned _starpu_memory_node_get_mapped(unsigned node);
112 
113 unsigned _starpu_memory_node_register(enum starpu_node_kind kind, int devid);
114 
115 //void _starpu_memory_node_attach_queue(struct starpu_jobq_s *q, unsigned nodeid);
116 void _starpu_memory_node_register_condition(struct _starpu_worker *worker, starpu_pthread_cond_t *cond, unsigned nodeid);
117 
118 static inline struct _starpu_memory_node_descr *_starpu_memory_node_get_description(void)
119 {
120  return &_starpu_descr;
121 }
122 
123 #define _starpu_node_needs_map_update(node) \
124  (starpu_node_get_kind(node) == STARPU_OPENCL_RAM)
125 
126 static inline enum starpu_node_kind _starpu_node_get_kind(unsigned node)
127 {
128  return _starpu_descr.nodes[node];
129 }
130 #define starpu_node_get_kind _starpu_node_get_kind
131 
132 #if STARPU_MAXNODES == 1
133 #define _starpu_memory_nodes_get_count() 1
134 #else
135 static inline unsigned _starpu_memory_nodes_get_count(void)
136 {
137  return _starpu_descr.nnodes;
138 }
139 #endif
140 #define starpu_memory_nodes_get_count _starpu_memory_nodes_get_count
141 
142 #if STARPU_MAXNODES == 1
143 #define _starpu_worker_get_memory_node(workerid) 0
144 #else
145 static inline unsigned _starpu_worker_get_memory_node(unsigned workerid)
146 {
147  struct _starpu_machine_config *config = _starpu_get_machine_config();
148 
150  unsigned nworkers = config->topology.nworkers;
151 
152  if (workerid < config->topology.nworkers)
153  return config->workers[workerid].memory_node;
154 
156  unsigned ncombinedworkers STARPU_ATTRIBUTE_UNUSED = config->topology.ncombinedworkers;
157  STARPU_ASSERT_MSG(workerid < ncombinedworkers + nworkers, "Bad workerid %u, maximum %u", workerid, ncombinedworkers + nworkers);
158  return config->combined_workers[workerid - nworkers].memory_node;
159 
160 }
161 #endif
162 #define starpu_worker_get_memory_node _starpu_worker_get_memory_node
163 
164 #if STARPU_MAXNODES == 1
165 #define _starpu_worker_get_local_memory_node() 0
166 #else
167 static inline unsigned _starpu_worker_get_local_memory_node(void)
168 {
169  struct _starpu_worker *worker = _starpu_get_local_worker_key();
170  if (!worker)
171  return STARPU_MAIN_RAM;
172  return worker->memory_node;
173 }
174 #endif
175 #define starpu_worker_get_local_memory_node _starpu_worker_get_local_memory_node
176 
177 #pragma GCC visibility pop
178 
179 #endif // __MEMORY_NODES_H__
starpu_node_kind
Definition: starpu_worker.h:44
#define STARPU_MAXNODES
Definition: starpu_config.h:217
#define STARPU_NMAXWORKERS
Definition: starpu_config.h:284
void _starpu_worker_drives_memory_node(struct _starpu_worker *worker, unsigned memnode)
starpu_pthread_rwlock_t conditions_rwlock
Definition: memory_nodes.h:66
int devid[STARPU_MAXNODES]
Definition: memory_nodes.h:52
unsigned total_condition_count
Definition: memory_nodes.h:70
static unsigned _starpu_worker_get_memory_node(unsigned workerid)
Definition: memory_nodes.h:145
Definition: memory_nodes.h:39
Definition: memory_nodes.h:46
unsigned memory_node
Definition: workers.h:315
Definition: workers.h:441
struct _starpu_combined_worker combined_workers[STARPU_NMAX_COMBINEDWORKERS]
Definition: workers.h:475
struct _starpu_worker workers[STARPU_NMAXWORKERS]
Definition: workers.h:468
unsigned nworkers
Definition: workers.h:354
unsigned ncombinedworkers
Definition: workers.h:357
Definition: node_ops.h:92
Definition: workers.h:155
unsigned memory_node
Definition: workers.h:172