starpu_machine_display.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 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. #define PROGNAME "starpu_machine_display"
  20. static void display_worker_names(enum starpu_archtype type)
  21. {
  22. unsigned nworkers = starpu_worker_get_count_by_type(type);
  23. int ids[nworkers];
  24. starpu_worker_get_ids_by_type(type, ids, nworkers);
  25. unsigned i;
  26. for (i = 0; i < nworkers; i++)
  27. {
  28. char name[256];
  29. starpu_worker_get_name(ids[i], name, 256);
  30. fprintf(stdout, "\t\t%s\n", name);
  31. }
  32. }
  33. static void display_combined_worker(unsigned workerid)
  34. {
  35. int worker_size;
  36. int *combined_workerid;
  37. starpu_combined_worker_get_description(workerid, &worker_size, &combined_workerid);
  38. fprintf(stdout, "\t\t");
  39. int i;
  40. for (i = 0; i < worker_size; i++)
  41. {
  42. char name[256];
  43. starpu_worker_get_name(combined_workerid[i], name, 256);
  44. fprintf(stdout, "%s\t", name);
  45. }
  46. fprintf(stdout, "\n");
  47. }
  48. static void display_all_combined_workers(void)
  49. {
  50. unsigned ncombined_workers = starpu_combined_worker_get_count();
  51. if (ncombined_workers == 0)
  52. return;
  53. unsigned nworkers = starpu_worker_get_count();
  54. fprintf(stdout, "\t%d Combined workers\n", ncombined_workers);
  55. unsigned i;
  56. for (i = 0; i < ncombined_workers; i++)
  57. display_combined_worker(nworkers + i);
  58. }
  59. static void parse_args(int argc, char **argv, int *force)
  60. {
  61. int i;
  62. if (argc == 1)
  63. return;
  64. for (i = 1; i < argc; i++)
  65. {
  66. if (strncmp(argv[i], "--force", 7) == 0 || strncmp(argv[i], "-f", 2) == 0)
  67. {
  68. *force = 1;
  69. }
  70. else if (strncmp(argv[i], "--help", 6) == 0 || strncmp(argv[i], "-h", 2) == 0)
  71. {
  72. (void) fprintf(stderr, "\
  73. Show the processing units that StarPU can use, and the \n \
  74. bandwitdh and affinity measured between the memory nodes. \n \
  75. \n \
  76. Usage: %s [OPTION] \n \
  77. \n \
  78. Options: \n \
  79. -h, --help display this help and exit \n \
  80. -v, --version output version information and exit \n \
  81. -f, --force force bus sampling \n \
  82. \n \
  83. Report bugs to <" PACKAGE_BUGREPORT ">.\n",
  84. PROGNAME);
  85. exit(EXIT_FAILURE);
  86. }
  87. else if (strncmp(argv[i], "--version", 9) == 0 || strncmp(argv[i], "-v", 2) == 0)
  88. {
  89. (void) fprintf(stderr, "%s %d.%d\n",
  90. PROGNAME, STARPU_MAJOR_VERSION, STARPU_MINOR_VERSION);
  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 force = 0;
  103. parse_args(argc, argv, &force);
  104. /* Even if starpu_init returns -ENODEV, we should go on : we will just
  105. * print that we found no device. */
  106. (void) starpu_init(NULL);
  107. if (force)
  108. {
  109. starpu_force_bus_sampling();
  110. }
  111. unsigned ncpu = starpu_cpu_worker_get_count();
  112. unsigned ncuda = starpu_cuda_worker_get_count();
  113. unsigned nopencl = starpu_opencl_worker_get_count();
  114. fprintf(stdout, "StarPU has found :\n");
  115. fprintf(stdout, "\t%d CPU cores\n", ncpu);
  116. display_worker_names(STARPU_CPU_WORKER);
  117. fprintf(stdout, "\t%d CUDA devices\n", ncuda);
  118. display_worker_names(STARPU_CUDA_WORKER);
  119. fprintf(stdout, "\t%d OpenCL devices\n", nopencl);
  120. display_worker_names(STARPU_OPENCL_WORKER);
  121. display_all_combined_workers();
  122. fprintf(stdout, "\nbandwidth ...\n");
  123. starpu_bus_print_bandwidth(stdout);
  124. fprintf(stdout, "\naffinity ...\n");
  125. starpu_bus_print_affinity(stdout);
  126. starpu_shutdown();
  127. return 0;
  128. }