StarPU Internal Handbook
mp_common.h
Go to the documentation of this file.
1/* StarPU --- Runtime system for heterogeneous multicore architectures.
2 *
3 * Copyright (C) 2012-2023 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
4 * Copyright (C) 2013 Thibaut Lambert
5 *
6 * StarPU is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or (at
9 * your option) any later version.
10 *
11 * StarPU is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 *
15 * See the GNU Lesser General Public License in COPYING.LGPL for more details.
16 */
17
18#ifndef __MP_COMMON_H__
19#define __MP_COMMON_H__
20
23#include <semaphore.h>
24
25#include <starpu.h>
26#include <common/config.h>
27#include <common/list.h>
28#include <common/barrier.h>
29#include <common/thread.h>
32
33#pragma GCC visibility push(hidden)
34
35#ifdef STARPU_USE_MP
36
37#define BUFFER_SIZE 65536
38
39#define STARPU_MP_SRC_NODE 0
40#define STARPU_MP_SINK_NODE(a) ((a) + 1)
41
42#define STARPU_MP_COMMON_REPORT_ERROR(node, status) \
43 (node)->report_error(__starpu_func__, __FILE__, __LINE__, (status))
44enum _starpu_mp_command
45{
46 /* Commands from master to slave */
47
48 STARPU_MP_COMMAND_EXIT,
49 STARPU_MP_COMMAND_EXECUTE,
50 STARPU_MP_COMMAND_EXECUTE_DETACHED,
51 STARPU_MP_COMMAND_SINK_NBCORES,
52 STARPU_MP_COMMAND_LOOKUP,
53 STARPU_MP_COMMAND_ALLOCATE,
54 STARPU_MP_COMMAND_FREE,
55 STARPU_MP_COMMAND_MAP,
56 STARPU_MP_COMMAND_UNMAP,
57 STARPU_MP_COMMAND_SYNC_WORKERS,
58
59 /* Note: synchronous send */
60 STARPU_MP_COMMAND_RECV_FROM_HOST,
61 STARPU_MP_COMMAND_SEND_TO_HOST,
62 STARPU_MP_COMMAND_RECV_FROM_SINK,
63 STARPU_MP_COMMAND_SEND_TO_SINK,
64
65 /* Note: Asynchronous send */
66 STARPU_MP_COMMAND_RECV_FROM_HOST_ASYNC,
67 STARPU_MP_COMMAND_SEND_TO_HOST_ASYNC,
68 STARPU_MP_COMMAND_RECV_FROM_SINK_ASYNC,
69 STARPU_MP_COMMAND_SEND_TO_SINK_ASYNC,
70
71 /* Synchronous answers from slave to master */
72 STARPU_MP_COMMAND_ERROR_EXECUTE,
73 STARPU_MP_COMMAND_ERROR_EXECUTE_DETACHED,
74 STARPU_MP_COMMAND_ANSWER_LOOKUP,
75 STARPU_MP_COMMAND_ERROR_LOOKUP,
76 STARPU_MP_COMMAND_ANSWER_ALLOCATE,
77 STARPU_MP_COMMAND_ERROR_ALLOCATE,
78 STARPU_MP_COMMAND_ANSWER_MAP,
79 STARPU_MP_COMMAND_ERROR_MAP,
80 STARPU_MP_COMMAND_ANSWER_TRANSFER_COMPLETE,
81 STARPU_MP_COMMAND_ANSWER_SINK_NBCORES,
82 STARPU_MP_COMMAND_ANSWER_EXECUTION_SUBMITTED,
83 STARPU_MP_COMMAND_ANSWER_EXECUTION_DETACHED_SUBMITTED,
84
85 /* Asynchronous notifications from slave to master */
86 STARPU_MP_COMMAND_NOTIF_RECV_FROM_HOST_ASYNC_COMPLETED,
87 STARPU_MP_COMMAND_NOTIF_SEND_TO_HOST_ASYNC_COMPLETED,
88 STARPU_MP_COMMAND_NOTIF_RECV_FROM_SINK_ASYNC_COMPLETED,
89 STARPU_MP_COMMAND_NOTIF_SEND_TO_SINK_ASYNC_COMPLETED,
90 STARPU_MP_COMMAND_NOTIF_EXECUTION_COMPLETED,
91 STARPU_MP_COMMAND_NOTIF_EXECUTION_DETACHED_COMPLETED,
92 STARPU_MP_COMMAND_NOTIF_PRE_EXECUTION,
93
94 STARPU_MP_COMMAND_NOTIF_FIRST = STARPU_MP_COMMAND_NOTIF_RECV_FROM_HOST_ASYNC_COMPLETED,
95 STARPU_MP_COMMAND_NOTIF_LAST = STARPU_MP_COMMAND_NOTIF_PRE_EXECUTION,
96};
97
98const char *_starpu_mp_common_command_to_string(const enum _starpu_mp_command command);
99
100enum _starpu_mp_node_kind
101{
102 STARPU_NODE_MPI_SINK,
103 STARPU_NODE_MPI_SOURCE,
104 STARPU_NODE_TCPIP_SINK,
105 STARPU_NODE_TCPIP_SOURCE,
106 STARPU_NODE_INVALID_KIND
107};
108
109const char *_starpu_mp_common_node_kind_to_string(const int kind);
110
111union _starpu_mp_connection
112{
113#ifdef STARPU_USE_MPI_MASTER_SLAVE
114 int mpi_remote_nodeid;
115#endif
116#ifdef STARPU_USE_TCPIP_MASTER_SLAVE
117 struct _starpu_tcpip_socket *tcpip_mp_connection;
118#endif
119};
120
121struct _starpu_mp_transfer_command
122{
123 size_t size;
124 void *addr;
125 void *event;
126};
127
128struct _starpu_mp_transfer_command_to_device
129{
130 size_t size;
131 void *addr;
132 void *event;
133 int devid;
134 char end[]; /* Keep last to compute non-padded size */
135};
136
137struct _starpu_mp_transfer_map_command
138{
139 size_t offset;
140 size_t size;
141 char fd_name[];
142};
143
144struct _starpu_mp_transfer_unmap_command
145{
146 uintptr_t addr;
147 size_t size;
148};
149
150LIST_TYPE(mp_barrier,
151 int id;
152 starpu_pthread_barrier_t before_work_barrier;
153 starpu_pthread_barrier_t after_work_barrier;
154 );
155
156LIST_TYPE(mp_message,
157 enum _starpu_mp_command type;
158 char *buffer;
159 int size;
160 );
161
162struct mp_task
163{
164 void (*kernel)(void **, void *);
165 enum starpu_data_interface_id *ids;
166 void **interfaces;
167 unsigned nb_interfaces;
168 void *cl_arg;
169 unsigned cl_arg_size;
170 void *cl_ret;
171 unsigned cl_ret_size;
172 unsigned coreid;
173 enum starpu_codelet_type type;
174 int is_parallel_task;
175 int combined_workerid;
176 int detached;
177 struct mp_barrier* mp_barrier;
178};
179
180LIST_TYPE(_starpu_mp_event,
181 struct _starpu_async_channel event;
182 void * remote_event;
183 enum _starpu_mp_command answer_cmd;
184);
185
186
189struct _starpu_mp_node
190{
191 enum _starpu_mp_node_kind kind;
192
193 int baseworkerid;
194
195 /*the number of core on the device
196 * Must be initialized during init function*/
197 int nb_cores;
198
199 /*Is starpu running*/
200 int is_running;
201
205 void *buffer;
206
210 int peer_id;
211
214 union _starpu_mp_connection mp_connection;
215
219 starpu_pthread_mutex_t connection_mutex;
220
224 struct _starpu_mp_event_list event_list;
225 /*list where threads add events to send to the source node */
226 struct _starpu_mp_event_list event_queue;
227
229 starpu_pthread_barrier_t init_completed_barrier;
230
232 void* thread_table;
233
234 /*list where threads add messages to send to the source node */
235 struct mp_message_list message_queue;
236 starpu_pthread_mutex_t message_queue_mutex;
237
238 /*list of barrier for combined worker*/
239 struct mp_barrier_list barrier_list;
240 starpu_pthread_mutex_t barrier_mutex;
241
242 /*table where worker comme pick task*/
243 struct mp_task ** run_table;
244 struct mp_task ** run_table_detached;
245 sem_t * sem_run_table;
246
248 void (*init) (struct _starpu_mp_node *node);
249 void (*launch_workers) (struct _starpu_mp_node *node);
250 void (*deinit) (struct _starpu_mp_node *node);
251 void (*report_error) (const char *, const char *, const int, const int);
252
254 int (*mp_recv_is_ready) (const struct _starpu_mp_node *);
255 void (*mp_send) (const struct _starpu_mp_node *, void *, int);
256 void (*mp_recv) (const struct _starpu_mp_node *, void *, int);
257
259 int (*nt_recv_is_ready) (const struct _starpu_mp_node *);
260 int (*nt_send_is_ready) (const struct _starpu_mp_node *);
261 void (*nt_send) (const struct _starpu_mp_node *, void *, int);
262 void (*nt_recv) (const struct _starpu_mp_node *, void *, int);
263
264 /*signal*/
265 void (*mp_wait) (struct _starpu_mp_node *);
266 void (*mp_signal) (const struct _starpu_mp_node *);
267
269 void (*dt_send) (const struct _starpu_mp_node *, void *, int, void *);
270 void (*dt_recv) (const struct _starpu_mp_node *, void *, int, void *);
271 void (*dt_send_to_device) (const struct _starpu_mp_node *, int, void *, int, void *);
272 void (*dt_recv_from_device) (const struct _starpu_mp_node *, int, void *, int, void *);
273
275 unsigned int (*dt_test) (struct _starpu_async_channel *);
276
277 void (*(*get_kernel_from_job) (const struct _starpu_mp_node *,struct _starpu_job *))(void);
278 void (*(*lookup) (const struct _starpu_mp_node *, char*))(void);
279 void (*bind_thread) (const struct _starpu_mp_node *, int,int *,int);
280 void (*execute) (struct _starpu_mp_node *, void *, int);
281 void (*allocate) (const struct _starpu_mp_node *, void *, int);
282 void (*free) (const struct _starpu_mp_node *, void *, int);
283 void (*map) (const struct _starpu_mp_node *, void *, int);
284 void (*unmap) (const struct _starpu_mp_node *, void *, int);
285};
286
287struct _starpu_mp_node * _starpu_mp_common_node_create(enum _starpu_mp_node_kind node_kind, int peer_devid) STARPU_ATTRIBUTE_MALLOC;
288
289void _starpu_mp_common_node_destroy(struct _starpu_mp_node *node);
290
291void _starpu_mp_common_send_command(const struct _starpu_mp_node *node,
292 const enum _starpu_mp_command command,
293 void *arg, int arg_size);
294
295void _starpu_nt_common_send_command(const struct _starpu_mp_node *node,
296 const enum _starpu_mp_command command,
297 void *arg, int arg_size);
298
299enum _starpu_mp_command _starpu_mp_common_recv_command(const struct _starpu_mp_node *node, void **arg, int *arg_size);
300
301enum _starpu_mp_command _starpu_nt_common_recv_command(const struct _starpu_mp_node *node, void **arg, int *arg_size);
302
303void _starpu_sink_deinit(struct _starpu_mp_node *node);
304void _starpu_sink_launch_workers(struct _starpu_mp_node *node);
305
306#endif /* STARPU_USE_MP */
307
308#pragma GCC visibility pop
309
310#endif /* __MP_COMMON_H__ */
Definition: copy_driver.h:71
Definition: jobs.h:74