dw_mult.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 __MULT_H__
  17. #define __MULT_H__
  18. #include <string.h>
  19. #include <math.h>
  20. #include <sys/types.h>
  21. #include <sys/time.h>
  22. #include <pthread.h>
  23. #include <signal.h>
  24. #include <common/blas.h>
  25. #include <common/blas_model.h>
  26. #include <starpu.h>
  27. #ifdef STARPU_USE_CUDA
  28. #include <cuda.h>
  29. #include <cublas.h>
  30. #endif
  31. #define MAXSLICESX 64
  32. #define MAXSLICESY 64
  33. #define MAXSLICESZ 64
  34. #define BLAS3_FLOP(n1,n2,n3) \
  35. (2*((uint64_t)n1)*((uint64_t)n2)*((uint64_t)n3))
  36. #define BLAS3_LS(n1,n2,n3) \
  37. ((2*(n1)*(n3) + (n1)*(n2) + (n2)*(n3))*sizeof(float))
  38. struct block_conf {
  39. uint32_t m;
  40. uint32_t n;
  41. uint32_t k;
  42. uint32_t pad;
  43. };
  44. #define NITER 100
  45. unsigned niter = NITER;
  46. unsigned nslicesx = 4;
  47. unsigned nslicesy = 4;
  48. unsigned nslicesz = 4;
  49. unsigned xdim = 256;
  50. unsigned ydim = 256;
  51. unsigned zdim = 64;
  52. unsigned norandom = 0;
  53. unsigned pin = 0;
  54. unsigned use_common_model = 0;
  55. unsigned check = 0;
  56. /* to compute MFlop/s */
  57. uint64_t flop_cublas = 0;
  58. uint64_t flop_atlas = 0;
  59. uint64_t flop_per_worker[STARPU_NMAXWORKERS] = {0};
  60. /* to compute MB/s (load/store) */
  61. uint64_t ls_cublas = 0;
  62. uint64_t ls_atlas = 0;
  63. uint64_t ls_per_worker[STARPU_NMAXWORKERS] = {0};
  64. struct timeval start;
  65. struct timeval end;
  66. static int taskcounter __attribute__ ((unused));
  67. static struct block_conf conf __attribute__ ((aligned (128)));
  68. #define BLOCKSIZEX (xdim / nslicesx)
  69. #define BLOCKSIZEY (ydim / nslicesy)
  70. #define BLOCKSIZEZ (zdim / nslicesz)
  71. static void display_stats(double timing)
  72. {
  73. unsigned worker;
  74. unsigned nworkers = starpu_worker_get_count();
  75. fprintf(stderr, "Computation took (ms):\n");
  76. printf("%2.2f\n", timing/1000);
  77. uint64_t flop_total = 0, ls_total = 0;
  78. for (worker = 0; worker < nworkers; worker++)
  79. {
  80. flop_total += flop_per_worker[worker];
  81. ls_total += ls_per_worker[worker];
  82. char name[32];
  83. starpu_worker_get_name(worker, name, 32);
  84. fprintf(stderr, "\t%s -> %2.2f GFlop\t%2.2f GFlop/s\n", name, (double)flop_per_worker[worker]/1000000000.0f, (double)flop_per_worker[worker]/(double)timing/1000);
  85. }
  86. fprintf(stderr, "Total: %2.2f GFlops\t%2.2f GFlop/s\n", (double)flop_total/1000000000.0f, (double)flop_total/(double)timing/1000);
  87. }
  88. static void parse_args(int argc, char **argv)
  89. {
  90. int i;
  91. for (i = 1; i < argc; i++) {
  92. if (strcmp(argv[i], "-nblocks") == 0) {
  93. char *argptr;
  94. nslicesx = strtol(argv[++i], &argptr, 10);
  95. nslicesy = nslicesx;
  96. nslicesz = nslicesx;
  97. }
  98. if (strcmp(argv[i], "-nblocksx") == 0) {
  99. char *argptr;
  100. nslicesx = strtol(argv[++i], &argptr, 10);
  101. }
  102. if (strcmp(argv[i], "-nblocksy") == 0) {
  103. char *argptr;
  104. nslicesy = strtol(argv[++i], &argptr, 10);
  105. }
  106. if (strcmp(argv[i], "-nblocksz") == 0) {
  107. char *argptr;
  108. nslicesz = strtol(argv[++i], &argptr, 10);
  109. }
  110. if (strcmp(argv[i], "-x") == 0) {
  111. char *argptr;
  112. xdim = strtol(argv[++i], &argptr, 10);
  113. }
  114. if (strcmp(argv[i], "-y") == 0) {
  115. char *argptr;
  116. ydim = strtol(argv[++i], &argptr, 10);
  117. }
  118. if (strcmp(argv[i], "-z") == 0) {
  119. char *argptr;
  120. zdim = strtol(argv[++i], &argptr, 10);
  121. }
  122. if (strcmp(argv[i], "-iter") == 0) {
  123. char *argptr;
  124. niter = strtol(argv[++i], &argptr, 10);
  125. }
  126. if (strcmp(argv[i], "-no-random") == 0) {
  127. norandom = 1;
  128. }
  129. if (strcmp(argv[i], "-pin") == 0) {
  130. pin = 1;
  131. }
  132. if (strcmp(argv[i], "-check") == 0) {
  133. check = 1;
  134. }
  135. if (strcmp(argv[i], "-common-model") == 0) {
  136. use_common_model = 1;
  137. }
  138. }
  139. assert(nslicesx <= MAXSLICESX);
  140. assert(nslicesy <= MAXSLICESY);
  141. assert(nslicesz <= MAXSLICESZ);
  142. }
  143. static void display_memory_consumption(void)
  144. {
  145. fprintf(stderr, "Total memory : %ld MB\n",
  146. (MAXSLICESY*MAXSLICESZ*sizeof(float *)
  147. + MAXSLICESZ*MAXSLICESX*sizeof(float *)
  148. + MAXSLICESY*MAXSLICESX*sizeof(float *)
  149. + MAXSLICESY*MAXSLICESZ*sizeof(starpu_data_handle)
  150. + MAXSLICESZ*MAXSLICESX*sizeof(starpu_data_handle)
  151. + MAXSLICESY*MAXSLICESX*sizeof(starpu_data_handle)
  152. + ydim*zdim*sizeof(float)
  153. + zdim*xdim*sizeof(float)
  154. + ydim*xdim*sizeof(float))/(1024*1024) );
  155. }
  156. #ifdef STARPU_USE_CUDA
  157. void cublas_mult(void *descr[], __attribute__((unused)) void *arg);
  158. #endif
  159. void cpu_mult(void *descr[], __attribute__((unused)) void *arg);
  160. #endif // __MULT_H__