starpu_perfmodel.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. enum starpu_perfmodel_archtype
  30. {
  31. STARPU_CPU_DEFAULT = 0,
  32. STARPU_CUDA_DEFAULT = STARPU_MAXCPUS,
  33. STARPU_OPENCL_DEFAULT = STARPU_CUDA_DEFAULT + STARPU_MAXCUDADEVS,
  34. STARPU_MIC_DEFAULT = STARPU_OPENCL_DEFAULT + STARPU_MAXOPENCLDEVS,
  35. STARPU_SCC_DEFAULT = STARPU_MIC_DEFAULT + STARPU_MAXMICDEVS
  36. };
  37. #ifdef __STDC_VERSION__
  38. # if __STDC_VERSION__ > 199901L || STARPU_GNUC_PREREQ(4, 6)
  39. /* Make sure the following assertions hold, since StarPU relies on it. */
  40. _Static_assert(STARPU_CPU_DEFAULT == 0,
  41. "invalid STARPU_CPU_DEFAULT value");
  42. _Static_assert(STARPU_CPU_DEFAULT < STARPU_CUDA_DEFAULT,
  43. "invalid STARPU_{CPU,CUDA}_DEFAULT values");
  44. _Static_assert(STARPU_CUDA_DEFAULT < STARPU_OPENCL_DEFAULT,
  45. "invalid STARPU_{CUDA,OPENCL}_DEFAULT values");
  46. _Static_assert(STARPU_OPENCL_DEFAULT < STARPU_MIC_DEFAULT,
  47. "invalid STARPU_{OPENCL,MIC}_DEFAULT values");
  48. _Static_assert(STARPU_MIC_DEFAULT < STARPU_SCC_DEFAULT,
  49. "invalid STARPU_{MIC,SCC}_DEFAULT values");
  50. # endif
  51. #endif
  52. #define STARPU_NARCH_VARIATIONS (STARPU_MIC_DEFAULT + STARPU_MAXMICDEVS)
  53. struct starpu_perfmodel_history_entry
  54. {
  55. double mean;
  56. double deviation;
  57. double sum;
  58. double sum2;
  59. unsigned nsample;
  60. uint32_t footprint;
  61. #ifdef STARPU_HAVE_WINDOWS
  62. unsigned size;
  63. #else
  64. size_t size;
  65. #endif
  66. double flops;
  67. };
  68. struct starpu_perfmodel_history_list
  69. {
  70. struct starpu_perfmodel_history_list *next;
  71. struct starpu_perfmodel_history_entry *entry;
  72. };
  73. struct starpu_perfmodel_regression_model
  74. {
  75. double sumlny;
  76. double sumlnx;
  77. double sumlnx2;
  78. unsigned long minx;
  79. unsigned long maxx;
  80. double sumlnxlny;
  81. double alpha;
  82. double beta;
  83. unsigned valid;
  84. double a, b, c;
  85. unsigned nl_valid;
  86. unsigned nsample;
  87. };
  88. struct starpu_perfmodel_history_table;
  89. #define starpu_per_arch_perfmodel starpu_perfmodel_per_arch STARPU_DEPRECATED
  90. struct starpu_perfmodel_per_arch
  91. {
  92. double (*cost_model)(struct starpu_data_descr *t) STARPU_DEPRECATED;
  93. double (*cost_function)(struct starpu_task *task, enum starpu_perfmodel_archtype arch, unsigned nimpl);
  94. size_t (*size_base)(struct starpu_task *, enum starpu_perfmodel_archtype arch, unsigned nimpl);
  95. struct starpu_perfmodel_history_table *history;
  96. struct starpu_perfmodel_history_list *list;
  97. struct starpu_perfmodel_regression_model regression;
  98. #ifdef STARPU_MODEL_DEBUG
  99. char debug_path[256];
  100. #endif
  101. };
  102. enum starpu_perfmodel_type
  103. {
  104. STARPU_PER_ARCH,
  105. STARPU_COMMON,
  106. STARPU_HISTORY_BASED,
  107. STARPU_REGRESSION_BASED,
  108. STARPU_NL_REGRESSION_BASED
  109. };
  110. struct starpu_perfmodel
  111. {
  112. enum starpu_perfmodel_type type;
  113. double (*cost_model)(struct starpu_data_descr *) STARPU_DEPRECATED;
  114. double (*cost_function)(struct starpu_task *, unsigned nimpl);
  115. size_t (*size_base)(struct starpu_task *, unsigned nimpl);
  116. struct starpu_perfmodel_per_arch per_arch[STARPU_NARCH_VARIATIONS][STARPU_MAXIMPLEMENTATIONS];
  117. const char *symbol;
  118. unsigned is_loaded;
  119. unsigned benchmarking;
  120. starpu_pthread_rwlock_t model_rwlock;
  121. };
  122. enum starpu_perfmodel_archtype starpu_worker_get_perf_archtype(int workerid);
  123. int starpu_perfmodel_load_symbol(const char *symbol, struct starpu_perfmodel *model);
  124. int starpu_perfmodel_unload_model(struct starpu_perfmodel *model);
  125. void starpu_perfmodel_debugfilepath(struct starpu_perfmodel *model, enum starpu_perfmodel_archtype arch, char *path, size_t maxlen, unsigned nimpl);
  126. void starpu_perfmodel_get_arch_name(enum starpu_perfmodel_archtype arch, char *archname, size_t maxlen, unsigned nimpl);
  127. double starpu_permodel_history_based_expected_perf(struct starpu_perfmodel *model, enum starpu_perfmodel_archtype arch, uint32_t footprint);
  128. int starpu_perfmodel_list(FILE *output);
  129. void starpu_perfmodel_print(struct starpu_perfmodel *model, enum starpu_perfmodel_archtype arch, unsigned nimpl, char *parameter, uint32_t *footprint, FILE *output);
  130. int starpu_perfmodel_print_all(struct starpu_perfmodel *model, char *arch, char *parameter, uint32_t *footprint, FILE *output);
  131. void starpu_perfmodel_update_history(struct starpu_perfmodel *model, struct starpu_task *task, enum starpu_perfmodel_archtype arch, unsigned cpuid, unsigned nimpl, double measured);
  132. void starpu_bus_print_bandwidth(FILE *f);
  133. void starpu_bus_print_affinity(FILE *f);
  134. double starpu_get_bandwidth_RAM_CUDA(unsigned cudadev);
  135. double starpu_get_latency_RAM_CUDA(unsigned cudadev);
  136. #ifdef __cplusplus
  137. }
  138. #endif
  139. #endif /* __STARPU_PERFMODEL_H__ */