strassen_models.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include "strassen_models.h"
  17. #include <starpu.h>
  18. /*
  19. * As a convention, in that file, descr[0] is represented by A,
  20. * descr[1] is B ...
  21. */
  22. /*
  23. * Number of flops of Gemm
  24. */
  25. //#define USE_PERTURBATION 1
  26. #ifdef USE_PERTURBATION
  27. #define PERTURBATE(a) ((starpu_drand48()*2.0f*(AMPL) + 1.0f - (AMPL))*(a))
  28. #else
  29. #define PERTURBATE(a) (a)
  30. #endif
  31. static double self_add_sub_cost(starpu_buffer_descr *descr)
  32. {
  33. uint32_t n;
  34. n = starpu_get_blas_nx(descr[0].handle);
  35. double cost = (n*n)/10.0f/4.0f/7.75f;
  36. #ifdef MODEL_DEBUG
  37. printf("self add sub cost %e n = %d\n", cost, n);
  38. #endif
  39. return PERTURBATE(cost);
  40. }
  41. static double cuda_self_add_sub_cost(starpu_buffer_descr *descr)
  42. {
  43. uint32_t n;
  44. n = starpu_get_blas_nx(descr[0].handle);
  45. double cost = (n*n)/10.0f/4.0f;
  46. #ifdef MODEL_DEBUG
  47. printf("self add sub cost %e n = %d\n", cost, n);
  48. #endif
  49. return PERTURBATE(cost);
  50. }
  51. static double add_sub_cost(starpu_buffer_descr *descr)
  52. {
  53. uint32_t n;
  54. n = starpu_get_blas_nx(descr[0].handle);
  55. double cost = (1.45f*n*n)/10.0f/2.0f;
  56. #ifdef MODEL_DEBUG
  57. printf("add sub cost %e n = %d\n", cost, n);
  58. #endif
  59. return PERTURBATE(cost);
  60. }
  61. static double cuda_add_sub_cost(starpu_buffer_descr *descr)
  62. {
  63. uint32_t n;
  64. n = starpu_get_blas_nx(descr[0].handle);
  65. double cost = (1.45f*n*n)/10.0f/2.0f;
  66. #ifdef MODEL_DEBUG
  67. printf("add sub cost %e n = %d\n", cost, n);
  68. #endif
  69. return PERTURBATE(cost);
  70. }
  71. static double mult_cost(starpu_buffer_descr *descr)
  72. {
  73. uint32_t n;
  74. n = starpu_get_blas_nx(descr[0].handle);
  75. double cost = (((double)(n)*n*n)/1000.0f/4.11f/0.2588);
  76. #ifdef MODEL_DEBUG
  77. printf("mult cost %e n = %d \n", cost, n);
  78. #endif
  79. return PERTURBATE(cost);
  80. }
  81. static double cuda_mult_cost(starpu_buffer_descr *descr)
  82. {
  83. uint32_t n;
  84. n = starpu_get_blas_nx(descr[0].handle);
  85. double cost = (((double)(n)*n*n)/1000.0f/4.11f);
  86. #ifdef MODEL_DEBUG
  87. printf("mult cost %e n = %d \n", cost, n);
  88. #endif
  89. return PERTURBATE(cost);
  90. }
  91. struct starpu_perfmodel_t strassen_model_mult = {
  92. .per_arch = {
  93. [STARPU_CPU_DEFAULT] = { .cost_model = mult_cost },
  94. [STARPU_CUDA_DEFAULT] = { .cost_model = cuda_mult_cost }
  95. },
  96. .type = STARPU_HISTORY_BASED,
  97. .symbol = "strassen_model_mult"
  98. };
  99. struct starpu_perfmodel_t strassen_model_add_sub = {
  100. .per_arch = {
  101. [STARPU_CPU_DEFAULT] = { .cost_model = add_sub_cost },
  102. [STARPU_CUDA_DEFAULT] = { .cost_model = cuda_add_sub_cost }
  103. },
  104. .type = STARPU_HISTORY_BASED,
  105. .symbol = "strassen_model_add_sub"
  106. };
  107. struct starpu_perfmodel_t strassen_model_self_add_sub = {
  108. .per_arch = {
  109. [STARPU_CPU_DEFAULT] = { .cost_model = self_add_sub_cost },
  110. [STARPU_CUDA_DEFAULT] = { .cost_model = cuda_self_add_sub_cost }
  111. },
  112. .type = STARPU_HISTORY_BASED,
  113. .symbol = "strassen_model_self_add_sub"
  114. };