starpu_perfmodel.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (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 <stdio.h>
  19. #ifndef __MINGW32__
  20. #include <pthread.h>
  21. #else
  22. #include <windows.h>
  23. #undef interface
  24. #endif
  25. #include <starpu.h>
  26. #include <starpu_config.h>
  27. #include <starpu_task.h>
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. struct starpu_htbl32_node_s;
  32. struct starpu_history_list_t;
  33. struct starpu_buffer_descr_t;
  34. /*
  35. it is possible that we have multiple versions of the same kind of workers,
  36. for instance multiple GPUs or even different CPUs within the same machine
  37. so we do not use the archtype enum type directly for performance models
  38. */
  39. enum starpu_perf_archtype {
  40. STARPU_CPU_DEFAULT = 0,
  41. STARPU_CUDA_DEFAULT = 1,
  42. STARPU_OPENCL_DEFAULT = STARPU_CUDA_DEFAULT + STARPU_MAXCUDADEVS,
  43. /* STARPU_OPENCL_DEFAULT + devid */
  44. STARPU_GORDON_DEFAULT = STARPU_OPENCL_DEFAULT + STARPU_MAXOPENCLDEVS
  45. };
  46. #define STARPU_NARCH_VARIATIONS (STARPU_GORDON_DEFAULT+1)
  47. struct starpu_regression_model_t {
  48. /* sum of ln(measured) */
  49. double sumlny;
  50. /* sum of ln(size) */
  51. double sumlnx;
  52. double sumlnx2;
  53. /* sum of ln(size) ln(measured) */
  54. double sumlnxlny;
  55. /* y = alpha size ^ beta */
  56. double alpha;
  57. double beta;
  58. /* y = a size ^b + c */
  59. double a, b, c;
  60. unsigned valid;
  61. unsigned nsample;
  62. };
  63. struct starpu_per_arch_perfmodel_t {
  64. double (*cost_model)(struct starpu_buffer_descr_t *t);
  65. double alpha;
  66. struct starpu_htbl32_node_s *history;
  67. struct starpu_history_list_t *list;
  68. struct starpu_regression_model_t regression;
  69. #ifdef STARPU_MODEL_DEBUG
  70. FILE *debug_file;
  71. #endif
  72. };
  73. typedef enum {STARPU_PER_ARCH, STARPU_COMMON, STARPU_HISTORY_BASED, STARPU_REGRESSION_BASED} 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. enum {
  83. STARPU_PERFMODEL_NOT_LOADED,
  84. STARPU_PERFMODEL_LOADING,
  85. STARPU_PERFMODEL_LOADED
  86. } is_loaded;
  87. unsigned benchmarking;
  88. #ifndef __MINGW32__
  89. pthread_rwlock_t model_rwlock;
  90. #else
  91. HANDLE model_rwlock;
  92. #endif
  93. };
  94. /* This function is intended to be used by external tools that should read the
  95. * performance model files */
  96. int starpu_load_history_debug(const char *symbol, struct starpu_perfmodel_t *model);
  97. void starpu_perfmodel_debugfilepath(struct starpu_perfmodel_t *model,
  98. enum starpu_perf_archtype arch, char *path, size_t maxlen);
  99. void starpu_perfmodel_get_arch_name(enum starpu_perf_archtype arch,
  100. char *archname, size_t maxlen);
  101. void starpu_force_bus_sampling(void);
  102. #ifdef __cplusplus
  103. }
  104. #endif
  105. #endif // __STARPU_PERFMODEL_H__