starpu_perfmodel.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2011 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012 Centre National de la Recherche Scientifique
  5. * Copyright (C) 2011 Télécom-SudParis
  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_PERFMODEL_H__
  19. #define __STARPU_PERFMODEL_H__
  20. #include <starpu.h>
  21. #include <stdio.h>
  22. #include <starpu_util.h>
  23. #if ! defined(_MSC_VER)
  24. # include <pthread.h>
  25. #endif
  26. #ifdef __cplusplus
  27. extern "C"
  28. {
  29. #endif
  30. struct starpu_task;
  31. struct starpu_htbl32_node;
  32. struct starpu_history_list;
  33. struct starpu_buffer_descr;
  34. /*
  35. it is possible that we have multiple versions of the same kind of workers,
  36. for instance multiple GPUs or even different CPUs within the same machine
  37. so we do not use the archtype enum type directly for performance models
  38. */
  39. enum starpu_perf_archtype
  40. {
  41. STARPU_CPU_DEFAULT = 0,
  42. /* CPU combined workers between 0 and STARPU_MAXCPUS-1 */
  43. STARPU_CUDA_DEFAULT = STARPU_MAXCPUS,
  44. STARPU_OPENCL_DEFAULT = STARPU_CUDA_DEFAULT + STARPU_MAXCUDADEVS,
  45. /* STARPU_OPENCL_DEFAULT + devid */
  46. STARPU_GORDON_DEFAULT = STARPU_OPENCL_DEFAULT + STARPU_MAXOPENCLDEVS
  47. };
  48. #if __STDC_VERSION__ > 199901L || defined __GNUC__
  49. /* Make sure the following assertions hold, since StarPU relies on it. */
  50. _Static_assert(STARPU_CPU_DEFAULT == 0,
  51. "invalid STARPU_CPU_DEFAULT value");
  52. _Static_assert(STARPU_CUDA_DEFAULT > STARPU_CPU_DEFAULT,
  53. "invalid STARPU_CPU_DEFAULT value");
  54. _Static_assert(STARPU_CUDA_DEFAULT < STARPU_OPENCL_DEFAULT,
  55. "invalid STARPU_{CUDA,OPENCL}_DEFAULT values");
  56. #endif
  57. #define STARPU_NARCH_VARIATIONS (STARPU_GORDON_DEFAULT+1)
  58. struct starpu_history_entry
  59. {
  60. //double measured;
  61. /* mean_n = 1/n sum */
  62. double mean;
  63. /* n dev_n = sum2 - 1/n (sum)^2 */
  64. double deviation;
  65. /* sum of samples */
  66. double sum;
  67. /* sum of samples^2 */
  68. double sum2;
  69. // /* sum of ln(measured) */
  70. // double sumlny;
  71. //
  72. // /* sum of ln(size) */
  73. // double sumlnx;
  74. // double sumlnx2;
  75. //
  76. // /* sum of ln(size) ln(measured) */
  77. // double sumlnxlny;
  78. //
  79. unsigned nsample;
  80. uint32_t footprint;
  81. #ifdef STARPU_HAVE_WINDOWS
  82. unsigned size; /* in bytes */
  83. #else
  84. size_t size; /* in bytes */
  85. #endif
  86. };
  87. struct starpu_history_list
  88. {
  89. struct starpu_history_list *next;
  90. struct starpu_history_entry *entry;
  91. };
  92. struct starpu_model_list
  93. {
  94. struct starpu_model_list *next;
  95. struct starpu_perfmodel *model;
  96. };
  97. struct starpu_regression_model
  98. {
  99. /* sum of ln(measured) */
  100. double sumlny;
  101. /* sum of ln(size) */
  102. double sumlnx;
  103. double sumlnx2;
  104. /* minimum/maximum(size) */
  105. unsigned long minx;
  106. unsigned long maxx;
  107. /* sum of ln(size) ln(measured) */
  108. double sumlnxlny;
  109. /* y = alpha size ^ beta */
  110. double alpha;
  111. double beta;
  112. unsigned valid;
  113. /* y = a size ^b + c */
  114. double a, b, c;
  115. unsigned nl_valid;
  116. unsigned nsample;
  117. };
  118. struct starpu_per_arch_perfmodel
  119. {
  120. double (*cost_model)(struct starpu_buffer_descr *t) STARPU_DEPRECATED; /* returns expected duration in µs */
  121. double (*cost_function)(struct starpu_task *task, enum starpu_perf_archtype arch, unsigned nimpl); /* returns expected duration in µs */
  122. size_t (*size_base)(struct starpu_task *, enum starpu_perf_archtype arch, unsigned nimpl);
  123. /* internal variables */
  124. struct starpu_htbl32_node *history;
  125. struct starpu_history_list *list;
  126. struct starpu_regression_model regression;
  127. #ifdef STARPU_MODEL_DEBUG
  128. char debug_path[256];
  129. #endif
  130. };
  131. enum starpu_perfmodel_type
  132. {
  133. STARPU_PER_ARCH, /* Application-provided per-arch cost model function */
  134. STARPU_COMMON, /* Application-provided common cost model function, with per-arch factor */
  135. STARPU_HISTORY_BASED, /* Automatic history-based cost model */
  136. STARPU_REGRESSION_BASED, /* Automatic linear regression-based cost model (alpha * size ^ beta) */
  137. STARPU_NL_REGRESSION_BASED /* Automatic non-linear regression-based cost model (a * size ^ b + c) */
  138. };
  139. struct starpu_perfmodel
  140. {
  141. /* which model is used for that task ? */
  142. enum starpu_perfmodel_type type;
  143. /* single cost model (STARPU_COMMON), returns expected duration in µs */
  144. double (*cost_model)(struct starpu_buffer_descr *) STARPU_DEPRECATED;
  145. double (*cost_function)(struct starpu_task *, unsigned nimpl);
  146. size_t (*size_base)(struct starpu_task *, unsigned nimpl);
  147. /* per-architecture model */
  148. struct starpu_per_arch_perfmodel per_arch[STARPU_NARCH_VARIATIONS][STARPU_MAXIMPLEMENTATIONS];
  149. /* Name of the performance model, this is used as a file name when saving history-based performance models */
  150. const char *symbol;
  151. /* Internal variables */
  152. unsigned is_loaded;
  153. unsigned benchmarking;
  154. #if defined(_MSC_VER)
  155. void *model_rwlock;
  156. #else
  157. pthread_rwlock_t model_rwlock;
  158. #endif
  159. };
  160. enum starpu_perf_archtype starpu_worker_get_perf_archtype(int workerid);
  161. /* This function is intended to be used by external tools that should read the
  162. * performance model files */
  163. int starpu_load_history_debug(const char *symbol, struct starpu_perfmodel *model);
  164. void starpu_perfmodel_debugfilepath(struct starpu_perfmodel *model,
  165. enum starpu_perf_archtype arch, char *path, size_t maxlen, unsigned nimpl);
  166. void starpu_perfmodel_get_arch_name(enum starpu_perf_archtype arch, char *archname, size_t maxlen, unsigned nimpl);
  167. int starpu_list_models(FILE *output);
  168. void starpu_force_bus_sampling(void);
  169. void starpu_print_bus_bandwidth(FILE *f);
  170. #ifdef __cplusplus
  171. }
  172. #endif
  173. #endif /* __STARPU_PERFMODEL_H__ */