starpu_machine_display.c 4.2 KB

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