dw_sparse_cg.h 3.2 KB

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