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-2021 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>
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
34extern 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
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
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];
68 unsigned condition_count[STARPU_MAXNODES];
69};
70
71extern struct _starpu_memory_node_descr _starpu_descr;
72
73void _starpu_memory_nodes_init(void);
74void _starpu_memory_nodes_deinit(void);
75
76static inline void _starpu_memory_node_add_nworkers(unsigned node)
77{
78 _starpu_descr.nworkers[node]++;
79}
80
82void _starpu_worker_drives_memory_node(struct _starpu_worker *worker, unsigned memnode);
83
84static inline struct _starpu_node_ops *_starpu_memory_node_get_node_ops(unsigned node)
85{
86 return _starpu_descr.node_ops[node];
87}
88
89static inline unsigned _starpu_memory_node_get_nworkers(unsigned node)
90{
91 return _starpu_descr.nworkers[node];
92}
93
94#ifdef STARPU_SIMGRID
95static inline void _starpu_simgrid_memory_node_set_host(unsigned node, starpu_sg_host_t host)
96{
97 _starpu_descr.host[node] = host;
98}
99
100static inline starpu_sg_host_t _starpu_simgrid_memory_node_get_host(unsigned node)
101{
102 return _starpu_descr.host[node];
103}
104#endif
105unsigned _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);
107void _starpu_memory_node_register_condition(struct _starpu_worker *worker, starpu_pthread_cond_t *cond, unsigned nodeid);
108
109static inline struct _starpu_memory_node_descr *_starpu_memory_node_get_description(void)
110{
111 return &_starpu_descr;
112}
113
114static 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#if STARPU_MAXNODES == 1
121#define _starpu_memory_nodes_get_count() 1
122#else
123static inline unsigned _starpu_memory_nodes_get_count(void)
124{
125 return _starpu_descr.nnodes;
126}
127#endif
128#define starpu_memory_nodes_get_count _starpu_memory_nodes_get_count
129
130#if STARPU_MAXNODES == 1
131#define _starpu_worker_get_memory_node(workerid) 0
132#else
133static inline unsigned _starpu_worker_get_memory_node(unsigned workerid)
134{
135 struct _starpu_machine_config *config = _starpu_get_machine_config();
136
138 unsigned nworkers = config->topology.nworkers;
139
140 if (workerid < config->topology.nworkers)
141 return config->workers[workerid].memory_node;
142
144 unsigned ncombinedworkers STARPU_ATTRIBUTE_UNUSED = config->topology.ncombinedworkers;
145 STARPU_ASSERT_MSG(workerid < ncombinedworkers + nworkers, "Bad workerid %u, maximum %u", workerid, ncombinedworkers + nworkers);
146 return config->combined_workers[workerid - nworkers].memory_node;
147
148}
149#endif
150#define starpu_worker_get_memory_node _starpu_worker_get_memory_node
151
152#if STARPU_MAXNODES == 1
153#define _starpu_worker_get_local_memory_node() 0
154#else
155static inline unsigned _starpu_worker_get_local_memory_node(void)
156{
157 struct _starpu_worker *worker = _starpu_get_local_worker_key();
158 if (!worker)
159 return STARPU_MAIN_RAM;
160 return worker->memory_node;
161}
162#endif
163#define starpu_worker_get_local_memory_node _starpu_worker_get_local_memory_node
164
165#endif // __MEMORY_NODES_H__
void _starpu_worker_drives_memory_node(struct _starpu_worker *worker, unsigned memnode)
starpu_pthread_rwlock_t conditions_rwlock
Definition: memory_nodes.h:63
int devid[STARPU_MAXNODES]
Definition: memory_nodes.h:49
unsigned total_condition_count
Definition: memory_nodes.h:67
static unsigned _starpu_worker_get_memory_node(unsigned workerid)
Definition: memory_nodes.h:133
Definition: memory_nodes.h:37
Definition: memory_nodes.h:43
unsigned memory_node
Definition: workers.h:207
Definition: workers.h:352
struct _starpu_combined_worker combined_workers[STARPU_NMAX_COMBINEDWORKERS]
Definition: workers.h:397
struct _starpu_worker workers[STARPU_NMAXWORKERS]
Definition: workers.h:393
unsigned nworkers
Definition: workers.h:249
unsigned ncombinedworkers
Definition: workers.h:252
Definition: node_ops.h:48
Definition: workers.h:70
unsigned memory_node
Definition: workers.h:86