starpu_perfmodel.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #ifndef __STARPU_PERFMODEL_H__
  18. #define __STARPU_PERFMODEL_H__
  19. #include <starpu_config.h>
  20. #include <stdio.h>
  21. #include <starpu.h>
  22. #include <starpu_task.h>
  23. #if ! defined(_MSC_VER)
  24. # include <pthread.h>
  25. #endif
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. struct starpu_htbl32_node_s;
  30. struct starpu_history_list_t;
  31. struct starpu_buffer_descr_t;
  32. /*
  33. it is possible that we have multiple versions of the same kind of workers,
  34. for instance multiple GPUs or even different CPUs within the same machine
  35. so we do not use the archtype enum type directly for performance models
  36. */
  37. enum starpu_perf_archtype {
  38. STARPU_CPU_DEFAULT = 0,
  39. /* CPU combined workers between 0 and STARPU_MAXCPUS-1 */
  40. STARPU_CUDA_DEFAULT = STARPU_MAXCPUS,
  41. STARPU_OPENCL_DEFAULT = STARPU_CUDA_DEFAULT + STARPU_MAXCUDADEVS,
  42. /* STARPU_OPENCL_DEFAULT + devid */
  43. STARPU_GORDON_DEFAULT = STARPU_OPENCL_DEFAULT + STARPU_MAXOPENCLDEVS
  44. };
  45. #define STARPU_NARCH_VARIATIONS (STARPU_GORDON_DEFAULT+1)
  46. struct starpu_regression_model_t {
  47. /* sum of ln(measured) */
  48. double sumlny;
  49. /* sum of ln(size) */
  50. double sumlnx;
  51. double sumlnx2;
  52. /* sum of ln(size) ln(measured) */
  53. double sumlnxlny;
  54. /* y = alpha size ^ beta */
  55. double alpha;
  56. double beta;
  57. unsigned valid;
  58. /* y = a size ^b + c */
  59. double a, b, c;
  60. unsigned nl_valid;
  61. unsigned nsample;
  62. };
  63. struct starpu_per_arch_perfmodel_t {
  64. double (*cost_model)(struct starpu_buffer_descr_t *t); /* returns expected duration in µs */
  65. /* internal variables */
  66. double alpha;
  67. struct starpu_htbl32_node_s *history;
  68. struct starpu_history_list_t *list;
  69. struct starpu_regression_model_t regression;
  70. #ifdef STARPU_MODEL_DEBUG
  71. FILE *debug_file;
  72. #endif
  73. };
  74. typedef enum {
  75. STARPU_PER_ARCH, /* Application-provided per-arch cost model function */
  76. STARPU_COMMON, /* Application-provided common cost model function, with per-arch factor */
  77. STARPU_HISTORY_BASED, /* Automatic history-based cost model */
  78. STARPU_REGRESSION_BASED, /* Automatic linear regression-based cost model (alpha * size ^ beta) */
  79. STARPU_NL_REGRESSION_BASED /* Automatic non-linear regression-based cost model (a * size ^ b + c) */
  80. } starpu_perfmodel_type;
  81. struct starpu_perfmodel_t {
  82. /* which model is used for that task ? */
  83. starpu_perfmodel_type type;
  84. /* single cost model (STARPU_COMMON), returns expected duration in µs */
  85. double (*cost_model)(struct starpu_buffer_descr_t *);
  86. /* per-architecture model */
  87. struct starpu_per_arch_perfmodel_t per_arch[STARPU_NARCH_VARIATIONS];
  88. /* Name of the performance model, this is used as a file name when saving history-based performance models */
  89. const char *symbol;
  90. /* Internal variables */
  91. unsigned is_loaded;
  92. unsigned benchmarking;
  93. #if defined(_MSC_VER)
  94. void *model_rwlock;
  95. #else
  96. pthread_rwlock_t model_rwlock;
  97. #endif
  98. };
  99. enum starpu_perf_archtype starpu_worker_get_perf_archtype(int workerid);
  100. /* This function is intended to be used by external tools that should read the
  101. * performance model files */
  102. int starpu_load_history_debug(const char *symbol, struct starpu_perfmodel_t *model);
  103. void starpu_perfmodel_debugfilepath(struct starpu_perfmodel_t *model,
  104. enum starpu_perf_archtype arch, char *path, size_t maxlen);
  105. void starpu_perfmodel_get_arch_name(enum starpu_perf_archtype arch,
  106. char *archname, size_t maxlen);
  107. int starpu_list_models(void);
  108. void starpu_force_bus_sampling(void);
  109. void starpu_print_bus_bandwidth(FILE *f);
  110. #ifdef __cplusplus
  111. }
  112. #endif
  113. #endif /* __STARPU_PERFMODEL_H__ */