starpu_machine_display.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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)
  60. {
  61. if (argc == 1)
  62. return;
  63. if (argc > 2 || /* Argc should be either 1 or 2 */
  64. strncmp(argv[1], "--help", 6) == 0 ||
  65. strncmp(argv[1], "-h", 2) == 0)
  66. {
  67. (void) fprintf(stderr, "\
  68. Show the processing units that StarPU can use, and the \
  69. bandwitdh measured between the memory nodes. \n\
  70. \n\
  71. Usage: %s [OPTION] \n\
  72. \n\
  73. Options: \n\
  74. -h, --help display this help and exit \n\
  75. -v, --version output version information and exit \n\
  76. \n\
  77. Report bugs to <" PACKAGE_BUGREPORT ">.",
  78. PROGNAME);
  79. }
  80. else if (strncmp(argv[1], "--version", 9) == 0 ||
  81. strncmp(argv[1], "-v", 2) == 0)
  82. {
  83. (void) fprintf(stderr, "%s %d.%d\n",
  84. PROGNAME, STARPU_MAJOR_VERSION, STARPU_MINOR_VERSION);
  85. }
  86. else
  87. {
  88. fprintf(stderr, "Unknown arg %s\n", argv[1]);
  89. }
  90. exit(EXIT_FAILURE);
  91. }
  92. int main(int argc, char **argv)
  93. {
  94. parse_args(argc, argv);
  95. /* Even if starpu_init returns -ENODEV, we should go on : we will just
  96. * print that we found no device. */
  97. (void) starpu_init(NULL);
  98. unsigned ncpu = starpu_cpu_worker_get_count();
  99. unsigned ncuda = starpu_cuda_worker_get_count();
  100. unsigned nopencl = starpu_opencl_worker_get_count();
  101. fprintf(stdout, "StarPU has found :\n");
  102. fprintf(stdout, "\t%d CPU cores\n", ncpu);
  103. display_worker_names(STARPU_CPU_WORKER);
  104. fprintf(stdout, "\t%d CUDA devices\n", ncuda);
  105. display_worker_names(STARPU_CUDA_WORKER);
  106. fprintf(stdout, "\t%d OpenCL devices\n", nopencl);
  107. display_worker_names(STARPU_OPENCL_WORKER);
  108. display_all_combined_workers();
  109. starpu_bus_print_bandwidth(stdout);
  110. starpu_shutdown();
  111. return 0;
  112. }