dw_factolu.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #ifndef __DW_FACTO_LU_H__
  17. #define __DW_FACTO_LU_H__
  18. #include <semaphore.h>
  19. #include <string.h>
  20. #include <math.h>
  21. /* for USE_CUDA */
  22. #include <starpu_config.h>
  23. #ifdef USE_CUDA
  24. #include <cuda.h>
  25. #include <cublas.h>
  26. #endif
  27. #include "../common/blas.h"
  28. #include <starpu.h>
  29. #include "lu_kernels_model.h"
  30. #define BLAS3_FLOP(n1,n2,n3) \
  31. (2*((uint64_t)n1)*((uint64_t)n2)*((uint64_t)n3))
  32. typedef struct {
  33. starpu_data_handle dataA;
  34. unsigned i;
  35. unsigned j;
  36. unsigned k;
  37. unsigned nblocks;
  38. unsigned *remaining;
  39. sem_t *sem;
  40. } cl_args;
  41. #ifdef CHECK_RESULTS
  42. static void __attribute__ ((unused)) compare_A_LU(float *A, float *LU,
  43. 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. printf("(LU): \n");
  70. for (j = 0; j < size; j++)
  71. {
  72. for (i = 0; i < size; i++)
  73. {
  74. // if (i <= j) {
  75. printf("%2.2f\t", LU[j +i*size]);
  76. // }
  77. // else {
  78. // printf(".\t");
  79. // }
  80. }
  81. printf("\n");
  82. }
  83. /* display L */
  84. printf("L: \n");
  85. for (j = 0; j < size; j++)
  86. {
  87. for (i = 0; i < size; i++)
  88. {
  89. // if (i <= j) {
  90. printf("%2.2f\t", L[j +i*size]);
  91. // }
  92. // else {
  93. // printf(".\t");
  94. // }
  95. }
  96. printf("\n");
  97. }
  98. /* display U */
  99. printf("U: \n");
  100. for (j = 0; j < size; j++)
  101. {
  102. for (i = 0; i < size; i++)
  103. {
  104. // if (i <= j) {
  105. printf("%2.2f\t", U[j +i*size]);
  106. // }
  107. // else {
  108. // printf(".\t");
  109. // }
  110. }
  111. printf("\n");
  112. }
  113. #endif
  114. /* now A_err = L, compute L*U */
  115. STRMM("R", "U", "N", "U", size, size, 1.0f, U, size, L, size);
  116. float max_err = 0.0f;
  117. for (i = 0; i < size ; i++)
  118. {
  119. for (j = 0; j < size; j++)
  120. {
  121. max_err = STARPU_MAX(max_err, fabs( L[j+i*size] - A[j+i*ld] ));
  122. }
  123. }
  124. #if 0
  125. /* display A */
  126. printf("A: \n");
  127. for (j = 0; j < size; j++)
  128. {
  129. for (i = 0; i < size; i++)
  130. {
  131. // if (i <= j) {
  132. printf("%2.2f\t", A[j +i*size]);
  133. // }
  134. // else {
  135. // printf(".\t");
  136. // }
  137. }
  138. printf("\n");
  139. }
  140. /* display LU */
  141. printf("LU: \n");
  142. for (j = 0; j < size; j++)
  143. {
  144. for (i = 0; i < size; i++)
  145. {
  146. // if (i <= j) {
  147. printf("%2.2f\t", L[j +i*size]);
  148. // }
  149. // else {
  150. // printf(".\t");
  151. // }
  152. }
  153. printf("\n");
  154. }
  155. #endif
  156. printf("max error between A and L*U = %f \n", max_err);
  157. }
  158. #endif // CHECK_RESULTS
  159. void dw_core_codelet_update_u11(starpu_data_interface_t *, void *);
  160. void dw_core_codelet_update_u12(starpu_data_interface_t *, void *);
  161. void dw_core_codelet_update_u21(starpu_data_interface_t *, void *);
  162. void dw_core_codelet_update_u22(starpu_data_interface_t *, void *);
  163. #ifdef USE_CUDA
  164. void dw_cublas_codelet_update_u11(starpu_data_interface_t *descr, void *_args);
  165. void dw_cublas_codelet_update_u12(starpu_data_interface_t *descr, void *_args);
  166. void dw_cublas_codelet_update_u21(starpu_data_interface_t *descr, void *_args);
  167. void dw_cublas_codelet_update_u22(starpu_data_interface_t *descr, void *_args);
  168. #endif
  169. void dw_callback_codelet_update_u11(void *);
  170. void dw_callback_codelet_update_u12_21(void *);
  171. void dw_callback_codelet_update_u22(void *);
  172. void dw_callback_v2_codelet_update_u11(void *);
  173. void dw_callback_v2_codelet_update_u12(void *);
  174. void dw_callback_v2_codelet_update_u21(void *);
  175. void dw_callback_v2_codelet_update_u22(void *);
  176. extern struct starpu_perfmodel_t model_11;
  177. extern struct starpu_perfmodel_t model_12;
  178. extern struct starpu_perfmodel_t model_21;
  179. extern struct starpu_perfmodel_t model_22;
  180. #endif // __DW_FACTO_LU_H__