lu_kernels_model.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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, enum starpu_perf_archtype 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, enum starpu_perf_archtype 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, enum starpu_perf_archtype 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, enum starpu_perf_archtype 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, enum starpu_perf_archtype 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, enum starpu_perf_archtype 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, enum starpu_perf_archtype 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, enum starpu_perf_archtype 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. struct starpu_perfmodel model_11 =
  150. {
  151. .cost_function = task_11_cost,
  152. .per_arch =
  153. {
  154. [STARPU_CPU_DEFAULT][0] = { .cost_function = task_11_cost_cpu },
  155. [STARPU_CUDA_DEFAULT][0] = { .cost_function = task_11_cost_cuda }
  156. },
  157. .type = STARPU_HISTORY_BASED,
  158. #ifdef STARPU_ATLAS
  159. .symbol = "lu_model_11_atlas"
  160. #elif defined(STARPU_GOTO)
  161. .symbol = "lu_model_11_goto"
  162. #else
  163. .symbol = "lu_model_11"
  164. #endif
  165. };
  166. struct starpu_perfmodel model_12 =
  167. {
  168. .cost_function = task_12_cost,
  169. .per_arch =
  170. {
  171. [STARPU_CPU_DEFAULT][0] = { .cost_function = task_12_cost_cpu },
  172. [STARPU_CUDA_DEFAULT][0] = { .cost_function = task_12_cost_cuda }
  173. },
  174. .type = STARPU_HISTORY_BASED,
  175. #ifdef STARPU_ATLAS
  176. .symbol = "lu_model_12_atlas"
  177. #elif defined(STARPU_GOTO)
  178. .symbol = "lu_model_12_goto"
  179. #else
  180. .symbol = "lu_model_12"
  181. #endif
  182. };
  183. struct starpu_perfmodel model_21 =
  184. {
  185. .cost_function = task_21_cost,
  186. .per_arch =
  187. {
  188. [STARPU_CPU_DEFAULT][0] = { .cost_function = task_21_cost_cpu },
  189. [STARPU_CUDA_DEFAULT][0] = { .cost_function = task_21_cost_cuda }
  190. },
  191. .type = STARPU_HISTORY_BASED,
  192. #ifdef STARPU_ATLAS
  193. .symbol = "lu_model_21_atlas"
  194. #elif defined(STARPU_GOTO)
  195. .symbol = "lu_model_21_goto"
  196. #else
  197. .symbol = "lu_model_21"
  198. #endif
  199. };
  200. struct starpu_perfmodel model_22 =
  201. {
  202. .cost_function = task_22_cost,
  203. .per_arch =
  204. {
  205. [STARPU_CPU_DEFAULT][0] = { .cost_function = task_22_cost_cpu },
  206. [STARPU_CUDA_DEFAULT][0] = { .cost_function = task_22_cost_cuda }
  207. },
  208. .type = STARPU_HISTORY_BASED,
  209. #ifdef STARPU_ATLAS
  210. .symbol = "lu_model_22_atlas"
  211. #elif defined(STARPU_GOTO)
  212. .symbol = "lu_model_22_goto"
  213. #else
  214. .symbol = "lu_model_22"
  215. #endif
  216. };