starpu_helper.h 5.0 KB

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