dw_factolu.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010-2012 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012 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. #include <starpu.h>
  24. #ifdef STARPU_USE_CUDA
  25. #include <cuda.h>
  26. #include <cuda_runtime.h>
  27. #include <cublas.h>
  28. #endif
  29. #include "../common/blas.h"
  30. #include "lu_kernels_model.h"
  31. #define FPRINTF(ofile, fmt, args ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ##args); }} while(0)
  32. #define BLAS3_FLOP(n1,n2,n3) \
  33. (2*((uint64_t)n1)*((uint64_t)n2)*((uint64_t)n3))
  34. typedef struct
  35. {
  36. starpu_data_handle_t dataA;
  37. unsigned i;
  38. unsigned j;
  39. unsigned k;
  40. unsigned nblocks;
  41. unsigned *remaining;
  42. } cl_args;
  43. #ifdef CHECK_RESULTS
  44. static void __attribute__ ((unused)) compare_A_LU(float *A, float *LU,
  45. unsigned size, unsigned ld)
  46. {
  47. unsigned i,j;
  48. float *L;
  49. float *U;
  50. L = malloc(size*size*sizeof(float));
  51. U = malloc(size*size*sizeof(float));
  52. memset(L, 0, size*size*sizeof(float));
  53. memset(U, 0, size*size*sizeof(float));
  54. /* only keep the lower part */
  55. for (j = 0; j < size; j++)
  56. {
  57. for (i = 0; i < j; i++)
  58. {
  59. L[j+i*size] = LU[j+i*ld];
  60. }
  61. /* diag i = j */
  62. L[j+j*size] = LU[j+j*ld];
  63. U[j+j*size] = 1.0f;
  64. for (i = j+1; i < size; i++)
  65. {
  66. U[j+i*size] = LU[j+i*ld];
  67. }
  68. }
  69. #if 0
  70. /* display L */
  71. FPRINTF(stdout, "(LU): \n");
  72. for (j = 0; j < size; j++)
  73. {
  74. for (i = 0; i < size; i++)
  75. {
  76. /* if (i <= j)
  77. { */
  78. FPRINTF(stdout, "%2.2f\t", LU[j +i*size]);
  79. /* }
  80. else
  81. {
  82. FPRINTF(stdout, ".\t");
  83. } */
  84. }
  85. FPRINTF(stdout, "\n");
  86. }
  87. /* display L */
  88. FPRINTF(stdout, "L: \n");
  89. for (j = 0; j < size; j++)
  90. {
  91. for (i = 0; i < size; i++)
  92. {
  93. /* if (i <= j)
  94. { */
  95. FPRINTF(stdout, "%2.2f\t", L[j +i*size]);
  96. /* }
  97. else
  98. {
  99. FPRINTF(stdout, ".\t");
  100. } */
  101. }
  102. FPRINTF(stdout, "\n");
  103. }
  104. /* display U */
  105. FPRINTF(stdout, "U: \n");
  106. for (j = 0; j < size; j++)
  107. {
  108. for (i = 0; i < size; i++)
  109. {
  110. /* if (i <= j)
  111. { */
  112. FPRINTF(stdout, "%2.2f\t", U[j +i*size]);
  113. /* }
  114. else
  115. {
  116. FPRINTF(stdout, ".\t");
  117. } */
  118. }
  119. FPRINTF(stdout, "\n");
  120. }
  121. #endif
  122. /* now A_err = L, compute L*U */
  123. STRMM("R", "U", "N", "U", size, size, 1.0f, U, size, L, size);
  124. float max_err = 0.0f;
  125. for (i = 0; i < size ; i++)
  126. {
  127. for (j = 0; j < size; j++)
  128. {
  129. max_err = STARPU_MAX(max_err, fabs( L[j+i*size] - A[j+i*ld] ));
  130. }
  131. }
  132. #if 0
  133. /* display A */
  134. FPRINTF(stdout, "A: \n");
  135. for (j = 0; j < size; j++)
  136. {
  137. for (i = 0; i < size; i++)
  138. {
  139. /* if (i <= j)
  140. { */
  141. FPRINTF(stdout, "%2.2f\t", A[j +i*size]);
  142. /* }
  143. else
  144. {
  145. FPRINTF(stdout, ".\t");
  146. } */
  147. }
  148. FPRINTF(stdout, "\n");
  149. }
  150. /* display LU */
  151. FPRINTF(stdout, "LU: \n");
  152. for (j = 0; j < size; j++)
  153. {
  154. for (i = 0; i < size; i++)
  155. {
  156. /* if (i <= j)
  157. { */
  158. FPRINTF(stdout, "%2.2f\t", L[j +i*size]);
  159. /* }
  160. else
  161. {
  162. FPRINTF(stdout, ".\t");
  163. } */
  164. }
  165. FPRINTF(stdout, "\n");
  166. }
  167. #endif
  168. FPRINTF(stdout, "max error between A and L*U = %f \n", max_err);
  169. }
  170. #endif /* CHECK_RESULTS */
  171. void dw_cpu_codelet_update_u11(void **, void *);
  172. void dw_cpu_codelet_update_u12(void **, void *);
  173. void dw_cpu_codelet_update_u21(void **, void *);
  174. void dw_cpu_codelet_update_u22(void **, void *);
  175. #ifdef STARPU_USE_CUDA
  176. void dw_cublas_codelet_update_u11(void *descr[], void *_args);
  177. void dw_cublas_codelet_update_u12(void *descr[], void *_args);
  178. void dw_cublas_codelet_update_u21(void *descr[], void *_args);
  179. void dw_cublas_codelet_update_u22(void *descr[], void *_args);
  180. #endif
  181. void dw_callback_codelet_update_u11(void *);
  182. void dw_callback_codelet_update_u12_21(void *);
  183. void dw_callback_codelet_update_u22(void *);
  184. void dw_callback_v2_codelet_update_u11(void *);
  185. void dw_callback_v2_codelet_update_u12(void *);
  186. void dw_callback_v2_codelet_update_u21(void *);
  187. void dw_callback_v2_codelet_update_u22(void *);
  188. extern struct starpu_perfmodel model_11;
  189. extern struct starpu_perfmodel model_12;
  190. extern struct starpu_perfmodel model_21;
  191. extern struct starpu_perfmodel model_22;
  192. #endif /* __DW_FACTO_LU_H__ */