lu_kernels_model.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include "lu_kernels_model.h"
  18. /*
  19. * As a convention, in that file, descr[0] is represented by A,
  20. * descr[1] is B ...
  21. */
  22. /*
  23. * Number of flops of Gemm
  24. */
  25. /* #define USE_PERTURBATION 1 */
  26. #ifdef USE_PERTURBATION
  27. #define PERTURBATE(a) ((starpu_drand48()*2.0f*(AMPL) + 1.0f - (AMPL))*(a))
  28. #else
  29. #define PERTURBATE(a) (a)
  30. #endif
  31. /*
  32. *
  33. * Generic models
  34. *
  35. */
  36. double task_11_cost(starpu_buffer_descr *descr)
  37. {
  38. uint32_t n;
  39. n = starpu_matrix_get_nx(descr[0].handle);
  40. double cost = ((n*n*n)/537.5);
  41. return PERTURBATE(cost);
  42. }
  43. double task_12_cost(starpu_buffer_descr *descr)
  44. {
  45. uint32_t n;
  46. n = starpu_matrix_get_nx(descr[0].handle);
  47. /* double cost = ((n*n*n)/1744.695); */
  48. double cost = ((n*n*n)/3210.80);
  49. /* fprintf(stderr, "task 12 predicts %e\n", cost); */
  50. return PERTURBATE(cost);
  51. }
  52. double task_21_cost(starpu_buffer_descr *descr)
  53. {
  54. uint32_t n;
  55. n = starpu_matrix_get_nx(descr[0].handle);
  56. /* double cost = ((n*n*n)/1744.695); */
  57. double cost = ((n*n*n)/3691.53);
  58. /* fprintf(stderr, "task 12 predicts %e\n", cost); */
  59. return PERTURBATE(cost);
  60. }
  61. double task_22_cost(starpu_buffer_descr *descr)
  62. {
  63. uint32_t nx, ny, nz;
  64. nx = starpu_matrix_get_nx(descr[2].handle);
  65. ny = starpu_matrix_get_ny(descr[2].handle);
  66. nz = starpu_matrix_get_ny(descr[0].handle);
  67. double cost = ((nx*ny*nz)/4110.0);
  68. return PERTURBATE(cost);
  69. }
  70. /*
  71. *
  72. * Models for CUDA
  73. *
  74. */
  75. double task_11_cost_cuda(starpu_buffer_descr *descr)
  76. {
  77. uint32_t n;
  78. n = starpu_matrix_get_nx(descr[0].handle);
  79. double cost = ((n*n*n)/1853.7806);
  80. /* printf("CUDA task 11 ; predict %e\n", cost); */
  81. return PERTURBATE(cost);
  82. }
  83. double task_12_cost_cuda(starpu_buffer_descr *descr)
  84. {
  85. uint32_t n;
  86. n = starpu_matrix_get_nx(descr[0].handle);
  87. double cost = ((n*n*n)/42838.5718);
  88. /* printf("CUDA task 12 ; predict %e\n", cost); */
  89. return PERTURBATE(cost);
  90. }
  91. double task_21_cost_cuda(starpu_buffer_descr *descr)
  92. {
  93. uint32_t n;
  94. n = starpu_matrix_get_nx(descr[0].handle);
  95. double cost = ((n*n*n)/49208.667);
  96. /* printf("CUDA task 21 ; predict %e\n", cost); */
  97. return PERTURBATE(cost);
  98. }
  99. double task_22_cost_cuda(starpu_buffer_descr *descr)
  100. {
  101. uint32_t nx, ny, nz;
  102. nx = starpu_matrix_get_nx(descr[2].handle);
  103. ny = starpu_matrix_get_ny(descr[2].handle);
  104. nz = starpu_matrix_get_ny(descr[0].handle);
  105. double cost = ((nx*ny*nz)/57523.560);
  106. /* printf("CUDA task 22 ; predict %e\n", cost); */
  107. return PERTURBATE(cost);
  108. }
  109. /*
  110. *
  111. * Models for CPUs
  112. *
  113. */
  114. double task_11_cost_cpu(starpu_buffer_descr *descr)
  115. {
  116. uint32_t n;
  117. n = starpu_matrix_get_nx(descr[0].handle);
  118. double cost = ((n*n*n)/537.5);
  119. /* printf("CPU task 11 ; predict %e\n", cost); */
  120. return PERTURBATE(cost);
  121. }
  122. double task_12_cost_cpu(starpu_buffer_descr *descr)
  123. {
  124. uint32_t n;
  125. n = starpu_matrix_get_nx(descr[0].handle);
  126. double cost = ((n*n*n)/6668.224);
  127. /* printf("CPU task 12 ; predict %e\n", cost); */
  128. return PERTURBATE(cost);
  129. }
  130. double task_21_cost_cpu(starpu_buffer_descr *descr)
  131. {
  132. uint32_t n;
  133. n = starpu_matrix_get_nx(descr[0].handle);
  134. double cost = ((n*n*n)/6793.8423);
  135. /* printf("CPU task 21 ; predict %e\n", cost); */
  136. return PERTURBATE(cost);
  137. }
  138. double task_22_cost_cpu(starpu_buffer_descr *descr)
  139. {
  140. uint32_t nx, ny, nz;
  141. nx = starpu_matrix_get_nx(descr[2].handle);
  142. ny = starpu_matrix_get_ny(descr[2].handle);
  143. nz = starpu_matrix_get_ny(descr[0].handle);
  144. double cost = ((nx*ny*nz)/4203.0175);
  145. /* printf("CPU task 22 ; predict %e\n", cost); */
  146. return PERTURBATE(cost);
  147. }
  148. struct starpu_perfmodel_t model_11 = {
  149. .cost_model = task_11_cost,
  150. .per_arch = {
  151. [STARPU_CPU_DEFAULT] = { .cost_model = task_11_cost_cpu },
  152. [STARPU_CUDA_DEFAULT] = { .cost_model = task_11_cost_cuda }
  153. },
  154. .type = STARPU_HISTORY_BASED,
  155. #ifdef STARPU_ATLAS
  156. .symbol = "lu_model_11_atlas"
  157. #elif defined(STARPU_GOTO)
  158. .symbol = "lu_model_11_goto"
  159. #else
  160. .symbol = "lu_model_11"
  161. #endif
  162. };
  163. struct starpu_perfmodel_t model_12 = {
  164. .cost_model = task_12_cost,
  165. .per_arch = {
  166. [STARPU_CPU_DEFAULT] = { .cost_model = task_12_cost_cpu },
  167. [STARPU_CUDA_DEFAULT] = { .cost_model = task_12_cost_cuda }
  168. },
  169. .type = STARPU_HISTORY_BASED,
  170. #ifdef STARPU_ATLAS
  171. .symbol = "lu_model_12_atlas"
  172. #elif defined(STARPU_GOTO)
  173. .symbol = "lu_model_12_goto"
  174. #else
  175. .symbol = "lu_model_12"
  176. #endif
  177. };
  178. struct starpu_perfmodel_t model_21 = {
  179. .cost_model = task_21_cost,
  180. .per_arch = {
  181. [STARPU_CPU_DEFAULT] = { .cost_model = task_21_cost_cpu },
  182. [STARPU_CUDA_DEFAULT] = { .cost_model = task_21_cost_cuda }
  183. },
  184. .type = STARPU_HISTORY_BASED,
  185. #ifdef STARPU_ATLAS
  186. .symbol = "lu_model_21_atlas"
  187. #elif defined(STARPU_GOTO)
  188. .symbol = "lu_model_21_goto"
  189. #else
  190. .symbol = "lu_model_21"
  191. #endif
  192. };
  193. struct starpu_perfmodel_t model_22 = {
  194. .cost_model = task_22_cost,
  195. .per_arch = {
  196. [STARPU_CPU_DEFAULT] = { .cost_model = task_22_cost_cpu },
  197. [STARPU_CUDA_DEFAULT] = { .cost_model = task_22_cost_cuda }
  198. },
  199. .type = STARPU_HISTORY_BASED,
  200. #ifdef STARPU_ATLAS
  201. .symbol = "lu_model_22_atlas"
  202. #elif defined(STARPU_GOTO)
  203. .symbol = "lu_model_22_goto"
  204. #else
  205. .symbol = "lu_model_22"
  206. #endif
  207. };