02_list_units.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2017-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  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. /* This example lists the CPU and device units detected and managed by
  17. * StarPURM. */
  18. #include <stdio.h>
  19. #include <starpurm.h>
  20. int main(int argc, char *argv[])
  21. {
  22. int ids[3];
  23. int i;
  24. starpurm_initialize();
  25. ids[0] = starpurm_get_device_type_id("cpu");
  26. ids[1] = starpurm_get_device_type_id("opencl");
  27. ids[2] = starpurm_get_device_type_id("cuda");
  28. for (i=0; i<3; i++)
  29. {
  30. const int id = ids[i];
  31. if (id == -1)
  32. continue;
  33. const int nb_units = starpurm_get_nb_devices_by_type(id);
  34. printf("%s: %d units\n", starpurm_get_device_type_name(id), nb_units);
  35. int j;
  36. for (j=0; j<nb_units; j++)
  37. {
  38. hwloc_cpuset_t cpuset = starpurm_get_device_worker_cpuset(id, j);
  39. int strl = hwloc_bitmap_snprintf(NULL, 0, cpuset);
  40. char str[strl+1];
  41. hwloc_bitmap_snprintf(str, strl+1, cpuset);
  42. printf(". %d: %s\n", j, str);
  43. hwloc_bitmap_free(cpuset);
  44. }
  45. }
  46. starpurm_shutdown();
  47. return 0;
  48. }