dw_factolu.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * StarPU
  3. * Copyright (C) Université Bordeaux 1, CNRS 2008-2010 (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. #include <sys/time.h>
  22. /* for STARPU_USE_CUDA */
  23. #include <starpu_config.h>
  24. #ifdef STARPU_USE_CUDA
  25. #include <cuda.h>
  26. #include <cuda_runtime.h>
  27. #include <cublas.h>
  28. #endif
  29. #include "../common/blas.h"
  30. #include <starpu.h>
  31. #include "lu_kernels_model.h"
  32. #define BLAS3_FLOP(n1,n2,n3) \
  33. (2*((uint64_t)n1)*((uint64_t)n2)*((uint64_t)n3))
  34. typedef struct {
  35. starpu_data_handle 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 __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. printf("(LU): \n");
  71. for (j = 0; j < size; j++)
  72. {
  73. for (i = 0; i < size; i++)
  74. {
  75. // if (i <= j) {
  76. printf("%2.2f\t", LU[j +i*size]);
  77. // }
  78. // else {
  79. // printf(".\t");
  80. // }
  81. }
  82. printf("\n");
  83. }
  84. /* display L */
  85. printf("L: \n");
  86. for (j = 0; j < size; j++)
  87. {
  88. for (i = 0; i < size; i++)
  89. {
  90. // if (i <= j) {
  91. printf("%2.2f\t", L[j +i*size]);
  92. // }
  93. // else {
  94. // printf(".\t");
  95. // }
  96. }
  97. printf("\n");
  98. }
  99. /* display U */
  100. printf("U: \n");
  101. for (j = 0; j < size; j++)
  102. {
  103. for (i = 0; i < size; i++)
  104. {
  105. // if (i <= j) {
  106. printf("%2.2f\t", U[j +i*size]);
  107. // }
  108. // else {
  109. // printf(".\t");
  110. // }
  111. }
  112. printf("\n");
  113. }
  114. #endif
  115. /* now A_err = L, compute L*U */
  116. STRMM("R", "U", "N", "U", size, size, 1.0f, U, size, L, size);
  117. float max_err = 0.0f;
  118. for (i = 0; i < size ; i++)
  119. {
  120. for (j = 0; j < size; j++)
  121. {
  122. max_err = STARPU_MAX(max_err, fabs( L[j+i*size] - A[j+i*ld] ));
  123. }
  124. }
  125. #if 0
  126. /* display A */
  127. printf("A: \n");
  128. for (j = 0; j < size; j++)
  129. {
  130. for (i = 0; i < size; i++)
  131. {
  132. // if (i <= j) {
  133. printf("%2.2f\t", A[j +i*size]);
  134. // }
  135. // else {
  136. // printf(".\t");
  137. // }
  138. }
  139. printf("\n");
  140. }
  141. /* display LU */
  142. printf("LU: \n");
  143. for (j = 0; j < size; j++)
  144. {
  145. for (i = 0; i < size; i++)
  146. {
  147. // if (i <= j) {
  148. printf("%2.2f\t", L[j +i*size]);
  149. // }
  150. // else {
  151. // printf(".\t");
  152. // }
  153. }
  154. printf("\n");
  155. }
  156. #endif
  157. printf("max error between A and L*U = %f \n", max_err);
  158. }
  159. #endif // CHECK_RESULTS
  160. void dw_cpu_codelet_update_u11(void **, void *);
  161. void dw_cpu_codelet_update_u12(void **, void *);
  162. void dw_cpu_codelet_update_u21(void **, void *);
  163. void dw_cpu_codelet_update_u22(void **, void *);
  164. #ifdef STARPU_USE_CUDA
  165. void dw_cublas_codelet_update_u11(void *descr[], void *_args);
  166. void dw_cublas_codelet_update_u12(void *descr[], void *_args);
  167. void dw_cublas_codelet_update_u21(void *descr[], void *_args);
  168. void dw_cublas_codelet_update_u22(void *descr[], void *_args);
  169. #endif
  170. void dw_callback_codelet_update_u11(void *);
  171. void dw_callback_codelet_update_u12_21(void *);
  172. void dw_callback_codelet_update_u22(void *);
  173. void dw_callback_v2_codelet_update_u11(void *);
  174. void dw_callback_v2_codelet_update_u12(void *);
  175. void dw_callback_v2_codelet_update_u21(void *);
  176. void dw_callback_v2_codelet_update_u22(void *);
  177. extern struct starpu_perfmodel_t model_11;
  178. extern struct starpu_perfmodel_t model_12;
  179. extern struct starpu_perfmodel_t model_21;
  180. extern struct starpu_perfmodel_t model_22;
  181. #endif // __DW_FACTO_LU_H__