starpu_perfmodel.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2011 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011 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. #include <starpu.h>
  19. #ifndef __STARPU_PERFMODEL_H__
  20. #define __STARPU_PERFMODEL_H__
  21. #include <starpu_config.h>
  22. #include <stdio.h>
  23. #include <starpu_task.h>
  24. #if ! defined(_MSC_VER)
  25. # include <pthread.h>
  26. #endif
  27. #ifdef __cplusplus
  28. extern "C"
  29. {
  30. #endif
  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. #define STARPU_NARCH_VARIATIONS (STARPU_GORDON_DEFAULT+1)
  49. struct starpu_history_entry
  50. {
  51. //double measured;
  52. /* mean_n = 1/n sum */
  53. double mean;
  54. /* n dev_n = sum2 - 1/n (sum)^2 */
  55. double deviation;
  56. /* sum of samples */
  57. double sum;
  58. /* sum of samples^2 */
  59. double sum2;
  60. // /* sum of ln(measured) */
  61. // double sumlny;
  62. //
  63. // /* sum of ln(size) */
  64. // double sumlnx;
  65. // double sumlnx2;
  66. //
  67. // /* sum of ln(size) ln(measured) */
  68. // double sumlnxlny;
  69. //
  70. unsigned nsample;
  71. uint32_t footprint;
  72. #ifdef STARPU_HAVE_WINDOWS
  73. unsigned size; /* in bytes */
  74. #else
  75. size_t size; /* in bytes */
  76. #endif
  77. };
  78. struct starpu_history_list
  79. {
  80. struct starpu_history_list *next;
  81. struct starpu_history_entry *entry;
  82. };
  83. struct starpu_model_list
  84. {
  85. struct starpu_model_list *next;
  86. struct starpu_perfmodel *model;
  87. };
  88. struct starpu_regression_model
  89. {
  90. /* sum of ln(measured) */
  91. double sumlny;
  92. /* sum of ln(size) */
  93. double sumlnx;
  94. double sumlnx2;
  95. /* minimum/maximum(size) */
  96. unsigned long minx;
  97. unsigned long maxx;
  98. /* sum of ln(size) ln(measured) */
  99. double sumlnxlny;
  100. /* y = alpha size ^ beta */
  101. double alpha;
  102. double beta;
  103. unsigned valid;
  104. /* y = a size ^b + c */
  105. double a, b, c;
  106. unsigned nl_valid;
  107. unsigned nsample;
  108. };
  109. struct starpu_per_arch_perfmodel
  110. {
  111. double (*cost_model)(struct starpu_buffer_descr *t); /* returns expected duration in µs */
  112. /* internal variables */
  113. double alpha;
  114. struct starpu_htbl32_node *history;
  115. struct starpu_history_list *list;
  116. struct starpu_regression_model regression;
  117. #ifdef STARPU_MODEL_DEBUG
  118. FILE *debug_file;
  119. #endif
  120. };
  121. enum starpu_perfmodel_type
  122. {
  123. STARPU_PER_ARCH, /* Application-provided per-arch cost model function */
  124. STARPU_COMMON, /* Application-provided common cost model function, with per-arch factor */
  125. STARPU_HISTORY_BASED, /* Automatic history-based cost model */
  126. STARPU_REGRESSION_BASED, /* Automatic linear regression-based cost model (alpha * size ^ beta) */
  127. STARPU_NL_REGRESSION_BASED /* Automatic non-linear regression-based cost model (a * size ^ b + c) */
  128. };
  129. struct starpu_perfmodel
  130. {
  131. /* which model is used for that task ? */
  132. enum starpu_perfmodel_type type;
  133. /* single cost model (STARPU_COMMON), returns expected duration in µs */
  134. double (*cost_model)(struct starpu_buffer_descr *);
  135. /* per-architecture model */
  136. struct starpu_per_arch_perfmodel per_arch[STARPU_NARCH_VARIATIONS][STARPU_MAXIMPLEMENTATIONS];
  137. /* Name of the performance model, this is used as a file name when saving history-based performance models */
  138. const char *symbol;
  139. /* Internal variables */
  140. unsigned is_loaded;
  141. unsigned benchmarking;
  142. #if defined(_MSC_VER)
  143. void *model_rwlock;
  144. #else
  145. pthread_rwlock_t model_rwlock;
  146. #endif
  147. };
  148. enum starpu_perf_archtype starpu_worker_get_perf_archtype(int workerid);
  149. /* This function is intended to be used by external tools that should read the
  150. * performance model files */
  151. int starpu_load_history_debug(const char *symbol, struct starpu_perfmodel *model);
  152. void starpu_perfmodel_debugfilepath(struct starpu_perfmodel *model,
  153. enum starpu_perf_archtype arch, char *path, size_t maxlen, unsigned nimpl);
  154. void starpu_perfmodel_get_arch_name(enum starpu_perf_archtype arch, char *archname, size_t maxlen, unsigned nimpl);
  155. int starpu_list_models(FILE *output);
  156. void starpu_force_bus_sampling(void);
  157. void starpu_print_bus_bandwidth(FILE *f);
  158. #ifdef __cplusplus
  159. }
  160. #endif
  161. #endif /* __STARPU_PERFMODEL_H__ */