starpu_perfmodel.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. };
  42. #ifdef __STDC_VERSION__
  43. # if __STDC_VERSION__ > 199901L || STARPU_GNUC_PREREQ(4, 6)
  44. /* Make sure the following assertions hold, since StarPU relies on it. */
  45. _Static_assert(STARPU_CPU_DEFAULT == 0,
  46. "invalid STARPU_CPU_DEFAULT value");
  47. _Static_assert(STARPU_CUDA_DEFAULT > STARPU_CPU_DEFAULT,
  48. "invalid STARPU_CPU_DEFAULT value");
  49. _Static_assert(STARPU_CUDA_DEFAULT < STARPU_OPENCL_DEFAULT,
  50. "invalid STARPU_{CUDA,OPENCL}_DEFAULT values");
  51. # endif
  52. #endif
  53. #define STARPU_NARCH_VARIATIONS (STARPU_OPENCL_DEFAULT + STARPU_MAXOPENCLDEVS)
  54. struct starpu_perfmodel_history_entry
  55. {
  56. //double measured;
  57. /* mean_n = 1/n sum */
  58. double mean;
  59. /* n dev_n = sum2 - 1/n (sum)^2 */
  60. double deviation;
  61. /* sum of samples */
  62. double sum;
  63. /* sum of samples^2 */
  64. double sum2;
  65. // /* sum of ln(measured) */
  66. // double sumlny;
  67. //
  68. // /* sum of ln(size) */
  69. // double sumlnx;
  70. // double sumlnx2;
  71. //
  72. // /* sum of ln(size) ln(measured) */
  73. // double sumlnxlny;
  74. //
  75. unsigned nsample;
  76. uint32_t footprint;
  77. #ifdef STARPU_HAVE_WINDOWS
  78. unsigned size; /* in bytes */
  79. #else
  80. size_t size; /* in bytes */
  81. #endif
  82. double flops; /* Provided by the application */
  83. };
  84. struct starpu_perfmodel_history_list
  85. {
  86. struct starpu_perfmodel_history_list *next;
  87. struct starpu_perfmodel_history_entry *entry;
  88. };
  89. struct starpu_perfmodel_regression_model
  90. {
  91. /* sum of ln(measured) */
  92. double sumlny;
  93. /* sum of ln(size) */
  94. double sumlnx;
  95. double sumlnx2;
  96. /* minimum/maximum(size) */
  97. unsigned long minx;
  98. unsigned long maxx;
  99. /* sum of ln(size) ln(measured) */
  100. double sumlnxlny;
  101. /* y = alpha size ^ beta */
  102. double alpha;
  103. double beta;
  104. unsigned valid;
  105. /* y = a size ^b + c */
  106. double a, b, c;
  107. unsigned nl_valid;
  108. unsigned nsample;
  109. };
  110. struct starpu_perfmodel_history_table;
  111. #define starpu_per_arch_perfmodel starpu_perfmodel_per_arch STARPU_DEPRECATED
  112. struct starpu_perfmodel_per_arch
  113. {
  114. double (*cost_model)(struct starpu_data_descr *t) STARPU_DEPRECATED; /* returns expected duration in µs */
  115. double (*cost_function)(struct starpu_task *task, enum starpu_perfmodel_archtype arch, unsigned nimpl); /* returns expected duration in µs */
  116. size_t (*size_base)(struct starpu_task *, enum starpu_perfmodel_archtype arch, unsigned nimpl);
  117. /* internal variables */
  118. struct starpu_perfmodel_history_table *history;
  119. struct starpu_perfmodel_history_list *list;
  120. struct starpu_perfmodel_regression_model regression;
  121. #ifdef STARPU_MODEL_DEBUG
  122. char debug_path[256];
  123. #endif
  124. };
  125. enum starpu_perfmodel_type
  126. {
  127. STARPU_PER_ARCH, /* Application-provided per-arch cost model function */
  128. STARPU_COMMON, /* Application-provided common cost model function, with per-arch factor */
  129. STARPU_HISTORY_BASED, /* Automatic history-based cost model */
  130. STARPU_REGRESSION_BASED, /* Automatic linear regression-based cost model (alpha * size ^ beta) */
  131. STARPU_NL_REGRESSION_BASED /* Automatic non-linear regression-based cost model (a * size ^ b + c) */
  132. };
  133. struct starpu_perfmodel
  134. {
  135. /* which model is used for that task ? */
  136. enum starpu_perfmodel_type type;
  137. /* single cost model (STARPU_COMMON), returns expected duration in µs */
  138. double (*cost_model)(struct starpu_data_descr *) STARPU_DEPRECATED;
  139. double (*cost_function)(struct starpu_task *, unsigned nimpl);
  140. size_t (*size_base)(struct starpu_task *, unsigned nimpl);
  141. /* per-architecture model */
  142. struct starpu_perfmodel_per_arch per_arch[STARPU_NARCH_VARIATIONS][STARPU_MAXIMPLEMENTATIONS];
  143. /* Name of the performance model, this is used as a file name when saving history-based performance models */
  144. const char *symbol;
  145. /* Internal variables */
  146. unsigned is_loaded;
  147. unsigned benchmarking;
  148. starpu_pthread_rwlock_t model_rwlock;
  149. };
  150. enum starpu_perfmodel_archtype starpu_worker_get_perf_archtype(int workerid);
  151. /* This function is intended to be used by external tools that should read the
  152. * performance model files */
  153. int starpu_perfmodel_load_symbol(const char *symbol, struct starpu_perfmodel *model);
  154. int starpu_perfmodel_unload_model(struct starpu_perfmodel *model);
  155. void starpu_perfmodel_debugfilepath(struct starpu_perfmodel *model, enum starpu_perfmodel_archtype arch, char *path, size_t maxlen, unsigned nimpl);
  156. void starpu_perfmodel_get_arch_name(enum starpu_perfmodel_archtype arch, char *archname, size_t maxlen, unsigned nimpl);
  157. double starpu_permodel_history_based_expected_perf(struct starpu_perfmodel *model, enum starpu_perfmodel_archtype arch, uint32_t footprint);
  158. int starpu_perfmodel_list(FILE *output);
  159. void starpu_perfmodel_print(struct starpu_perfmodel *model, enum starpu_perfmodel_archtype arch, unsigned nimpl, char *parameter, uint32_t *footprint, FILE *output);
  160. int starpu_perfmodel_print_all(struct starpu_perfmodel *model, char *arch, char *parameter, uint32_t *footprint, FILE *output);
  161. void starpu_perfmodel_update_history(struct starpu_perfmodel *model, struct starpu_task *task, enum starpu_perfmodel_archtype arch, unsigned cpuid, unsigned nimpl, double measured);
  162. void starpu_bus_print_bandwidth(FILE *f);
  163. void starpu_bus_print_affinity(FILE *f);
  164. /* use bw & latency to compute the velocity of resources*/
  165. double starpu_get_bandwidth_RAM_CUDA(unsigned cudadev);
  166. double starpu_get_latency_RAM_CUDA(unsigned cudadev);
  167. #ifdef __cplusplus
  168. }
  169. #endif
  170. #endif /* __STARPU_PERFMODEL_H__ */