cholesky.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2008-2017 Université de Bordeaux
  4. * Copyright (C) 2010-2013,2015-2017 CNRS
  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_CHOLESKY_H__
  18. #define __DW_CHOLESKY_H__
  19. #include <limits.h>
  20. #include <string.h>
  21. #include <math.h>
  22. #ifdef STARPU_USE_CUDA
  23. #include <cuda.h>
  24. #include <cuda_runtime.h>
  25. #endif
  26. #include <common/blas.h>
  27. #include <starpu.h>
  28. #define FPRINTF(ofile, fmt, ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ## __VA_ARGS__); }} while(0)
  29. #define PRINTF(fmt, ...) do { if (!getenv("STARPU_SSILENT")) {printf(fmt, ## __VA_ARGS__); }} while(0)
  30. #define NMAXBLOCKS 128
  31. #define TAG11(k) ((starpu_tag_t)( (1ULL<<60) | (unsigned long long)(k)))
  32. #define TAG21(k,j) ((starpu_tag_t)(((3ULL<<60) | (((unsigned long long)(k))<<32) \
  33. | (unsigned long long)(j))))
  34. #define TAG22(k,i,j) ((starpu_tag_t)(((4ULL<<60) | ((unsigned long long)(k)<<32) \
  35. | ((unsigned long long)(i)<<16) \
  36. | (unsigned long long)(j))))
  37. #define TAG11_AUX(k, prefix) ((starpu_tag_t)( (((unsigned long long)(prefix))<<60) | (1ULL<<56) | (unsigned long long)(k)))
  38. #define TAG21_AUX(k,j, prefix) ((starpu_tag_t)( (((unsigned long long)(prefix))<<60) \
  39. | ((3ULL<<56) | (((unsigned long long)(k))<<32) \
  40. | (unsigned long long)(j))))
  41. #define TAG22_AUX(k,i,j, prefix) ((starpu_tag_t)( (((unsigned long long)(prefix))<<60) \
  42. | ((4ULL<<56) | ((unsigned long long)(k)<<32) \
  43. | ((unsigned long long)(i)<<16) \
  44. | (unsigned long long)(j))))
  45. #define BLOCKSIZE (size_p/nblocks_p)
  46. #define BLAS3_FLOP(n1,n2,n3) \
  47. (2*((uint64_t)n1)*((uint64_t)n2)*((uint64_t)n3))
  48. /* This is from magma
  49. -- Innovative Computing Laboratory
  50. -- Electrical Engineering and Computer Science Department
  51. -- University of Tennessee
  52. -- (C) Copyright 2009
  53. Redistribution and use in source and binary forms, with or without
  54. modification, are permitted provided that the following conditions
  55. are met:
  56. * Redistributions of source code must retain the above copyright
  57. notice, this list of conditions and the following disclaimer.
  58. * Redistributions in binary form must reproduce the above copyright
  59. notice, this list of conditions and the following disclaimer in the
  60. documentation and/or other materials provided with the distribution.
  61. * Neither the name of the University of Tennessee, Knoxville nor the
  62. names of its contributors may be used to endorse or promote products
  63. derived from this software without specific prior written permission.
  64. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  65. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  66. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  67. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  68. HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  69. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  70. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  71. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  72. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  73. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  74. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  75. */
  76. #define FMULS_POTRF(__n) ((double)(__n) * (((1. / 6.) * (double)(__n) + 0.5) * (double)(__n) + (1. / 3.)))
  77. #define FADDS_POTRF(__n) ((double)(__n) * (((1. / 6.) * (double)(__n) ) * (double)(__n) - (1. / 6.)))
  78. #define FLOPS_SPOTRF(__n) ( FMULS_POTRF((__n)) + FADDS_POTRF((__n)) )
  79. #define FMULS_TRMM_2(__m, __n) (0.5 * (double)(__n) * (double)(__m) * ((double)(__m)+1.))
  80. #define FADDS_TRMM_2(__m, __n) (0.5 * (double)(__n) * (double)(__m) * ((double)(__m)-1.))
  81. #define FMULS_TRMM(__m, __n) ( /*( (__side) == PlasmaLeft ) ? FMULS_TRMM_2((__m), (__n)) :*/ FMULS_TRMM_2((__n), (__m)) )
  82. #define FADDS_TRMM(__m, __n) ( /*( (__side) == PlasmaLeft ) ? FADDS_TRMM_2((__m), (__n)) :*/ FADDS_TRMM_2((__n), (__m)) )
  83. #define FMULS_TRSM FMULS_TRMM
  84. #define FADDS_TRSM FMULS_TRMM
  85. #define FLOPS_STRSM(__m, __n) ( FMULS_TRSM((__m), (__n)) + FADDS_TRSM((__m), (__n)) )
  86. #define FMULS_GEMM(__m, __n, __k) ((double)(__m) * (double)(__n) * (double)(__k))
  87. #define FADDS_GEMM(__m, __n, __k) ((double)(__m) * (double)(__n) * (double)(__k))
  88. #define FLOPS_SGEMM(__m, __n, __k) ( FMULS_GEMM((__m), (__n), (__k)) + FADDS_GEMM((__m), (__n), (__k)) )
  89. /* End of magma code */
  90. static unsigned size_p;
  91. static unsigned nblocks_p;
  92. static unsigned nbigblocks_p;
  93. static inline void init_sizes(void)
  94. {
  95. int power = starpu_cpu_worker_get_count() + 32 * starpu_cuda_worker_get_count();
  96. int power_cbrt = cbrt(power);
  97. #ifndef STARPU_LONG_CHECK
  98. power_cbrt /= 2;
  99. #endif
  100. if (power_cbrt < 1)
  101. power_cbrt = 1;
  102. #ifdef STARPU_QUICK_CHECK
  103. if (!size_p)
  104. size_p = 320*2*power_cbrt;
  105. if (!nblocks_p)
  106. nblocks_p = 2*power_cbrt;
  107. if (!nbigblocks_p)
  108. nbigblocks_p = power_cbrt;
  109. #else
  110. if (!size_p)
  111. size_p = 960*8*power_cbrt;
  112. if (!nblocks_p)
  113. nblocks_p = 8*power_cbrt;
  114. if (!nbigblocks_p)
  115. nbigblocks_p = 4*power_cbrt;
  116. #endif
  117. }
  118. static unsigned pinned_p = 1;
  119. static unsigned noprio_p = 0;
  120. static unsigned check_p = 0;
  121. static unsigned bound_p = 0;
  122. static unsigned bound_deps_p = 0;
  123. static unsigned bound_lp_p = 0;
  124. static unsigned bound_mps_p = 0;
  125. static unsigned with_ctxs_p = 0;
  126. static unsigned with_noctxs_p = 0;
  127. static unsigned chole1_p = 0;
  128. static unsigned chole2_p = 0;
  129. struct starpu_perfmodel chol_model_11;
  130. struct starpu_perfmodel chol_model_21;
  131. struct starpu_perfmodel chol_model_22;
  132. struct starpu_codelet cl11;
  133. struct starpu_codelet cl21;
  134. struct starpu_codelet cl22;
  135. void chol_cpu_codelet_update_u11(void **, void *);
  136. void chol_cpu_codelet_update_u21(void **, void *);
  137. void chol_cpu_codelet_update_u22(void **, void *);
  138. double cpu_chol_task_11_cost(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl);
  139. double cpu_chol_task_21_cost(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl);
  140. double cpu_chol_task_22_cost(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl);
  141. #ifdef STARPU_USE_CUDA
  142. void chol_cublas_codelet_update_u11(void *descr[], void *_args);
  143. void chol_cublas_codelet_update_u21(void *descr[], void *_args);
  144. void chol_cublas_codelet_update_u22(void *descr[], void *_args);
  145. double cuda_chol_task_11_cost(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl);
  146. double cuda_chol_task_21_cost(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl);
  147. double cuda_chol_task_22_cost(struct starpu_task *task, struct starpu_perfmodel_arch* arch, unsigned nimpl);
  148. #endif
  149. void initialize_chol_model(struct starpu_perfmodel* model, char* symbol,
  150. double (*cpu_cost_function)(struct starpu_task *, struct starpu_perfmodel_arch*, unsigned),
  151. double (*cuda_cost_function)(struct starpu_task *, struct starpu_perfmodel_arch*, unsigned));
  152. static void parse_args(int argc, char **argv)
  153. {
  154. int i;
  155. for (i = 1; i < argc; i++)
  156. {
  157. if (strcmp(argv[i], "-with_ctxs") == 0)
  158. {
  159. with_ctxs_p = 1;
  160. break;
  161. }
  162. else if (strcmp(argv[i], "-with_noctxs") == 0)
  163. {
  164. with_noctxs_p = 1;
  165. break;
  166. }
  167. else if (strcmp(argv[i], "-chole1") == 0)
  168. {
  169. chole1_p = 1;
  170. break;
  171. }
  172. else if (strcmp(argv[i], "-chole2") == 0)
  173. {
  174. chole2_p = 1;
  175. break;
  176. }
  177. else if (strcmp(argv[i], "-size") == 0)
  178. {
  179. char *argptr;
  180. size_p = strtol(argv[++i], &argptr, 10);
  181. }
  182. else if (strcmp(argv[i], "-nblocks") == 0)
  183. {
  184. char *argptr;
  185. nblocks_p = strtol(argv[++i], &argptr, 10);
  186. }
  187. else if (strcmp(argv[i], "-nbigblocks") == 0)
  188. {
  189. char *argptr;
  190. nbigblocks_p = strtol(argv[++i], &argptr, 10);
  191. }
  192. else if (strcmp(argv[i], "-no-pin") == 0)
  193. {
  194. pinned_p = 0;
  195. }
  196. else if (strcmp(argv[i], "-no-prio") == 0)
  197. {
  198. noprio_p = 1;
  199. }
  200. else if (strcmp(argv[i], "-commute") == 0)
  201. {
  202. cl22.modes[2] |= STARPU_COMMUTE;
  203. }
  204. else if (strcmp(argv[i], "-bound") == 0)
  205. {
  206. bound_p = 1;
  207. }
  208. else if (strcmp(argv[i], "-bound-lp") == 0)
  209. {
  210. bound_lp_p = 1;
  211. }
  212. else if (strcmp(argv[i], "-bound-mps") == 0)
  213. {
  214. bound_mps_p = 1;
  215. }
  216. else if (strcmp(argv[i], "-bound-deps") == 0)
  217. {
  218. bound_deps_p = 1;
  219. }
  220. else if (strcmp(argv[i], "-check") == 0)
  221. {
  222. check_p = 1;
  223. }
  224. else
  225. /* if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i],"--help") == 0) */
  226. {
  227. fprintf(stderr,"usage : %s [-size size] [-nblocks nblocks] [-no-pin] [-no-prio] [-bound] [-bound-deps] [-bound-lp] [-check]\n", argv[0]);
  228. fprintf(stderr,"Currently selected: %ux%u and %ux%u blocks\n", size_p, size_p, nblocks_p, nblocks_p);
  229. exit(0);
  230. }
  231. }
  232. }
  233. #endif /* __DW_CHOLESKY_H__ */