From ad070d94dbfab65f0cbc56a62d750a0f1a42b2e2 Mon Sep 17 00:00:00 2001 From: ywang103-amd Date: Thu, 27 Mar 2025 18:15:41 -0400 Subject: [PATCH] fix the wrong number of channels of TCC counters to put in pmc txt file (#633) [ROCm/rocprofiler-compute commit: 7c1f14123abc88e2f33bedc420f768547c832796] --- .../src/rocprof_compute_soc/soc_base.py | 13 +- .../rocprofiler-compute/src/utils/utils.py | 3 +- .../tests/test_profile_general.py | 172 +++++++++++------- 3 files changed, 117 insertions(+), 71 deletions(-) diff --git a/projects/rocprofiler-compute/src/rocprof_compute_soc/soc_base.py b/projects/rocprofiler-compute/src/rocprof_compute_soc/soc_base.py index 8a0a37fe31..c47d4f9346 100644 --- a/projects/rocprofiler-compute/src/rocprof_compute_soc/soc_base.py +++ b/projects/rocprofiler-compute/src/rocprof_compute_soc/soc_base.py @@ -255,6 +255,10 @@ class OmniSoC_Base: # Handle TCC channel counters: if hw_counter_matches has elements ending with '[' # Expand and interleve the TCC channel counters # e.g. TCC_HIT[0] TCC_ATOMIC[0] ... TCC_HIT[1] TCC_ATOMIC[1] ... + num_xcd_for_pmc_file = 1 + if using_v3(): + num_xcd_for_pmc_file = int(self._mspec.num_xcd) + for counter_name in counters.copy(): if counter_name.startswith("TCC") and counter_name.endswith("["): counters.remove(counter_name) @@ -262,9 +266,7 @@ class OmniSoC_Base: counters = counters.union( { f"{counter_name}[{i}]" - for i in range( - int(self._mspec.num_xcd) * int(self._mspec._l2_banks) - ) + for i in range(num_xcd_for_pmc_file * int(self._mspec._l2_banks)) } ) @@ -309,10 +311,7 @@ class OmniSoC_Base: if counter_name.startswith(tuple(filter_hardware_blocks)) } - if using_v3(): - # Counters not supported in rocprof v3 - counters = counters - {"TCC_BUBBLE"} - else: + if not using_v3(): # Counters not supported in rocprof v1 / v2 counters = counters - {"SQ_INSTS_VALU_MFMA_F8", "SQ_INSTS_VALU_MFMA_MOPS_F8"} diff --git a/projects/rocprofiler-compute/src/utils/utils.py b/projects/rocprofiler-compute/src/utils/utils.py index 70661aaa1b..483554fafe 100644 --- a/projects/rocprofiler-compute/src/utils/utils.py +++ b/projects/rocprofiler-compute/src/utils/utils.py @@ -451,6 +451,7 @@ def v3_counter_csv_to_v2_csv(counter_file, agent_info_filepath, converted_csv_fi ) ) if result["Agent_Id"].dtype == "object": + # Apply the function to the 'Agent_Id' column and store it as int64 try: result["Agent_Id"] = ( result["Agent_Id"] @@ -560,7 +561,7 @@ def run_prof( # standard rocprof options default_options = ["-i", fname] options = default_options + profiler_options - if path_counter_config_yaml.exists(): + if using_v3() and path_counter_config_yaml.exists(): options = ["-E", str(path_counter_config_yaml)] + options # set required env var for mi300 diff --git a/projects/rocprofiler-compute/tests/test_profile_general.py b/projects/rocprofiler-compute/tests/test_profile_general.py index 1f0af76791..212d58be21 100644 --- a/projects/rocprofiler-compute/tests/test_profile_general.py +++ b/projects/rocprofiler-compute/tests/test_profile_general.py @@ -49,7 +49,7 @@ DEFAULT_ABS_DIFF = 15 DEFAULT_REL_DIFF = 50 MAX_REOCCURING_COUNT = 28 -ALL_CSVS = sorted( +ALL_CSVS_MI100 = sorted( [ "SQ_IFETCH_LEVEL.csv", "SQ_INST_LEVEL_LDS.csv", @@ -62,10 +62,12 @@ ALL_CSVS = sorted( "pmc_perf_2.csv", "pmc_perf_3.csv", "pmc_perf_4.csv", + "pmc_perf_5.csv", "sysinfo.csv", "timestamps.csv", ] ) + ALL_CSVS_MI200 = sorted( [ "SQ_IFETCH_LEVEL.csv", @@ -484,7 +486,7 @@ def test_path(binary_handler_profile_rocprof_compute): file_dict = test_utils.check_csv_files(workload_dir, num_devices, num_kernels) if soc == "MI100": - assert sorted(list(file_dict.keys())) == ALL_CSVS + assert sorted(list(file_dict.keys())) == ALL_CSVS_MI100 elif soc == "MI200": assert sorted(list(file_dict.keys())) == sorted(ALL_CSVS_MI200) elif "MI300" in soc: @@ -499,28 +501,28 @@ def test_path(binary_handler_profile_rocprof_compute): @pytest.mark.misc -def test_kernel_names(binary_handler_profile_rocprof_compute): +def test_roof_kernel_names(binary_handler_profile_rocprof_compute): + if soc == "MI100": + # roofline is not supported on MI100 + assert True + # Do not continue testing + return + options = ["--device", "0", "--roof-only", "--kernel-names"] workload_dir = test_utils.get_output_dir() returncode = binary_handler_profile_rocprof_compute( config, workload_dir, options, check_success=False, roof=True ) - if soc == "MI100": - # assert that it did not run - assert returncode >= 1 - # Do not continue testing - return # assert successful run assert returncode == 0 - file_dict = test_utils.check_csv_files(workload_dir, 1, num_kernels) if soc == "MI200" or "MI300" in soc: assert sorted(list(file_dict.keys())) == sorted( ROOF_ONLY_FILES + ["kernelName_legend.pdf"] ) else: - assert sorted(list(file_dict.keys())) == ALL_CSVS + assert sorted(list(file_dict.keys())) == ALL_CSVS_MI100 validate( inspect.stack()[0][3], @@ -539,7 +541,7 @@ def test_device_filter(binary_handler_profile_rocprof_compute): file_dict = test_utils.check_csv_files(workload_dir, 1, num_kernels) if soc == "MI100": - assert sorted(list(file_dict.keys())) == ALL_CSVS + assert sorted(list(file_dict.keys())) == ALL_CSVS_MI100 elif soc == "MI200": assert sorted(list(file_dict.keys())) == sorted(ALL_CSVS_MI200) elif "MI300" in soc: @@ -567,7 +569,7 @@ def test_kernel(binary_handler_profile_rocprof_compute): file_dict = test_utils.check_csv_files(workload_dir, num_devices, num_kernels) if soc == "MI100": - assert sorted(list(file_dict.keys())) == ALL_CSVS + assert sorted(list(file_dict.keys())) == ALL_CSVS_MI100 elif soc == "MI200": assert sorted(list(file_dict.keys())) == sorted(ALL_CSVS_MI200) elif "MI300" in soc: @@ -749,11 +751,27 @@ def test_block_TCP(binary_handler_profile_rocprof_compute): "pmc_perf_6.csv", "pmc_perf_7.csv", "pmc_perf_8.csv", - "pmc_perf_9.csv", "sysinfo.csv", "timestamps.csv", ] + if soc == "MI100" or soc == "MI200": + expected_csvs = [ + "pmc_perf.csv", + "pmc_perf_0.csv", + "pmc_perf_1.csv", + "pmc_perf_2.csv", + "pmc_perf_3.csv", + "pmc_perf_4.csv", + "pmc_perf_5.csv", + "pmc_perf_6.csv", + "pmc_perf_7.csv", + "pmc_perf_8.csv", + "pmc_perf_9.csv", + "sysinfo.csv", + "timestamps.csv", + ] + assert sorted(list(file_dict.keys())) == sorted(expected_csvs) validate( @@ -782,10 +800,32 @@ def test_block_TCC(binary_handler_profile_rocprof_compute): "pmc_perf_5.csv", "pmc_perf_6.csv", "pmc_perf_7.csv", + "pmc_perf_8.csv", + "pmc_perf_9.csv", + "pmc_perf_10.csv", + "pmc_perf_11.csv", "sysinfo.csv", "timestamps.csv", ] + if soc == "MI100" or soc == "MI200": + expected_csvs = [ + "pmc_perf.csv", + "pmc_perf_0.csv", + "pmc_perf_1.csv", + "pmc_perf_2.csv", + "pmc_perf_3.csv", + "pmc_perf_4.csv", + "pmc_perf_5.csv", + "pmc_perf_6.csv", + "pmc_perf_7.csv", + "pmc_perf_8.csv", + "pmc_perf_9.csv", + "pmc_perf_10.csv", + "sysinfo.csv", + "timestamps.csv", + ] + assert sorted(list(file_dict.keys())) == sorted(expected_csvs) validate( @@ -1094,6 +1134,25 @@ def test_block_SQ_SPI_TA_TCC_CPF(binary_handler_profile_rocprof_compute): "sysinfo.csv", "timestamps.csv", ] + + if soc == "MI100": + expected_csvs = [ + "SQ_IFETCH_LEVEL.csv", + "SQ_INST_LEVEL_LDS.csv", + "SQ_INST_LEVEL_SMEM.csv", + "SQ_INST_LEVEL_VMEM.csv", + "SQ_LEVEL_WAVES.csv", + "pmc_perf.csv", + "pmc_perf_0.csv", + "pmc_perf_1.csv", + "pmc_perf_2.csv", + "pmc_perf_3.csv", + "pmc_perf_4.csv", + "pmc_perf_5.csv", + "sysinfo.csv", + "timestamps.csv", + ] + if soc == "MI200" or "MI300" in soc: expected_csvs = [ "SQ_IFETCH_LEVEL.csv", @@ -1132,7 +1191,7 @@ def test_dispatch_0(binary_handler_profile_rocprof_compute): file_dict = test_utils.check_csv_files(workload_dir, num_devices, 1) if soc == "MI100": - assert sorted(list(file_dict.keys())) == ALL_CSVS + assert sorted(list(file_dict.keys())) == ALL_CSVS_MI100 elif soc == "MI200": assert sorted(list(file_dict.keys())) == ALL_CSVS_MI200 elif "MI300" in soc: @@ -1162,7 +1221,7 @@ def test_dispatch_0_1(binary_handler_profile_rocprof_compute): file_dict = test_utils.check_csv_files(workload_dir, num_devices, 2) if soc == "MI100": - assert sorted(list(file_dict.keys())) == ALL_CSVS + assert sorted(list(file_dict.keys())) == ALL_CSVS_MI100 elif soc == "MI200": assert sorted(list(file_dict.keys())) == ALL_CSVS_MI200 elif "MI300" in soc: @@ -1189,7 +1248,7 @@ def test_dispatch_2(binary_handler_profile_rocprof_compute): file_dict = test_utils.check_csv_files(workload_dir, num_devices, 1) if soc == "MI100": - assert sorted(list(file_dict.keys())) == ALL_CSVS + assert sorted(list(file_dict.keys())) == ALL_CSVS_MI100 elif soc == "MI200": assert sorted(list(file_dict.keys())) == ALL_CSVS_MI200 elif "MI300" in soc: @@ -1219,7 +1278,7 @@ def test_join_type_grid(binary_handler_profile_rocprof_compute): file_dict = test_utils.check_csv_files(workload_dir, num_devices, num_kernels) if soc == "MI100": - assert sorted(list(file_dict.keys())) == ALL_CSVS + assert sorted(list(file_dict.keys())) == ALL_CSVS_MI100 elif soc == "MI200": assert sorted(list(file_dict.keys())) == ALL_CSVS_MI200 elif "MI300" in soc: @@ -1246,7 +1305,7 @@ def test_join_type_kernel(binary_handler_profile_rocprof_compute): file_dict = test_utils.check_csv_files(workload_dir, num_devices, num_kernels) if soc == "MI100": - assert sorted(list(file_dict.keys())) == ALL_CSVS + assert sorted(list(file_dict.keys())) == ALL_CSVS_MI100 elif soc == "MI200": assert sorted(list(file_dict.keys())) == ALL_CSVS_MI200 elif "MI300" in soc: @@ -1265,29 +1324,25 @@ def test_join_type_kernel(binary_handler_profile_rocprof_compute): @pytest.mark.sort -def test_sort_dispatches(binary_handler_profile_rocprof_compute): +def test_roof_sort_dispatches(binary_handler_profile_rocprof_compute): # only test 1 device for roofline + if soc == "MI100": + # roofline is not supported on MI100 + assert True + # Do not continue testing + return + options = ["--device", "0", "--roof-only", "--sort", "dispatches"] workload_dir = test_utils.get_output_dir() returncode = binary_handler_profile_rocprof_compute( config, workload_dir, options, check_success=False, roof=True ) - if soc == "MI100": - # assert that it did not run - assert returncode >= 1 - # Do not continue testing - return - # assert successful run assert returncode == 0 file_dict = test_utils.check_csv_files(workload_dir, 1, num_kernels) - - if soc == "MI200" or "MI300" in soc: - assert sorted(list(file_dict.keys())) == ROOF_ONLY_FILES - else: - assert sorted(list(file_dict.keys())) == ALL_CSVS + assert sorted(list(file_dict.keys())) == ROOF_ONLY_FILES validate( inspect.stack()[0][3], @@ -1299,28 +1354,25 @@ def test_sort_dispatches(binary_handler_profile_rocprof_compute): @pytest.mark.sort -def test_sort_kernels(binary_handler_profile_rocprof_compute): +def test_roof_sort_kernels(binary_handler_profile_rocprof_compute): # only test 1 device for roofline + if soc == "MI100": + # roofline is not supported on MI100 + assert True + # Do not continue testing + return + options = ["--device", "0", "--roof-only", "--sort", "kernels"] workload_dir = test_utils.get_output_dir() returncode = binary_handler_profile_rocprof_compute( config, workload_dir, options, check_success=False, roof=True ) - if soc == "MI100": - # assert that it did not run - assert returncode >= 1 - # Do not continue testing - return - # assert successful run assert returncode == 0 file_dict = test_utils.check_csv_files(workload_dir, 1, num_kernels) - if soc == "MI200" or "MI300" in soc: - assert sorted(list(file_dict.keys())) == ROOF_ONLY_FILES - else: - assert sorted(list(file_dict.keys())) == ALL_CSVS + assert sorted(list(file_dict.keys())) == ROOF_ONLY_FILES validate( inspect.stack()[0][3], @@ -1332,28 +1384,25 @@ def test_sort_kernels(binary_handler_profile_rocprof_compute): @pytest.mark.mem -def test_mem_levels_vL1D(binary_handler_profile_rocprof_compute): +def test_roof_mem_levels_vL1D(binary_handler_profile_rocprof_compute): # only test 1 device for roofline + if soc == "MI100": + # roofline is not supported on MI100 + assert True + # Do not continue testing + return + options = ["--device", "0", "--roof-only", "--mem-level", "vL1D"] workload_dir = test_utils.get_output_dir() returncode = binary_handler_profile_rocprof_compute( config, workload_dir, options, check_success=False, roof=True ) - if soc == "MI100": - # assert that it did not run - assert returncode >= 1 - # Do not continue testing - return - # assert successful run assert returncode == 0 file_dict = test_utils.check_csv_files(workload_dir, 1, num_kernels) - if soc == "MI200" or "MI300" in soc: - assert sorted(list(file_dict.keys())) == ROOF_ONLY_FILES - else: - assert sorted(list(file_dict.keys())) == ALL_CSVS + assert sorted(list(file_dict.keys())) == ROOF_ONLY_FILES validate( inspect.stack()[0][3], @@ -1365,28 +1414,25 @@ def test_mem_levels_vL1D(binary_handler_profile_rocprof_compute): @pytest.mark.mem -def test_mem_levels_LDS(binary_handler_profile_rocprof_compute): +def test_roof_mem_levels_LDS(binary_handler_profile_rocprof_compute): # only test 1 device for roofline + if soc == "MI100": + # roofline is not supported on MI100 + assert True + # Do not continue testing + return + options = ["--device", "0", "--roof-only", "--mem-level", "LDS"] workload_dir = test_utils.get_output_dir() returncode = binary_handler_profile_rocprof_compute( config, workload_dir, options, check_success=False, roof=True ) - if soc == "MI100": - # assert that it did not run - assert returncode >= 1 - # Do not continue testing - return - # assert successful run assert returncode == 0 file_dict = test_utils.check_csv_files(workload_dir, 1, num_kernels) - if soc == "MI200" or "MI300" in soc: - assert sorted(list(file_dict.keys())) == ROOF_ONLY_FILES - else: - assert sorted(list(file_dict.keys())) == ALL_CSVS + assert sorted(list(file_dict.keys())) == ROOF_ONLY_FILES validate( inspect.stack()[0][3],