lu_kernels_model.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010-2011 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012 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. #include "lu_kernels_model.h"
  19. /*
  20. * As a convention, in that file, buffers[0] is represented by A,
  21. * buffers[1] is B ...
  22. */
  23. /*
  24. * Number of flops of Gemm
  25. */
  26. /* #define USE_PERTURBATION 1 */
  27. #ifdef USE_PERTURBATION
  28. #define PERTURBATE(a) ((starpu_drand48()*2.0f*(AMPL) + 1.0f - (AMPL))*(a))
  29. #else
  30. #define PERTURBATE(a) (a)
  31. #endif
  32. /*
  33. *
  34. * Generic models
  35. *
  36. */
  37. double task_11_cost(struct starpu_task *task, unsigned nimpl)
  38. {
  39. uint32_t n;
  40. n = starpu_matrix_get_nx(task->handles[0]);
  41. double cost = ((n*n*n)/537.5);
  42. return PERTURBATE(cost);
  43. }
  44. double task_12_cost(struct starpu_task *task, unsigned nimpl)
  45. {
  46. uint32_t n;
  47. n = starpu_matrix_get_nx(task->handles[0]);
  48. /* double cost = ((n*n*n)/1744.695); */
  49. double cost = ((n*n*n)/3210.80);
  50. /* fprintf(stderr, "task 12 predicts %e\n", cost); */
  51. return PERTURBATE(cost);
  52. }
  53. double task_21_cost(struct starpu_task *task, unsigned nimpl)
  54. {
  55. uint32_t n;
  56. n = starpu_matrix_get_nx(task->handles[0]);
  57. /* double cost = ((n*n*n)/1744.695); */
  58. double cost = ((n*n*n)/3691.53);
  59. /* fprintf(stderr, "task 12 predicts %e\n", cost); */
  60. return PERTURBATE(cost);
  61. }
  62. double task_22_cost(struct starpu_task *task, unsigned nimpl)
  63. {
  64. uint32_t nx, ny, nz;
  65. nx = starpu_matrix_get_nx(task->handles[2]);
  66. ny = starpu_matrix_get_ny(task->handles[2]);
  67. nz = starpu_matrix_get_ny(task->handles[0]);
  68. double cost = ((nx*ny*nz)/4110.0);
  69. return PERTURBATE(cost);
  70. }
  71. /*
  72. *
  73. * Models for CUDA
  74. *
  75. */
  76. double task_11_cost_cuda(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  77. {
  78. uint32_t n;
  79. n = starpu_matrix_get_nx(task->handles[0]);
  80. double cost = ((n*n*n)/1853.7806);
  81. /* printf("CUDA task 11 ; predict %e\n", cost); */
  82. return PERTURBATE(cost);
  83. }
  84. double task_12_cost_cuda(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  85. {
  86. uint32_t n;
  87. n = starpu_matrix_get_nx(task->handles[0]);
  88. double cost = ((n*n*n)/42838.5718);
  89. /* printf("CUDA task 12 ; predict %e\n", cost); */
  90. return PERTURBATE(cost);
  91. }
  92. double task_21_cost_cuda(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  93. {
  94. uint32_t n;
  95. n = starpu_matrix_get_nx(task->handles[0]);
  96. double cost = ((n*n*n)/49208.667);
  97. /* printf("CUDA task 21 ; predict %e\n", cost); */
  98. return PERTURBATE(cost);
  99. }
  100. double task_22_cost_cuda(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  101. {
  102. uint32_t nx, ny, nz;
  103. nx = starpu_matrix_get_nx(task->handles[2]);
  104. ny = starpu_matrix_get_ny(task->handles[2]);
  105. nz = starpu_matrix_get_ny(task->handles[0]);
  106. double cost = ((nx*ny*nz)/57523.560);
  107. /* printf("CUDA task 22 ; predict %e\n", cost); */
  108. return PERTURBATE(cost);
  109. }
  110. /*
  111. *
  112. * Models for CPUs
  113. *
  114. */
  115. double task_11_cost_cpu(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  116. {
  117. uint32_t n;
  118. n = starpu_matrix_get_nx(task->handles[0]);
  119. double cost = ((n*n*n)/537.5);
  120. /* printf("CPU task 11 ; predict %e\n", cost); */
  121. return PERTURBATE(cost);
  122. }
  123. double task_12_cost_cpu(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  124. {
  125. uint32_t n;
  126. n = starpu_matrix_get_nx(task->handles[0]);
  127. double cost = ((n*n*n)/6668.224);
  128. /* printf("CPU task 12 ; predict %e\n", cost); */
  129. return PERTURBATE(cost);
  130. }
  131. double task_21_cost_cpu(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  132. {
  133. uint32_t n;
  134. n = starpu_matrix_get_nx(task->handles[0]);
  135. double cost = ((n*n*n)/6793.8423);
  136. /* printf("CPU task 21 ; predict %e\n", cost); */
  137. return PERTURBATE(cost);
  138. }
  139. double task_22_cost_cpu(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  140. {
  141. uint32_t nx, ny, nz;
  142. nx = starpu_matrix_get_nx(task->handles[2]);
  143. ny = starpu_matrix_get_ny(task->handles[2]);
  144. nz = starpu_matrix_get_ny(task->handles[0]);
  145. double cost = ((nx*ny*nz)/4203.0175);
  146. /* printf("CPU task 22 ; predict %e\n", cost); */
  147. return PERTURBATE(cost);
  148. }
  149. void initialize_chol_model(struct starpu_perfmodel* model, char * symbol,
  150. double (*cost_function)(struct starpu_task *, unsigned),
  151. double (*cpu_cost_function)(struct starpu_task *, struct starpu_perfmodel_arch*, unsigned),
  152. double (*cuda_cost_function)(struct starpu_task *, struct starpu_perfmodel_arch*, unsigned))
  153. {
  154. initialize_model(model);
  155. model.type = STARPU_HISTORY_BASED;
  156. model.symbol = symbol;
  157. model.cost = cost_function;
  158. model.per_arch[STARPU_CPU_WORKER][0][0][0].cost_function = cpu_cost_function;
  159. model.per_arch[STARPU_CUDA_WORKER][0][0][0].cost_function = cuda_cost_function;
  160. }
  161. /*
  162. struct starpu_perfmodel model_11 =
  163. {
  164. .cost_function = task_11_cost,
  165. .per_arch =
  166. {
  167. [STARPU_CPU_DEFAULT][0] = { .cost_function = task_11_cost_cpu },
  168. [STARPU_CUDA_DEFAULT][0] = { .cost_function = task_11_cost_cuda }
  169. },
  170. .type = STARPU_HISTORY_BASED,
  171. #ifdef STARPU_ATLAS
  172. .symbol = "lu_model_11_atlas"
  173. #elif defined(STARPU_GOTO)
  174. .symbol = "lu_model_11_goto"
  175. #else
  176. .symbol = "lu_model_11"
  177. #endif
  178. };
  179. struct starpu_perfmodel model_12 =
  180. {
  181. .cost_function = task_12_cost,
  182. .per_arch =
  183. {
  184. [STARPU_CPU_DEFAULT][0] = { .cost_function = task_12_cost_cpu },
  185. [STARPU_CUDA_DEFAULT][0] = { .cost_function = task_12_cost_cuda }
  186. },
  187. .type = STARPU_HISTORY_BASED,
  188. #ifdef STARPU_ATLAS
  189. .symbol = "lu_model_12_atlas"
  190. #elif defined(STARPU_GOTO)
  191. .symbol = "lu_model_12_goto"
  192. #else
  193. .symbol = "lu_model_12"
  194. #endif
  195. };
  196. struct starpu_perfmodel model_21 =
  197. {
  198. .cost_function = task_21_cost,
  199. .per_arch =
  200. {
  201. [STARPU_CPU_DEFAULT][0] = { .cost_function = task_21_cost_cpu },
  202. [STARPU_CUDA_DEFAULT][0] = { .cost_function = task_21_cost_cuda }
  203. },
  204. .type = STARPU_HISTORY_BASED,
  205. #ifdef STARPU_ATLAS
  206. .symbol = "lu_model_21_atlas"
  207. #elif defined(STARPU_GOTO)
  208. .symbol = "lu_model_21_goto"
  209. #else
  210. .symbol = "lu_model_21"
  211. #endif
  212. };
  213. struct starpu_perfmodel model_22 =
  214. {
  215. .cost_function = task_22_cost,
  216. .per_arch =
  217. {
  218. [STARPU_CPU_DEFAULT][0] = { .cost_function = task_22_cost_cpu },
  219. [STARPU_CUDA_DEFAULT][0] = { .cost_function = task_22_cost_cuda }
  220. },
  221. .type = STARPU_HISTORY_BASED,
  222. #ifdef STARPU_ATLAS
  223. .symbol = "lu_model_22_atlas"
  224. #elif defined(STARPU_GOTO)
  225. .symbol = "lu_model_22_goto"
  226. #else
  227. .symbol = "lu_model_22"
  228. #endif
  229. };
  230. */