From 2a216ecbc1bc28e80f872c666198bf8430f3472f Mon Sep 17 00:00:00 2001 From: ywang103-amd Date: Sat, 23 Aug 2025 10:13:22 -0400 Subject: [PATCH] pc sampling unit tests (#194) --- projects/rocprofiler-compute/CMakeLists.txt | 8 ++ projects/rocprofiler-compute/pyproject.toml | 3 +- .../rocprofiler-compute/tests/CMakeLists.txt | 6 ++ .../tests/test_profile_general.py | 83 +++++++++++++++++++ .../rocprofiler-compute/tests/test_utils.py | 2 + 5 files changed, 101 insertions(+), 1 deletion(-) diff --git a/projects/rocprofiler-compute/CMakeLists.txt b/projects/rocprofiler-compute/CMakeLists.txt index 2ac590ae07..5755a8baae 100644 --- a/projects/rocprofiler-compute/CMakeLists.txt +++ b/projects/rocprofiler-compute/CMakeLists.txt @@ -244,6 +244,14 @@ add_test( ${PROJECT_SOURCE_DIR}/tests/test_profile_general.py WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) +add_test( + NAME test_profile_pc_sampling + COMMAND + ${Python3_EXECUTABLE} -m pytest -s -m pc_sampling + --junitxml=tests/test_profile_pc_sampling.xml ${COV_OPTION} + ${PROJECT_SOURCE_DIR}/tests/test_profile_general.py + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) + add_test( NAME test_profile_sets_func COMMAND diff --git a/projects/rocprofiler-compute/pyproject.toml b/projects/rocprofiler-compute/pyproject.toml index ba5f9467fc..b40f623a17 100644 --- a/projects/rocprofiler-compute/pyproject.toml +++ b/projects/rocprofiler-compute/pyproject.toml @@ -87,5 +87,6 @@ markers = [ "num_xcds_spec_class", "num_xcds_cli_output", "sets_func", - "sets_perf" + "sets_perf", + "pc_sampling", ] diff --git a/projects/rocprofiler-compute/tests/CMakeLists.txt b/projects/rocprofiler-compute/tests/CMakeLists.txt index 6914a18bd3..19978d8a99 100644 --- a/projects/rocprofiler-compute/tests/CMakeLists.txt +++ b/projects/rocprofiler-compute/tests/CMakeLists.txt @@ -30,3 +30,9 @@ set_source_files_properties(${VRAND_SOURCES} PROPERTIES LANGUAGE HIP) add_executable(vrandom_access ${VRAND_SOURCES}) set_target_properties(vrandom_access PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/tests) + +set(OCCUPANCY ../sample/occupancy.hip) +set_source_files_properties(${OCCUPANCY} PROPERTIES LANGUAGE HIP) +add_executable(occupancy ${OCCUPANCY}) +set_target_properties(occupancy PROPERTIES RUNTIME_OUTPUT_DIRECTORY + ${CMAKE_SOURCE_DIR}/tests) diff --git a/projects/rocprofiler-compute/tests/test_profile_general.py b/projects/rocprofiler-compute/tests/test_profile_general.py index 33dcd2f3c3..77045ec9de 100644 --- a/projects/rocprofiler-compute/tests/test_profile_general.py +++ b/projects/rocprofiler-compute/tests/test_profile_general.py @@ -60,6 +60,7 @@ CHIP_IDS = { config = {} config["kernel_name_1"] = "vecCopy" config["app_1"] = ["./tests/vcopy", "-n", "1048576", "-b", "256", "-i", "3"] +config["app_occupancy"] = ["./tests/occupancy"] config["cleanup"] = True config["COUNTER_LOGGING"] = False config["METRIC_COMPARE"] = False @@ -165,6 +166,24 @@ ROOF_ONLY_FILES = sorted([ "timestamps.csv", ]) +PC_SAMPLING_HOST_TRAP_FILES = sorted([ + "pmc_perf_0.csv", + "pmc_perf.csv", + "ps_file_agent_info.csv", + "ps_file_pc_sampling_host_trap.csv", + "ps_file_results.json", + "sysinfo.csv", +]) + +PC_SAMPLING_STOCHASTIC_FILES = sorted([ + "pmc_perf_0.csv", + "pmc_perf.csv", + "ps_file_agent_info.csv", + "ps_file_pc_sampling_stochastic.csv", + "ps_file_results.json", + "sysinfo.csv", +]) + METRIC_THRESHOLDS = { "2.1.12": {"absolute": 0, "relative": 8}, "3.1.1": {"absolute": 0, "relative": 10}, @@ -1658,6 +1677,70 @@ def test_comprehensive_error_paths(): assert "coll_level can not be None" in str(e) +@pytest.mark.pc_sampling +def test_pc_sampling_host_trap(binary_handler_profile_rocprof_compute): + if soc in ("MI100"): + assert True + return + + options = [ + "--block", + "21", + "--pc-sampling-method", + "host_trap", + "--pc-sampling-interval", + "1048576", + ] + workload_dir = test_utils.get_output_dir() + _ = binary_handler_profile_rocprof_compute( + config, + workload_dir, + options, + check_success=True, + roof=False, + app_name="app_occupancy", + ) + + file_dict = test_utils.check_csv_files(workload_dir, num_devices, num_kernels) + assert sorted(list(file_dict.keys())) == sorted(PC_SAMPLING_HOST_TRAP_FILES) + + validate(inspect.stack()[0][3], workload_dir, file_dict) + + test_utils.clean_output_dir(config["cleanup"], workload_dir) + + +@pytest.mark.pc_sampling +def test_pc_sampling_stochastic(binary_handler_profile_rocprof_compute): + if soc in ("MI100") or soc in ("MI200"): + assert True + return + + options = [ + "--block", + "21", + "--pc-sampling-method", + "stochastic", + "--pc-sampling-interval", + "1048576", + ] + workload_dir = test_utils.get_output_dir() + _ = binary_handler_profile_rocprof_compute( + config, + workload_dir, + options, + check_success=True, + roof=False, + app_name="app_occupancy", + ) + + file_dict = test_utils.check_csv_files(workload_dir, num_devices, num_kernels) + assert sorted(list(file_dict.keys())) == sorted(PC_SAMPLING_STOCHASTIC_FILES) + + validate(inspect.stack()[0][3], workload_dir, file_dict) + + test_utils.clean_output_dir(config["cleanup"], workload_dir) + + @pytest.mark.sets_func class TestSetsIntegration: def test_memory_throughput_set(self, binary_handler_profile_rocprof_compute): diff --git a/projects/rocprofiler-compute/tests/test_utils.py b/projects/rocprofiler-compute/tests/test_utils.py index dbeb35389e..1c2fe0e13e 100644 --- a/projects/rocprofiler-compute/tests/test_utils.py +++ b/projects/rocprofiler-compute/tests/test_utils.py @@ -162,6 +162,8 @@ def check_csv_files(output_dir, num_devices, num_kernels): assert len(file_dict[file].index) >= num_kernels elif file.endswith(".pdf"): file_dict[file] = "pdf" + elif file.endswith(".json"): + file_dict[file] = "json" return file_dict