StarPU Internal Handbook
Loading...
Searching...
No Matches
utils.h
Go to the documentation of this file.
1/* StarPU --- Runtime system for heterogeneous multicore architectures.
2 *
3 * Copyright (C) 2010-2021 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 __COMMON_UTILS_H__
18#define __COMMON_UTILS_H__
19
22#include <common/config.h>
23#include <starpu.h>
24#include <sys/stat.h>
25#include <string.h>
26#include <stdlib.h>
27#include <math.h>
28#ifdef STARPU_HAVE_SCHED_YIELD
29#include <sched.h>
30#endif
31
32#ifdef STARPU_HAVE_HELGRIND_H
33#include <valgrind/helgrind.h>
34#endif
35
36#ifndef DO_CREQ_v_WW
37#define DO_CREQ_v_WW(_creqF, _ty1F, _arg1F, _ty2F, _arg2F) ((void)0)
38#endif
39#ifndef DO_CREQ_v_W
40#define DO_CREQ_v_W(_creqF, _ty1F, _arg1F) ((void)0)
41#endif
42#ifndef ANNOTATE_HAPPENS_BEFORE
43#define ANNOTATE_HAPPENS_BEFORE(obj) ((void)0)
44#endif
45#ifndef ANNOTATE_HAPPENS_BEFORE_FORGET_ALL
46#define ANNOTATE_HAPPENS_BEFORE_FORGET_ALL(obj) ((void)0)
47#endif
48#ifndef ANNOTATE_HAPPENS_AFTER
49#define ANNOTATE_HAPPENS_AFTER(obj) ((void)0)
50#endif
51#ifndef VALGRIND_HG_DISABLE_CHECKING
52#define VALGRIND_HG_DISABLE_CHECKING(start, len) ((void)0)
53#endif
54#ifndef VALGRIND_HG_ENABLE_CHECKING
55#define VALGRIND_HG_ENABLE_CHECKING(start, len) ((void)0)
56#endif
57#ifndef VALGRIND_STACK_REGISTER
58#define VALGRIND_STACK_REGISTER(stackbottom, stacktop) 0
59#endif
60#ifndef VALGRIND_STACK_DEREGISTER
61#define VALGRIND_STACK_DEREGISTER(id) ((void)0)
62#endif
63#ifndef RUNNING_ON_VALGRIND
64#define RUNNING_ON_VALGRIND 0
65#endif
66#ifdef STARPU_SANITIZE_THREAD
67#define STARPU_RUNNING_ON_VALGRIND 1
68#else
69#define STARPU_RUNNING_ON_VALGRIND RUNNING_ON_VALGRIND
70#endif
71#define STARPU_HG_DISABLE_CHECKING(variable) VALGRIND_HG_DISABLE_CHECKING(&(variable), sizeof(variable))
72#define STARPU_HG_ENABLE_CHECKING(variable) VALGRIND_HG_ENABLE_CHECKING(&(variable), sizeof(variable))
73
74#if defined(__KNC__) || defined(__KNF__)
75#define STARPU_DEBUG_PREFIX "[starpu-mic]"
76#else
77#define STARPU_DEBUG_PREFIX "[starpu]"
78#endif
79
80/* This is needed in some places to make valgrind yield to another thread to be
81 * able to progress. */
82#if defined(__i386__) || defined(__x86_64__)
83#define _STARPU_UYIELD() __asm__ __volatile("rep; nop")
84#else
85#define _STARPU_UYIELD() ((void)0)
86#endif
87#if defined(STARPU_HAVE_SCHED_YIELD) && defined(STARPU_HAVE_HELGRIND_H)
88#define STARPU_VALGRIND_YIELD() do { if (STARPU_RUNNING_ON_VALGRIND) sched_yield(); } while (0)
89#define STARPU_UYIELD() do { if (STARPU_RUNNING_ON_VALGRIND) sched_yield(); else _STARPU_UYIELD(); } while (0)
90#else
91#define STARPU_VALGRIND_YIELD() do { } while (0)
92#define STARPU_UYIELD() _STARPU_UYIELD()
93#endif
94
95#ifdef STARPU_VERBOSE
96# define _STARPU_DEBUG(fmt, ...) do { if (!_starpu_silent) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%s] " fmt ,__starpu_func__ ,## __VA_ARGS__); fflush(stderr); }} while(0)
97# define _STARPU_DEBUG_NO_HEADER(fmt, ...) do { if (!_starpu_silent) {fprintf(stderr, fmt , ## __VA_ARGS__); fflush(stderr); }} while(0)
98#else
99# define _STARPU_DEBUG(fmt, ...) do { } while (0)
100# define _STARPU_DEBUG_NO_HEADER(fmt, ...) do { } while (0)
101#endif
102
103#ifdef STARPU_EXTRA_VERBOSE
104# define _STARPU_EXTRA_DEBUG(fmt, ...) do { if (!_starpu_silent) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%s] " fmt ,__starpu_func__ ,## __VA_ARGS__); fflush(stderr); }} while(0)
105#else
106# define _STARPU_EXTRA_DEBUG(fmt, ...) do { } while (0)
107#endif
108
109#ifdef STARPU_EXTRA_VERBOSE
110# define _STARPU_LOG_IN() do { if (!_starpu_silent) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%ld][%s:%s@%d] -->\n", starpu_pthread_self(), __starpu_func__,__FILE__, __LINE__); }} while(0)
111# define _STARPU_LOG_OUT() do { if (!_starpu_silent) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%ld][%s:%s@%d] <--\n", starpu_pthread_self(), __starpu_func__, __FILE__, __LINE__); }} while(0)
112# define _STARPU_LOG_OUT_TAG(outtag) do { if (!_starpu_silent) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%ld][%s:%s@%d] <-- (%s)\n", starpu_pthread_self(), __starpu_func__, __FILE__, __LINE__, outtag); }} while(0)
113#else
114# define _STARPU_LOG_IN()
115# define _STARPU_LOG_OUT()
116# define _STARPU_LOG_OUT_TAG(outtag)
117#endif
118
119/* TODO: cache */
120#define _STARPU_MSG(fmt, ...) do { fprintf(stderr, STARPU_DEBUG_PREFIX"[%s] " fmt ,__starpu_func__ ,## __VA_ARGS__); } while(0)
121#define _STARPU_DISP(fmt, ...) do { if (!_starpu_silent) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%s] " fmt ,__starpu_func__ ,## __VA_ARGS__); }} while(0)
122#define _STARPU_ERROR(fmt, ...) \
123 do { \
124 fprintf(stderr, "\n\n[starpu][%s] Error: " fmt ,__starpu_func__ ,## __VA_ARGS__); \
125 fprintf(stderr, "\n\n"); \
126 STARPU_ABORT(); \
127 } while (0)
128
129
130#ifdef _MSC_VER
131# if defined(__cplusplus)
132# define _STARPU_DECLTYPE(x) (decltype(x))
133# else
134# define _STARPU_DECLTYPE(x)
135# endif
136#else
137# define _STARPU_DECLTYPE(x) (__typeof(x))
138#endif
139
140#define _STARPU_MALLOC(ptr, size) do { ptr = _STARPU_DECLTYPE(ptr) malloc(size); STARPU_ASSERT_MSG(ptr != NULL || size == 0, "Cannot allocate %ld bytes\n", (long) (size)); } while (0)
141#define _STARPU_CALLOC(ptr, nmemb, size) do { ptr = _STARPU_DECLTYPE(ptr) calloc(nmemb, size); STARPU_ASSERT_MSG(ptr != NULL || size == 0, "Cannot allocate %ld bytes\n", (long) (nmemb*size)); } while (0)
142#define _STARPU_REALLOC(ptr, size) do { void *_new_ptr = realloc(ptr, size); STARPU_ASSERT_MSG(_new_ptr != NULL || size == 0, "Cannot reallocate %ld bytes\n", (long) (size)); ptr = _STARPU_DECLTYPE(ptr) _new_ptr;} while (0)
143
144#ifdef _MSC_VER
145#define _STARPU_IS_ZERO(a) (a == 0.0)
146#else
147#define _STARPU_IS_ZERO(a) (fpclassify(a) == FP_ZERO)
148#endif
149
150char *_starpu_mkdtemp_internal(char *tmpl);
151char *_starpu_mkdtemp(char *tmpl);
152int _starpu_mkpath(const char *s, mode_t mode);
153void _starpu_mkpath_and_check(const char *s, mode_t mode);
154char *_starpu_mktemp(const char *directory, int flags, int *fd);
157char *_starpu_mktemp_many(const char *directory, int depth, int flags, int *fd);
158void _starpu_rmtemp_many(char *path, int depth);
159void _starpu_rmdir_many(char *path, int depth);
160int _starpu_fftruncate(FILE *file, size_t length);
161int _starpu_ftruncate(int fd, size_t length);
162int _starpu_frdlock(FILE *file);
163int _starpu_frdunlock(FILE *file);
164int _starpu_fwrlock(FILE *file);
165int _starpu_fwrunlock(FILE *file);
166char *_starpu_get_home_path(void);
167void _starpu_gethostname(char *hostname, size_t size);
168
171
172struct _starpu_job;
177
178struct starpu_codelet;
180const char *_starpu_codelet_get_model_name(struct starpu_codelet *cl);
181
182int _starpu_check_mutex_deadlock(starpu_pthread_mutex_t *mutex);
183
184void _starpu_util_init(void);
185
186#endif // __COMMON_UTILS_H__
Definition: jobs.h:79
char * _starpu_mktemp_many(const char *directory, int depth, int flags, int *fd)
const char * _starpu_codelet_get_model_name(struct starpu_codelet *cl)
const char * _starpu_job_get_task_name(struct _starpu_job *j)
void _starpu_drop_comments(FILE *f)
const char * _starpu_job_get_model_name(struct _starpu_job *j)