dw_sparse_cg.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010-2011 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_SPARSE_CG_H__
  18. #define __DW_SPARSE_CG_H__
  19. #include <stdio.h>
  20. #include <stdint.h>
  21. #include <semaphore.h>
  22. #include <string.h>
  23. #include <stdint.h>
  24. #include <math.h>
  25. #include <sys/types.h>
  26. #include <pthread.h>
  27. #include <signal.h>
  28. #include <starpu_config.h>
  29. #include <starpu.h>
  30. #ifdef STARPU_USE_CUDA
  31. #include <cublas.h>
  32. #endif
  33. #include "../common/blas.h"
  34. #define MAXITER 100000
  35. #define EPSILON 0.0000001f
  36. /* code parameters */
  37. static uint32_t size = 33554432;
  38. static unsigned usecpu = 0;
  39. static unsigned blocks = 512;
  40. static unsigned grids = 8;
  41. struct cg_problem {
  42. starpu_data_handle ds_matrixA;
  43. starpu_data_handle ds_vecx;
  44. starpu_data_handle ds_vecb;
  45. starpu_data_handle ds_vecr;
  46. starpu_data_handle ds_vecd;
  47. starpu_data_handle ds_vecq;
  48. sem_t *sem;
  49. float alpha;
  50. float beta;
  51. float delta_0;
  52. float delta_old;
  53. float delta_new;
  54. float epsilon;
  55. int i;
  56. unsigned size;
  57. };
  58. /* some useful functions */
  59. static void __attribute__((unused)) parse_args(int argc, char **argv)
  60. {
  61. int i;
  62. for (i = 1; i < argc; i++) {
  63. if (strcmp(argv[i], "-size") == 0) {
  64. char *argptr;
  65. size = strtol(argv[++i], &argptr, 10);
  66. }
  67. if (strcmp(argv[i], "-block") == 0) {
  68. char *argptr;
  69. blocks = strtol(argv[++i], &argptr, 10);
  70. }
  71. if (strcmp(argv[i], "-grid") == 0) {
  72. char *argptr;
  73. grids = strtol(argv[++i], &argptr, 10);
  74. }
  75. if (strcmp(argv[i], "-cpu") == 0) {
  76. usecpu = 1;
  77. }
  78. }
  79. }
  80. static void __attribute__ ((unused)) print_results(float *result, unsigned size)
  81. {
  82. printf("**** RESULTS **** \n");
  83. unsigned i;
  84. for (i = 0; i < STARPU_MIN(size, 16); i++)
  85. {
  86. printf("%u -> %f\n", i, result[i]);
  87. }
  88. }
  89. void cpu_codelet_func_1(void *descr[], void *arg);
  90. void cpu_codelet_func_2(void *descr[], void *arg);
  91. void cublas_codelet_func_3(void *descr[], void *arg);
  92. void cpu_codelet_func_3(void *descr[], void *arg);
  93. void cpu_codelet_func_4(void *descr[], void *arg);
  94. void cpu_codelet_func_5(void *descr[], void *arg);
  95. void cublas_codelet_func_5(void *descr[], void *arg);
  96. void cublas_codelet_func_6(void *descr[], void *arg);
  97. void cpu_codelet_func_6(void *descr[], void *arg);
  98. void cublas_codelet_func_7(void *descr[], void *arg);
  99. void cpu_codelet_func_7(void *descr[], void *arg);
  100. void cublas_codelet_func_8(void *descr[], void *arg);
  101. void cpu_codelet_func_8(void *descr[], void *arg);
  102. void cublas_codelet_func_9(void *descr[], void *arg);
  103. void cpu_codelet_func_9(void *descr[], void *arg);
  104. void iteration_cg(void *problem);
  105. void conjugate_gradient(float *nzvalA, float *vecb, float *vecx, uint32_t nnz,
  106. unsigned nrow, uint32_t *colind, uint32_t *rowptr);
  107. #endif /* __DW_SPARSE_CG_H__ */