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_CPU ((1ULL)<<1)
39 #define STARPU_CUDA ((1ULL)<<3)
40 #define STARPU_OPENCL ((1ULL)<<6)
41 
43 {
47 };
48 
50 {
52 #define STARPU_TASK_INVALID 0
60 };
61 
62 typedef uint64_t starpu_tag_t;
63 
64 typedef void (*starpu_cpu_func_t)(void **, void*);
65 typedef void (*starpu_cuda_func_t)(void **, void*);
66 typedef void (*starpu_opencl_func_t)(void **, void*);
67 
68 #define STARPU_MULTIPLE_CPU_IMPLEMENTATIONS ((starpu_cpu_func_t) -1)
69 #define STARPU_MULTIPLE_CUDA_IMPLEMENTATIONS ((starpu_cuda_func_t) -1)
70 #define STARPU_MULTIPLE_OPENCL_IMPLEMENTATIONS ((starpu_opencl_func_t) -1)
71 
72 struct starpu_task;
74 {
75  uint32_t where;
76  int (*can_execute)(unsigned workerid, struct starpu_task *task, unsigned nimpl);
79 
80  starpu_cpu_func_t cpu_func STARPU_DEPRECATED;
81  starpu_cuda_func_t cuda_func STARPU_DEPRECATED;
82  starpu_opencl_func_t opencl_func STARPU_DEPRECATED;
83 
84  starpu_cpu_func_t cpu_funcs[STARPU_MAXIMPLEMENTATIONS];
85  starpu_cuda_func_t cuda_funcs[STARPU_MAXIMPLEMENTATIONS];
86  starpu_opencl_func_t opencl_funcs[STARPU_MAXIMPLEMENTATIONS];
87 
88  unsigned nbuffers;
91 
92  unsigned specific_nodes;
94  int *dyn_nodes;
95 
98 
100 
101  const char *name;
102 };
103 
105 {
107 
108  struct starpu_data_descr buffers[STARPU_NMAXBUFS] STARPU_DEPRECATED;
111 
114 
115  void *cl_arg;
116  size_t cl_arg_size;
117  /* must StarPU release cl_arg ? - 0 by default */
118  unsigned cl_arg_free;
119 
120  void (*callback_func)(void *);
122  /* must StarPU release callback_arg ? - 0 by default */
124 
125  void (*prologue_callback_func)(void *);
127  /* must StarPU release prologue_callback_arg ? - 0 by default */
129 
130  unsigned use_tag;
131  starpu_tag_t tag_id;
132 
134 
135  unsigned synchronous;
136  int priority;
137 
139  unsigned workerid;
140 
142 
143  int detach;
144  int destroy;
146 
148 
150 
151  double predicted;
153 
154  unsigned int mf_skip;
155 
156  struct starpu_task *prev;
157  struct starpu_task *next;
159  int magic;
160 
161  unsigned sched_ctx;
163  double flops;
164 
165  unsigned scheduled;
166 };
167 
168 #define STARPU_TASK_INITIALIZER \
169 { \
170  .cl = NULL, \
171  .cl_arg = NULL, \
172  .cl_arg_size = 0, \
173  .callback_func = NULL, \
174  .callback_arg = NULL, \
175  .priority = STARPU_DEFAULT_PRIO, \
176  .use_tag = 0, \
177  .synchronous = 0, \
178  .execute_on_a_specific_worker = 0, \
179  .bundle = NULL, \
180  .detach = 1, \
181  .destroy = 0, \
182  .regenerate = 0, \
183  .status = STARPU_TASK_INVALID, \
184  .profiling_info = NULL, \
185  .predicted = -1.0, \
186  .predicted_transfer = -1.0, \
187  .starpu_private = NULL, \
188  .magic = 42, \
189  .sched_ctx = 0, \
190  .hypervisor_tag = 0, \
191  .flops = 0.0, \
192  .scheduled = 0, \
193  .dyn_handles = NULL, \
194  .dyn_interfaces = NULL \
195 }
196 
197 #define STARPU_TASK_GET_HANDLE(task, i) ((task->dyn_handles) ? task->dyn_handles[i] : task->handles[i])
198 #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)
199 
200 #define STARPU_CODELET_GET_MODE(codelet, i) ((codelet->dyn_modes) ? codelet->dyn_modes[i] : codelet->modes[i])
201 #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)
202 
203 #define STARPU_CODELET_GET_NODE(codelet, i) ((codelet->dyn_nodes) ? codelet->dyn_nodes[i] : codelet->nodes[i])
204 #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)
205 
206 void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...);
207 void starpu_tag_declare_deps_array(starpu_tag_t id, unsigned ndeps, starpu_tag_t *array);
208 
209 void starpu_task_declare_deps_array(struct starpu_task *task, unsigned ndeps, struct starpu_task *task_array[]);
210 
211 int starpu_tag_wait(starpu_tag_t id);
212 int starpu_tag_wait_array(unsigned ntags, starpu_tag_t *id);
213 
214 void starpu_tag_notify_from_apps(starpu_tag_t id);
215 
216 void starpu_tag_restart(starpu_tag_t id);
217 
218 void starpu_tag_remove(starpu_tag_t id);
219 
220 void starpu_task_init(struct starpu_task *task);
221 void starpu_task_clean(struct starpu_task *task);
222 
223 struct starpu_task *starpu_task_create(void);
224 
225 void starpu_task_destroy(struct starpu_task *task);
227 int starpu_task_submit_to_ctx(struct starpu_task *task, unsigned sched_ctx_id);
228 
230 
231 int starpu_task_wait_for_all(void);
232 
233 int starpu_task_wait_for_all_in_ctx(unsigned sched_ctx_id);
234 
236 
237 int starpu_task_nready(void);
238 int starpu_task_nsubmitted(void);
239 
241 
243 
245 
247 void starpu_parallel_task_barrier_init_n(struct starpu_task *task, int worker_size);
248 
249 struct starpu_task *starpu_task_dup(struct starpu_task *task);
250 
251 void starpu_task_set_implementation(struct starpu_task *task, unsigned impl);
252 unsigned starpu_task_get_implementation(struct starpu_task *task);
253 
254 #ifdef __cplusplus
255 }
256 #endif
257 
258 #endif /* __STARPU_TASK_H__ */