dw_factolu.h 4.4 KB

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