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