From ac832eb2c79d77a004861aa0accc886805da72dc Mon Sep 17 00:00:00 2001 From: "Jonathan R. Madsen" Date: Thu, 21 Sep 2023 10:07:07 -0500 Subject: [PATCH] Fix rocprofiler installation (#73) - install rocprofiler library - define AMD_INTERNAL_BUILD when including hsa/hsa.h - install include/rocprofiler/registration.h header - fix samples/pc_sampling cmake via installed rocprofiler - fix samples/api_callback_tracing cmake via installed rocprofiler - fix samples/api_buffered_tracing cmake via installed rocprofiler - set cmake_minimum_required in samples/CMakeLists.txt - find dependent packages in rocprofiler-config.cmake.in - AMDDeviceLibs - amd_comgr - hsa-runtime64 - hip - export rocprofiler-hip and rocprofiler-hsa-runtime libraries - add Test Install Build step to CI workflow [ROCm/rocprofiler-sdk commit: 8be4ca1a0403cb47c3e12e635c992607acfcfedf] --- .../workflows/continuous_integration.yml | 9 ++- .../Templates/rocprofiler-config.cmake.in | 56 ++++++++++++++++++- .../cmake/rocprofiler_interfaces.cmake | 4 +- .../rocprofiler-sdk/samples/CMakeLists.txt | 2 + .../api_buffered_tracing/CMakeLists.txt | 4 ++ .../api_callback_tracing/CMakeLists.txt | 4 ++ .../samples/pc_sampling/CMakeLists.txt | 6 ++ .../source/include/rocprofiler/CMakeLists.txt | 1 + .../source/include/rocprofiler/hsa.h | 14 +++++ .../source/lib/rocprofiler/CMakeLists.txt | 7 +++ 10 files changed, 101 insertions(+), 6 deletions(-) diff --git a/projects/rocprofiler-sdk/.github/workflows/continuous_integration.yml b/projects/rocprofiler-sdk/.github/workflows/continuous_integration.yml index 92f5ca0003..fa55f79a37 100644 --- a/projects/rocprofiler-sdk/.github/workflows/continuous_integration.yml +++ b/projects/rocprofiler-sdk/.github/workflows/continuous_integration.yml @@ -100,7 +100,7 @@ jobs: ${{ matrix.ci-flags }} -- -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} - -DCMAKE_INSTALL_PREFIX="${{ env.ROCM_PATH }}" + -DCMAKE_INSTALL_PREFIX=/opt/rocprofiler/v2 -DCPACK_GENERATOR='DEB;RPM;TGZ' -DPython3_EXECUTABLE=$(which python3) @@ -109,6 +109,13 @@ jobs: run: cmake --build build --target install --parallel 8 + - name: Test Install Build + timeout-minutes: 10 + shell: bash + run: | + CMAKE_PREFIX_PATH=/opt/rocprofiler/v2 cmake -B build-samples samples + cmake --build build-samples --target all --parallel 8 + - name: Build Packaging timeout-minutes: 10 run: diff --git a/projects/rocprofiler-sdk/cmake/Templates/rocprofiler-config.cmake.in b/projects/rocprofiler-sdk/cmake/Templates/rocprofiler-config.cmake.in index e2f585a443..c096984620 100644 --- a/projects/rocprofiler-sdk/cmake/Templates/rocprofiler-config.cmake.in +++ b/projects/rocprofiler-sdk/cmake/Templates/rocprofiler-config.cmake.in @@ -21,6 +21,56 @@ set(@PROJECT_NAME@_LIBRARIES) add_library(@PROJECT_NAME@::@PROJECT_NAME@ INTERFACE IMPORTED) +find_package( + AMDDeviceLibs + REQUIRED + CONFIG + HINTS + @AMDDeviceLibs_DIR@ + @rocm_version_DIR@ + PATHS + @AMDDeviceLibs_DIR@ + @rocm_version_DIR@) + +find_package( + amd_comgr + @amd_comgr_VERSION@ + EXACT + REQUIRED + CONFIG + HINTS + @amd_comgr_DIR@ + @rocm_version_DIR@ + PATHS + @amd_comgr_DIR@ + @rocm_version_DIR@) + +find_package( + hsa-runtime64 + @hsa-runtime64_VERSION@ + EXACT + REQUIRED + CONFIG + HINTS + @hsa-runtime64_DIR@ + @rocm_version_DIR@ + PATHS + @hsa-runtime64_DIR@ + @rocm_version_DIR@) + +find_package( + hip + @hip_VERSION@ + EXACT + REQUIRED + CONFIG + HINTS + @hip_DIR@ + @rocm_version_DIR@ + PATHS + @hip_DIR@ + @rocm_version_DIR@) + include("${@PROJECT_NAME@_CMAKE_DIR}/@PROJECT_NAME@-library-targets.cmake") # Library dependencies @@ -39,8 +89,7 @@ if(@PROJECT_NAME@_FIND_COMPONENTS) if(TARGET ${TARG}) set(@PROJECT_NAME@_${COMP}_FOUND 1) list(APPEND @PROJECT_NAME@_LIBRARIES ${TARG}) - target_link_libraries(@PROJECT_NAME@::@PROJECT_NAME@ - INTERFACE ${TARG}) + target_link_libraries(@PROJECT_NAME@::@PROJECT_NAME@ INTERFACE ${TARG}) else() set(@PROJECT_NAME@_${COMP}_FOUND 0) endif() @@ -51,6 +100,7 @@ include(FindPackageHandleStandardArgs) find_package_handle_standard_args( @PROJECT_NAME@ FOUND_VAR @PROJECT_NAME@_FOUND - REQUIRED_VARS @PROJECT_NAME@_ROOT_DIR @PROJECT_NAME@_INCLUDE_DIR @PROJECT_NAME@_LIBRARIES + REQUIRED_VARS @PROJECT_NAME@_ROOT_DIR @PROJECT_NAME@_INCLUDE_DIR + @PROJECT_NAME@_LIBRARIES VERSION_VAR @PROJECT_NAME@_VERSION HANDLE_COMPONENTS) diff --git a/projects/rocprofiler-sdk/cmake/rocprofiler_interfaces.cmake b/projects/rocprofiler-sdk/cmake/rocprofiler_interfaces.cmake index 8914efb451..0a038d8d69 100644 --- a/projects/rocprofiler-sdk/cmake/rocprofiler_interfaces.cmake +++ b/projects/rocprofiler-sdk/cmake/rocprofiler_interfaces.cmake @@ -42,8 +42,8 @@ rocprofiler_add_interface_library(rocprofiler-dl "Build flags for dynamic linking library" INTERNAL) rocprofiler_add_interface_library(rocprofiler-rt "Build flags for runtime library" INTERNAL) -rocprofiler_add_interface_library(rocprofiler-hip "HIP library" INTERNAL) -rocprofiler_add_interface_library(rocprofiler-hsa-runtime "HSA runtime library" INTERNAL) +rocprofiler_add_interface_library(rocprofiler-hip "HIP library") +rocprofiler_add_interface_library(rocprofiler-hsa-runtime "HSA runtime library") rocprofiler_add_interface_library(rocprofiler-amd-comgr "AMD comgr library" INTERNAL) rocprofiler_add_interface_library(rocprofiler-gtest "Google Test library" INTERNAL) rocprofiler_add_interface_library(rocprofiler-glog "Google Log library" INTERNAL) diff --git a/projects/rocprofiler-sdk/samples/CMakeLists.txt b/projects/rocprofiler-sdk/samples/CMakeLists.txt index fcfac7d151..d17d19e3c0 100644 --- a/projects/rocprofiler-sdk/samples/CMakeLists.txt +++ b/projects/rocprofiler-sdk/samples/CMakeLists.txt @@ -1,6 +1,8 @@ # # # +cmake_minimum_required(VERSION 3.21.0 FATAL_ERROR) + project(rocprofiler-samples LANGUAGES C CXX) # add_subdirectory(api_tracing) diff --git a/projects/rocprofiler-sdk/samples/api_buffered_tracing/CMakeLists.txt b/projects/rocprofiler-sdk/samples/api_buffered_tracing/CMakeLists.txt index cd97d37178..11e8ba55f1 100644 --- a/projects/rocprofiler-sdk/samples/api_buffered_tracing/CMakeLists.txt +++ b/projects/rocprofiler-sdk/samples/api_buffered_tracing/CMakeLists.txt @@ -25,6 +25,10 @@ foreach(_TYPE DEBUG MINSIZEREL RELEASE RELWITHDEBINFO) endif() endforeach() +if(NOT TARGET rocprofiler::rocprofiler-library) + find_package(rocprofiler REQUIRED) +endif() + add_library(buffered-api-tracing-client SHARED) target_sources(buffered-api-tracing-client PRIVATE client.cpp client.hpp) target_link_libraries(buffered-api-tracing-client diff --git a/projects/rocprofiler-sdk/samples/api_callback_tracing/CMakeLists.txt b/projects/rocprofiler-sdk/samples/api_callback_tracing/CMakeLists.txt index 7c349b05fa..7605fd5bd1 100644 --- a/projects/rocprofiler-sdk/samples/api_callback_tracing/CMakeLists.txt +++ b/projects/rocprofiler-sdk/samples/api_callback_tracing/CMakeLists.txt @@ -25,6 +25,10 @@ foreach(_TYPE DEBUG MINSIZEREL RELEASE RELWITHDEBINFO) endif() endforeach() +if(NOT TARGET rocprofiler::rocprofiler-library) + find_package(rocprofiler REQUIRED) +endif() + add_library(callback-api-tracing-client SHARED) target_sources(callback-api-tracing-client PRIVATE client.cpp client.hpp) target_link_libraries(callback-api-tracing-client diff --git a/projects/rocprofiler-sdk/samples/pc_sampling/CMakeLists.txt b/projects/rocprofiler-sdk/samples/pc_sampling/CMakeLists.txt index 197b6b7989..2968b2e578 100644 --- a/projects/rocprofiler-sdk/samples/pc_sampling/CMakeLists.txt +++ b/projects/rocprofiler-sdk/samples/pc_sampling/CMakeLists.txt @@ -1,8 +1,14 @@ # # # +cmake_minimum_required(VERSION 3.21.0 FATAL_ERROR) + project(rocprofiler-samples-pc-sampling LANGUAGES C CXX) +if(NOT TARGET rocprofiler::rocprofiler-library) + find_package(rocprofiler REQUIRED) +endif() + add_executable(pc_sampling_single-user-host-trap) target_sources(pc_sampling_single-user-host-trap PRIVATE common.h single-user-host-trap.cpp) diff --git a/projects/rocprofiler-sdk/source/include/rocprofiler/CMakeLists.txt b/projects/rocprofiler-sdk/source/include/rocprofiler/CMakeLists.txt index 1f4a3708d6..48c343d1e0 100644 --- a/projects/rocprofiler-sdk/source/include/rocprofiler/CMakeLists.txt +++ b/projects/rocprofiler-sdk/source/include/rocprofiler/CMakeLists.txt @@ -28,6 +28,7 @@ set(ROCPROFILER_HEADER_FILES marker.h pc_sampling.h profile_config.h + registration.h spm.h ${CMAKE_CURRENT_BINARY_DIR}/version.h) diff --git a/projects/rocprofiler-sdk/source/include/rocprofiler/hsa.h b/projects/rocprofiler-sdk/source/include/rocprofiler/hsa.h index 9ebed17b45..51fe506648 100644 --- a/projects/rocprofiler-sdk/source/include/rocprofiler/hsa.h +++ b/projects/rocprofiler-sdk/source/include/rocprofiler/hsa.h @@ -22,12 +22,26 @@ #pragma once +// without AMD_INTERNAL_BUILD defined, including the hsa/hsa.h looks for headers in inc/ folder +// so we always want it defined but we set ROCPROFILER_DEFINED_AMD_INTERNAL_BUILD to 1 to tell +// us that after this include, we should undefine it +#ifndef AMD_INTERNAL_BUILD +# define AMD_INTERNAL_BUILD +# ifndef ROCPROFILER_DEFINED_AMD_INTERNAL_BUILD +# define ROCPROFILER_DEFINED_AMD_INTERNAL_BUILD 1 +# endif +#endif + #include #include #include #include +#if defined(ROCPROFILER_DEFINED_AMD_INTERNAL_BUILD) && ROCPROFILER_DEFINED_AMD_INTERNAL_BUILD > 0 +# undef AMD_INTERNAL_BUILD +#endif + #include typedef struct hsa_kernel_dispatch_packet_s hsa_kernel_dispatch_packet_t; diff --git a/projects/rocprofiler-sdk/source/lib/rocprofiler/CMakeLists.txt b/projects/rocprofiler-sdk/source/lib/rocprofiler/CMakeLists.txt index 888b535cc4..1164eaebe3 100644 --- a/projects/rocprofiler-sdk/source/lib/rocprofiler/CMakeLists.txt +++ b/projects/rocprofiler-sdk/source/lib/rocprofiler/CMakeLists.txt @@ -28,4 +28,11 @@ set_target_properties( PROPERTIES OUTPUT_NAME rocprofiler64 SOVERSION ${PROJECT_VERSION_MAJOR} VERSION ${PROJECT_VERSION} + INSTALL_RPATH "\$ORIGIN" DEFINE_SYMBOL rocprofiler_EXPORTS) + +install( + TARGETS rocprofiler-library + DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT core + EXPORT ${PROJECT_NAME}-library-targets)