dw_factolu.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. starpu_data_handle dataA;
  38. unsigned i;
  39. unsigned j;
  40. unsigned k;
  41. unsigned nblocks;
  42. unsigned *remaining;
  43. } cl_args;
  44. #ifdef CHECK_RESULTS
  45. static void __attribute__ ((unused)) compare_A_LU(float *A, float *LU,
  46. unsigned size, unsigned ld)
  47. {
  48. unsigned i,j;
  49. float *L;
  50. float *U;
  51. L = malloc(size*size*sizeof(float));
  52. U = malloc(size*size*sizeof(float));
  53. memset(L, 0, size*size*sizeof(float));
  54. memset(U, 0, size*size*sizeof(float));
  55. /* only keep the lower part */
  56. for (j = 0; j < size; j++)
  57. {
  58. for (i = 0; i < j; i++)
  59. {
  60. L[j+i*size] = LU[j+i*ld];
  61. }
  62. /* diag i = j */
  63. L[j+j*size] = LU[j+j*ld];
  64. U[j+j*size] = 1.0f;
  65. for (i = j+1; i < size; i++)
  66. {
  67. U[j+i*size] = LU[j+i*ld];
  68. }
  69. }
  70. #if 0
  71. /* display L */
  72. FPRINTF(stdout, "(LU): \n");
  73. for (j = 0; j < size; j++)
  74. {
  75. for (i = 0; i < size; i++)
  76. {
  77. /* if (i <= j) { */
  78. FPRINTF(stdout, "%2.2f\t", LU[j +i*size]);
  79. /* }
  80. else {
  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. FPRINTF(stdout, "%2.2f\t", L[j +i*size]);
  94. /* }
  95. else {
  96. FPRINTF(stdout, ".\t");
  97. } */
  98. }
  99. FPRINTF(stdout, "\n");
  100. }
  101. /* display U */
  102. FPRINTF(stdout, "U: \n");
  103. for (j = 0; j < size; j++)
  104. {
  105. for (i = 0; i < size; i++)
  106. {
  107. /* if (i <= j) { */
  108. FPRINTF(stdout, "%2.2f\t", U[j +i*size]);
  109. /* }
  110. else {
  111. FPRINTF(stdout, ".\t");
  112. } */
  113. }
  114. FPRINTF(stdout, "\n");
  115. }
  116. #endif
  117. /* now A_err = L, compute L*U */
  118. STRMM("R", "U", "N", "U", size, size, 1.0f, U, size, L, size);
  119. float max_err = 0.0f;
  120. for (i = 0; i < size ; i++)
  121. {
  122. for (j = 0; j < size; j++)
  123. {
  124. max_err = STARPU_MAX(max_err, fabs( L[j+i*size] - A[j+i*ld] ));
  125. }
  126. }
  127. #if 0
  128. /* display A */
  129. FPRINTF(stdout, "A: \n");
  130. for (j = 0; j < size; j++)
  131. {
  132. for (i = 0; i < size; i++)
  133. {
  134. /* if (i <= j) { */
  135. FPRINTF(stdout, "%2.2f\t", A[j +i*size]);
  136. /* }
  137. else {
  138. FPRINTF(stdout, ".\t");
  139. } */
  140. }
  141. FPRINTF(stdout, "\n");
  142. }
  143. /* display LU */
  144. FPRINTF(stdout, "LU: \n");
  145. for (j = 0; j < size; j++)
  146. {
  147. for (i = 0; i < size; i++)
  148. {
  149. /* if (i <= j) { */
  150. FPRINTF(stdout, "%2.2f\t", L[j +i*size]);
  151. /* }
  152. else {
  153. FPRINTF(stdout, ".\t");
  154. } */
  155. }
  156. FPRINTF(stdout, "\n");
  157. }
  158. #endif
  159. FPRINTF(stdout, "max error between A and L*U = %f \n", max_err);
  160. }
  161. #endif /* CHECK_RESULTS */
  162. void dw_cpu_codelet_update_u11(void **, void *);
  163. void dw_cpu_codelet_update_u12(void **, void *);
  164. void dw_cpu_codelet_update_u21(void **, void *);
  165. void dw_cpu_codelet_update_u22(void **, void *);
  166. #ifdef STARPU_USE_CUDA
  167. void dw_cublas_codelet_update_u11(void *descr[], void *_args);
  168. void dw_cublas_codelet_update_u12(void *descr[], void *_args);
  169. void dw_cublas_codelet_update_u21(void *descr[], void *_args);
  170. void dw_cublas_codelet_update_u22(void *descr[], void *_args);
  171. #endif
  172. void dw_callback_codelet_update_u11(void *);
  173. void dw_callback_codelet_update_u12_21(void *);
  174. void dw_callback_codelet_update_u22(void *);
  175. void dw_callback_v2_codelet_update_u11(void *);
  176. void dw_callback_v2_codelet_update_u12(void *);
  177. void dw_callback_v2_codelet_update_u21(void *);
  178. void dw_callback_v2_codelet_update_u22(void *);
  179. extern struct starpu_perfmodel_t model_11;
  180. extern struct starpu_perfmodel_t model_12;
  181. extern struct starpu_perfmodel_t model_21;
  182. extern struct starpu_perfmodel_t model_22;
  183. #endif /* __DW_FACTO_LU_H__ */