dw_factolu.h 4.7 KB

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