dw_factolu.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010-2011 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #ifndef __DW_FACTO_LU_H__
  18. #define __DW_FACTO_LU_H__
  19. #include <semaphore.h>
  20. #include <string.h>
  21. #include <math.h>
  22. #include <sys/time.h>
  23. /* for STARPU_USE_CUDA */
  24. #include <starpu_config.h>
  25. #ifdef STARPU_USE_CUDA
  26. #include <cuda.h>
  27. #include <cuda_runtime.h>
  28. #include <cublas.h>
  29. #endif
  30. #include "../common/blas.h"
  31. #include <starpu.h>
  32. #include "lu_kernels_model.h"
  33. #define FPRINTF(ofile, fmt, args ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ##args); }} while(0)
  34. #define BLAS3_FLOP(n1,n2,n3) \
  35. (2*((uint64_t)n1)*((uint64_t)n2)*((uint64_t)n3))
  36. typedef struct
  37. {
  38. starpu_data_handle_t dataA;
  39. unsigned i;
  40. unsigned j;
  41. unsigned k;
  42. unsigned nblocks;
  43. unsigned *remaining;
  44. } cl_args;
  45. #ifdef CHECK_RESULTS
  46. static void __attribute__ ((unused)) compare_A_LU(float *A, float *LU,
  47. unsigned size, unsigned ld)
  48. {
  49. unsigned i,j;
  50. float *L;
  51. float *U;
  52. L = malloc(size*size*sizeof(float));
  53. U = malloc(size*size*sizeof(float));
  54. memset(L, 0, size*size*sizeof(float));
  55. memset(U, 0, size*size*sizeof(float));
  56. /* only keep the lower part */
  57. for (j = 0; j < size; j++)
  58. {
  59. for (i = 0; i < j; i++)
  60. {
  61. L[j+i*size] = LU[j+i*ld];
  62. }
  63. /* diag i = j */
  64. L[j+j*size] = LU[j+j*ld];
  65. U[j+j*size] = 1.0f;
  66. for (i = j+1; i < size; i++)
  67. {
  68. U[j+i*size] = LU[j+i*ld];
  69. }
  70. }
  71. #if 0
  72. /* display L */
  73. FPRINTF(stdout, "(LU): \n");
  74. for (j = 0; j < size; j++)
  75. {
  76. for (i = 0; i < size; i++)
  77. {
  78. /* if (i <= j)
  79. { */
  80. FPRINTF(stdout, "%2.2f\t", LU[j +i*size]);
  81. /* }
  82. else
  83. {
  84. FPRINTF(stdout, ".\t");
  85. } */
  86. }
  87. FPRINTF(stdout, "\n");
  88. }
  89. /* display L */
  90. FPRINTF(stdout, "L: \n");
  91. for (j = 0; j < size; j++)
  92. {
  93. for (i = 0; i < size; i++)
  94. {
  95. /* if (i <= j)
  96. { */
  97. FPRINTF(stdout, "%2.2f\t", L[j +i*size]);
  98. /* }
  99. else
  100. {
  101. FPRINTF(stdout, ".\t");
  102. } */
  103. }
  104. FPRINTF(stdout, "\n");
  105. }
  106. /* display U */
  107. FPRINTF(stdout, "U: \n");
  108. for (j = 0; j < size; j++)
  109. {
  110. for (i = 0; i < size; i++)
  111. {
  112. /* if (i <= j)
  113. { */
  114. FPRINTF(stdout, "%2.2f\t", U[j +i*size]);
  115. /* }
  116. else
  117. {
  118. FPRINTF(stdout, ".\t");
  119. } */
  120. }
  121. FPRINTF(stdout, "\n");
  122. }
  123. #endif
  124. /* now A_err = L, compute L*U */
  125. STRMM("R", "U", "N", "U", size, size, 1.0f, U, size, L, size);
  126. float max_err = 0.0f;
  127. for (i = 0; i < size ; i++)
  128. {
  129. for (j = 0; j < size; j++)
  130. {
  131. max_err = STARPU_MAX(max_err, fabs( L[j+i*size] - A[j+i*ld] ));
  132. }
  133. }
  134. #if 0
  135. /* display A */
  136. FPRINTF(stdout, "A: \n");
  137. for (j = 0; j < size; j++)
  138. {
  139. for (i = 0; i < size; i++)
  140. {
  141. /* if (i <= j)
  142. { */
  143. FPRINTF(stdout, "%2.2f\t", A[j +i*size]);
  144. /* }
  145. else
  146. {
  147. FPRINTF(stdout, ".\t");
  148. } */
  149. }
  150. FPRINTF(stdout, "\n");
  151. }
  152. /* display LU */
  153. FPRINTF(stdout, "LU: \n");
  154. for (j = 0; j < size; j++)
  155. {
  156. for (i = 0; i < size; i++)
  157. {
  158. /* if (i <= j)
  159. { */
  160. FPRINTF(stdout, "%2.2f\t", L[j +i*size]);
  161. /* }
  162. else
  163. {
  164. FPRINTF(stdout, ".\t");
  165. } */
  166. }
  167. FPRINTF(stdout, "\n");
  168. }
  169. #endif
  170. FPRINTF(stdout, "max error between A and L*U = %f \n", max_err);
  171. }
  172. #endif /* CHECK_RESULTS */
  173. void dw_cpu_codelet_update_u11(void **, void *);
  174. void dw_cpu_codelet_update_u12(void **, void *);
  175. void dw_cpu_codelet_update_u21(void **, void *);
  176. void dw_cpu_codelet_update_u22(void **, void *);
  177. #ifdef STARPU_USE_CUDA
  178. void dw_cublas_codelet_update_u11(void *descr[], void *_args);
  179. void dw_cublas_codelet_update_u12(void *descr[], void *_args);
  180. void dw_cublas_codelet_update_u21(void *descr[], void *_args);
  181. void dw_cublas_codelet_update_u22(void *descr[], void *_args);
  182. #endif
  183. void dw_callback_codelet_update_u11(void *);
  184. void dw_callback_codelet_update_u12_21(void *);
  185. void dw_callback_codelet_update_u22(void *);
  186. void dw_callback_v2_codelet_update_u11(void *);
  187. void dw_callback_v2_codelet_update_u12(void *);
  188. void dw_callback_v2_codelet_update_u21(void *);
  189. void dw_callback_v2_codelet_update_u22(void *);
  190. extern struct starpu_perfmodel model_11;
  191. extern struct starpu_perfmodel model_12;
  192. extern struct starpu_perfmodel model_21;
  193. extern struct starpu_perfmodel model_22;
  194. #endif /* __DW_FACTO_LU_H__ */