lu_kernels_model.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 Inria
  4. * Copyright (C) 2008-2011,2014 Université de Bordeaux
  5. * Copyright (C) 2010-2015,2017 CNRS
  6. * Copyright (C) 2011 Télécom-SudParis
  7. *
  8. * StarPU is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation; either version 2.1 of the License, or (at
  11. * your option) any later version.
  12. *
  13. * StarPU is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  17. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  18. */
  19. #include "lu_kernels_model.h"
  20. /*
  21. * As a convention, in that file, buffers[0] is represented by A,
  22. * buffers[1] is B ...
  23. */
  24. /*
  25. * Number of flops of Gemm
  26. */
  27. /* #define USE_PERTURBATION 1 */
  28. #ifdef USE_PERTURBATION
  29. #define PERTURBATE(a) ((starpu_drand48()*2.0f*(AMPL) + 1.0f - (AMPL))*(a))
  30. #else
  31. #define PERTURBATE(a) (a)
  32. #endif
  33. /*
  34. *
  35. * Generic models
  36. *
  37. */
  38. double task_11_cost(struct starpu_task *task, unsigned nimpl)
  39. {
  40. (void)nimpl;
  41. uint32_t n;
  42. n = starpu_matrix_get_nx(task->handles[0]);
  43. double cost = ((n*n*n)/537.5);
  44. return PERTURBATE(cost);
  45. }
  46. double task_12_cost(struct starpu_task *task, unsigned nimpl)
  47. {
  48. (void)nimpl;
  49. uint32_t n;
  50. n = starpu_matrix_get_nx(task->handles[0]);
  51. /* double cost = ((n*n*n)/1744.695); */
  52. double cost = ((n*n*n)/3210.80);
  53. /* fprintf(stderr, "task 12 predicts %e\n", cost); */
  54. return PERTURBATE(cost);
  55. }
  56. double task_21_cost(struct starpu_task *task, unsigned nimpl)
  57. {
  58. (void)nimpl;
  59. uint32_t n;
  60. n = starpu_matrix_get_nx(task->handles[0]);
  61. /* double cost = ((n*n*n)/1744.695); */
  62. double cost = ((n*n*n)/3691.53);
  63. /* fprintf(stderr, "task 12 predicts %e\n", cost); */
  64. return PERTURBATE(cost);
  65. }
  66. double task_22_cost(struct starpu_task *task, unsigned nimpl)
  67. {
  68. (void)nimpl;
  69. uint32_t nx, ny, nz;
  70. nx = starpu_matrix_get_nx(task->handles[2]);
  71. ny = starpu_matrix_get_ny(task->handles[2]);
  72. nz = starpu_matrix_get_ny(task->handles[0]);
  73. double cost = ((nx*ny*nz)/4110.0);
  74. return PERTURBATE(cost);
  75. }
  76. /*
  77. *
  78. * Models for CUDA
  79. *
  80. */
  81. double task_11_cost_cuda(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  82. {
  83. (void)arch;
  84. (void)nimpl;
  85. uint32_t n;
  86. n = starpu_matrix_get_nx(task->handles[0]);
  87. double cost = ((n*n*n)/1853.7806);
  88. /* printf("CUDA task 11 ; predict %e\n", cost); */
  89. return PERTURBATE(cost);
  90. }
  91. double task_12_cost_cuda(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  92. {
  93. (void)arch;
  94. (void)nimpl;
  95. uint32_t n;
  96. n = starpu_matrix_get_nx(task->handles[0]);
  97. double cost = ((n*n*n)/42838.5718);
  98. /* printf("CUDA task 12 ; predict %e\n", cost); */
  99. return PERTURBATE(cost);
  100. }
  101. double task_21_cost_cuda(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  102. {
  103. (void)arch;
  104. (void)nimpl;
  105. uint32_t n;
  106. n = starpu_matrix_get_nx(task->handles[0]);
  107. double cost = ((n*n*n)/49208.667);
  108. /* printf("CUDA task 21 ; predict %e\n", cost); */
  109. return PERTURBATE(cost);
  110. }
  111. double task_22_cost_cuda(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  112. {
  113. (void)arch;
  114. (void)nimpl;
  115. uint32_t nx, ny, nz;
  116. nx = starpu_matrix_get_nx(task->handles[2]);
  117. ny = starpu_matrix_get_ny(task->handles[2]);
  118. nz = starpu_matrix_get_ny(task->handles[0]);
  119. double cost = ((nx*ny*nz)/57523.560);
  120. /* printf("CUDA task 22 ; predict %e\n", cost); */
  121. return PERTURBATE(cost);
  122. }
  123. /*
  124. *
  125. * Models for CPUs
  126. *
  127. */
  128. double task_11_cost_cpu(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  129. {
  130. (void)arch;
  131. (void)nimpl;
  132. uint32_t n;
  133. n = starpu_matrix_get_nx(task->handles[0]);
  134. double cost = ((n*n*n)/537.5);
  135. /* printf("CPU task 11 ; predict %e\n", cost); */
  136. return PERTURBATE(cost);
  137. }
  138. double task_12_cost_cpu(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  139. {
  140. (void)arch;
  141. (void)nimpl;
  142. uint32_t n;
  143. n = starpu_matrix_get_nx(task->handles[0]);
  144. double cost = ((n*n*n)/6668.224);
  145. /* printf("CPU task 12 ; predict %e\n", cost); */
  146. return PERTURBATE(cost);
  147. }
  148. double task_21_cost_cpu(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  149. {
  150. (void)arch;
  151. (void)nimpl;
  152. uint32_t n;
  153. n = starpu_matrix_get_nx(task->handles[0]);
  154. double cost = ((n*n*n)/6793.8423);
  155. /* printf("CPU task 21 ; predict %e\n", cost); */
  156. return PERTURBATE(cost);
  157. }
  158. double task_22_cost_cpu(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  159. {
  160. (void)arch;
  161. (void)nimpl;
  162. uint32_t nx, ny, nz;
  163. nx = starpu_matrix_get_nx(task->handles[2]);
  164. ny = starpu_matrix_get_ny(task->handles[2]);
  165. nz = starpu_matrix_get_ny(task->handles[0]);
  166. double cost = ((nx*ny*nz)/4203.0175);
  167. /* printf("CPU task 22 ; predict %e\n", cost); */
  168. return PERTURBATE(cost);
  169. }
  170. void initialize_lu_kernels_model(struct starpu_perfmodel* model, char * symbol,
  171. double (*cost_function)(struct starpu_task *, unsigned),
  172. double (*cpu_cost_function)(struct starpu_task *, struct starpu_perfmodel_arch*, unsigned),
  173. double (*cuda_cost_function)(struct starpu_task *, struct starpu_perfmodel_arch*, unsigned))
  174. {
  175. (void)cost_function;
  176. model->symbol = symbol;
  177. model->type = STARPU_HISTORY_BASED;
  178. starpu_perfmodel_init(model);
  179. starpu_perfmodel_set_per_devices_cost_function(model, 0, cpu_cost_function, STARPU_CPU_WORKER, 0, 1, -1);
  180. if(starpu_worker_get_count_by_type(STARPU_CUDA_WORKER) != 0)
  181. {
  182. starpu_perfmodel_set_per_devices_cost_function(model, 0, cuda_cost_function, STARPU_CUDA_WORKER, 0, 1, -1);
  183. }
  184. }