lu_kernels_model.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010-2011 Université de Bordeaux 1
  4. * Copyright (C) 2010 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, descr[0] is represented by A,
  21. * descr[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_buffer_descr *descr)
  38. {
  39. uint32_t n;
  40. n = starpu_matrix_get_nx(descr[0].handle);
  41. double cost = ((n*n*n)/537.5);
  42. return PERTURBATE(cost);
  43. }
  44. double task_12_cost(struct starpu_buffer_descr *descr)
  45. {
  46. uint32_t n;
  47. n = starpu_matrix_get_nx(descr[0].handle);
  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_buffer_descr *descr)
  54. {
  55. uint32_t n;
  56. n = starpu_matrix_get_nx(descr[0].handle);
  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_buffer_descr *descr)
  63. {
  64. uint32_t nx, ny, nz;
  65. nx = starpu_matrix_get_nx(descr[2].handle);
  66. ny = starpu_matrix_get_ny(descr[2].handle);
  67. nz = starpu_matrix_get_ny(descr[0].handle);
  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_buffer_descr *descr)
  77. {
  78. uint32_t n;
  79. n = starpu_matrix_get_nx(descr[0].handle);
  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_buffer_descr *descr)
  85. {
  86. uint32_t n;
  87. n = starpu_matrix_get_nx(descr[0].handle);
  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_buffer_descr *descr)
  93. {
  94. uint32_t n;
  95. n = starpu_matrix_get_nx(descr[0].handle);
  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_buffer_descr *descr)
  101. {
  102. uint32_t nx, ny, nz;
  103. nx = starpu_matrix_get_nx(descr[2].handle);
  104. ny = starpu_matrix_get_ny(descr[2].handle);
  105. nz = starpu_matrix_get_ny(descr[0].handle);
  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_buffer_descr *descr)
  116. {
  117. uint32_t n;
  118. n = starpu_matrix_get_nx(descr[0].handle);
  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_buffer_descr *descr)
  124. {
  125. uint32_t n;
  126. n = starpu_matrix_get_nx(descr[0].handle);
  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_buffer_descr *descr)
  132. {
  133. uint32_t n;
  134. n = starpu_matrix_get_nx(descr[0].handle);
  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_buffer_descr *descr)
  140. {
  141. uint32_t nx, ny, nz;
  142. nx = starpu_matrix_get_nx(descr[2].handle);
  143. ny = starpu_matrix_get_ny(descr[2].handle);
  144. nz = starpu_matrix_get_ny(descr[0].handle);
  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. .cost_model = task_11_cost,
  151. .per_arch = {
  152. [STARPU_CPU_DEFAULT][0] = { .cost_model = task_11_cost_cpu },
  153. [STARPU_CUDA_DEFAULT][0] = { .cost_model = task_11_cost_cuda }
  154. },
  155. .type = STARPU_HISTORY_BASED,
  156. #ifdef STARPU_ATLAS
  157. .symbol = "lu_model_11_atlas"
  158. #elif defined(STARPU_GOTO)
  159. .symbol = "lu_model_11_goto"
  160. #else
  161. .symbol = "lu_model_11"
  162. #endif
  163. };
  164. struct starpu_perfmodel model_12 = {
  165. .cost_model = task_12_cost,
  166. .per_arch = {
  167. [STARPU_CPU_DEFAULT][0] = { .cost_model = task_12_cost_cpu },
  168. [STARPU_CUDA_DEFAULT][0] = { .cost_model = task_12_cost_cuda }
  169. },
  170. .type = STARPU_HISTORY_BASED,
  171. #ifdef STARPU_ATLAS
  172. .symbol = "lu_model_12_atlas"
  173. #elif defined(STARPU_GOTO)
  174. .symbol = "lu_model_12_goto"
  175. #else
  176. .symbol = "lu_model_12"
  177. #endif
  178. };
  179. struct starpu_perfmodel model_21 = {
  180. .cost_model = task_21_cost,
  181. .per_arch = {
  182. [STARPU_CPU_DEFAULT][0] = { .cost_model = task_21_cost_cpu },
  183. [STARPU_CUDA_DEFAULT][0] = { .cost_model = task_21_cost_cuda }
  184. },
  185. .type = STARPU_HISTORY_BASED,
  186. #ifdef STARPU_ATLAS
  187. .symbol = "lu_model_21_atlas"
  188. #elif defined(STARPU_GOTO)
  189. .symbol = "lu_model_21_goto"
  190. #else
  191. .symbol = "lu_model_21"
  192. #endif
  193. };
  194. struct starpu_perfmodel model_22 = {
  195. .cost_model = task_22_cost,
  196. .per_arch = {
  197. [STARPU_CPU_DEFAULT][0] = { .cost_model = task_22_cost_cpu },
  198. [STARPU_CUDA_DEFAULT][0] = { .cost_model = task_22_cost_cuda }
  199. },
  200. .type = STARPU_HISTORY_BASED,
  201. #ifdef STARPU_ATLAS
  202. .symbol = "lu_model_22_atlas"
  203. #elif defined(STARPU_GOTO)
  204. .symbol = "lu_model_22_goto"
  205. #else
  206. .symbol = "lu_model_22"
  207. #endif
  208. };