starpu_machine_display.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  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 <stdio.h>
  17. #include <starpu.h>
  18. #include <starpu_scheduler.h>
  19. #include <common/config.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, "\t-w, --worker <type> only show workers of the given type\n");
  34. fprintf(stderr, "\n");
  35. fprintf(stderr, "Report bugs to <%s>.\n", PACKAGE_BUGREPORT);
  36. }
  37. static void display_combined_worker(unsigned workerid)
  38. {
  39. int worker_size;
  40. int *combined_workerid;
  41. starpu_combined_worker_get_description(workerid, &worker_size, &combined_workerid);
  42. fprintf(stdout, "\t\t");
  43. int i;
  44. for (i = 0; i < worker_size; i++)
  45. {
  46. char name[256];
  47. starpu_worker_get_name(combined_workerid[i], name, 256);
  48. fprintf(stdout, "%s\t", name);
  49. }
  50. fprintf(stdout, "\n");
  51. }
  52. static void display_all_combined_workers(void)
  53. {
  54. unsigned ncombined_workers = starpu_combined_worker_get_count();
  55. if (ncombined_workers == 0)
  56. return;
  57. unsigned nworkers = starpu_worker_get_count();
  58. fprintf(stdout, "\t%u Combined workers\n", ncombined_workers);
  59. unsigned i;
  60. for (i = 0; i < ncombined_workers; i++)
  61. display_combined_worker(nworkers + i);
  62. }
  63. static void parse_args(int argc, char **argv, int *force, int *info, char **worker_type)
  64. {
  65. int i;
  66. if (argc == 1)
  67. return;
  68. for (i = 1; i < argc; i++)
  69. {
  70. if (strncmp(argv[i], "--force", 7) == 0 || strncmp(argv[i], "-f", 2) == 0)
  71. {
  72. *force = 1;
  73. }
  74. else if (strncmp(argv[i], "--info", 6) == 0 || strncmp(argv[i], "-i", 2) == 0)
  75. {
  76. *info = 1;
  77. }
  78. else if (strncmp(argv[i], "--help", 6) == 0 || strncmp(argv[i], "-h", 2) == 0)
  79. {
  80. usage();
  81. exit(EXIT_FAILURE);
  82. }
  83. else if (strncmp(argv[i], "--version", 9) == 0 || strncmp(argv[i], "-v", 2) == 0)
  84. {
  85. fputs(PROGNAME " (" PACKAGE_NAME ") " PACKAGE_VERSION "\n", stderr);
  86. exit(EXIT_FAILURE);
  87. }
  88. else if (strncmp(argv[i], "--worker", 8) == 0 || strncmp(argv[i], "-w", 2) == 0)
  89. {
  90. *worker_type = strdup(argv[++i]);
  91. }
  92. else
  93. {
  94. fprintf(stderr, "Unknown arg %s\n", argv[1]);
  95. usage();
  96. exit(EXIT_FAILURE);
  97. }
  98. }
  99. }
  100. int main(int argc, char **argv)
  101. {
  102. int ret;
  103. int force = 0;
  104. int info = 0;
  105. char *worker_type = NULL;
  106. struct starpu_conf conf;
  107. parse_args(argc, argv, &force, &info, &worker_type);
  108. starpu_conf_init(&conf);
  109. if (force)
  110. conf.bus_calibrate = 1;
  111. /* Even if starpu_init returns -ENODEV, we should go on : we will just
  112. * print that we found no device. */
  113. ret = starpu_init(&conf);
  114. if (ret != 0 && ret != -ENODEV)
  115. {
  116. return ret;
  117. }
  118. if (info)
  119. {
  120. starpu_bus_print_filenames(stdout);
  121. starpu_shutdown();
  122. return 0;
  123. }
  124. if (worker_type)
  125. {
  126. if (strcmp(worker_type, "CPU") == 0)
  127. starpu_worker_display_names(stdout, STARPU_CPU_WORKER);
  128. else if (strcmp(worker_type, "CUDA") == 0)
  129. starpu_worker_display_names(stdout, STARPU_CUDA_WORKER);
  130. else if (strcmp(worker_type, "OpenCL") == 0)
  131. starpu_worker_display_names(stdout, STARPU_OPENCL_WORKER);
  132. #ifdef STARPU_USE_MPI_MASTER_SLAVE
  133. else if (strcmp(worker_type, "MPI_MS") == 0)
  134. starpu_worker_display_names(stdout, STARPU_MPI_MS_WORKER);
  135. #endif
  136. else
  137. fprintf(stderr, "Unknown worker type '%s'\n", worker_type);
  138. starpu_shutdown();
  139. return 0;
  140. }
  141. fprintf(stdout, "StarPU has found :\n");
  142. starpu_worker_display_names(stdout, STARPU_CPU_WORKER);
  143. starpu_worker_display_names(stdout, STARPU_CUDA_WORKER);
  144. starpu_worker_display_names(stdout, STARPU_OPENCL_WORKER);
  145. #ifdef STARPU_USE_MPI_MASTER_SLAVE
  146. starpu_worker_display_names(stdout, STARPU_MPI_MS_WORKER);
  147. #endif
  148. display_all_combined_workers();
  149. if (ret != -ENODEV)
  150. {
  151. fprintf(stdout, "\ntopology ... (hwloc logical indexes)\n");
  152. starpu_topology_print(stdout);
  153. fprintf(stdout, "\nbandwidth (MB/s) and latency (us)...\n");
  154. starpu_bus_print_bandwidth(stdout);
  155. starpu_shutdown();
  156. }
  157. return 0;
  158. }