starpu_machine_display.c 4.5 KB

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