starpu_perfmodel.h 3.6 KB

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