aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoshua Bakita <bakitajoshua@gmail.com>2023-03-15 18:33:32 -0400
committerJoshua Bakita <bakitajoshua@gmail.com>2023-03-15 18:33:32 -0400
commitd827c6c152c8dd52463f82ef11ccdfc66083a9db (patch)
tree642cc6684b1e8d026a088f7151dc522bc681b5ac
parent7db0d3088a6e25c7c64999a20267f55751571dee (diff)
Correct a sign-extension issue in libsmctrl_get_gpc_info()
This function would previously would yield invalid results for GPUs with more than 31 TPCs.
-rw-r--r--libsmctrl.c3
-rw-r--r--libsmctrl.h3
-rw-r--r--libsmctrl_test_gpc_info.c2
3 files changed, 6 insertions, 2 deletions
diff --git a/libsmctrl.c b/libsmctrl.c
index 69b19a1..640001a 100644
--- a/libsmctrl.c
+++ b/libsmctrl.c
@@ -281,6 +281,7 @@ static int read_int_procfile(char* filename, uint64_t* out) {
281} 281}
282 282
283static uint64_t tpc_mask_per_gpc_per_dev[16][12]; 283static uint64_t tpc_mask_per_gpc_per_dev[16][12];
284// Output mask is vtpc-indexed (virtual TPC)
284int libsmctrl_get_gpc_info(uint32_t* num_enabled_gpcs, uint64_t** tpcs_for_gpc, int dev) { 285int libsmctrl_get_gpc_info(uint32_t* num_enabled_gpcs, uint64_t** tpcs_for_gpc, int dev) {
285 uint32_t i, j, vtpc_idx = 0; 286 uint32_t i, j, vtpc_idx = 0;
286 uint64_t gpc_mask, num_tpc_per_gpc, max_gpcs, gpc_tpc_mask; 287 uint64_t gpc_mask, num_tpc_per_gpc, max_gpcs, gpc_tpc_mask;
@@ -322,7 +323,7 @@ int libsmctrl_get_gpc_info(uint32_t* num_enabled_gpcs, uint64_t** tpcs_for_gpc,
322 // Skip disabled TPCs 323 // Skip disabled TPCs
323 if ((1 << j) & gpc_tpc_mask) 324 if ((1 << j) & gpc_tpc_mask)
324 continue; 325 continue;
325 *tpc_mask |= (1 << vtpc_idx); 326 *tpc_mask |= (1ull << vtpc_idx);
326 vtpc_idx++; 327 vtpc_idx++;
327 } 328 }
328 } 329 }
diff --git a/libsmctrl.h b/libsmctrl.h
index 7be425d..f342afa 100644
--- a/libsmctrl.h
+++ b/libsmctrl.h
@@ -55,6 +55,9 @@ extern int libsmctrl_get_tpc_info(uint32_t* num_tpcs, int dev);
55// Get number of GPCs for devices number `dev`, and a GPC-indexed array 55// Get number of GPCs for devices number `dev`, and a GPC-indexed array
56// containing masks of which TPCs are associated with each GPC. 56// containing masks of which TPCs are associated with each GPC.
57// Note that the `nvdebug` module must be loaded to use this function. 57// Note that the `nvdebug` module must be loaded to use this function.
58// @param num_enabled_gpcs Location to store number of GPCs in
59// @param tpcs_for_gpc Pointer to store pointer to output buffer at
60// @return 0 on success, error code on error
58extern int libsmctrl_get_gpc_info(uint32_t* num_enabled_gpcs, uint64_t** tpcs_for_gpc, int dev); 61extern int libsmctrl_get_gpc_info(uint32_t* num_enabled_gpcs, uint64_t** tpcs_for_gpc, int dev);
59 62
60#ifdef __cplusplus 63#ifdef __cplusplus
diff --git a/libsmctrl_test_gpc_info.c b/libsmctrl_test_gpc_info.c
index 93bfc1e..5ef44b1 100644
--- a/libsmctrl_test_gpc_info.c
+++ b/libsmctrl_test_gpc_info.c
@@ -8,7 +8,7 @@ int main() {
8 libsmctrl_get_gpc_info(&num_gpcs, &masks, 1); 8 libsmctrl_get_gpc_info(&num_gpcs, &masks, 1);
9 printf("Num GPCs: %d\n", num_gpcs); 9 printf("Num GPCs: %d\n", num_gpcs);
10 for (int i = 0; i < num_gpcs; i++) { 10 for (int i = 0; i < num_gpcs; i++) {
11 printf("Mask of TPCs associated with GPC %d: %#lx\n", i, masks[i]); 11 printf("Mask of TPCs associated with GPC %d: %#018lx\n", i, masks[i]);
12 } 12 }
13 return 0; 13 return 0;
14} 14}