[rocprofiler-compute] Improve amdsmi interface (#2245)
* Improve amdsmi interface * Fix issue where max mem clock was being set as max gfx clock * Handle the case when all device handles might not be usable due to devices being hidden by ROCR and HIP environment variables * Fix get gpu vram size to return str in KB * Improve testing of amdsmi interface functions
This commit is contained in:
@@ -7719,21 +7719,22 @@ def test_amdsmi_ctx():
|
||||
amdsmi_shutdown_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_amdsmi_get_device_handle():
|
||||
from utils.amdsmi_interface import get_device_handle, import_amdsmi_module
|
||||
def test_amdsmi_get_device_handles():
|
||||
from utils.amdsmi_interface import get_device_handles, import_amdsmi_module
|
||||
|
||||
_ = import_amdsmi_module()
|
||||
|
||||
with mock.patch("amdsmi.amdsmi_get_processor_handles") as device_handles_mock:
|
||||
device_handles_mock.return_value = [12345]
|
||||
get_device_handle()
|
||||
handles = get_device_handles()
|
||||
assert handles[0] == 12345
|
||||
device_handles_mock.assert_called_once()
|
||||
|
||||
with mock.patch(
|
||||
"amdsmi.amdsmi_get_processor_handles", side_effect=Exception("Mock exception")
|
||||
) as device_handles_mock:
|
||||
handle = get_device_handle()
|
||||
assert handle is None
|
||||
handle = get_device_handles()
|
||||
assert len(handle) == 0
|
||||
|
||||
|
||||
def test_amdsmi_get_mem_max_clock():
|
||||
@@ -7741,12 +7742,18 @@ def test_amdsmi_get_mem_max_clock():
|
||||
|
||||
_ = import_amdsmi_module()
|
||||
|
||||
with mock.patch("amdsmi.amdsmi_get_processor_handles") as device_handles_mock:
|
||||
device_handles_mock.return_value = [12345]
|
||||
with mock.patch("utils.amdsmi_interface.get_device_handles") as device_handles_mock:
|
||||
device_handles_mock.return_value = [0, 4567]
|
||||
with mock.patch("amdsmi.amdsmi_get_clock_info") as mem_max_clock_mock:
|
||||
mem_max_clock_mock.return_value = {"max_clk": 100}
|
||||
|
||||
def side_effect(handle, *args, **kwargs):
|
||||
if handle == 0:
|
||||
raise Exception("Invalid handle: 0")
|
||||
return {"max_clk": 100}
|
||||
|
||||
mem_max_clock_mock.side_effect = side_effect
|
||||
clk = get_mem_max_clock()
|
||||
mem_max_clock_mock.assert_called_once()
|
||||
assert mem_max_clock_mock.call_count == 2
|
||||
assert clk == 100
|
||||
|
||||
|
||||
@@ -7755,7 +7762,7 @@ def test_amdsmi_get_gpu_model():
|
||||
|
||||
_ = import_amdsmi_module()
|
||||
|
||||
with mock.patch("amdsmi.amdsmi_get_processor_handles") as device_handles_mock:
|
||||
with mock.patch("utils.amdsmi_interface.get_device_handles") as device_handles_mock:
|
||||
device_handles_mock.return_value = [12345]
|
||||
with mock.patch("amdsmi.amdsmi_get_gpu_board_info") as device_name_mock:
|
||||
with mock.patch("amdsmi.amdsmi_get_gpu_asic_info") as asic_name_mock:
|
||||
@@ -7771,7 +7778,7 @@ def test_amdsmi_get_gpu_model():
|
||||
"amdsmi.amdsmi_get_gpu_board_info", side_effect=Exception("Mock exception")
|
||||
):
|
||||
model = get_gpu_model()
|
||||
assert model == "N/A"
|
||||
assert model == ("N/A", "N/A", "N/A")
|
||||
|
||||
|
||||
def test_amdsmi_get_gpu_vbios_part_number():
|
||||
@@ -7779,7 +7786,7 @@ def test_amdsmi_get_gpu_vbios_part_number():
|
||||
|
||||
_ = import_amdsmi_module()
|
||||
|
||||
with mock.patch("amdsmi.amdsmi_get_processor_handles") as device_handles_mock:
|
||||
with mock.patch("utils.amdsmi_interface.get_device_handles") as device_handles_mock:
|
||||
device_handles_mock.return_value = [12345]
|
||||
with mock.patch("amdsmi.amdsmi_get_gpu_vbios_info") as vbios_part_number_mock:
|
||||
vbios_part_number_mock.return_value = {
|
||||
@@ -7801,7 +7808,7 @@ def test_amdsmi_get_gpu_compute_partition():
|
||||
|
||||
_ = import_amdsmi_module()
|
||||
|
||||
with mock.patch("amdsmi.amdsmi_get_processor_handles") as device_handles_mock:
|
||||
with mock.patch("utils.amdsmi_interface.get_device_handles") as device_handles_mock:
|
||||
device_handles_mock.return_value = [12345]
|
||||
with mock.patch(
|
||||
"amdsmi.amdsmi_get_gpu_compute_partition"
|
||||
@@ -7824,7 +7831,7 @@ def test_amdsmi_get_gpu_memory_partition():
|
||||
|
||||
_ = import_amdsmi_module()
|
||||
|
||||
with mock.patch("amdsmi.amdsmi_get_processor_handles") as device_handles_mock:
|
||||
with mock.patch("utils.amdsmi_interface.get_device_handles") as device_handles_mock:
|
||||
device_handles_mock.return_value = [12345]
|
||||
with mock.patch(
|
||||
"amdsmi.amdsmi_get_gpu_memory_partition"
|
||||
|
||||
Reference in New Issue
Block a user