cholesky_models.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2013 Inria
  4. * Copyright (C) 2010-2015,2017 CNRS
  5. * Copyright (C) 2009-2011,2014 Université de Bordeaux
  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. /*
  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. #include <starpu.h>
  27. #include <starpu_perfmodel.h>
  28. #include "cholesky.h"
  29. /* #define USE_PERTURBATION 1 */
  30. #ifdef USE_PERTURBATION
  31. #define PERTURBATE(a) ((starpu_drand48()*2.0f*(AMPL) + 1.0f - (AMPL))*(a))
  32. #else
  33. #define PERTURBATE(a) (a)
  34. #endif
  35. double cpu_chol_task_11_cost(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  36. {
  37. uint32_t n;
  38. n = starpu_matrix_get_nx(task->handles[0]);
  39. double cost = (((double)(n)*n*n)/1000.0f*0.894/0.79176);
  40. #ifdef STARPU_MODEL_DEBUG
  41. FPRINTF(stdout, "cpu_chol_task_11_cost n %d cost %e\n", n, cost);
  42. #endif
  43. return PERTURBATE(cost);
  44. }
  45. double cuda_chol_task_11_cost(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  46. {
  47. uint32_t n;
  48. n = starpu_matrix_get_nx(task->handles[0]);
  49. double cost = (((double)(n)*n*n)/50.0f/10.75/5.088633/0.9883);
  50. #ifdef STARPU_MODEL_DEBUG
  51. FPRINTF(stdout, "cuda_chol_task_11_cost n %d cost %e\n", n, cost);
  52. #endif
  53. return PERTURBATE(cost);
  54. }
  55. double cpu_chol_task_21_cost(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  56. {
  57. uint32_t n;
  58. n = starpu_matrix_get_nx(task->handles[0]);
  59. double cost = (((double)(n)*n*n)/7706.674/0.95/0.9965);
  60. #ifdef STARPU_MODEL_DEBUG
  61. FPRINTF(stdout, "cpu_chol_task_21_cost n %d cost %e\n", n, cost);
  62. #endif
  63. return PERTURBATE(cost);
  64. }
  65. double cuda_chol_task_21_cost(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  66. {
  67. uint32_t n;
  68. n = starpu_matrix_get_nx(task->handles[0]);
  69. double cost = (((double)(n)*n*n)/50.0f/10.75/87.29520);
  70. #ifdef STARPU_MODEL_DEBUG
  71. FPRINTF(stdout, "cuda_chol_task_21_cost n %d cost %e\n", n, cost);
  72. #endif
  73. return PERTURBATE(cost);
  74. }
  75. double cpu_chol_task_22_cost(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  76. {
  77. uint32_t n;
  78. n = starpu_matrix_get_nx(task->handles[0]);
  79. double cost = (((double)(n)*n*n)/50.0f/10.75/8.0760);
  80. #ifdef STARPU_MODEL_DEBUG
  81. FPRINTF(stdout, "cpu_chol_task_22_cost n %d cost %e\n", n, cost);
  82. #endif
  83. return PERTURBATE(cost);
  84. }
  85. double cuda_chol_task_22_cost(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl)
  86. {
  87. uint32_t n;
  88. n = starpu_matrix_get_nx(task->handles[0]);
  89. double cost = (((double)(n)*n*n)/50.0f/10.75/76.30666);
  90. #ifdef STARPU_MODEL_DEBUG
  91. FPRINTF(stdout, "cuda_chol_task_22_cost n %d cost %e\n", n, cost);
  92. #endif
  93. return PERTURBATE(cost);
  94. }
  95. void initialize_chol_model(struct starpu_perfmodel* model, char * symbol,
  96. double (*cpu_cost_function)(struct starpu_task *, struct starpu_perfmodel_arch*, unsigned),
  97. double (*cuda_cost_function)(struct starpu_task *, struct starpu_perfmodel_arch*, unsigned))
  98. {
  99. struct starpu_perfmodel_per_arch *per_arch;
  100. model->symbol = symbol;
  101. model->type = STARPU_HISTORY_BASED;
  102. starpu_perfmodel_init(model);
  103. per_arch = starpu_perfmodel_get_model_per_devices(model, 0, STARPU_CPU_WORKER, 0, 1, -1);
  104. per_arch->cost_function = cpu_cost_function;
  105. // We could also call directly:
  106. // starpu_perfmodel_set_per_devices_cost_function(model, 0, cpu_cost_function, STARPU_CPU_WORKER, 0, 1, -1);
  107. if(starpu_worker_get_count_by_type(STARPU_CUDA_WORKER) != 0)
  108. {
  109. per_arch = starpu_perfmodel_get_model_per_devices(model, 0, STARPU_CUDA_WORKER, 0, 1, -1);
  110. per_arch->cost_function = cuda_cost_function;
  111. }
  112. }