Move rocprof on-demand repro to tests/ and convert to CMake

Conform to the new repo layout (master moved repros under tests/, e.g.
tests/cuda/repro/graph). Relocate examples/RocprofOnDemandRepro to
tests/rocprof/repro/on_demand and replace the hand-written Makefile with
a CMake build mirroring the CUDA repro: builds the HIP reproducer, wires
it as a ctest target, and optionally builds the check_gpu_ctx_name
verification helper against the Tracy server library.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Basil Milanich
2026-06-08 09:47:08 -05:00
parent 16cdf3d645
commit 030e699eb5
5 changed files with 78 additions and 36 deletions

View File

@@ -1,31 +0,0 @@
TRACY_PUBLIC := ../../public
HIPCC := /opt/rocm/bin/hipcc
CXX := g++
ROCM_LIB := /opt/rocm/lib
TRACY_SRCS := $(TRACY_PUBLIC)/TracyClient.cpp
ROCM_INC := /opt/rocm/include
INCLUDES := -I$(TRACY_PUBLIC) -I$(ROCM_INC)
LIBS := -L$(ROCM_LIB) -lrocprofiler-sdk -lpthread -ldl
# On-demand mode (the default for this repro) — profiling starts when
# a client connects, not at program launch.
DEFINES := -DTRACY_ENABLE -DTRACY_ON_DEMAND -DTRACY_ROCPROF -D__HIP_PLATFORM_AMD__
CXXFLAGS := -O2 $(DEFINES)
HIPCCFLAGS := -O2 $(DEFINES)
.PHONY: all clean
all: repro
repro: repro.o tracy_client.o
$(HIPCC) -o $@ $^ $(LIBS)
repro.o: repro.cpp
$(HIPCC) $(HIPCCFLAGS) $(INCLUDES) -c -o $@ $<
tracy_client.o: $(TRACY_SRCS)
$(CXX) $(CXXFLAGS) $(INCLUDES) -c -o $@ $<
clean:
rm -f repro repro.o tracy_client.o

View File

@@ -0,0 +1,63 @@
cmake_minimum_required(VERSION 3.21)
project(RocprofOnDemandReproTests LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(TRACY_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../.."
CACHE PATH "Root of the Tracy repository")
set(TRACY_PUBLIC "${TRACY_PATH}/public")
set(ROCM_PATH "/opt/rocm" CACHE PATH "Root of the ROCm installation")
# Locate hipcc so the HIP language can be enabled.
if(NOT DEFINED CMAKE_HIP_COMPILER)
find_program(CMAKE_HIP_COMPILER hipcc HINTS "${ROCM_PATH}/bin")
endif()
enable_language(HIP)
find_package(Threads REQUIRED)
# rocprofiler-sdk: prefer the packaged config, fall back to a bare library
# search under ROCM_PATH (mirrors the original Makefile's -lrocprofiler-sdk).
find_library(ROCPROFILER_SDK_LIB rocprofiler-sdk HINTS "${ROCM_PATH}/lib")
if(NOT ROCPROFILER_SDK_LIB)
message(FATAL_ERROR "Could not find librocprofiler-sdk under ${ROCM_PATH}/lib")
endif()
# Defines shared by the Tracy client and the reproducer. On-demand mode is
# the point of this repro: profiling starts when a client connects.
set(REPRO_DEFINES TRACY_ENABLE TRACY_ON_DEMAND TRACY_ROCPROF __HIP_PLATFORM_AMD__)
# Tracy client (built with the rocprof backend enabled).
add_library(TracyClient STATIC ${TRACY_PUBLIC}/TracyClient.cpp)
target_include_directories(TracyClient PUBLIC ${TRACY_PUBLIC} "${ROCM_PATH}/include")
target_compile_definitions(TracyClient PUBLIC ${REPRO_DEFINES})
target_link_libraries(TracyClient PUBLIC Threads::Threads ${CMAKE_DL_LIBS})
# repro: minimal HIP program that emits GPU zones via the rocprof backend.
add_executable(repro repro.cpp)
set_source_files_properties(repro.cpp PROPERTIES LANGUAGE HIP)
target_include_directories(repro PRIVATE "${ROCM_PATH}/include")
target_compile_definitions(repro PRIVATE ${REPRO_DEFINES})
target_link_libraries(repro PRIVATE TracyClient ${ROCPROFILER_SDK_LIB})
# check_gpu_ctx_name: loads a .tracy capture and verifies the GPU context
# name was deferred to (and received by) a late-connecting client. Links the
# Tracy server library, assembled the same way tracy-capture does it
# (cmake/server.cmake + vendor.cmake). Off by default since it pulls in the
# full server build and its vendored dependencies.
option(BUILD_CHECK_TOOL "Build the check_gpu_ctx_name verification helper" OFF)
if(BUILD_CHECK_TOOL)
set(NO_STATISTICS ON)
include(${TRACY_PATH}/cmake/vendor.cmake)
include(${TRACY_PATH}/cmake/server.cmake)
add_executable(check_gpu_ctx_name check_gpu_ctx_name.cpp)
target_compile_features(check_gpu_ctx_name PRIVATE cxx_std_20)
target_include_directories(check_gpu_ctx_name PRIVATE ${TRACY_PATH})
target_link_libraries(check_gpu_ctx_name PRIVATE TracyServer)
endif()
# ctest integration. To run the binaries via ctest:
# ctest --test-dir <cmake-build-dir> -R repro
enable_testing()
add_test(NAME repro COMMAND repro)

View File

@@ -36,19 +36,29 @@ Three bugs in `TracyRocprof.cpp` break on-demand profiling:
## Build and run
```bash
make
./repro &
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
./build/repro &
tracy-capture -o repro.tracy -s 5
```
If ROCm is not under `/opt/rocm`, pass `-DROCM_PATH=/path/to/rocm`.
The reproducer is also registered as a ctest target:
```bash
ctest --test-dir build -R repro
```
## Verifying the context name
`check_gpu_ctx_name` loads a `.tracy` file and prints the GPU context
names. Build it against the Tracy server library (e.g. from a capture
build directory) and run:
names. It links the Tracy server library, so it is built only on request:
```bash
./check_gpu_ctx_name repro.tracy
cmake -B build -DBUILD_CHECK_TOOL=ON
cmake --build build --target check_gpu_ctx_name
./build/check_gpu_ctx_name repro.tracy
# Expected (patched): "GPU context 0: rocprofv3"
# Expected (unpatched): "GPU context 0: (unnamed)"
```