dw_factolu_kernels.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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 "dw_factolu.h"
  17. unsigned count_11_core = 0;
  18. unsigned count_12_core = 0;
  19. unsigned count_21_core = 0;
  20. unsigned count_22_core = 0;
  21. unsigned count_11_cublas = 0;
  22. unsigned count_12_cublas = 0;
  23. unsigned count_21_cublas = 0;
  24. unsigned count_22_cublas = 0;
  25. void display_stat_heat(void)
  26. {
  27. fprintf(stderr, "STATS : \n");
  28. fprintf(stderr, "11 : core %d (%2.2f) cublas %d (%2.2f)\n", count_11_core, (100.0*count_11_core)/(count_11_core+count_11_cublas), count_11_cublas, (100.0*count_11_cublas)/(count_11_core+count_11_cublas));
  29. fprintf(stderr, "12 : core %d (%2.2f) cublas %d (%2.2f)\n", count_12_core, (100.0*count_12_core)/(count_12_core+count_12_cublas), count_12_cublas, (100.0*count_12_cublas)/(count_12_core+count_12_cublas));
  30. fprintf(stderr, "21 : core %d (%2.2f) cublas %d (%2.2f)\n", count_21_core, (100.0*count_21_core)/(count_21_core+count_21_cublas), count_21_cublas, (100.0*count_21_cublas)/(count_21_core+count_21_cublas));
  31. fprintf(stderr, "22 : core %d (%2.2f) cublas %d (%2.2f)\n", count_22_core, (100.0*count_22_core)/(count_22_core+count_22_cublas), count_22_cublas, (100.0*count_22_cublas)/(count_22_core+count_22_cublas));
  32. }
  33. /*
  34. * U22
  35. */
  36. static inline void dw_common_core_codelet_update_u22(starpu_data_interface_t *buffers, int s, __attribute__((unused)) void *_args)
  37. {
  38. float *left = (float *)buffers[0].blas.ptr;
  39. float *right = (float *)buffers[1].blas.ptr;
  40. float *center = (float *)buffers[2].blas.ptr;
  41. unsigned dx = buffers[2].blas.nx;
  42. unsigned dy = buffers[2].blas.ny;
  43. unsigned dz = buffers[0].blas.ny;
  44. unsigned ld12 = buffers[0].blas.ld;
  45. unsigned ld21 = buffers[1].blas.ld;
  46. unsigned ld22 = buffers[2].blas.ld;
  47. #ifdef USE_CUDA
  48. cublasStatus status;
  49. #endif
  50. switch (s) {
  51. case 0:
  52. SGEMM("N", "N", dy, dx, dz,
  53. -1.0f, left, ld21, right, ld12,
  54. 1.0f, center, ld22);
  55. break;
  56. #ifdef USE_CUDA
  57. case 1:
  58. cublasSgemm('n', 'n', dx, dy, dz, -1.0f, left, ld21,
  59. right, ld12, 1.0f, center, ld22);
  60. status = cublasGetError();
  61. if (status != CUBLAS_STATUS_SUCCESS)
  62. STARPU_ASSERT(0);
  63. break;
  64. #endif
  65. default:
  66. STARPU_ASSERT(0);
  67. break;
  68. }
  69. }
  70. void dw_core_codelet_update_u22(starpu_data_interface_t *descr, void *_args)
  71. {
  72. dw_common_core_codelet_update_u22(descr, 0, _args);
  73. (void)STARPU_ATOMIC_ADD(&count_22_core, 1);
  74. }
  75. #ifdef USE_CUDA
  76. void dw_cublas_codelet_update_u22(starpu_data_interface_t *descr, void *_args)
  77. {
  78. dw_common_core_codelet_update_u22(descr, 1, _args);
  79. (void)STARPU_ATOMIC_ADD(&count_22_cublas, 1);
  80. }
  81. #endif// USE_CUDA
  82. /*
  83. * U12
  84. */
  85. static inline void dw_common_codelet_update_u12(starpu_data_interface_t *buffers, int s, __attribute__((unused)) void *_args) {
  86. float *sub11;
  87. float *sub12;
  88. sub11 = (float *)buffers[0].blas.ptr;
  89. sub12 = (float *)buffers[1].blas.ptr;
  90. unsigned ld11 = buffers[0].blas.ld;
  91. unsigned ld12 = buffers[1].blas.ld;
  92. unsigned nx12 = buffers[1].blas.nx;
  93. unsigned ny12 = buffers[1].blas.ny;
  94. #ifdef USE_CUDA
  95. cublasStatus status;
  96. #endif
  97. /* solve L11 U12 = A12 (find U12) */
  98. switch (s) {
  99. case 0:
  100. STRSM("L", "L", "N", "N",
  101. nx12, ny12, 1.0f, sub11, ld11, sub12, ld12);
  102. break;
  103. #ifdef USE_CUDA
  104. case 1:
  105. cublasStrsm('L', 'L', 'N', 'N', ny12, nx12,
  106. 1.0f, sub11, ld11, sub12, ld12);
  107. status = cublasGetError();
  108. if (status != CUBLAS_STATUS_SUCCESS)
  109. STARPU_ASSERT(0);
  110. break;
  111. #endif
  112. default:
  113. STARPU_ASSERT(0);
  114. break;
  115. }
  116. }
  117. void dw_core_codelet_update_u12(starpu_data_interface_t *descr, void *_args)
  118. {
  119. dw_common_codelet_update_u12(descr, 0, _args);
  120. (void)STARPU_ATOMIC_ADD(&count_12_core, 1);
  121. }
  122. #ifdef USE_CUDA
  123. void dw_cublas_codelet_update_u12(starpu_data_interface_t *descr, void *_args)
  124. {
  125. dw_common_codelet_update_u12(descr, 1, _args);
  126. (void)STARPU_ATOMIC_ADD(&count_12_cublas, 1);
  127. }
  128. #endif // USE_CUDA
  129. /*
  130. * U21
  131. */
  132. static inline void dw_common_codelet_update_u21(starpu_data_interface_t *buffers, int s, __attribute__((unused)) void *_args) {
  133. float *sub11;
  134. float *sub21;
  135. sub11 = (float *)buffers[0].blas.ptr;
  136. sub21 = (float *)buffers[1].blas.ptr;
  137. unsigned ld11 = buffers[0].blas.ld;
  138. unsigned ld21 = buffers[1].blas.ld;
  139. unsigned nx21 = buffers[1].blas.nx;
  140. unsigned ny21 = buffers[1].blas.ny;
  141. #ifdef USE_CUDA
  142. cublasStatus status;
  143. #endif
  144. switch (s) {
  145. case 0:
  146. STRSM("R", "U", "N", "U", nx21, ny21, 1.0f, sub11, ld11, sub21, ld21);
  147. break;
  148. #ifdef USE_CUDA
  149. case 1:
  150. cublasStrsm('R', 'U', 'N', 'U', ny21, nx21, 1.0f, sub11, ld11, sub21, ld21);
  151. status = cublasGetError();
  152. if (status != CUBLAS_STATUS_SUCCESS)
  153. STARPU_ASSERT(0);
  154. break;
  155. #endif
  156. default:
  157. STARPU_ASSERT(0);
  158. break;
  159. }
  160. }
  161. void dw_core_codelet_update_u21(starpu_data_interface_t *descr, void *_args)
  162. {
  163. dw_common_codelet_update_u21(descr, 0, _args);
  164. (void)STARPU_ATOMIC_ADD(&count_21_core, 1);
  165. }
  166. #ifdef USE_CUDA
  167. void dw_cublas_codelet_update_u21(starpu_data_interface_t *descr, void *_args)
  168. {
  169. dw_common_codelet_update_u21(descr, 1, _args);
  170. (void)STARPU_ATOMIC_ADD(&count_21_cublas, 1);
  171. }
  172. #endif
  173. /*
  174. * U11
  175. */
  176. static inline void debug_print(float *tab, unsigned ld, unsigned n)
  177. {
  178. unsigned j,i;
  179. for (j = 0; j < n; j++)
  180. {
  181. for (i = 0; i < n; i++)
  182. {
  183. fprintf(stderr, "%2.2f\t", tab[j+i*ld]);
  184. }
  185. fprintf(stderr, "\n");
  186. }
  187. fprintf(stderr, "\n");
  188. }
  189. static inline void dw_common_codelet_update_u11(starpu_data_interface_t *descr, int s, __attribute__((unused)) void *_args)
  190. {
  191. float *sub11;
  192. sub11 = (float *)descr[0].blas.ptr;
  193. unsigned nx = descr[0].blas.nx;
  194. unsigned ld = descr[0].blas.ld;
  195. unsigned z;
  196. switch (s) {
  197. case 0:
  198. for (z = 0; z < nx; z++)
  199. {
  200. float pivot;
  201. pivot = sub11[z+z*ld];
  202. STARPU_ASSERT(pivot != 0.0f);
  203. SSCAL(nx - z - 1, (1.0f/pivot), &sub11[z+(z+1)*ld], ld);
  204. SGER(nx - z - 1, nx - z - 1, -1.0f,
  205. &sub11[z+(z+1)*ld], ld,
  206. &sub11[(z+1)+z*ld], 1,
  207. &sub11[(z+1) + (z+1)*ld],ld);
  208. }
  209. break;
  210. #ifdef USE_CUDA
  211. case 1:
  212. for (z = 0; z < nx; z++)
  213. {
  214. float pivot;
  215. /* ok that's dirty and ridiculous ... */
  216. cublasGetVector(1, sizeof(float), &sub11[z+z*ld], sizeof(float), &pivot, sizeof(float));
  217. STARPU_ASSERT(pivot != 0.0f);
  218. cublasSscal(nx - z - 1, 1.0f/pivot, &sub11[z+(z+1)*ld], ld);
  219. cublasSger(nx - z - 1, nx - z - 1, -1.0f,
  220. &sub11[z+(z+1)*ld], ld,
  221. &sub11[(z+1)+z*ld], 1,
  222. &sub11[(z+1) + (z+1)*ld],ld);
  223. }
  224. break;
  225. #endif
  226. default:
  227. STARPU_ASSERT(0);
  228. break;
  229. }
  230. }
  231. void dw_core_codelet_update_u11(starpu_data_interface_t *descr, void *_args)
  232. {
  233. dw_common_codelet_update_u11(descr, 0, _args);
  234. (void)STARPU_ATOMIC_ADD(&count_11_core, 1);
  235. }
  236. #ifdef USE_CUDA
  237. void dw_cublas_codelet_update_u11(starpu_data_interface_t *descr, void *_args)
  238. {
  239. dw_common_codelet_update_u11(descr, 1, _args);
  240. (void)STARPU_ATOMIC_ADD(&count_11_cublas, 1);
  241. }
  242. #endif// USE_CUDA