diff options
author | Joshua Bakita <jbakita@cs.unc.edu> | 2024-11-26 10:30:57 -0500 |
---|---|---|
committer | Joshua Bakita <jbakita@cs.unc.edu> | 2024-11-26 10:30:57 -0500 |
commit | ebf2f07de91d9e341acc6df25e928e87b25b958d (patch) | |
tree | c25654dd929e3619c2233dea2bc43f33897010e9 | |
parent | 5029151978a20831558480ae052c98b7e528af95 (diff) |
Rewrite libsmctrl_test_gpc_info to output clearly and take a GPU ID
-rw-r--r-- | libsmctrl_test_gpc_info.c | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/libsmctrl_test_gpc_info.c b/libsmctrl_test_gpc_info.c index 5ef44b1..9b2b963 100644 --- a/libsmctrl_test_gpc_info.c +++ b/libsmctrl_test_gpc_info.c | |||
@@ -1,14 +1,35 @@ | |||
1 | // Copyright 2024 Joshua Bakita | ||
2 | #define _GNU_SOURCE | ||
3 | #include <error.h> | ||
4 | #include <errno.h> | ||
1 | #include <stdio.h> | 5 | #include <stdio.h> |
2 | #include <stdint.h> | 6 | #include <stdint.h> |
7 | #include <stdlib.h> | ||
8 | #include <string.h> | ||
9 | |||
3 | #include "libsmctrl.h" | 10 | #include "libsmctrl.h" |
4 | 11 | ||
5 | int main() { | 12 | int main(int argc, char** argv) { |
6 | uint32_t num_gpcs; | 13 | uint32_t num_gpcs = 0, num_tpcs = 0; |
7 | uint64_t* masks; | 14 | uint64_t* masks = NULL; |
8 | libsmctrl_get_gpc_info(&num_gpcs, &masks, 1); | 15 | int res; |
9 | printf("Num GPCs: %d\n", num_gpcs); | 16 | int gpu_id = 0; |
17 | // Optionally support specifying the GPU ID to query via an argument | ||
18 | // Important: This GPU ID must match the ID used by the nvdebug module. See | ||
19 | // the documentation on libsmctrl_get_gpc_info() for details. | ||
20 | if (argc > 2 || (argc == 2 && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")))) { | ||
21 | fprintf(stderr, "Usage: %s <nvdebug GPU ID>\n", argv[0]); | ||
22 | return 1; | ||
23 | } | ||
24 | if (argc > 1) | ||
25 | gpu_id = atoi(argv[1]); | ||
26 | if ((res = libsmctrl_get_gpc_info(&num_gpcs, &masks, gpu_id)) != 0) | ||
27 | error(1, res, "libsmctrl_get_gpc_info() failed"); | ||
28 | printf("%s: GPU%d has %d enabled GPCs.\n", program_invocation_name, gpu_id, num_gpcs); | ||
10 | for (int i = 0; i < num_gpcs; i++) { | 29 | for (int i = 0; i < num_gpcs; i++) { |
11 | printf("Mask of TPCs associated with GPC %d: %#018lx\n", i, masks[i]); | 30 | num_tpcs += __builtin_popcountl(masks[i]); |
31 | printf("%s: Mask of %d TPCs associated with GPC %d: %#018lx\n", program_invocation_name, __builtin_popcountl(masks[i]), i, masks[i]); | ||
12 | } | 32 | } |
33 | printf("%s: Total of %u enabled TPCs.\n", program_invocation_name, num_tpcs); | ||
13 | return 0; | 34 | return 0; |
14 | } | 35 | } |