cholesky_models.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011,2014 Inria
  4. * Copyright (C) 2008-2011,2014,2015 Université de Bordeaux
  5. * Copyright (C) 2010-2015,2017 CNRS
  6. * Copyright (C) 2013 Thibaut Lambert
  7. * Copyright (C) 2011 Télécom-SudParis
  8. *
  9. * StarPU is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU Lesser General Public License as published by
  11. * the Free Software Foundation; either version 2.1 of the License, or (at
  12. * your option) any later version.
  13. *
  14. * StarPU is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. *
  18. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  19. */
  20. /*
  21. * Example of a cost model for BLAS operations. This is really just an
  22. * example!
  23. */
  24. /*
  25. * As a convention, in that file, buffers[0] is represented by A,
  26. * buffers[1] is B ...
  27. */
  28. /*
  29. * Number of flops of Gemm
  30. */
  31. #include <starpu.h>
  32. #include <starpu_perfmodel.h>
  33. #include "cholesky.h"
  34. /* #define USE_PERTURBATION 1 */
  35. #ifdef USE_PERTURBATION
  36. #define PERTURBATE(a) ((starpu_drand48()*2.0f*(AMPL) + 1.0f - (AMPL))*(a))
  37. #else
  38. #define PERTURBATE(a) (a)
  39. #endif
  40. double cpu_chol_task_11_cost(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  41. {
  42. (void)arch;
  43. (void)nimpl;
  44. uint32_t n;
  45. n = starpu_matrix_get_nx(task->handles[0]);
  46. double cost = (((double)(n)*n*n)/1000.0f*0.894/0.79176);
  47. #ifdef STARPU_MODEL_DEBUG
  48. FPRINTF(stdout, "cpu_chol_task_11_cost n %u cost %e\n", n, cost);
  49. #endif
  50. return PERTURBATE(cost);
  51. }
  52. double cuda_chol_task_11_cost(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  53. {
  54. (void)arch;
  55. (void)nimpl;
  56. uint32_t n;
  57. n = starpu_matrix_get_nx(task->handles[0]);
  58. double cost = (((double)(n)*n*n)/50.0f/10.75/5.088633/0.9883);
  59. #ifdef STARPU_MODEL_DEBUG
  60. FPRINTF(stdout, "cuda_chol_task_11_cost n %u cost %e\n", n, cost);
  61. #endif
  62. return PERTURBATE(cost);
  63. }
  64. double cpu_chol_task_21_cost(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  65. {
  66. (void)arch;
  67. (void)nimpl;
  68. uint32_t n;
  69. n = starpu_matrix_get_nx(task->handles[0]);
  70. double cost = (((double)(n)*n*n)/7706.674/0.95/0.9965);
  71. #ifdef STARPU_MODEL_DEBUG
  72. FPRINTF(stdout, "cpu_chol_task_21_cost n %u cost %e\n", n, cost);
  73. #endif
  74. return PERTURBATE(cost);
  75. }
  76. double cuda_chol_task_21_cost(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  77. {
  78. (void)arch;
  79. (void)nimpl;
  80. uint32_t n;
  81. n = starpu_matrix_get_nx(task->handles[0]);
  82. double cost = (((double)(n)*n*n)/50.0f/10.75/87.29520);
  83. #ifdef STARPU_MODEL_DEBUG
  84. FPRINTF(stdout, "cuda_chol_task_21_cost n %u cost %e\n", n, cost);
  85. #endif
  86. return PERTURBATE(cost);
  87. }
  88. double cpu_chol_task_22_cost(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  89. {
  90. (void)arch;
  91. (void)nimpl;
  92. uint32_t n;
  93. n = starpu_matrix_get_nx(task->handles[0]);
  94. double cost = (((double)(n)*n*n)/50.0f/10.75/8.0760);
  95. #ifdef STARPU_MODEL_DEBUG
  96. FPRINTF(stdout, "cpu_chol_task_22_cost n %u cost %e\n", n, cost);
  97. #endif
  98. return PERTURBATE(cost);
  99. }
  100. double cuda_chol_task_22_cost(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  101. {
  102. (void)arch;
  103. (void)nimpl;
  104. uint32_t n;
  105. n = starpu_matrix_get_nx(task->handles[0]);
  106. double cost = (((double)(n)*n*n)/50.0f/10.75/76.30666);
  107. #ifdef STARPU_MODEL_DEBUG
  108. FPRINTF(stdout, "cuda_chol_task_22_cost n %u cost %e\n", n, cost);
  109. #endif
  110. return PERTURBATE(cost);
  111. }
  112. void initialize_chol_model(struct starpu_perfmodel* model, char * symbol,
  113. double (*cpu_cost_function)(struct starpu_task *, struct starpu_perfmodel_arch*, unsigned),
  114. double (*cuda_cost_function)(struct starpu_task *, struct starpu_perfmodel_arch*, unsigned))
  115. {
  116. struct starpu_perfmodel_per_arch *per_arch;
  117. model->symbol = symbol;
  118. model->type = STARPU_HISTORY_BASED;
  119. starpu_perfmodel_init(model);
  120. per_arch = starpu_perfmodel_get_model_per_devices(model, 0, STARPU_CPU_WORKER, 0, 1, -1);
  121. per_arch->cost_function = cpu_cost_function;
  122. // We could also call directly:
  123. // starpu_perfmodel_set_per_devices_cost_function(model, 0, cpu_cost_function, STARPU_CPU_WORKER, 0, 1, -1);
  124. if(starpu_worker_get_count_by_type(STARPU_CUDA_WORKER) != 0)
  125. {
  126. per_arch = starpu_perfmodel_get_model_per_devices(model, 0, STARPU_CUDA_WORKER, 0, 1, -1);
  127. per_arch->cost_function = cuda_cost_function;
  128. }
  129. }