StarPU Internal Handbook
Loading...
Searching...
No Matches
memory_nodes.h
Go to the documentation of this file.
1/* StarPU --- Runtime system for heterogeneous multicore architectures.
2 *
3 * Copyright (C) 2009-2023 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
34#pragma GCC visibility push(hidden)
35
36extern 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;
48 enum starpu_node_kind nodes[STARPU_MAXNODES];
49 const struct _starpu_node_ops *node_ops[STARPU_MAXNODES];
50
52 int devid[STARPU_MAXNODES];
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];
68 struct _starpu_cond_and_worker conditions_all[STARPU_MAXNODES*STARPU_NMAXWORKERS];
71 unsigned condition_count[STARPU_MAXNODES];
72 unsigned mapped[STARPU_MAXNODES];
73};
74
75extern struct _starpu_memory_node_descr _starpu_descr;
76
77void _starpu_memory_nodes_init(void);
78void _starpu_memory_nodes_deinit(void);
79
81static inline void _starpu_memory_node_add_nworkers(unsigned node)
82{
83 _starpu_descr.nworkers[node]++;
84}
85
87void _starpu_worker_drives_memory_node(struct _starpu_worker *worker, unsigned memnode);
88
89static inline const struct _starpu_node_ops *_starpu_memory_node_get_node_ops(unsigned node)
90{
91 return _starpu_descr.node_ops[node];
92}
93
95static inline unsigned _starpu_memory_node_get_nworkers(unsigned node)
96{
97 return _starpu_descr.nworkers[node];
98}
99
100#ifdef STARPU_SIMGRID
101static inline void _starpu_simgrid_memory_node_set_host(unsigned node, starpu_sg_host_t host)
102{
103 _starpu_descr.host[node] = host;
104}
105
106static inline starpu_sg_host_t _starpu_simgrid_memory_node_get_host(unsigned node)
107{
108 return _starpu_descr.host[node];
109}
110#endif
111
115unsigned _starpu_memory_node_get_mapped(unsigned node);
116
118unsigned _starpu_memory_node_register(enum starpu_node_kind kind, int devid);
119
120//void _starpu_memory_node_attach_queue(struct starpu_jobq_s *q, unsigned nodeid);
123void _starpu_memory_node_register_condition(struct _starpu_worker *worker, starpu_pthread_cond_t *cond, unsigned nodeid);
124
127{
128 return &_starpu_descr;
129}
130
131#define _starpu_node_needs_map_update(node) \
132 (starpu_node_get_kind(node) == STARPU_OPENCL_RAM)
133
135static inline enum starpu_node_kind _starpu_node_get_kind(unsigned node)
136{
137 return _starpu_descr.nodes[node];
138}
139#define starpu_node_get_kind _starpu_node_get_kind
140
141#if STARPU_MAXNODES == 1
142#define _starpu_memory_nodes_get_count() 1
143#else
145static inline unsigned _starpu_memory_nodes_get_count(void)
146{
147 return _starpu_descr.nnodes;
148}
149#endif
150#define starpu_memory_nodes_get_count _starpu_memory_nodes_get_count
151
152#if STARPU_MAXNODES == 1
153#define _starpu_worker_get_memory_node(workerid) 0
154#else
156static inline unsigned _starpu_worker_get_memory_node(unsigned workerid)
157{
158 struct _starpu_machine_config *config = _starpu_get_machine_config();
159
161 unsigned nworkers = config->topology.nworkers;
162
163 if (workerid < config->topology.nworkers)
164 return config->workers[workerid].memory_node;
165
167 unsigned ncombinedworkers STARPU_ATTRIBUTE_UNUSED = config->topology.ncombinedworkers;
168 STARPU_ASSERT_MSG(workerid < ncombinedworkers + nworkers, "Bad workerid %u, maximum %u", workerid, ncombinedworkers + nworkers);
169 return config->combined_workers[workerid - nworkers].memory_node;
170
171}
172#endif
173#define starpu_worker_get_memory_node _starpu_worker_get_memory_node
174
175#if STARPU_MAXNODES == 1
176#define _starpu_worker_get_local_memory_node() 0
177#else
179static inline unsigned _starpu_worker_get_local_memory_node(void)
180{
181 struct _starpu_worker *worker = _starpu_get_local_worker_key();
182 if (!worker)
183 return STARPU_MAIN_RAM;
184 return worker->memory_node;
185}
186#endif
187#define starpu_worker_get_local_memory_node _starpu_worker_get_local_memory_node
188
189#pragma GCC visibility pop
190
191#endif // __MEMORY_NODES_H__
starpu_node_kind
Definition starpu_worker.h:44
static struct _starpu_memory_node_descr * _starpu_memory_node_get_description(void)
Definition memory_nodes.h:126
unsigned _starpu_memory_node_register(enum starpu_node_kind kind, int devid)
static enum starpu_node_kind _starpu_node_get_kind(unsigned node)
Definition memory_nodes.h:135
void _starpu_memory_node_set_mapped(unsigned node)
void _starpu_worker_drives_memory_node(struct _starpu_worker *worker, unsigned memnode)
starpu_pthread_rwlock_t conditions_rwlock
Definition memory_nodes.h:66
static unsigned _starpu_memory_node_get_nworkers(unsigned node)
Definition memory_nodes.h:95
static unsigned _starpu_worker_get_local_memory_node(void)
Definition memory_nodes.h:179
void _starpu_memory_node_register_condition(struct _starpu_worker *worker, starpu_pthread_cond_t *cond, unsigned nodeid)
int devid[STARPU_MAXNODES]
Definition memory_nodes.h:52
unsigned _starpu_memory_node_get_mapped(unsigned node)
static unsigned _starpu_memory_nodes_get_count(void)
Definition memory_nodes.h:145
unsigned total_condition_count
Definition memory_nodes.h:70
static void _starpu_memory_node_add_nworkers(unsigned node)
Definition memory_nodes.h:81
static unsigned _starpu_worker_get_memory_node(unsigned workerid)
Definition memory_nodes.h:156
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
int workerid
Definition workers.h:166