diff --git a/amdsmi_cli/amdsmi_commands.py b/amdsmi_cli/amdsmi_commands.py index 027ab4212a..79ce0ec9a5 100644 --- a/amdsmi_cli/amdsmi_commands.py +++ b/amdsmi_cli/amdsmi_commands.py @@ -828,22 +828,32 @@ class AMDSMICommands(): try: cpu_set = amdsmi_interface.amdsmi_get_cpu_affinity_with_scope(args.gpu, amdsmi_interface.AmdSmiAffinityScope.NUMA_SCOPE) + cpu_set = [f"{cpus:016X}" for cpus in cpu_set] + cpu_set = {f'cpu_list_{i}': f"{cpus}" for i, cpus in enumerate(cpu_set)} + bitmask_ranges = self.helpers.get_bitmask_ranges(cpu_set) + cpu_affinity = {} + + for key in cpu_set: + cpu_affinity[key] = { + "bitmask": cpu_set[key], + "cpu_cores_affinity" : bitmask_ranges[key] + } + except amdsmi_exception.AmdSmiLibraryException as e: - cpu_set = [] - cpu_set.append(-1) + cpu_affinity = "N/A" logging.debug("Failed to get cpu affinity for gpu %s | %s", gpu_id, e.get_error_info()) try: cpusockets = amdsmi_interface.amdsmi_get_cpu_affinity_with_scope(args.gpu, amdsmi_interface.AmdSmiAffinityScope.SOCKET_SCOPE) + cpusockets = {f'socket_{i}': socket for i, socket in enumerate(set(cpusockets))} except amdsmi_exception.AmdSmiLibraryException as e: - cpusockets = [] - cpusockets.append(-1) + cpusockets = {} logging.debug("Failed to get socket affinity for gpu %s | %s", gpu_id, e.get_error_info()) - static_dict['numa'] = {'node' : numa_node_number, + static_dict['numa'] = { 'node' : numa_node_number, 'affinity' : numa_affinity, - 'CPU affinity' : [hex(cpus) for cpus in cpu_set], - 'Socket affinity' : [socket for socket in set(cpusockets)]} + 'cpu_affinity' : cpu_affinity, + 'socket_affinity' : cpusockets if cpusockets else "N/A"} if args.vram: vram_info_dict = {"type" : "N/A", "vendor" : "N/A", diff --git a/amdsmi_cli/amdsmi_helpers.py b/amdsmi_cli/amdsmi_helpers.py index 3c4b2483b0..b98638b507 100755 --- a/amdsmi_cli/amdsmi_helpers.py +++ b/amdsmi_cli/amdsmi_helpers.py @@ -1396,3 +1396,36 @@ class AMDSMIHelpers(): break else: self.display_cper_files_generated(entries, device_handle, args.folder) + + def get_bitmask_ranges(self, bitmask_dict): + ranges = {} + #start index of the first bitmask + current_start = 0 + + for cpu, bitmask in bitmask_dict.items(): + # Convert the bitmask to a binary string + binary_str = bin(int(bitmask, 16))[2:].zfill(64) + + binary_str = binary_str[::-1] + start = 0 + end = len(binary_str) - 1 + # Find the range of set bits + start_b = binary_str.find('1') + end_b = binary_str.rfind('1') + + start_setbit = start_b + current_start + end_setbit = end_b + current_start + + # Calculate the actual bit positions + end_bit = current_start + end + + # Update the start index for the next bitmask + current_start = end_bit + 1 + + # Store the range in the dictionary + if start_b == -1 and end_b == -1: + ranges[cpu] = "N/A" + else: + ranges[cpu] = f"{start_setbit}-{end_setbit}" + + return ranges