StarPU Handbook - StarPU Extensions
starpu_helper.h
Go to the documentation of this file.
1 /* StarPU --- Runtime system for heterogeneous multicore architectures.
2  *
3  * Copyright (C) 2008-2022 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 __STARPU_HELPER_H__
18 #define __STARPU_HELPER_H__
19 
20 #include <stdio.h>
21 #include <starpu.h>
22 
23 #ifdef STARPU_HAVE_HWLOC
24 #include <hwloc.h>
25 #endif
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
39 #define STARPU_MIN(a, b) ((a) < (b) ? (a) : (b))
43 #define STARPU_MAX(a, b) ((a) < (b) ? (b) : (a))
44 
49 #define STARPU_POISON_PTR ((void *)0xdeadbeef)
50 
51 extern int _starpu_silent;
52 
57 char *starpu_getenv(const char *str);
58 
62 #define starpu_getenv_string_var_default(s, ss, d) starpu_get_env_string_var_default(s, ss, d)
63 
70 int starpu_get_env_string_var_default(const char *str, const char *strings[], int defvalue);
71 
75 #define starpu_getenv_size_default(s, d) starpu_get_env_size_default(s, d)
76 
83 int starpu_get_env_size_default(const char *str, int defval);
84 
88 #define starpu_getenv_number(s) starpu_get_env_number(s)
89 
95 static __starpu_inline int starpu_get_env_number(const char *str)
96 {
97  char *strval;
98 
99  strval = starpu_getenv(str);
100  if (strval)
101  {
102  /* the env variable was actually set */
103  long int val;
104  char *pcheck;
105 
106  val = strtol(strval, &pcheck, 10);
107  if (*pcheck)
108  {
109  fprintf(stderr, "The %s environment variable must contain an integer\n", str);
110  STARPU_ABORT();
111  }
112 
113  /* fprintf(stderr, "ENV %s WAS %d\n", str, val); */
114  STARPU_ASSERT_MSG(val >= 0, "The value for the environment variable '%s' cannot be negative", str);
115  return (int)val;
116  }
117  else
118  {
119  /* there is no such env variable */
120  /* fprintf("There was no %s ENV\n", str); */
121  return -1;
122  }
123 }
124 
128 #define starpu_getenv_number_default(s, d) starpu_get_env_number_default(s, d)
129 
130 static __starpu_inline int starpu_get_env_number_default(const char *str, int defval)
131 {
132  int ret = starpu_get_env_number(str);
133  if (ret == -1)
134  ret = defval;
135  return ret;
136 }
137 
141 #define starpu_getenv_float_default(s, d) starpu_get_env_float_default(s, d)
142 
143 static __starpu_inline float starpu_get_env_float_default(const char *str, float defval)
144 {
145  char *strval;
146 
147  strval = starpu_getenv(str);
148  if (strval)
149  {
150  /* the env variable was actually set */
151  float val;
152  char *pcheck;
153 
154  val = strtof(strval, &pcheck);
155  if (*pcheck)
156  {
157  fprintf(stderr, "The %s environment variable must contain a float\n", str);
158  STARPU_ABORT();
159  }
160 
161  /* fprintf(stderr, "ENV %s WAS %f\n", str, val); */
162  return val;
163  }
164  else
165  {
166  /* there is no such env variable */
167  /* fprintf("There was no %s ENV\n", str); */
168  return defval;
169  }
170 }
171 
187 void starpu_execute_on_each_worker(void (*func)(void *), void *arg, uint32_t where);
188 
194 void starpu_execute_on_each_worker_ex(void (*func)(void *), void *arg, uint32_t where, const char *name);
195 
203 void starpu_execute_on_specific_workers(void (*func)(void *), void *arg, unsigned num_workers, unsigned *workers, const char *name);
204 
208 double starpu_timing_now(void);
209 
221 int starpu_data_cpy(starpu_data_handle_t dst_handle, starpu_data_handle_t src_handle, int asynchronous, void (*callback_func)(void *), void *callback_arg);
222 
229 int starpu_data_cpy_priority(starpu_data_handle_t dst_handle, starpu_data_handle_t src_handle, int asynchronous, void (*callback_func)(void *), void *callback_arg, int priority);
230 
245 int starpu_data_dup_ro(starpu_data_handle_t *dst_handle, starpu_data_handle_t src_handle, int asynchronous);
246 
255 
261 int starpu_get_pu_os_index(unsigned logical_index);
262 
268 long starpu_get_memory_location_bitmap(void *ptr, size_t size);
269 
270 #ifdef STARPU_HAVE_HWLOC
276 hwloc_topology_t starpu_get_hwloc_topology(void);
277 #endif
280 #ifdef __cplusplus
281 }
282 #endif
283 
284 #endif // __STARPU_HELPER_H__
struct _starpu_data_state * starpu_data_handle_t
Definition: starpu_data.h:44
void starpu_execute_on_specific_workers(void(*func)(void *), void *arg, unsigned num_workers, unsigned *workers, const char *name)
int starpu_data_cpy_priority(starpu_data_handle_t dst_handle, starpu_data_handle_t src_handle, int asynchronous, void(*callback_func)(void *), void *callback_arg, int priority)
int starpu_get_pu_os_index(unsigned logical_index)
int starpu_get_env_size_default(const char *str, int defval)
void starpu_display_bindings(void)
double starpu_timing_now(void)
long starpu_get_memory_location_bitmap(void *ptr, size_t size)
void starpu_execute_on_each_worker_ex(void(*func)(void *), void *arg, uint32_t where, const char *name)
void starpu_execute_on_each_worker(void(*func)(void *), void *arg, uint32_t where)
int starpu_data_dup_ro(starpu_data_handle_t *dst_handle, starpu_data_handle_t src_handle, int asynchronous)
int starpu_get_env_string_var_default(const char *str, const char *strings[], int defvalue)
int starpu_data_cpy(starpu_data_handle_t dst_handle, starpu_data_handle_t src_handle, int asynchronous, void(*callback_func)(void *), void *callback_arg)
hwloc_topology_t starpu_get_hwloc_topology(void)
static __starpu_inline int starpu_get_env_number(const char *str)
Definition: starpu_helper.h:95
char * starpu_getenv(const char *str)
#define STARPU_ABORT()
Definition: starpu_util.h:342
#define STARPU_ASSERT_MSG(x, msg,...)
Definition: starpu_util.h:313