starpu_machine_display.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2012, 2014-2015 Université de Bordeaux
  4. *
  5. * StarPU 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. * StarPU 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. #include <config.h>
  17. #include <stdio.h>
  18. #include <starpu.h>
  19. #include <starpu_scheduler.h>
  20. #define PROGNAME "starpu_machine_display"
  21. static void usage()
  22. {
  23. fprintf(stderr, "Show the processing units that StarPU can use,\n");
  24. fprintf(stderr, "and the bandwitdh and affinity measured between the memory nodes.\n");
  25. fprintf(stderr, "\n");
  26. fprintf(stderr, "Usage: %s [OPTION]\n", PROGNAME);
  27. fprintf(stderr, "\n");
  28. fprintf(stderr, "Options:\n");
  29. fprintf(stderr, "\t-h, --help display this help and exit\n");
  30. fprintf(stderr, "\t-v, --version output version information and exit\n");
  31. fprintf(stderr, "\t-i, --info display the name of the files containing the information\n");
  32. fprintf(stderr, "\t-f, --force force bus sampling and show measures \n");
  33. fprintf(stderr, "\n");
  34. fprintf(stderr, "Report bugs to <" PACKAGE_BUGREPORT ">.\n");
  35. }
  36. static void display_worker_names(enum starpu_worker_archtype type)
  37. {
  38. int nworkers = starpu_worker_get_count_by_type(type);
  39. if (!nworkers)
  40. return;
  41. STARPU_ASSERT(nworkers>0);
  42. int ids[nworkers];
  43. starpu_worker_get_ids_by_type(type, ids, nworkers);
  44. int i;
  45. for (i = 0; i < nworkers; i++)
  46. {
  47. char name[256];
  48. starpu_worker_get_name(ids[i], name, 256);
  49. fprintf(stdout, "\t\t%s\n", name);
  50. }
  51. }
  52. static void display_combined_worker(unsigned workerid)
  53. {
  54. int worker_size;
  55. int *combined_workerid;
  56. starpu_combined_worker_get_description(workerid, &worker_size, &combined_workerid);
  57. fprintf(stdout, "\t\t");
  58. int i;
  59. for (i = 0; i < worker_size; i++)
  60. {
  61. char name[256];
  62. starpu_worker_get_name(combined_workerid[i], name, 256);
  63. fprintf(stdout, "%s\t", name);
  64. }
  65. fprintf(stdout, "\n");
  66. }
  67. static void display_all_combined_workers(void)
  68. {
  69. unsigned ncombined_workers = starpu_combined_worker_get_count();
  70. if (ncombined_workers == 0)
  71. return;
  72. unsigned nworkers = starpu_worker_get_count();
  73. fprintf(stdout, "\t%u Combined workers\n", ncombined_workers);
  74. unsigned i;
  75. for (i = 0; i < ncombined_workers; i++)
  76. display_combined_worker(nworkers + i);
  77. }
  78. static void parse_args(int argc, char **argv, int *force, int *info)
  79. {
  80. int i;
  81. if (argc == 1)
  82. return;
  83. for (i = 1; i < argc; i++)
  84. {
  85. if (strncmp(argv[i], "--force", 7) == 0 || strncmp(argv[i], "-f", 2) == 0)
  86. {
  87. *force = 1;
  88. }
  89. else if (strncmp(argv[i], "--info", 6) == 0 || strncmp(argv[i], "-i", 2) == 0)
  90. {
  91. *info = 1;
  92. }
  93. else if (strncmp(argv[i], "--help", 6) == 0 || strncmp(argv[i], "-h", 2) == 0)
  94. {
  95. usage();
  96. exit(EXIT_FAILURE);
  97. }
  98. else if (strncmp(argv[i], "--version", 9) == 0 || strncmp(argv[i], "-v", 2) == 0)
  99. {
  100. fputs(PROGNAME " (" PACKAGE_NAME ") " PACKAGE_VERSION "\n", stderr);
  101. exit(EXIT_FAILURE);
  102. }
  103. else
  104. {
  105. fprintf(stderr, "Unknown arg %s\n", argv[1]);
  106. usage();
  107. exit(EXIT_FAILURE);
  108. }
  109. }
  110. }
  111. int main(int argc, char **argv)
  112. {
  113. int ret;
  114. int force = 0;
  115. int info = 0;
  116. struct starpu_conf conf;
  117. parse_args(argc, argv, &force, &info);
  118. starpu_conf_init(&conf);
  119. if (force)
  120. conf.bus_calibrate = 1;
  121. /* Even if starpu_init returns -ENODEV, we should go on : we will just
  122. * print that we found no device. */
  123. ret = starpu_init(&conf);
  124. if (ret != 0 && ret != -ENODEV)
  125. {
  126. return ret;
  127. }
  128. if (info)
  129. {
  130. starpu_bus_print_filenames(stdout);
  131. starpu_shutdown();
  132. return 0;
  133. }
  134. unsigned ncpu = starpu_cpu_worker_get_count();
  135. unsigned ncuda = starpu_cuda_worker_get_count();
  136. unsigned nopencl = starpu_opencl_worker_get_count();
  137. #ifdef STARPU_USE_MIC
  138. unsigned nmicdevs = starpu_mic_device_get_count();
  139. unsigned nmiccores = starpu_mic_worker_get_count();
  140. #endif
  141. fprintf(stdout, "StarPU has found :\n");
  142. fprintf(stdout, "\t%u CPU threads\n", ncpu);
  143. display_worker_names(STARPU_CPU_WORKER);
  144. fprintf(stdout, "\t%u CUDA devices\n", ncuda);
  145. display_worker_names(STARPU_CUDA_WORKER);
  146. fprintf(stdout, "\t%u OpenCL devices\n", nopencl);
  147. display_worker_names(STARPU_OPENCL_WORKER);
  148. #ifdef STARPU_USE_MIC
  149. fprintf(stdout, "\t%d MIC cores (from %d devices)\n", nmiccores, nmicdevs);
  150. display_worker_names(STARPU_MIC_WORKER);
  151. #endif
  152. display_all_combined_workers();
  153. if (ret != -ENODEV)
  154. {
  155. fprintf(stdout, "\ntopology ...\n");
  156. starpu_topology_print(stdout);
  157. fprintf(stdout, "\nbandwidth and latency ...\n");
  158. starpu_bus_print_bandwidth(stdout);
  159. starpu_shutdown();
  160. }
  161. return 0;
  162. }