From 918faf98203e295afd6c2734c61bed8d64c1f24c Mon Sep 17 00:00:00 2001 From: John Robbins Date: Tue, 27 May 2025 13:20:09 -0400 Subject: [PATCH 1/3] Add BUILD_CODE_COVERGAGE option --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f73ce7..bf85e9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,6 +107,7 @@ option(BUILD_CODE_COVERAGE "Build with code coverage enabled" OFF) option(BUILD_ADDRESS_SANITIZER "Build with address sanitizer enabled" OFF) option(BUILD_DOCS "Build documentation" OFF) option(USE_CUDA "Build hipGRAPH using CUDA backend" OFF) +option(BUILD_CODE_COVERAGE "Build with code coverage flags (clang only)" OFF) # If CUGRAPH_BUILD_DIR is not set, look at CUGRAPH_SOURCE_DIR/cpp/build. cmake_dependent_option(CUGRAPH_SOURCE_DIR "Point at a cugraph source directory" "" USE_CUDA "") cmake_dependent_option(CUGRAPH_BUILD_DIR "Point at a cugraph build directory (often cpp/build)" "" USE_CUDA "") From 14eb1e058ecdb8d222405690a81225c7b4bbca98 Mon Sep 17 00:00:00 2001 From: John Robbins Date: Tue, 27 May 2025 13:27:11 -0400 Subject: [PATCH 2/3] Instrument the code when BUILD_CODE_COVERAGE option is set to ON --- library/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 725f4e2..6587ce7 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -154,6 +154,11 @@ if(NOT BUILD_SHARED_LIBS) set_target_properties(hipgraph PROPERTIES PREFIX "lib") endif() +if(BUILD_CODE_COVERAGE) + target_compile_options( hipgraph PRIVATE -g -O0 -fprofile-instr-generate -fcoverage-mapping ) + target_link_options( hipgraph PUBLIC -fprofile-instr-generate ) +endif() + # Include sources add_subdirectory(src) From edc3901fa30b55df9299e03b61e8d971a93deba1 Mon Sep 17 00:00:00 2001 From: John Robbins Date: Tue, 27 May 2025 13:30:12 -0400 Subject: [PATCH 3/3] Add coverage target to generate code coverage report --- clients/tests/CMakeLists.txt | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/clients/tests/CMakeLists.txt b/clients/tests/CMakeLists.txt index e3ae5b9..387bef5 100644 --- a/clients/tests/CMakeLists.txt +++ b/clients/tests/CMakeLists.txt @@ -57,6 +57,44 @@ if(USE_CUDA) target_link_libraries(hipgraph-test PRIVATE ${CUDA_LIBRARIES}) endif() +if(BUILD_CODE_COVERAGE) + add_custom_target( + code_cov_tests + DEPENDS hipgraph-test + COMMAND ${CMAKE_COMMAND} -E rm -rf ./coverage-report + COMMAND ${CMAKE_COMMAND} -E make_directory ./coverage-report/profraw + COMMAND ${CMAKE_COMMAND} -E env LLVM_PROFILE_FILE="./coverage-report/profraw/hipgraph-coverage_%p.profraw" $ + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + + find_program( + LLVM_PROFDATA + llvm-profdata + REQUIRED + HINTS ${ROCM_PATH}/llvm/bin + PATHS /opt/rocm/llvm/bin + ) + + find_program( + LLVM_COV + llvm-cov + REQUIRED + HINTS ${ROCM_PATH}/llvm/bin + PATHS /opt/rocm/llvm/bin + ) + + add_custom_target( + coverage + DEPENDS code_cov_tests + COMMAND ${LLVM_PROFDATA} merge -sparse ./coverage-report/profraw/hipgraph-coverage_*.profraw -o ./coverage-report/hipgraph.profdata + COMMAND ${LLVM_COV} report -object ./library/src/libhipgraph.so -instr-profile=./coverage-report/hipgraph.profdata + COMMAND ${LLVM_COV} show -object ./library/src/libhipgraph.so -instr-profile=./coverage-report/hipgraph.profdata -format=html -output-dir=coverage-report + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + +endif() + + set_target_properties(hipgraph-test PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging") rocm_install(TARGETS hipgraph-test COMPONENT tests)