From d827c6c152c8dd52463f82ef11ccdfc66083a9db Mon Sep 17 00:00:00 2001 From: Joshua Bakita Date: Wed, 15 Mar 2023 18:33:32 -0400 Subject: 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. --- libsmctrl.c | 3 ++- libsmctrl.h | 3 +++ libsmctrl_test_gpc_info.c | 2 +- 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) { } static uint64_t tpc_mask_per_gpc_per_dev[16][12]; +// Output mask is vtpc-indexed (virtual TPC) int libsmctrl_get_gpc_info(uint32_t* num_enabled_gpcs, uint64_t** tpcs_for_gpc, int dev) { uint32_t i, j, vtpc_idx = 0; 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, // Skip disabled TPCs if ((1 << j) & gpc_tpc_mask) continue; - *tpc_mask |= (1 << vtpc_idx); + *tpc_mask |= (1ull << vtpc_idx); vtpc_idx++; } } 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); // Get number of GPCs for devices number `dev`, and a GPC-indexed array // containing masks of which TPCs are associated with each GPC. // Note that the `nvdebug` module must be loaded to use this function. +// @param num_enabled_gpcs Location to store number of GPCs in +// @param tpcs_for_gpc Pointer to store pointer to output buffer at +// @return 0 on success, error code on error extern int libsmctrl_get_gpc_info(uint32_t* num_enabled_gpcs, uint64_t** tpcs_for_gpc, int dev); #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() { libsmctrl_get_gpc_info(&num_gpcs, &masks, 1); printf("Num GPCs: %d\n", num_gpcs); for (int i = 0; i < num_gpcs; i++) { - printf("Mask of TPCs associated with GPC %d: %#lx\n", i, masks[i]); + printf("Mask of TPCs associated with GPC %d: %#018lx\n", i, masks[i]); } return 0; } -- cgit v1.2.2