starpu_perfmodel.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2013 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012, 2013 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. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. struct starpu_task;
  28. struct starpu_data_descr;
  29. /*
  30. it is possible that we have multiple versions of the same kind of workers,
  31. for instance multiple GPUs or even different CPUs within the same machine
  32. so we do not use the archtype enum type directly for performance models
  33. */
  34. enum starpu_perfmodel_archtype
  35. {
  36. STARPU_CPU_DEFAULT = 0,
  37. /* CPU combined workers between 0 and STARPU_MAXCPUS-1 */
  38. STARPU_CUDA_DEFAULT = STARPU_MAXCPUS,
  39. STARPU_OPENCL_DEFAULT = STARPU_CUDA_DEFAULT + STARPU_MAXCUDADEVS,
  40. /* STARPU_OPENCL_DEFAULT + devid */
  41. STARPU_MIC_DEFAULT = STARPU_OPENCL_DEFAULT + STARPU_MAXOPENCLDEVS,
  42. STARPU_SCC_DEFAULT = STARPU_MIC_DEFAULT + STARPU_MAXMICDEVS
  43. };
  44. #ifdef __STDC_VERSION__
  45. # if __STDC_VERSION__ > 199901L || STARPU_GNUC_PREREQ(4, 6)
  46. /* Make sure the following assertions hold, since StarPU relies on it. */
  47. _Static_assert(STARPU_CPU_DEFAULT == 0,
  48. "invalid STARPU_CPU_DEFAULT value");
  49. _Static_assert(STARPU_CPU_DEFAULT < STARPU_CUDA_DEFAULT,
  50. "invalid STARPU_{CPU,CUDA}_DEFAULT values");
  51. _Static_assert(STARPU_CUDA_DEFAULT < STARPU_OPENCL_DEFAULT,
  52. "invalid STARPU_{CUDA,OPENCL}_DEFAULT values");
  53. _Static_assert(STARPU_OPENCL_DEFAULT < STARPU_MIC_DEFAULT,
  54. "invalid STARPU_{OPENCL,MIC}_DEFAULT values");
  55. _Static_assert(STARPU_MIC_DEFAULT < STARPU_SCC_DEFAULT,
  56. "invalid STARPU_{MIC,SCC}_DEFAULT values");
  57. # endif
  58. #endif
  59. #define STARPU_NARCH_VARIATIONS (STARPU_MIC_DEFAULT + STARPU_MAXMICDEVS)
  60. struct starpu_perfmodel_history_entry
  61. {
  62. //double measured;
  63. /* mean_n = 1/n sum */
  64. double mean;
  65. /* n dev_n = sum2 - 1/n (sum)^2 */
  66. double deviation;
  67. /* sum of samples */
  68. double sum;
  69. /* sum of samples^2 */
  70. double sum2;
  71. // /* sum of ln(measured) */
  72. // double sumlny;
  73. //
  74. // /* sum of ln(size) */
  75. // double sumlnx;
  76. // double sumlnx2;
  77. //
  78. // /* sum of ln(size) ln(measured) */
  79. // double sumlnxlny;
  80. //
  81. unsigned nsample;
  82. uint32_t footprint;
  83. #ifdef STARPU_HAVE_WINDOWS
  84. unsigned size; /* in bytes */
  85. #else
  86. size_t size; /* in bytes */
  87. #endif
  88. double flops; /* Provided by the application */
  89. };
  90. struct starpu_perfmodel_history_list
  91. {
  92. struct starpu_perfmodel_history_list *next;
  93. struct starpu_perfmodel_history_entry *entry;
  94. };
  95. struct starpu_perfmodel_regression_model
  96. {
  97. /* sum of ln(measured) */
  98. double sumlny;
  99. /* sum of ln(size) */
  100. double sumlnx;
  101. double sumlnx2;
  102. /* minimum/maximum(size) */
  103. unsigned long minx;
  104. unsigned long maxx;
  105. /* sum of ln(size) ln(measured) */
  106. double sumlnxlny;
  107. /* y = alpha size ^ beta */
  108. double alpha;
  109. double beta;
  110. unsigned valid;
  111. /* y = a size ^b + c */
  112. double a, b, c;
  113. unsigned nl_valid;
  114. unsigned nsample;
  115. };
  116. struct starpu_perfmodel_history_table;
  117. #define starpu_per_arch_perfmodel starpu_perfmodel_per_arch STARPU_DEPRECATED
  118. struct starpu_perfmodel_per_arch
  119. {
  120. double (*cost_model)(struct starpu_data_descr *t) STARPU_DEPRECATED; /* returns expected duration in µs */
  121. double (*cost_function)(struct starpu_task *task, enum starpu_perfmodel_archtype arch, unsigned nimpl); /* returns expected duration in µs */
  122. size_t (*size_base)(struct starpu_task *, enum starpu_perfmodel_archtype arch, unsigned nimpl);
  123. /* internal variables */
  124. struct starpu_perfmodel_history_table *history;
  125. struct starpu_perfmodel_history_list *list;
  126. struct starpu_perfmodel_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_data_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_perfmodel_per_arch 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. starpu_pthread_rwlock_t model_rwlock;
  155. };
  156. enum starpu_perfmodel_archtype starpu_worker_get_perf_archtype(int workerid);
  157. /* This function is intended to be used by external tools that should read the
  158. * performance model files */
  159. int starpu_perfmodel_load_symbol(const char *symbol, struct starpu_perfmodel *model);
  160. int starpu_perfmodel_unload_model(struct starpu_perfmodel *model);
  161. void starpu_perfmodel_debugfilepath(struct starpu_perfmodel *model, enum starpu_perfmodel_archtype arch, char *path, size_t maxlen, unsigned nimpl);
  162. void starpu_perfmodel_get_arch_name(enum starpu_perfmodel_archtype arch, char *archname, size_t maxlen, unsigned nimpl);
  163. double starpu_permodel_history_based_expected_perf(struct starpu_perfmodel *model, enum starpu_perfmodel_archtype arch, uint32_t footprint);
  164. int starpu_perfmodel_list(FILE *output);
  165. void starpu_perfmodel_print(struct starpu_perfmodel *model, enum starpu_perfmodel_archtype arch, unsigned nimpl, char *parameter, uint32_t *footprint, FILE *output);
  166. int starpu_perfmodel_print_all(struct starpu_perfmodel *model, char *arch, char *parameter, uint32_t *footprint, FILE *output);
  167. void starpu_perfmodel_update_history(struct starpu_perfmodel *model, struct starpu_task *task, enum starpu_perfmodel_archtype arch, unsigned cpuid, unsigned nimpl, double measured);
  168. void starpu_bus_print_bandwidth(FILE *f);
  169. void starpu_bus_print_affinity(FILE *f);
  170. /* use bw & latency to compute the velocity of resources*/
  171. double starpu_get_bandwidth_RAM_CUDA(unsigned cudadev);
  172. double starpu_get_latency_RAM_CUDA(unsigned cudadev);
  173. #ifdef __cplusplus
  174. }
  175. #endif
  176. #endif /* __STARPU_PERFMODEL_H__ */