starpu_perfmodel.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2012 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_buffer_descr;
  32. /*
  33. it is possible that we have multiple versions of the same kind of workers,
  34. for instance multiple GPUs or even different CPUs within the same machine
  35. so we do not use the archtype enum type directly for performance models
  36. */
  37. enum starpu_perf_archtype
  38. {
  39. STARPU_CPU_DEFAULT = 0,
  40. /* CPU combined workers between 0 and STARPU_MAXCPUS-1 */
  41. STARPU_CUDA_DEFAULT = STARPU_MAXCPUS,
  42. STARPU_OPENCL_DEFAULT = STARPU_CUDA_DEFAULT + STARPU_MAXCUDADEVS,
  43. /* STARPU_OPENCL_DEFAULT + devid */
  44. STARPU_GORDON_DEFAULT = STARPU_OPENCL_DEFAULT + STARPU_MAXOPENCLDEVS
  45. };
  46. #ifdef __STDC_VERSION__
  47. # if __STDC_VERSION__ > 199901L || STARPU_GNUC_PREREQ(4, 6)
  48. /* Make sure the following assertions hold, since StarPU relies on it. */
  49. _Static_assert(STARPU_CPU_DEFAULT == 0,
  50. "invalid STARPU_CPU_DEFAULT value");
  51. _Static_assert(STARPU_CUDA_DEFAULT > STARPU_CPU_DEFAULT,
  52. "invalid STARPU_CPU_DEFAULT value");
  53. _Static_assert(STARPU_CUDA_DEFAULT < STARPU_OPENCL_DEFAULT,
  54. "invalid STARPU_{CUDA,OPENCL}_DEFAULT values");
  55. # endif
  56. #endif
  57. #define STARPU_NARCH_VARIATIONS (STARPU_GORDON_DEFAULT+1)
  58. struct starpu_perfmodel_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_perfmodel_history_list
  88. {
  89. struct starpu_perfmodel_history_list *next;
  90. struct starpu_perfmodel_history_entry *entry;
  91. };
  92. struct starpu_perfmodel_regression_model
  93. {
  94. /* sum of ln(measured) */
  95. double sumlny;
  96. /* sum of ln(size) */
  97. double sumlnx;
  98. double sumlnx2;
  99. /* minimum/maximum(size) */
  100. unsigned long minx;
  101. unsigned long maxx;
  102. /* sum of ln(size) ln(measured) */
  103. double sumlnxlny;
  104. /* y = alpha size ^ beta */
  105. double alpha;
  106. double beta;
  107. unsigned valid;
  108. /* y = a size ^b + c */
  109. double a, b, c;
  110. unsigned nl_valid;
  111. unsigned nsample;
  112. };
  113. struct starpu_perfmodel_history_table;
  114. #define starpu_per_arch_perfmodel starpu_perfmodel_per_arch STARPU_DEPRECATED
  115. struct starpu_perfmodel_per_arch
  116. {
  117. double (*cost_model)(struct starpu_buffer_descr *t) STARPU_DEPRECATED; /* returns expected duration in µs */
  118. double (*cost_function)(struct starpu_task *task, enum starpu_perf_archtype arch, unsigned nimpl); /* returns expected duration in µs */
  119. size_t (*size_base)(struct starpu_task *, enum starpu_perf_archtype arch, unsigned nimpl);
  120. /* internal variables */
  121. struct starpu_perfmodel_history_table *history;
  122. struct starpu_perfmodel_history_list *list;
  123. struct starpu_perfmodel_regression_model regression;
  124. #ifdef STARPU_MODEL_DEBUG
  125. char debug_path[256];
  126. #endif
  127. };
  128. enum starpu_perfmodel_type
  129. {
  130. STARPU_PER_ARCH, /* Application-provided per-arch cost model function */
  131. STARPU_COMMON, /* Application-provided common cost model function, with per-arch factor */
  132. STARPU_HISTORY_BASED, /* Automatic history-based cost model */
  133. STARPU_REGRESSION_BASED, /* Automatic linear regression-based cost model (alpha * size ^ beta) */
  134. STARPU_NL_REGRESSION_BASED /* Automatic non-linear regression-based cost model (a * size ^ b + c) */
  135. };
  136. struct starpu_perfmodel
  137. {
  138. /* which model is used for that task ? */
  139. enum starpu_perfmodel_type type;
  140. /* single cost model (STARPU_COMMON), returns expected duration in µs */
  141. double (*cost_model)(struct starpu_buffer_descr *) STARPU_DEPRECATED;
  142. double (*cost_function)(struct starpu_task *, unsigned nimpl);
  143. size_t (*size_base)(struct starpu_task *, unsigned nimpl);
  144. /* per-architecture model */
  145. struct starpu_perfmodel_per_arch per_arch[STARPU_NARCH_VARIATIONS][STARPU_MAXIMPLEMENTATIONS];
  146. /* Name of the performance model, this is used as a file name when saving history-based performance models */
  147. const char *symbol;
  148. /* Internal variables */
  149. unsigned is_loaded;
  150. unsigned benchmarking;
  151. #if defined(_MSC_VER)
  152. void *model_rwlock;
  153. #else
  154. pthread_rwlock_t model_rwlock;
  155. #endif
  156. };
  157. enum starpu_perf_archtype starpu_worker_get_perf_archtype(int workerid);
  158. /* This function is intended to be used by external tools that should read the
  159. * performance model files */
  160. int starpu_perfmodel_load_symbol(const char *symbol, struct starpu_perfmodel *model);
  161. void starpu_perfmodel_debugfilepath(struct starpu_perfmodel *model, enum starpu_perf_archtype arch, char *path, size_t maxlen, unsigned nimpl);
  162. void starpu_perfmodel_get_arch_name(enum starpu_perf_archtype arch, char *archname, size_t maxlen, unsigned nimpl);
  163. int starpu_perfmodel_list(FILE *output);
  164. void starpu_perfmodel_print(struct starpu_perfmodel *model, enum starpu_perf_archtype arch, unsigned nimpl, char *parameter, uint32_t *footprint, FILE *output);
  165. int starpu_perfmodel_print_all(struct starpu_perfmodel *model, char *arch, char *parameter, uint32_t *footprint, FILE *output);
  166. void starpu_perfmodel_update_history(struct starpu_perfmodel *model, struct starpu_task *task, enum starpu_perf_archtype arch, unsigned cpuid, unsigned nimpl, double measured);
  167. void starpu_bus_print_bandwidth(FILE *f);
  168. void starpu_bus_print_affinity(FILE *f);
  169. #ifdef __cplusplus
  170. }
  171. #endif
  172. #endif /* __STARPU_PERFMODEL_H__ */