dw_factolu.h 4.5 KB

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