starpu_machine_display.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 display_worker_names(enum starpu_worker_archtype type)
  22. {
  23. int nworkers = starpu_worker_get_count_by_type(type);
  24. if (!nworkers)
  25. return;
  26. STARPU_ASSERT(nworkers>0);
  27. int ids[nworkers];
  28. starpu_worker_get_ids_by_type(type, ids, nworkers);
  29. int i;
  30. for (i = 0; i < nworkers; i++)
  31. {
  32. char name[256];
  33. starpu_worker_get_name(ids[i], name, 256);
  34. fprintf(stdout, "\t\t%s\n", name);
  35. }
  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)
  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], "--help", 6) == 0 || strncmp(argv[i], "-h", 2) == 0)
  75. {
  76. (void) fprintf(stderr, "\
  77. Show the processing units that StarPU can use, and the \n \
  78. bandwitdh and affinity measured between the memory nodes. \n \
  79. \n \
  80. Usage: %s [OPTION] \n \
  81. \n \
  82. Options: \n \
  83. -h, --help display this help and exit \n \
  84. -v, --version output version information and exit \n \
  85. -f, --force force bus sampling and show measures \n \
  86. \n \
  87. Report bugs to <" PACKAGE_BUGREPORT ">.\n",
  88. PROGNAME);
  89. exit(EXIT_FAILURE);
  90. }
  91. else if (strncmp(argv[i], "--version", 9) == 0 || strncmp(argv[i], "-v", 2) == 0)
  92. {
  93. fputs(PROGNAME " (" PACKAGE_NAME ") " PACKAGE_VERSION "\n", stderr);
  94. exit(EXIT_FAILURE);
  95. }
  96. else
  97. {
  98. fprintf(stderr, "Unknown arg %s\n", argv[1]);
  99. exit(EXIT_FAILURE);
  100. }
  101. }
  102. }
  103. int main(int argc, char **argv)
  104. {
  105. int ret;
  106. int force = 0;
  107. struct starpu_conf conf;
  108. parse_args(argc, argv, &force);
  109. starpu_conf_init(&conf);
  110. if (force)
  111. conf.bus_calibrate = 1;
  112. /* Even if starpu_init returns -ENODEV, we should go on : we will just
  113. * print that we found no device. */
  114. ret = starpu_init(&conf);
  115. if (ret != 0 && ret != -ENODEV)
  116. {
  117. return ret;
  118. }
  119. unsigned ncpu = starpu_cpu_worker_get_count();
  120. unsigned ncuda = starpu_cuda_worker_get_count();
  121. unsigned nopencl = starpu_opencl_worker_get_count();
  122. #ifdef STARPU_USE_MIC
  123. unsigned nmicdevs = starpu_mic_device_get_count();
  124. unsigned nmiccores = starpu_mic_worker_get_count();
  125. #endif
  126. fprintf(stdout, "StarPU has found :\n");
  127. fprintf(stdout, "\t%u CPU threads\n", ncpu);
  128. display_worker_names(STARPU_CPU_WORKER);
  129. fprintf(stdout, "\t%u CUDA devices\n", ncuda);
  130. display_worker_names(STARPU_CUDA_WORKER);
  131. fprintf(stdout, "\t%u OpenCL devices\n", nopencl);
  132. display_worker_names(STARPU_OPENCL_WORKER);
  133. #ifdef STARPU_USE_MIC
  134. fprintf(stdout, "\t%d MIC cores (from %d devices)\n", nmiccores, nmicdevs);
  135. display_worker_names(STARPU_MIC_WORKER);
  136. #endif
  137. display_all_combined_workers();
  138. if (ret != -ENODEV)
  139. {
  140. fprintf(stdout, "\ntopology ...\n");
  141. starpu_topology_print(stdout);
  142. fprintf(stdout, "\nbandwidth and latency ...\n");
  143. starpu_bus_print_bandwidth(stdout);
  144. starpu_shutdown();
  145. }
  146. return 0;
  147. }