[rocprofv3] signal handler fix (#332)

* rocprofv3: LD_PRELOAD for signal and sigaction

- wrappers around `signal` and `sigaction` to prevent applications which install signal handlers to replace the rocprofv3 signal handlers
- minor tweaks to buffer sizes (use page_size instead of
KiB)

* [DO NOT COMMIT] extra logging

* Switch git submodule url for perfetto

- use GitHub URL as this is more accessible

* Update ring_buffer<Tp>

- account for alignment padding

* Update buffered_output

- track number of bytes stored
- add nullptr checks

* Update tmp_file_buffer

- track number of bytes
- read_tmp_file does not create tmp file if it does not already exist

* Update tmp_file

- add exists member function for checking whether temporary file already exists
- tweak remove() implementation

* Update config.hpp

- add option to enable/disable signal handlers
- add option for minimum_output_bytes

* Make signal, sigaction functions visible

* rocprofv3 tool updates

- chained signals
- override the signal handler(s) installed by the application
- improve cleanup of temporary files
- support minimum output bytes

* Add commandline support

* fixing test

* minor fix

* minor fix

* fix clang issue

* fix

* Adding docs

* review comments

* review changes

* review

* YUV pulldown additions to rocdecode

* More rocdecode changes

---------

Co-authored-by: Jonathan R. Madsen <jonathanrmadsen@gmail.com>
Co-authored-by: Jonathan R. Madsen <Jonathan.Madsen@amd.com>
Co-authored-by: Benjamin Welton <bewelton@amd.com>
This commit is contained in:
authored and GitHub committed 2025-04-17 21:10:52 -07:00
1 parent 46818b0167
commit 87badfbd15
22 files changed
+866 -107

No files matched your search

+8
Vedi File
@@ -274,6 +274,14 @@ GetSurfaceStrideInternal(rocDecVideoSurfaceFormat surface_format,
*pitch = align(width, 128) * 2;
*vstride = align(height, 16);
break;
case rocDecVideoSurfaceFormat_YUV422:
*pitch = align(width, 256);
*vstride = align(height, 16);
break;
case rocDecVideoSurfaceFormat_YUV422_16Bit:
*pitch = align(width, 128) * 2;
*vstride = align(height, 16);
break;
}
return;
}
+10
Vedi File
@@ -94,8 +94,11 @@ GetChromaPlaneCount(rocDecVideoSurfaceFormat surface_format)
{
case rocDecVideoSurfaceFormat_NV12:
case rocDecVideoSurfaceFormat_P016: num_planes = 1; break;
// All YUV formats have 2 planes (to my knowledge).
case rocDecVideoSurfaceFormat_YUV444:
case rocDecVideoSurfaceFormat_YUV444_16Bit: num_planes = 2; break;
case rocDecVideoSurfaceFormat_YUV422:
case rocDecVideoSurfaceFormat_YUV422_16Bit:
case rocDecVideoSurfaceFormat_YUV420:
case rocDecVideoSurfaceFormat_YUV420_16Bit: num_planes = 2; break;
}
@@ -109,10 +112,17 @@ GetChromaHeightFactor(rocDecVideoSurfaceFormat surface_format)
float factor = 0.5;
switch(surface_format)
{
// NV12 and P016 have 1/2 vertical resolution, 1/2 horizontal resolution
// (different 420 sampling techniques across a single plane)
case rocDecVideoSurfaceFormat_NV12:
case rocDecVideoSurfaceFormat_P016:
// 420 pulldown has 1/2 vertical resolution, 1/2 horizontal resolution
case rocDecVideoSurfaceFormat_YUV420:
case rocDecVideoSurfaceFormat_YUV420_16Bit: factor = 0.5; break;
// 422 pulldown has full vertical resolution, 1/2 horizontal resolution
case rocDecVideoSurfaceFormat_YUV422:
case rocDecVideoSurfaceFormat_YUV422_16Bit:
// 444 pulldown has full vertical and horizontal resolution
case rocDecVideoSurfaceFormat_YUV444:
case rocDecVideoSurfaceFormat_YUV444_16Bit: factor = 1.0; break;
}
+1 -1
Vedi File
@@ -100,7 +100,7 @@ if(NOT TARGET rocprofiler-sdk::rocprofiler-sdk-perfetto)
# perfetto
fetchcontent_declare(
perfetto
GIT_REPOSITORY https://android.googlesource.com/platform/external/perfetto
GIT_REPOSITORY https://github.com/google/perfetto
GIT_TAG v44.0
SOURCE_DIR ${PROJECT_BINARY_DIR}/external/perfetto BINARY_DIR
${PROJECT_BINARY_DIR}/external/build/perfetto-build SUBBUILD_DIR
+1
Vedi File
@@ -44,3 +44,4 @@ endif()
add_subdirectory(hip-stream-display)
add_subdirectory(agent-index)
add_subdirectory(negate-aggregate-tracing-options)
add_subdirectory(minimum-bytes)
@@ -0,0 +1,49 @@
#
# rocprofv3 tool test
#
cmake_minimum_required(VERSION 3.21.0 FATAL_ERROR)
project(
rocprofiler-sdk-tests-rocprofv3-minimum-bytes
LANGUAGES CXX
VERSION 0.0.0)
find_package(rocprofiler-sdk REQUIRED)
rocprofiler_configure_pytest_files(CONFIG pytest.ini COPY validate.py conftest.py
input.json)
# pmc2
add_test(
NAME rocprofv3-test-minimum-bytes-execute
COMMAND
$<TARGET_FILE:rocprofiler-sdk::rocprofv3> -i
${CMAKE_CURRENT_BINARY_DIR}/input.json --output-format csv json pftrace -d
${CMAKE_CURRENT_BINARY_DIR}/%argt%-kernel-trace -o out --
$<TARGET_FILE:simple-transpose>)
string(REPLACE "LD_PRELOAD=" "ROCPROF_PRELOAD=" PRELOAD_ENV
"${ROCPROFILER_MEMCHECK_PRELOAD_ENV}")
set(cc-env-pmc2 "${PRELOAD_ENV}")
set_tests_properties(
rocprofv3-test-minimum-bytes-execute
PROPERTIES TIMEOUT 45 LABELS "integration-tests" ENVIRONMENT "${cc-env-pmc2}"
FAIL_REGULAR_EXPRESSION "${ROCPROFILER_DEFAULT_FAIL_REGEX}")
add_test(
NAME rocprofv3-test-minimum-bytes-validate
COMMAND
${Python3_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/validate.py --trace-input-csv
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-kernel-trace/out*.csv
--trace-input-json
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-kernel-trace/out_results.json
--trace-input-pftrace
${CMAKE_CURRENT_BINARY_DIR}/simple-transpose-kernel-trace/out_results.pftrace)
set_tests_properties(
rocprofv3-test-minimum-bytes-validate
PROPERTIES TIMEOUT 45 LABELS "integration-tests" DEPENDS
"rocprofv3-test-minimum-bytes-execute" FAIL_REGULAR_EXPRESSION
"${ROCPROFILER_DEFAULT_FAIL_REGEX}")
@@ -0,0 +1,69 @@
#!/usr/bin/env python3
# MIT License
#
# Copyright (c) 2024-2025 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import json
import pytest
import csv
from rocprofiler_sdk.pytest_utils.dotdict import dotdict
from rocprofiler_sdk.pytest_utils import collapse_dict_list
def pytest_addoption(parser):
parser.addoption(
"--trace-input-csv",
action="store",
help="Path to kernel trace CSV file.",
)
parser.addoption(
"--trace-input-json",
action="store",
help="Path to kernel trace JSON file.",
)
parser.addoption(
"--trace-input-pftrace",
action="store",
help="Path to kernel trace perfetto file.",
)
@pytest.fixture
def trace_data_csv(request):
filename = request.config.getoption("--trace-input-csv")
return filename
@pytest.fixture
def trace_data_json(request):
filename = request.config.getoption("--trace-input-json")
return filename
@pytest.fixture
def trace_data_pftrace(request):
filename = request.config.getoption("--trace-input-pftrace")
return filename
@@ -0,0 +1,9 @@
{
"jobs": [
{
"runtime_trace": true,
"minimum_output_data":1000000
}
]
}
@@ -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,41 @@
#!/usr/bin/env python3
# MIT License
#
# Copyright (c) 2024-2025 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import sys
import pytest
import os
import glob
def test_file_exists(trace_data_csv, trace_data_json, trace_data_pftrace):
csv_files = glob.glob(trace_data_csv)
# glob.glob will return empty list if there are no matching files
assert len(csv_files) == 0, f"CSV glob: {trace_data_csv}\nCSV files: {csv_files}"
assert os.path.exists(trace_data_json) is False
assert os.path.exists(trace_data_pftrace) is False
if __name__ == "__main__":
exit_code = pytest.main(["-x", __file__] + sys.argv[1:])
sys.exit(exit_code)