dw_factolu.h 4.3 KB

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