lu_kernels_model.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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, 2013 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_lu_kernels_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. model->symbol = symbol;
  155. model->type = STARPU_HISTORY_BASED;
  156. starpu_perfmodel_init(NULL, model);
  157. struct starpu_perfmodel_arch arch_cpu;
  158. arch_cpu.ndevices = 1;
  159. arch_cpu.devices = (struct starpu_perfmodel_device*)malloc(sizeof(struct starpu_perfmodel_device));
  160. arch_cpu.devices[0].type = STARPU_CPU_WORKER;
  161. arch_cpu.devices[0].devid = 0;
  162. arch_cpu.devices[0].ncores = 1;
  163. int comb_cpu = starpu_get_arch_comb(arch_cpu.ndevices, arch_cpu.devices);
  164. if(comb_cpu == -1)
  165. comb_cpu = starpu_add_arch_comb(arch_cpu.ndevices, arch_cpu.devices);
  166. model->per_arch[comb_cpu] = (struct starpu_perfmodel_per_arch*)malloc(sizeof(struct starpu_perfmodel_per_arch));
  167. memset(&model->per_arch[comb_cpu][0], 0, sizeof(struct starpu_perfmodel_per_arch));
  168. // model->nimpls[comb_cpu] = 1;
  169. model->per_arch[comb_cpu][0].cost_function = cpu_cost_function;
  170. if(starpu_worker_get_count_by_type(STARPU_CUDA_WORKER) != 0)
  171. {
  172. struct starpu_perfmodel_arch arch_cuda;
  173. arch_cuda.ndevices = 1;
  174. arch_cuda.devices = (struct starpu_perfmodel_device*)malloc(sizeof(struct starpu_perfmodel_device));
  175. arch_cuda.devices[0].type = STARPU_CUDA_WORKER;
  176. arch_cuda.devices[0].devid = 0;
  177. arch_cuda.devices[0].ncores = 1;
  178. int comb_cuda = starpu_get_arch_comb(arch_cuda.ndevices, arch_cuda.devices);
  179. if(comb_cuda == -1)
  180. comb_cuda = starpu_add_arch_comb(arch_cuda.ndevices, arch_cuda.devices);
  181. model->per_arch[comb_cuda] = (struct starpu_perfmodel_per_arch*)malloc(sizeof(struct starpu_perfmodel_per_arch));
  182. memset(&model->per_arch[comb_cuda][0], 0, sizeof(struct starpu_perfmodel_per_arch));
  183. // model->nimpls[comb_cuda] = 1;
  184. model->per_arch[comb_cuda][0].cost_function = cuda_cost_function;
  185. }
  186. /* model->cost_function = cost_function; */
  187. /* model->per_arch[STARPU_CPU_WORKER][0][0][0].cost_function = cpu_cost_function; */
  188. /* if(starpu_worker_get_count_by_type(STARPU_CUDA_WORKER) != 0) */
  189. /* model->per_arch[STARPU_CUDA_WORKER][0][0][0].cost_function = cuda_cost_function; */
  190. }