starpu_perfmodel.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. #include <starpu_worker.h>
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. struct starpu_task;
  29. struct starpu_data_descr;
  30. #define STARPU_NARCH STARPU_ANY_WORKER
  31. //char archtype_name[STARPU_NARCH] = {"cpu","cuda","opencl","mic","scc"};
  32. struct starpu_perfmodel_arch
  33. {
  34. enum starpu_worker_archtype type;
  35. int devid;
  36. int ncore;
  37. };
  38. #ifdef __STDC_VERSION__
  39. # if __STDC_VERSION__ > 199901L || STARPU_GNUC_PREREQ(4, 6)
  40. /* Make sure the following assertions hold, since StarPU relies on it. */
  41. _Static_assert(STARPU_CPU_DEFAULT == 0,
  42. "invalid STARPU_CPU_DEFAULT value");
  43. _Static_assert(STARPU_CPU_DEFAULT < STARPU_CUDA_DEFAULT,
  44. "invalid STARPU_{CPU,CUDA}_DEFAULT values");
  45. _Static_assert(STARPU_CUDA_DEFAULT < STARPU_OPENCL_DEFAULT,
  46. "invalid STARPU_{CUDA,OPENCL}_DEFAULT values");
  47. _Static_assert(STARPU_OPENCL_DEFAULT < STARPU_MIC_DEFAULT,
  48. "invalid STARPU_{OPENCL,MIC}_DEFAULT values");
  49. _Static_assert(STARPU_MIC_DEFAULT < STARPU_SCC_DEFAULT,
  50. "invalid STARPU_{MIC,SCC}_DEFAULT values");
  51. # endif
  52. #endif
  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, struct starpu_perfmodel_arch* arch, unsigned nimpl);
  94. size_t (*size_base)(struct starpu_task *, struct starpu_perfmodel_arch* 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_MAXIMPLEMENTATIONS*/
  117. const char *symbol;
  118. unsigned is_loaded;
  119. unsigned benchmarking;
  120. starpu_pthread_rwlock_t model_rwlock;
  121. };
  122. void initialize_model(struct starpu_perfmodel *model);
  123. struct starpu_perfmodel_arch* starpu_worker_get_perf_archtype(int workerid);
  124. int starpu_perfmodel_load_symbol(const char *symbol, struct starpu_perfmodel *model);
  125. int starpu_perfmodel_unload_model(struct starpu_perfmodel *model);
  126. void starpu_perfmodel_debugfilepath(struct starpu_perfmodel *model, struct starpu_perfmodel_arch* arch, char *path, size_t maxlen, unsigned nimpl);
  127. char* starpu_perfmodel_get_archtype_name(enum starpu_worker_archtype archtype);
  128. void starpu_perfmodel_get_arch_name(struct starpu_perfmodel_arch* arch, char *archname, size_t maxlen, unsigned nimpl);
  129. double starpu_permodel_history_based_expected_perf(struct starpu_perfmodel *model, struct starpu_perfmodel_arch* arch, uint32_t footprint);
  130. int starpu_perfmodel_list(FILE *output);
  131. void starpu_perfmodel_print(struct starpu_perfmodel *model, struct starpu_perfmodel_arch* arch, unsigned nimpl, char *parameter, uint32_t *footprint, FILE *output);
  132. int starpu_perfmodel_print_all(struct starpu_perfmodel *model, char *arch, char *parameter, uint32_t *footprint, FILE *output);
  133. void starpu_perfmodel_update_history(struct starpu_perfmodel *model, struct starpu_task *task, struct starpu_perfmodel_arch * arch, unsigned cpuid, unsigned nimpl, double measured);
  134. void starpu_bus_print_bandwidth(FILE *f);
  135. void starpu_bus_print_affinity(FILE *f);
  136. double starpu_transfer_bandwidth(unsigned src_node, unsigned dst_node);
  137. double starpu_transfer_latency(unsigned src_node, unsigned dst_node);
  138. double starpu_transfer_predict(unsigned src_node, unsigned dst_node, size_t size);
  139. #ifdef __cplusplus
  140. }
  141. #endif
  142. #endif /* __STARPU_PERFMODEL_H__ */