starpu_helper.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2008-2018 Université de Bordeaux
  4. * Copyright (C) 2011,2012,2017 Inria
  5. * Copyright (C) 2010-2017, 2019 CNRS
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #ifndef __STARPU_HELPER_H__
  19. #define __STARPU_HELPER_H__
  20. #include <stdio.h>
  21. #include <starpu.h>
  22. #ifdef __cplusplus
  23. extern "C"
  24. {
  25. #endif
  26. /**
  27. @defgroup API_Miscellaneous_Helpers Miscellaneous Helpers
  28. @{
  29. */
  30. /**
  31. Return the min of the two parameters.
  32. */
  33. #define STARPU_MIN(a,b) ((a)<(b)?(a):(b))
  34. /**
  35. Return the max of the two parameters.
  36. */
  37. #define STARPU_MAX(a,b) ((a)<(b)?(b):(a))
  38. /**
  39. Define a value which can be used to mark pointers as invalid
  40. values.
  41. */
  42. #define STARPU_POISON_PTR ((void *)0xdeadbeef)
  43. extern int _starpu_silent;
  44. char *starpu_getenv(const char *str);
  45. /**
  46. Return the integer value of the environment variable named \p str.
  47. Return 0 otherwise (the variable does not exist or has a
  48. non-integer value).
  49. */
  50. static __starpu_inline int starpu_get_env_number(const char *str)
  51. {
  52. char *strval;
  53. strval = starpu_getenv(str);
  54. if (strval)
  55. {
  56. /* the env variable was actually set */
  57. long int val;
  58. char *pcheck;
  59. val = strtol(strval, &pcheck, 10);
  60. if (*pcheck) {
  61. fprintf(stderr,"The %s environment variable must contain an integer\n", str);
  62. STARPU_ABORT();
  63. }
  64. /* fprintf(stderr, "ENV %s WAS %d\n", str, val); */
  65. STARPU_ASSERT_MSG(val >= 0, "The value for the environment variable '%s' cannot be negative", str);
  66. return (int)val;
  67. }
  68. else
  69. {
  70. /* there is no such env variable */
  71. /* fprintf("There was no %s ENV\n", str); */
  72. return -1;
  73. }
  74. }
  75. static __starpu_inline int starpu_get_env_number_default(const char *str, int defval)
  76. {
  77. int ret = starpu_get_env_number(str);
  78. if (ret == -1)
  79. ret = defval;
  80. return ret;
  81. }
  82. static __starpu_inline float starpu_get_env_float_default(const char *str, float defval)
  83. {
  84. char *strval;
  85. strval = starpu_getenv(str);
  86. if (strval)
  87. {
  88. /* the env variable was actually set */
  89. float val;
  90. char *pcheck;
  91. val = strtof(strval, &pcheck);
  92. if (*pcheck) {
  93. fprintf(stderr,"The %s environment variable must contain a float\n", str);
  94. STARPU_ABORT();
  95. }
  96. /* fprintf(stderr, "ENV %s WAS %f\n", str, val); */
  97. return val;
  98. }
  99. else
  100. {
  101. /* there is no such env variable */
  102. /* fprintf("There was no %s ENV\n", str); */
  103. return defval;
  104. }
  105. }
  106. /**
  107. Execute the given function \p func on a subset of workers. When
  108. calling this method, the offloaded function \p func is executed by
  109. every StarPU worker that are eligible to execute the function. The
  110. argument \p arg is passed to the offloaded function. The argument
  111. \p where specifies on which types of processing units the function
  112. should be executed.
  113. Similarly to the field starpu_codelet::where, it is possible to
  114. specify that the function should be executed on every CUDA device
  115. and every CPU by passing ::STARPU_CPU|::STARPU_CUDA. This function
  116. blocks until \p func has been executed on every appropriate
  117. processing units, and thus may not be called from a callback
  118. function for instance.
  119. */
  120. void starpu_execute_on_each_worker(void (*func)(void *), void *arg, uint32_t where);
  121. /**
  122. Same as starpu_execute_on_each_worker(), except that the task name
  123. is specified in the argument \p name.
  124. */
  125. void starpu_execute_on_each_worker_ex(void (*func)(void *), void *arg, uint32_t where, const char *name);
  126. /**
  127. Call \p func(\p arg) on every worker in the \p workers array. \p
  128. num_workers indicates the number of workers in this array. This
  129. function is synchronous, but the different workers may execute the
  130. function in parallel.
  131. */
  132. void starpu_execute_on_specific_workers(void (*func)(void*), void *arg, unsigned num_workers, unsigned *workers, const char *name);
  133. /**
  134. Return the current date in micro-seconds.
  135. */
  136. double starpu_timing_now(void);
  137. /**
  138. Copy the content of \p src_handle into \p dst_handle. The parameter \p
  139. asynchronous indicates whether the function should block or not. In
  140. the case of an asynchronous call, it is possible to synchronize with
  141. the termination of this operation either by the means of implicit
  142. dependencies (if enabled) or by calling starpu_task_wait_for_all(). If
  143. \p callback_func is not <c>NULL</c>, this callback function is executed after
  144. the handle has been copied, and it is given the pointer \p
  145. callback_arg as argument.
  146. */
  147. 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);
  148. /** @} */
  149. #ifdef __cplusplus
  150. }
  151. #endif
  152. #endif // __STARPU_HELPER_H__