cholesky_models.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2008-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. * Copyright (C) 2011 Télécom-SudParis
  5. * Copyright (C) 2013 Thibaut Lambert
  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. /*
  19. * Example of a cost model for BLAS operations. This is really just an
  20. * example!
  21. */
  22. /*
  23. * As a convention, in that file, buffers[0] is represented by A,
  24. * buffers[1] is B ...
  25. */
  26. /*
  27. * Number of flops of Gemm
  28. */
  29. #include <starpu.h>
  30. #include <starpu_perfmodel.h>
  31. #include "cholesky.h"
  32. /* #define USE_PERTURBATION 1 */
  33. #ifdef USE_PERTURBATION
  34. #define PERTURBATE(a) ((starpu_drand48()*2.0f*(AMPL) + 1.0f - (AMPL))*(a))
  35. #else
  36. #define PERTURBATE(a) (a)
  37. #endif
  38. double cpu_chol_task_11_cost(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  39. {
  40. (void)arch;
  41. (void)nimpl;
  42. uint32_t n;
  43. n = starpu_matrix_get_nx(task->handles[0]);
  44. double cost = (((double)(n)*n*n)/1000.0f*0.894/0.79176);
  45. #ifdef STARPU_MODEL_DEBUG
  46. FPRINTF(stdout, "cpu_chol_task_11_cost n %u cost %e\n", n, cost);
  47. #endif
  48. return PERTURBATE(cost);
  49. }
  50. double cuda_chol_task_11_cost(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  51. {
  52. (void)arch;
  53. (void)nimpl;
  54. uint32_t n;
  55. n = starpu_matrix_get_nx(task->handles[0]);
  56. double cost = (((double)(n)*n*n)/50.0f/10.75/5.088633/0.9883);
  57. #ifdef STARPU_MODEL_DEBUG
  58. FPRINTF(stdout, "cuda_chol_task_11_cost n %u cost %e\n", n, cost);
  59. #endif
  60. return PERTURBATE(cost);
  61. }
  62. double cpu_chol_task_21_cost(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  63. {
  64. (void)arch;
  65. (void)nimpl;
  66. uint32_t n;
  67. n = starpu_matrix_get_nx(task->handles[0]);
  68. double cost = (((double)(n)*n*n)/7706.674/0.95/0.9965);
  69. #ifdef STARPU_MODEL_DEBUG
  70. FPRINTF(stdout, "cpu_chol_task_21_cost n %u cost %e\n", n, cost);
  71. #endif
  72. return PERTURBATE(cost);
  73. }
  74. double cuda_chol_task_21_cost(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  75. {
  76. (void)arch;
  77. (void)nimpl;
  78. uint32_t n;
  79. n = starpu_matrix_get_nx(task->handles[0]);
  80. double cost = (((double)(n)*n*n)/50.0f/10.75/87.29520);
  81. #ifdef STARPU_MODEL_DEBUG
  82. FPRINTF(stdout, "cuda_chol_task_21_cost n %u cost %e\n", n, cost);
  83. #endif
  84. return PERTURBATE(cost);
  85. }
  86. double cpu_chol_task_22_cost(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  87. {
  88. (void)arch;
  89. (void)nimpl;
  90. uint32_t n;
  91. n = starpu_matrix_get_nx(task->handles[0]);
  92. double cost = (((double)(n)*n*n)/50.0f/10.75/8.0760);
  93. #ifdef STARPU_MODEL_DEBUG
  94. FPRINTF(stdout, "cpu_chol_task_22_cost n %u cost %e\n", n, cost);
  95. #endif
  96. return PERTURBATE(cost);
  97. }
  98. double cuda_chol_task_22_cost(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  99. {
  100. (void)arch;
  101. (void)nimpl;
  102. uint32_t n;
  103. n = starpu_matrix_get_nx(task->handles[0]);
  104. double cost = (((double)(n)*n*n)/50.0f/10.75/76.30666);
  105. #ifdef STARPU_MODEL_DEBUG
  106. FPRINTF(stdout, "cuda_chol_task_22_cost n %u cost %e\n", n, cost);
  107. #endif
  108. return PERTURBATE(cost);
  109. }
  110. void initialize_chol_model(struct starpu_perfmodel* model, char * symbol,
  111. double (*cpu_cost_function)(struct starpu_task *, struct starpu_perfmodel_arch*, unsigned),
  112. double (*cuda_cost_function)(struct starpu_task *, struct starpu_perfmodel_arch*, unsigned))
  113. {
  114. struct starpu_perfmodel_per_arch *per_arch;
  115. model->symbol = symbol;
  116. model->type = STARPU_HISTORY_BASED;
  117. starpu_perfmodel_init(model);
  118. per_arch = starpu_perfmodel_get_model_per_devices(model, 0, STARPU_CPU_WORKER, 0, 1, -1);
  119. per_arch->cost_function = cpu_cost_function;
  120. // We could also call directly:
  121. // starpu_perfmodel_set_per_devices_cost_function(model, 0, cpu_cost_function, STARPU_CPU_WORKER, 0, 1, -1);
  122. if(starpu_worker_get_count_by_type(STARPU_CUDA_WORKER) != 0)
  123. {
  124. per_arch = starpu_perfmodel_get_model_per_devices(model, 0, STARPU_CUDA_WORKER, 0, 1, -1);
  125. per_arch->cost_function = cuda_cost_function;
  126. }
  127. }