starpu_machine_display.c 4.2 KB

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