Analysis report block based filtering for profiling (#566)
* Analysis report block based filtering for profiling
* Profiling mode changes
- `-b` option now additionally accepts metric id(s), similar to `-b` option in analyze mode (e.g. 6, 6.2, 6.23)
- Only counters mentioned in the selected analysis report blocks will be collected
- Add parsing logic to identify hardware counters from analysis report blocks
- Add filtering logic to only write filtered counters in perfmon files
- Log not collected counters in one line
- `--list-metrics` option added in profile mode to list possible metric id(s) similar to analyze mode
- Write arguments provided during profiling in profiling_configuration.yaml file
* Analysis mode changes
- During analysis mode, only show report blocks selected during profiling
- If `-b` option is provided in analysis mode, then follow provided filters
- Do not show empty tables in analysis report
* Miscellaneous changes
- Update CHANGELOG
- Add test cases
- Instruction mix report block filter
- Instruction mix and Memory chart report block filter
- Instruction mix report block filter and CPC hardware block filter
- TA hardware block filter
- --list-metrics in profile mode should work
- Move binary handler fixtures to conftest.py to avoid importing
fixtures
- cmake file in tests directory has been updated to compile sample/vmem.hip for testing
* Public documentation changes
- Use the term "Hardware report block" instead of "Hardware block"
- Add documentation for "--list-metrics" option in profile mode
- Add example of filtering by hardware report block such as instruction
mix and wavefront launch statistics
- Add deprecation warning for hardware component (sq, tcc) based filtering
This commit is contained in:
zatwierdzone przez
GitHub
rodzic
0aefd15b7b
commit
55cf0e237e
@@ -13,3 +13,8 @@ set(VCOPY_SOURCES ../sample/vcopy.cpp)
|
||||
set_source_files_properties(${VCOPY_SOURCES} PROPERTIES LANGUAGE HIP)
|
||||
add_executable(vcopy ${VCOPY_SOURCES})
|
||||
set_target_properties(vcopy PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/tests)
|
||||
|
||||
set(VMEM_SOURCES ../sample/vmem.hip)
|
||||
set_source_files_properties(${VMEM_SOURCES} PROPERTIES LANGUAGE HIP)
|
||||
add_executable(vmem ${VMEM_SOURCES})
|
||||
set_target_properties(vmem PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/tests)
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import subprocess
|
||||
from importlib.machinery import SourceFileLoader
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
rocprof_compute = SourceFileLoader("rocprof-compute", "src/rocprof-compute").load_module()
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption(
|
||||
@@ -8,3 +14,69 @@ def pytest_addoption(parser):
|
||||
default=False,
|
||||
help="Call standalone binary instead of main function during tests",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def binary_handler_profile_rocprof_compute(request):
|
||||
def _handler(config, workload_dir, options=[], check_success=True, roof=False):
|
||||
if request.config.getoption("--call-binary"):
|
||||
baseline_opts = [
|
||||
"build/rocprof-compute.bin",
|
||||
"profile",
|
||||
"-n",
|
||||
"app_1",
|
||||
"-VVV",
|
||||
]
|
||||
if not roof:
|
||||
baseline_opts.append("--no-roof")
|
||||
process = subprocess.run(
|
||||
baseline_opts
|
||||
+ options
|
||||
+ ["--path", workload_dir, "--"]
|
||||
+ config["app_1"],
|
||||
text=True,
|
||||
)
|
||||
# verify run status
|
||||
if check_success:
|
||||
assert process.returncode == 0
|
||||
return process.returncode
|
||||
else:
|
||||
baseline_opts = ["rocprof-compute", "profile", "-n", "app_1", "-VVV"]
|
||||
if not roof:
|
||||
baseline_opts.append("--no-roof")
|
||||
with pytest.raises(SystemExit) as e:
|
||||
with patch(
|
||||
"sys.argv",
|
||||
baseline_opts
|
||||
+ options
|
||||
+ ["--path", workload_dir, "--"]
|
||||
+ config["app_1"],
|
||||
):
|
||||
rocprof_compute.main()
|
||||
# verify run status
|
||||
if check_success:
|
||||
assert e.value.code == 0
|
||||
return e.value.code
|
||||
|
||||
return _handler
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def binary_handler_analyze_rocprof_compute(request):
|
||||
def _handler(arguments):
|
||||
if request.config.getoption("--call-binary"):
|
||||
process = subprocess.run(
|
||||
["build/rocprof-compute.bin", *arguments],
|
||||
text=True,
|
||||
)
|
||||
return process.returncode
|
||||
else:
|
||||
with pytest.raises(SystemExit) as e:
|
||||
with patch(
|
||||
"sys.argv",
|
||||
["rocprof-compute", *arguments],
|
||||
):
|
||||
rocprof_compute.main()
|
||||
return e.value.code
|
||||
|
||||
return _handler
|
||||
|
||||
@@ -6,7 +6,6 @@ from unittest.mock import patch
|
||||
import pandas as pd
|
||||
import pytest
|
||||
import test_utils
|
||||
from test_utils import binary_handler_analyze_rocprof_compute
|
||||
|
||||
config = {}
|
||||
config["cleanup"] = True if "PYTEST_XDIST_WORKER_COUNT" in os.environ else False
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
import pandas as pd
|
||||
import pytest
|
||||
from test_utils import binary_handler_analyze_rocprof_compute
|
||||
|
||||
##################################################
|
||||
## Generated tests ##
|
||||
|
||||
@@ -11,7 +11,6 @@ from unittest.mock import patch
|
||||
import pandas as pd
|
||||
import pytest
|
||||
import test_utils
|
||||
from test_utils import binary_handler_profile_rocprof_compute
|
||||
|
||||
# Globals
|
||||
|
||||
@@ -1458,3 +1457,136 @@ def test_mem_levels_LDS(binary_handler_profile_rocprof_compute):
|
||||
)
|
||||
|
||||
test_utils.clean_output_dir(config["cleanup"], workload_dir)
|
||||
|
||||
|
||||
@pytest.mark.section
|
||||
def test_instmix_section(binary_handler_profile_rocprof_compute):
|
||||
options = ["--block", "10"]
|
||||
workload_dir = test_utils.get_output_dir()
|
||||
_ = binary_handler_profile_rocprof_compute(
|
||||
config, workload_dir, options, check_success=True, roof=False
|
||||
)
|
||||
|
||||
file_dict = test_utils.check_csv_files(workload_dir, 1, num_kernels)
|
||||
validate(
|
||||
inspect.stack()[0][3],
|
||||
workload_dir,
|
||||
file_dict,
|
||||
)
|
||||
|
||||
assert test_utils.check_file_pattern(
|
||||
"'10': metric_id", f"{workload_dir}/profiling_config.yaml"
|
||||
)
|
||||
assert test_utils.check_file_pattern(
|
||||
"SQ_INSTS_VALU_MFMA_F64", f"{workload_dir}/pmc_perf.csv"
|
||||
)
|
||||
test_utils.clean_output_dir(config["cleanup"], workload_dir)
|
||||
|
||||
|
||||
@pytest.mark.section
|
||||
def test_instmix_memchart_section(binary_handler_profile_rocprof_compute):
|
||||
options = ["--block", "10", "3"]
|
||||
workload_dir = test_utils.get_output_dir()
|
||||
_ = binary_handler_profile_rocprof_compute(
|
||||
config, workload_dir, options, check_success=True, roof=False
|
||||
)
|
||||
|
||||
file_dict = test_utils.check_csv_files(workload_dir, 1, num_kernels)
|
||||
validate(
|
||||
inspect.stack()[0][3],
|
||||
workload_dir,
|
||||
file_dict,
|
||||
)
|
||||
|
||||
assert test_utils.check_file_pattern(
|
||||
"'10': metric_id", f"{workload_dir}/profiling_config.yaml"
|
||||
)
|
||||
assert test_utils.check_file_pattern(
|
||||
"'3': metric_id", f"{workload_dir}/profiling_config.yaml"
|
||||
)
|
||||
assert test_utils.check_file_pattern(
|
||||
"SQ_INSTS_VALU_MFMA_F64", f"{workload_dir}/pmc_perf.csv"
|
||||
)
|
||||
assert test_utils.check_file_pattern(
|
||||
"SQC_TC_DATA_READ_REQ", f"{workload_dir}/pmc_perf.csv"
|
||||
)
|
||||
test_utils.clean_output_dir(config["cleanup"], workload_dir)
|
||||
|
||||
|
||||
@pytest.mark.section
|
||||
def test_instmix_section_TA_block(binary_handler_profile_rocprof_compute):
|
||||
options = ["--block", "10", "TA"]
|
||||
workload_dir = test_utils.get_output_dir()
|
||||
_ = binary_handler_profile_rocprof_compute(
|
||||
config, workload_dir, options, check_success=True, roof=False
|
||||
)
|
||||
|
||||
file_dict = test_utils.check_csv_files(workload_dir, 1, num_kernels)
|
||||
validate(
|
||||
inspect.stack()[0][3],
|
||||
workload_dir,
|
||||
file_dict,
|
||||
)
|
||||
|
||||
assert test_utils.check_file_pattern(
|
||||
"'10': metric_id", f"{workload_dir}/profiling_config.yaml"
|
||||
)
|
||||
assert test_utils.check_file_pattern(
|
||||
"TA: hardware_block", f"{workload_dir}/profiling_config.yaml"
|
||||
)
|
||||
assert test_utils.check_file_pattern(
|
||||
"TA_FLAT_WAVEFRONTS", f"{workload_dir}/pmc_perf.csv"
|
||||
)
|
||||
assert not test_utils.check_file_pattern(
|
||||
"SQC_TC_DATA_READ_REQ", f"{workload_dir}/pmc_perf.csv"
|
||||
)
|
||||
assert test_utils.check_file_pattern("", f"{workload_dir}/pmc_perf.csv")
|
||||
test_utils.clean_output_dir(config["cleanup"], workload_dir)
|
||||
|
||||
|
||||
@pytest.mark.section
|
||||
def test_instmix_section_global_write_kernel(binary_handler_profile_rocprof_compute):
|
||||
options = ["-k", "global_write", "--block", "10"]
|
||||
custom_config = dict(config)
|
||||
custom_config["kernel_name_1"] = "global_write"
|
||||
custom_config["app_1"] = ["./tests/vmem"]
|
||||
num_kernels = 1
|
||||
|
||||
workload_dir = test_utils.get_output_dir()
|
||||
_ = binary_handler_profile_rocprof_compute(
|
||||
custom_config, workload_dir, options, check_success=True, roof=False
|
||||
)
|
||||
|
||||
file_dict = test_utils.check_csv_files(workload_dir, 1, num_kernels)
|
||||
validate(
|
||||
inspect.stack()[0][3],
|
||||
workload_dir,
|
||||
file_dict,
|
||||
)
|
||||
|
||||
assert test_utils.check_file_pattern(
|
||||
"'10': metric_id", f"{workload_dir}/profiling_config.yaml"
|
||||
)
|
||||
assert test_utils.check_file_pattern(
|
||||
"- global_write", f"{workload_dir}/profiling_config.yaml"
|
||||
)
|
||||
assert test_utils.check_file_pattern(
|
||||
"SQ_INSTS_VALU_MFMA_F64", f"{workload_dir}/pmc_perf.csv"
|
||||
)
|
||||
assert test_utils.check_file_pattern("global_write", f"{workload_dir}/pmc_perf.csv")
|
||||
assert not test_utils.check_file_pattern(
|
||||
"global_read", f"{workload_dir}/pmc_perf.csv"
|
||||
)
|
||||
test_utils.clean_output_dir(config["cleanup"], workload_dir)
|
||||
|
||||
|
||||
@pytest.mark.section
|
||||
def test_list_metrics(binary_handler_profile_rocprof_compute):
|
||||
options = ["--list-metrics"]
|
||||
workload_dir = test_utils.get_output_dir()
|
||||
_ = binary_handler_profile_rocprof_compute(
|
||||
config, workload_dir, options, check_success=True, roof=False
|
||||
)
|
||||
# workload dir should be empty
|
||||
assert not os.listdir(workload_dir)
|
||||
test_utils.clean_output_dir(config["cleanup"], workload_dir)
|
||||
|
||||
+9
-72
@@ -25,16 +25,11 @@
|
||||
|
||||
import inspect
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
from importlib.machinery import SourceFileLoader
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
import pandas as pd
|
||||
import pytest
|
||||
|
||||
rocprof_compute = SourceFileLoader("rocprof-compute", "src/rocprof-compute").load_module()
|
||||
|
||||
|
||||
def check_resource_allocation():
|
||||
@@ -57,6 +52,14 @@ def check_resource_allocation():
|
||||
return
|
||||
|
||||
|
||||
def check_file_pattern(pattern, file_path):
|
||||
"""Check if the given pattern exists in the file"""
|
||||
content = ""
|
||||
with open(file_path) as f:
|
||||
content = f.read()
|
||||
return len(re.findall(pattern, content)) != 0
|
||||
|
||||
|
||||
def get_output_dir(suffix="_output", clean_existing=True):
|
||||
"""Provides a unique output directory based on the name of the calling test function with a suffix applied.
|
||||
|
||||
@@ -130,69 +133,3 @@ def check_csv_files(output_dir, num_devices, num_kernels):
|
||||
elif file.endswith(".pdf"):
|
||||
file_dict[file] = "pdf"
|
||||
return file_dict
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def binary_handler_profile_rocprof_compute(request):
|
||||
def _handler(config, workload_dir, options=[], check_success=True, roof=False):
|
||||
if request.config.getoption("--call-binary"):
|
||||
baseline_opts = [
|
||||
"build/rocprof-compute.bin",
|
||||
"profile",
|
||||
"-n",
|
||||
"app_1",
|
||||
"-VVV",
|
||||
]
|
||||
if not roof:
|
||||
baseline_opts.append("--no-roof")
|
||||
process = subprocess.run(
|
||||
baseline_opts
|
||||
+ options
|
||||
+ ["--path", workload_dir, "--"]
|
||||
+ config["app_1"],
|
||||
text=True,
|
||||
)
|
||||
# verify run status
|
||||
if check_success:
|
||||
assert process.returncode == 0
|
||||
return process.returncode
|
||||
else:
|
||||
baseline_opts = ["rocprof-compute", "profile", "-n", "app_1", "-VVV"]
|
||||
if not roof:
|
||||
baseline_opts.append("--no-roof")
|
||||
with pytest.raises(SystemExit) as e:
|
||||
with patch(
|
||||
"sys.argv",
|
||||
baseline_opts
|
||||
+ options
|
||||
+ ["--path", workload_dir, "--"]
|
||||
+ config["app_1"],
|
||||
):
|
||||
rocprof_compute.main()
|
||||
# verify run status
|
||||
if check_success:
|
||||
assert e.value.code == 0
|
||||
return e.value.code
|
||||
|
||||
return _handler
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def binary_handler_analyze_rocprof_compute(request):
|
||||
def _handler(arguments):
|
||||
if request.config.getoption("--call-binary"):
|
||||
process = subprocess.run(
|
||||
["build/rocprof-compute.bin", *arguments],
|
||||
text=True,
|
||||
)
|
||||
return process.returncode
|
||||
else:
|
||||
with pytest.raises(SystemExit) as e:
|
||||
with patch(
|
||||
"sys.argv",
|
||||
["rocprof-compute", *arguments],
|
||||
):
|
||||
rocprof_compute.main()
|
||||
return e.value.code
|
||||
|
||||
return _handler
|
||||
|
||||
Reference in New Issue
Block a user