starpu_perfmodel.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2011 Université de Bordeaux 1
  4. * Copyright (C) 2010 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 <pthread.h>
  22. #include <starpu.h>
  23. #include <starpu_task.h>
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. struct starpu_htbl32_node_s;
  28. struct starpu_history_list_t;
  29. struct starpu_buffer_descr_t;
  30. /*
  31. it is possible that we have multiple versions of the same kind of workers,
  32. for instance multiple GPUs or even different CPUs within the same machine
  33. so we do not use the archtype enum type directly for performance models
  34. */
  35. enum starpu_perf_archtype {
  36. STARPU_CPU_DEFAULT = 0,
  37. /* CPU combined workers between 0 and STARPU_NMAXCPUS-1 */
  38. STARPU_CUDA_DEFAULT = STARPU_NMAXCPUS,
  39. STARPU_OPENCL_DEFAULT = STARPU_CUDA_DEFAULT + STARPU_MAXCUDADEVS,
  40. /* STARPU_OPENCL_DEFAULT + devid */
  41. STARPU_GORDON_DEFAULT = STARPU_OPENCL_DEFAULT + STARPU_MAXOPENCLDEVS
  42. };
  43. #define STARPU_NARCH_VARIATIONS (STARPU_GORDON_DEFAULT+1)
  44. struct starpu_regression_model_t {
  45. /* sum of ln(measured) */
  46. double sumlny;
  47. /* sum of ln(size) */
  48. double sumlnx;
  49. double sumlnx2;
  50. /* sum of ln(size) ln(measured) */
  51. double sumlnxlny;
  52. /* y = alpha size ^ beta */
  53. double alpha;
  54. double beta;
  55. unsigned valid;
  56. /* y = a size ^b + c */
  57. double a, b, c;
  58. unsigned nl_valid;
  59. unsigned nsample;
  60. };
  61. struct starpu_per_arch_perfmodel_t {
  62. double (*cost_model)(struct starpu_buffer_descr_t *t);
  63. double alpha;
  64. struct starpu_htbl32_node_s *history;
  65. struct starpu_history_list_t *list;
  66. struct starpu_regression_model_t regression;
  67. #ifdef STARPU_MODEL_DEBUG
  68. FILE *debug_file;
  69. #endif
  70. };
  71. typedef enum {
  72. STARPU_PER_ARCH, /* Application-provided per-arch cost model function */
  73. STARPU_COMMON, /* Application-provided common cost model function, with per-arch factor */
  74. STARPU_HISTORY_BASED, /* Automatic history-based cost model */
  75. STARPU_REGRESSION_BASED, /* Automatic linear regression-based cost model (alpha * size ^ beta) */
  76. STARPU_NL_REGRESSION_BASED /* Automatic non-linear regression-based cost model (a * size ^ b + c) */
  77. } starpu_perfmodel_type;
  78. struct starpu_perfmodel_t {
  79. /* which model is used for that task ? */
  80. starpu_perfmodel_type type;
  81. /* single cost model */
  82. double (*cost_model)(struct starpu_buffer_descr_t *);
  83. /* per-architecture model */
  84. struct starpu_per_arch_perfmodel_t per_arch[STARPU_NARCH_VARIATIONS];
  85. const char *symbol;
  86. unsigned is_loaded;
  87. unsigned benchmarking;
  88. pthread_rwlock_t model_rwlock;
  89. };
  90. /* This function is intended to be used by external tools that should read the
  91. * performance model files */
  92. int starpu_load_history_debug(const char *symbol, struct starpu_perfmodel_t *model);
  93. void starpu_perfmodel_debugfilepath(struct starpu_perfmodel_t *model,
  94. enum starpu_perf_archtype arch, char *path, size_t maxlen);
  95. void starpu_perfmodel_get_arch_name(enum starpu_perf_archtype arch,
  96. char *archname, size_t maxlen);
  97. int starpu_list_models(void);
  98. /* Returns expected task duration in µs */
  99. double starpu_task_expected_length(struct starpu_task *task, enum starpu_perf_archtype arch);
  100. /* Returns an estimated speedup factor relative to CPU speed */
  101. double starpu_worker_get_relative_speedup(enum starpu_perf_archtype perf_archtype);
  102. /* Returns expected data transfer time in µs */
  103. double starpu_data_expected_penalty(uint32_t memory_node, struct starpu_task *task);
  104. /* Returns expected power consumption in J */
  105. double starpu_task_expected_power(struct starpu_task *task, enum starpu_perf_archtype arch);
  106. void starpu_force_bus_sampling(void);
  107. #ifdef __cplusplus
  108. }
  109. #endif
  110. #endif // __STARPU_PERFMODEL_H__