Add rocprofiler_load_counter_definition (#1193)

Adds rocprofiler_load_counter_definition. This function allows a counter definition file to be supplied to rocprofiler-sdk directly. Takes in a string containing the counter definition YAML, its size (in bytes), and a flag value to state whether this is an append operation or not.

---------

Co-authored-by: Benjamin Welton <ben@amd.com>
Co-authored-by: Jonathan R. Madsen <jrmadsen@users.noreply.github.com>
Co-authored-by: usrihari123 <srihari.u@amd.com>

[ROCm/rocprofiler-sdk commit: 7ddc72ad45]
This commit is contained in:
Benjamin Welton
2024-11-22 01:55:47 -08:00
committed by GitHub
parent 5bea1772ea
commit 39db3e8a1d
22 changed files with 384 additions and 8 deletions
@@ -8,3 +8,4 @@ add_subdirectory(input3)
add_subdirectory(list_metrics)
add_subdirectory(kernel_filtering)
add_subdirectory(range_filtering)
add_subdirectory(extra_counters)
@@ -0,0 +1,47 @@
#
# rocprofv3 tool test
#
cmake_minimum_required(VERSION 3.21.0 FATAL_ERROR)
project(
rocprofiler-tests-counter-collection
LANGUAGES CXX
VERSION 0.0.0)
find_package(rocprofiler-sdk REQUIRED)
rocprofiler_configure_pytest_files(CONFIG pytest.ini COPY validate.py conftest.py
input.txt extra_counters.yaml)
# pmc1 with extra counters
add_test(
NAME rocprofv3-test-counter-collection-txt-pmc1-extra-counters-execute
COMMAND
$<TARGET_FILE:rocprofiler-sdk::rocprofv3> -i
${CMAKE_CURRENT_BINARY_DIR}/input.txt -E
${CMAKE_CURRENT_BINARY_DIR}/extra_counters.yaml -T -d
${CMAKE_CURRENT_BINARY_DIR}/out_counter_collection_1_extra -o pmc1
--output-format csv -- $<TARGET_FILE:vector-ops>)
string(REPLACE "LD_PRELOAD=" "ROCPROF_PRELOAD=" PRELOAD_ENV
"${ROCPROFILER_MEMCHECK_PRELOAD_ENV}")
set(cc-env-pmc1 "${PRELOAD_ENV}")
set_tests_properties(
rocprofv3-test-counter-collection-txt-pmc1-extra-counters-execute
PROPERTIES TIMEOUT 45 LABELS "integration-tests" ENVIRONMENT "${cc-env-pmc1}"
FAIL_REGULAR_EXPRESSION "${ROCPROFILER_DEFAULT_FAIL_REGEX}")
add_test(
NAME rocprofv3-test-counter-collection-pmc1-extra-counters-validate
COMMAND
${Python3_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/validate.py --input
${CMAKE_CURRENT_BINARY_DIR}/out_counter_collection_1_extra/pmc_1/pmc1_counter_collection.csv
)
set_tests_properties(
rocprofv3-test-counter-collection-pmc1-extra-counters-validate
PROPERTIES TIMEOUT 45 LABELS "integration-tests" DEPENDS
"rocprofv3-test-counter-collection-txt-pmc1-extra-counters-execute"
FAIL_REGULAR_EXPRESSION "${ROCPROFILER_DEFAULT_FAIL_REGEX}")
@@ -0,0 +1,31 @@
#!/usr/bin/env python3
import json
import pytest
import pandas as pd
from rocprofiler_sdk.pytest_utils.dotdict import dotdict
from rocprofiler_sdk.pytest_utils import collapse_dict_list
def pytest_addoption(parser):
parser.addoption("--input", action="store", help="Path to csv file.")
parser.addoption(
"--json-input",
action="store",
help="Path to JSON file.",
)
@pytest.fixture
def input_data(request):
filename = request.config.getoption("--input")
with open(filename, "r") as inp:
return pd.read_csv(inp)
@pytest.fixture
def json_data(request):
filename = request.config.getoption("--json-input")
with open(filename, "r") as inp:
return dotdict(collapse_dict_list(json.load(inp)))
@@ -0,0 +1,5 @@
TEST_YAML_LOAD:
architectures:
gfx942/gfx10/gfx1010/gfx1030/gfx1031/gfx11/gfx1032/gfx1102/gfx906/gfx1100/gfx1101/gfx908/gfx90a/gfx9:
expression: reduce(GRBM_GUI_ACTIVE,max)*CU_NUM
description: 'Unit: cycles'
@@ -0,0 +1 @@
pmc: TEST_YAML_LOAD
@@ -0,0 +1,5 @@
[pytest]
addopts = --durations=20 -rA -s -vv
testpaths = validate.py
pythonpath = @ROCPROFILER_SDK_TESTS_BINARY_DIR@/pytest-packages
@@ -0,0 +1,57 @@
#!/usr/bin/env python3
import sys
import pytest
import numpy as np
import pandas as pd
import re
kernel_list = sorted(
["addition_kernel", "subtract_kernel", "multiply_kernel", "divide_kernel"]
)
def unique(lst):
return list(set(lst))
def test_validate_counter_collection_pmc1_extra_counters(input_data: pd.DataFrame):
df = input_data
assert not df.empty
assert (df["Agent_Id"].astype(int).values > 0).all()
assert (df["Queue_Id"].astype(int).values > 0).all()
assert (df["Process_Id"].astype(int).values > 0).all()
assert len(df["Kernel_Name"]) > 0
counter_collection_pmc1_kernel_list = [
x
for x in sorted(df["Kernel_Name"].unique().tolist())
if not re.search(r"__amd_rocclr_.*", x)
]
assert kernel_list == counter_collection_pmc1_kernel_list
kernel_count = dict([[itr, 0] for itr in kernel_list])
assert len(kernel_count) == len(kernel_list)
for itr in df["Kernel_Name"]:
if re.search(r"__amd_rocclr_.*", itr):
continue
kernel_count[itr] += 1
kn_cnt = [itr for _, itr in kernel_count.items()]
assert min(kn_cnt) == max(kn_cnt) and len(unique(kn_cnt)) == 1
assert len(df["Counter_Value"]) > 0
assert df["Counter_Name"].str.contains("TEST_YAML_LOAD").all()
assert (df["Counter_Value"].astype(int).values > 0).all()
di_list = df["Dispatch_Id"].astype(int).values.tolist()
di_uniq = sorted(df["Dispatch_Id"].unique().tolist())
# make sure the dispatch ids are unique and ordered
di_expect = [idx + 1 for idx in range(len(di_list))]
assert di_expect == di_uniq
if __name__ == "__main__":
exit_code = pytest.main(["-x", __file__] + sys.argv[1:])
sys.exit(exit_code)