dw_factolu.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010-2012, 2014 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013, 2016 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 STARPU_ATTRIBUTE_UNUSED compare_A_LU(float *A, float *LU,
  44. unsigned size, unsigned ld)
  45. {
  46. unsigned i,j;
  47. float *L;
  48. float *U;
  49. L = malloc(size*size*sizeof(float));
  50. U = malloc(size*size*sizeof(float));
  51. memset(L, 0, size*size*sizeof(float));
  52. memset(U, 0, size*size*sizeof(float));
  53. /* only keep the lower part */
  54. for (j = 0; j < size; j++)
  55. {
  56. for (i = 0; i < j; i++)
  57. {
  58. L[j+i*size] = LU[j+i*ld];
  59. }
  60. /* diag i = j */
  61. L[j+j*size] = LU[j+j*ld];
  62. U[j+j*size] = 1.0f;
  63. for (i = j+1; i < size; i++)
  64. {
  65. U[j+i*size] = LU[j+i*ld];
  66. }
  67. }
  68. #if 0
  69. /* display L */
  70. FPRINTF(stdout, "(LU): \n");
  71. for (j = 0; j < size; j++)
  72. {
  73. for (i = 0; i < size; i++)
  74. {
  75. /* if (i <= j)
  76. { */
  77. FPRINTF(stdout, "%2.2f\t", LU[j +i*size]);
  78. /* }
  79. else
  80. {
  81. FPRINTF(stdout, ".\t");
  82. } */
  83. }
  84. FPRINTF(stdout, "\n");
  85. }
  86. /* display L */
  87. FPRINTF(stdout, "L: \n");
  88. for (j = 0; j < size; j++)
  89. {
  90. for (i = 0; i < size; i++)
  91. {
  92. /* if (i <= j)
  93. { */
  94. FPRINTF(stdout, "%2.2f\t", L[j +i*size]);
  95. /* }
  96. else
  97. {
  98. FPRINTF(stdout, ".\t");
  99. } */
  100. }
  101. FPRINTF(stdout, "\n");
  102. }
  103. /* display U */
  104. FPRINTF(stdout, "U: \n");
  105. for (j = 0; j < size; j++)
  106. {
  107. for (i = 0; i < size; i++)
  108. {
  109. /* if (i <= j)
  110. { */
  111. FPRINTF(stdout, "%2.2f\t", U[j +i*size]);
  112. /* }
  113. else
  114. {
  115. FPRINTF(stdout, ".\t");
  116. } */
  117. }
  118. FPRINTF(stdout, "\n");
  119. }
  120. #endif
  121. /* now A_err = L, compute L*U */
  122. STARPU_STRMM("R", "U", "N", "U", size, size, 1.0f, U, size, L, size);
  123. float max_err = 0.0f;
  124. for (i = 0; i < size ; i++)
  125. {
  126. for (j = 0; j < size; j++)
  127. {
  128. max_err = STARPU_MAX(max_err, fabs( L[j+i*size] - A[j+i*ld] ));
  129. }
  130. }
  131. #if 0
  132. /* display A */
  133. FPRINTF(stdout, "A: \n");
  134. for (j = 0; j < size; j++)
  135. {
  136. for (i = 0; i < size; i++)
  137. {
  138. /* if (i <= j)
  139. { */
  140. FPRINTF(stdout, "%2.2f\t", A[j +i*size]);
  141. /* }
  142. else
  143. {
  144. FPRINTF(stdout, ".\t");
  145. } */
  146. }
  147. FPRINTF(stdout, "\n");
  148. }
  149. /* display LU */
  150. FPRINTF(stdout, "LU: \n");
  151. for (j = 0; j < size; j++)
  152. {
  153. for (i = 0; i < size; i++)
  154. {
  155. /* if (i <= j)
  156. { */
  157. FPRINTF(stdout, "%2.2f\t", L[j +i*size]);
  158. /* }
  159. else
  160. {
  161. FPRINTF(stdout, ".\t");
  162. } */
  163. }
  164. FPRINTF(stdout, "\n");
  165. }
  166. #endif
  167. FPRINTF(stdout, "max error between A and L*U = %f \n", max_err);
  168. }
  169. #endif /* CHECK_RESULTS */
  170. void dw_cpu_codelet_update_u11(void **, void *);
  171. void dw_cpu_codelet_update_u12(void **, void *);
  172. void dw_cpu_codelet_update_u21(void **, void *);
  173. void dw_cpu_codelet_update_u22(void **, void *);
  174. #ifdef STARPU_USE_CUDA
  175. void dw_cublas_codelet_update_u11(void *descr[], void *_args);
  176. void dw_cublas_codelet_update_u12(void *descr[], void *_args);
  177. void dw_cublas_codelet_update_u21(void *descr[], void *_args);
  178. void dw_cublas_codelet_update_u22(void *descr[], void *_args);
  179. #endif
  180. void dw_callback_codelet_update_u11(void *);
  181. void dw_callback_codelet_update_u12_21(void *);
  182. void dw_callback_codelet_update_u22(void *);
  183. void dw_callback_v2_codelet_update_u11(void *);
  184. void dw_callback_v2_codelet_update_u12(void *);
  185. void dw_callback_v2_codelet_update_u21(void *);
  186. void dw_callback_v2_codelet_update_u22(void *);
  187. #endif /* __DW_FACTO_LU_H__ */