StarPU Handbook
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
starpu_task.h
Go to the documentation of this file.
1 /* StarPU --- Runtime system for heterogeneous multicore architectures.
2  *
3  * Copyright (C) 2010-2014 Université de Bordeaux
4  * Copyright (C) 2010, 2011, 2012, 2013 Centre National de la Recherche Scientifique
5  * Copyright (C) 2011 Télécom-SudParis
6  * Copyright (C) 2011 INRIA
7  *
8  * StarPU is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 2.1 of the License, or (at
11  * your option) any later version.
12  *
13  * StarPU is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * See the GNU Lesser General Public License in COPYING.LGPL for more details.
18  */
19 
20 #ifndef __STARPU_TASK_H__
21 #define __STARPU_TASK_H__
22 
23 #include <starpu.h>
24 #include <starpu_data.h>
25 #include <starpu_util.h>
26 #include <starpu_task_bundle.h>
27 #include <errno.h>
28 
29 #if defined STARPU_USE_CUDA && !defined STARPU_DONT_INCLUDE_CUDA_HEADERS
30 # include <cuda.h>
31 #endif
32 
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #endif
37 
38 #define STARPU_NOWHERE ((1ULL)<<0)
39 #define STARPU_CPU ((1ULL)<<1)
40 #define STARPU_CUDA ((1ULL)<<3)
41 #define STARPU_OPENCL ((1ULL)<<6)
42 
44 {
48 };
49 
51 {
53 #define STARPU_TASK_INVALID 0
61 };
62 
63 typedef uint64_t starpu_tag_t;
64 
65 typedef void (*starpu_cpu_func_t)(void **, void*);
66 typedef void (*starpu_cuda_func_t)(void **, void*);
67 typedef void (*starpu_opencl_func_t)(void **, void*);
68 
69 #define STARPU_MULTIPLE_CPU_IMPLEMENTATIONS ((starpu_cpu_func_t) -1)
70 #define STARPU_MULTIPLE_CUDA_IMPLEMENTATIONS ((starpu_cuda_func_t) -1)
71 #define STARPU_MULTIPLE_OPENCL_IMPLEMENTATIONS ((starpu_opencl_func_t) -1)
72 
73 struct starpu_task;
75 {
76  uint32_t where;
77  int (*can_execute)(unsigned workerid, struct starpu_task *task, unsigned nimpl);
80 
81  starpu_cpu_func_t cpu_func STARPU_DEPRECATED;
82  starpu_cuda_func_t cuda_func STARPU_DEPRECATED;
83  starpu_opencl_func_t opencl_func STARPU_DEPRECATED;
84 
85  starpu_cpu_func_t cpu_funcs[STARPU_MAXIMPLEMENTATIONS];
86  starpu_cuda_func_t cuda_funcs[STARPU_MAXIMPLEMENTATIONS];
87  starpu_opencl_func_t opencl_funcs[STARPU_MAXIMPLEMENTATIONS];
88 
89  unsigned nbuffers;
92 
93  unsigned specific_nodes;
95  int *dyn_nodes;
96 
99 
101 
102  const char *name;
103 };
104 
106 {
108 
109  struct starpu_data_descr buffers[STARPU_NMAXBUFS] STARPU_DEPRECATED;
112 
115 
116  void *cl_arg;
117  size_t cl_arg_size;
118  /* must StarPU release cl_arg ? - 0 by default */
119  unsigned cl_arg_free;
120 
121  void (*callback_func)(void *);
123  /* must StarPU release callback_arg ? - 0 by default */
125 
126  void (*prologue_callback_func)(void *);
128  /* must StarPU release prologue_callback_arg ? - 0 by default */
130 
131  unsigned use_tag;
132  starpu_tag_t tag_id;
133 
135 
136  unsigned synchronous;
137  int priority;
138 
140  unsigned workerid;
141 
143 
144  int detach;
145  int destroy;
147 
149 
151 
152  double predicted;
154 
155  unsigned int mf_skip;
156 
157  struct starpu_task *prev;
158  struct starpu_task *next;
160  int magic;
161 
162  unsigned sched_ctx;
164  double flops;
165 
166  unsigned scheduled;
167 };
168 
169 #define STARPU_TASK_INITIALIZER \
170 { \
171  .cl = NULL, \
172  .cl_arg = NULL, \
173  .cl_arg_size = 0, \
174  .callback_func = NULL, \
175  .callback_arg = NULL, \
176  .priority = STARPU_DEFAULT_PRIO, \
177  .use_tag = 0, \
178  .synchronous = 0, \
179  .execute_on_a_specific_worker = 0, \
180  .bundle = NULL, \
181  .detach = 1, \
182  .destroy = 0, \
183  .regenerate = 0, \
184  .status = STARPU_TASK_INVALID, \
185  .profiling_info = NULL, \
186  .predicted = -1.0, \
187  .predicted_transfer = -1.0, \
188  .starpu_private = NULL, \
189  .magic = 42, \
190  .sched_ctx = 0, \
191  .hypervisor_tag = 0, \
192  .flops = 0.0, \
193  .scheduled = 0, \
194  .dyn_handles = NULL, \
195  .dyn_interfaces = NULL \
196 }
197 
198 #define STARPU_TASK_GET_HANDLE(task, i) ((task->dyn_handles) ? task->dyn_handles[i] : task->handles[i])
199 #define STARPU_TASK_SET_HANDLE(task, handle, i) do { if (task->dyn_handles) task->dyn_handles[i] = handle; else task->handles[i] = handle; } while(0)
200 
201 #define STARPU_CODELET_GET_MODE(codelet, i) ((codelet->dyn_modes) ? codelet->dyn_modes[i] : codelet->modes[i])
202 #define STARPU_CODELET_SET_MODE(codelet, mode, i) do { if (codelet->dyn_modes) codelet->dyn_modes[i] = mode; else codelet->modes[i] = mode; } while(0)
203 
204 #define STARPU_CODELET_GET_NODE(codelet, i) ((codelet->dyn_nodes) ? codelet->dyn_nodes[i] : codelet->nodes[i])
205 #define STARPU_CODELET_SET_NODE(codelet, __node, i) do { if (codelet->dyn_nodes) codelet->dyn_nodes[i] = __node; else codelet->nodes[i] = __node; } while(0)
206 
207 void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...);
208 void starpu_tag_declare_deps_array(starpu_tag_t id, unsigned ndeps, starpu_tag_t *array);
209 
210 void starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[]);
211 
212 int starpu_tag_wait(starpu_tag_t id);
213 int starpu_tag_wait_array(unsigned ntags, starpu_tag_t *id);
214 
215 void starpu_tag_notify_from_apps(starpu_tag_t id);
216 
217 void starpu_tag_restart(starpu_tag_t id);
218 
219 void starpu_tag_remove(starpu_tag_t id);
220 
221 void starpu_task_init(struct starpu_task *task);
222 void starpu_task_clean(struct starpu_task *task);
223 
224 struct starpu_task *starpu_task_create(void);
225 
226 void starpu_task_destroy(struct starpu_task *task);
228 int starpu_task_submit_to_ctx(struct starpu_task *task, unsigned sched_ctx_id);
229 
231 
232 int starpu_task_wait_for_all(void);
233 int starpu_task_wait_for_n_submitted(unsigned n);
234 
235 int starpu_task_wait_for_all_in_ctx(unsigned sched_ctx_id);
236 int starpu_task_wait_for_n_submitted_in_ctx(unsigned sched_ctx_id, unsigned n);
237 
239 
240 int starpu_task_nready(void);
241 int starpu_task_nsubmitted(void);
242 
244 
246 
248 
250 void starpu_parallel_task_barrier_init_n(struct starpu_task *task, int worker_size);
251 
252 struct starpu_task *starpu_task_dup(struct starpu_task *task);
253 
254 void starpu_task_set_implementation(struct starpu_task *task, unsigned impl);
255 unsigned starpu_task_get_implementation(struct starpu_task *task);
256 
257 #ifdef __cplusplus
258 }
259 #endif
260 
261 #endif /* __STARPU_TASK_H__ */