utils.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2012-2013 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012, 2013 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #ifndef __COMMON_UTILS_H__
  18. #define __COMMON_UTILS_H__
  19. #include <starpu.h>
  20. #include <common/config.h>
  21. #include <sys/stat.h>
  22. #include <string.h>
  23. #include <stdlib.h>
  24. #include <math.h>
  25. #include <pthread.h>
  26. #ifdef STARPU_HAVE_SCHED_YIELD
  27. #include <sched.h>
  28. #endif
  29. #ifdef STARPU_HAVE_HELGRIND_H
  30. #include <valgrind/helgrind.h>
  31. #endif
  32. #ifndef DO_CREQ_v_WW
  33. #define DO_CREQ_v_WW(_creqF, _ty1F, _arg1F, _ty2F, _arg2F) ((void)0)
  34. #endif
  35. #ifndef DO_CREQ_v_W
  36. #define DO_CREQ_v_W(_creqF, _ty1F, _arg1F) ((void)0)
  37. #endif
  38. #ifndef ANNOTATE_HAPPENS_BEFORE
  39. #define ANNOTATE_HAPPENS_BEFORE(obj) ((void)0)
  40. #endif
  41. #ifndef ANNOTATE_HAPPENS_AFTER
  42. #define ANNOTATE_HAPPENS_AFTER(obj) ((void)0)
  43. #endif
  44. #ifndef VALGRIND_HG_DISABLE_CHECKING
  45. #define VALGRIND_HG_DISABLE_CHECKING(start, len) ((void)0)
  46. #endif
  47. #ifndef VALGRIND_HG_ENABLE_CHECKING
  48. #define VALGRIND_HG_ENABLE_CHECKING(start, len) ((void)0)
  49. #endif
  50. #define STARPU_HG_DISABLE_CHECKING(variable) VALGRIND_HG_DISABLE_CHECKING(&(variable), sizeof(variable))
  51. #define STARPU_HG_ENABLE_CHECKING(variable) VALGRIND_HG_ENABLE_CHECKING(&(variable), sizeof(variable))
  52. #if defined(__KNC__) || defined(__KNF__)
  53. #define STARPU_DEBUG_PREFIX "[starpu-mic]"
  54. #else
  55. #define STARPU_DEBUG_PREFIX "[starpu]"
  56. #endif
  57. /* This is needed in some places to make valgrind yield to another thread to be
  58. * able to progress. */
  59. #if defined(__i386__) || defined(__x86_64__)
  60. #define _STARPU_UYIELD() __asm__ __volatile("rep; nop")
  61. #else
  62. #define _STARPU_UYIELD() ((void)0)
  63. #endif
  64. #if defined(STARPU_HAVE_SCHED_YIELD) && defined(STARPU_HAVE_HELGRIND_H)
  65. #define STARPU_UYIELD() do { if (RUNNING_ON_VALGRIND) sched_yield(); else _STARPU_UYIELD(); } while (0)
  66. #else
  67. #define STARPU_UYIELD() _STARPU_UYIELD()
  68. #endif
  69. #ifdef STARPU_VERBOSE
  70. # define _STARPU_DEBUG(fmt, ...) do { if (!getenv("STARPU_SILENT")) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%s] " fmt ,__starpu_func__ ,## __VA_ARGS__); fflush(stderr); }} while(0)
  71. #else
  72. # define _STARPU_DEBUG(fmt, ...) do { } while (0)
  73. #endif
  74. #ifdef STARPU_VERBOSE0
  75. # define _STARPU_LOG_IN() do { if (!getenv("STARPU_SILENT")) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%ld][%s] -->\n", pthread_self(), __starpu_func__ ); }} while(0)
  76. # define _STARPU_LOG_OUT() do { if (!getenv("STARPU_SILENT")) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%ld][%s] <--\n", pthread_self(), __starpu_func__ ); }} while(0)
  77. # define _STARPU_LOG_OUT_TAG(outtag) do { if (!getenv("STARPU_SILENT")) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%ld][%s] <-- (%s)\n", pthread_self(), __starpu_func__, outtag); }} while(0)
  78. #else
  79. # define _STARPU_LOG_IN()
  80. # define _STARPU_LOG_OUT()
  81. # define _STARPU_LOG_OUT_TAG(outtag)
  82. #endif
  83. #define _STARPU_DISP(fmt, ...) do { if (!getenv("STARPU_SILENT")) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%s] " fmt ,__starpu_func__ ,## __VA_ARGS__); }} while(0)
  84. #define _STARPU_ERROR(fmt, ...) \
  85. do { \
  86. fprintf(stderr, "\n\n[starpu][%s] Error: " fmt ,__starpu_func__ ,## __VA_ARGS__); \
  87. fprintf(stderr, "\n\n"); \
  88. STARPU_ABORT(); \
  89. } while (0)
  90. #define _STARPU_IS_ZERO(a) (fpclassify(a) == FP_ZERO)
  91. int _starpu_mkpath(const char *s, mode_t mode);
  92. void _starpu_mkpath_and_check(const char *s, mode_t mode);
  93. char *_starpu_get_home_path(void);
  94. void _starpu_gethostname(char *hostname, size_t size);
  95. /* If FILE is currently on a comment line, eat it. */
  96. void _starpu_drop_comments(FILE *f);
  97. struct _starpu_job;
  98. /* Returns the symbol associated to that job if any. */
  99. const char *_starpu_job_get_model_name(struct _starpu_job *j);
  100. struct starpu_codelet;
  101. /* Returns the symbol associated to that job if any. */
  102. const char *_starpu_codelet_get_model_name(struct starpu_codelet *cl);
  103. int _starpu_check_mutex_deadlock(starpu_pthread_mutex_t *mutex);
  104. void _starpu_sleep(struct timespec ts);
  105. #endif // __COMMON_UTILS_H__