From 6892907072b8cdc5ca5ec623de8283a80c96e9f8 Mon Sep 17 00:00:00 2001 From: "Galantsev, Dmitrii" Date: Wed, 11 Jun 2025 07:12:44 -0500 Subject: [PATCH] CMAKE - Remove example build from src/CMakeLists.txt (#469) * CMAKE - Remove example build from src/CMakeLists.txt For some reason it was building examples every time even when not necessary... * CMAKE - Format * Fix drm_example broken PRIu32 * CMAKE - Do NOT create lib64 when building examples * CMAKE - Examples should only install C and CMake files --------- Change-Id: I6274b72a085a41b5bd5ae698af798f60a8a092a0 Signed-off-by: Galantsev, Dmitrii [ROCm/amdsmi commit: f9b8066c26b5ddaa6808030944fa23f7915d4ebe] --- projects/amdsmi/.clangd | 2 +- projects/amdsmi/CMakeLists.txt | 8 +++++++- projects/amdsmi/example/CMakeLists.txt | 16 +++++++--------- projects/amdsmi/example/amd_smi_drm_example.cc | 4 ++-- projects/amdsmi/src/CMakeLists.txt | 6 ++---- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/projects/amdsmi/.clangd b/projects/amdsmi/.clangd index 2acc0ebb28..5f6f373c45 100644 --- a/projects/amdsmi/.clangd +++ b/projects/amdsmi/.clangd @@ -1,6 +1,6 @@ CompileFlags: Remove: -W* - Add: [-Wall, -Wno-c++20-designator, -pedantic, -I/opt/rocm/include, -I/opt/rocm/include/hsa, -I/opt/rocm/include/rocprofiler] + Add: [-Wall, -Wno-c++20-designator, -pedantic] Compiler: clang++ # list here: https://clang.llvm.org/extra/clang-tidy/checks/list.html diff --git a/projects/amdsmi/CMakeLists.txt b/projects/amdsmi/CMakeLists.txt index 51f0ebea88..91953f3380 100644 --- a/projects/amdsmi/CMakeLists.txt +++ b/projects/amdsmi/CMakeLists.txt @@ -268,7 +268,13 @@ install( install( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/example DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${AMD_SMI} - COMPONENT dev) + COMPONENT dev + FILES_MATCHING + PATTERN "*.h" + PATTERN "*.cc" + PATTERN "*.txt" + PATTERN "build*" EXCLUDE + PATTERN ".cache*" EXCLUDE) # Make for goamdsmi_shim library add_subdirectory(goamdsmi_shim) diff --git a/projects/amdsmi/example/CMakeLists.txt b/projects/amdsmi/example/CMakeLists.txt index 5ce174bd1a..876e276f53 100644 --- a/projects/amdsmi/example/CMakeLists.txt +++ b/projects/amdsmi/example/CMakeLists.txt @@ -31,13 +31,14 @@ else() set(ROCM_DIR "/opt/rocm" CACHE STRING "ROCm directory.") endif() +include(GNUInstallDirs) + # add package search paths -set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${ROCM_DIR} ../../../) -set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${ROCM_DIR}/lib) -if(NOT EXISTS ${ROCM_DIR}/lib64) - file(MAKE_DIRECTORY ${ROCM_DIR}/lib64) -endif() -set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${ROCM_DIR}/lib64) +# ../../../ should resolve to /opt/rocm or another rocm install path +# fall back to ROCM_DIR +list(APPEND CMAKE_PREFIX_PATH ../../../ ${ROCM_DIR}) +list(APPEND CMAKE_LIBRARY_PATH ${ROCM_DIR}/${CMAKE_INSTALL_LIBDIR}) + find_package(amd_smi CONFIG REQUIRED) message("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&") @@ -49,17 +50,14 @@ message("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&") set(SMI_DRM_EXAMPLE_EXE "amd_smi_drm_ex") add_executable(${SMI_DRM_EXAMPLE_EXE} "amd_smi_drm_example.cc") target_link_libraries(${SMI_DRM_EXAMPLE_EXE} amd_smi) -add_dependencies(${SMI_DRM_EXAMPLE_EXE} amd_smi) set(SMI_NODRM_EXAMPLE_EXE "amd_smi_nodrm_ex") add_executable(${SMI_NODRM_EXAMPLE_EXE} "amd_smi_nodrm_example.cc") target_link_libraries(${SMI_NODRM_EXAMPLE_EXE} amd_smi) -add_dependencies(${SMI_NODRM_EXAMPLE_EXE} amd_smi) if(ENABLE_ESMI_LIB) set(ESMI_SAMPLE_EXE "amd_smi_esmi_ex") add_executable(${ESMI_SAMPLE_EXE} "amdsmi_esmi_intg_example.cc") target_link_libraries(${ESMI_SAMPLE_EXE} amd_smi) target_compile_definitions(${ESMI_SAMPLE_EXE} PUBLIC ENABLE_ESMI_LIB) - add_dependencies(${ESMI_SAMPLE_EXE} amd_smi) endif() diff --git a/projects/amdsmi/example/amd_smi_drm_example.cc b/projects/amdsmi/example/amd_smi_drm_example.cc index 93a0038948..d5479b2546 100644 --- a/projects/amdsmi/example/amd_smi_drm_example.cc +++ b/projects/amdsmi/example/amd_smi_drm_example.cc @@ -891,7 +891,7 @@ int main() { printf("\tAsic serial: 0x%s\n", asic_info.asic_serial); if (asic_info.oam_id != UINT32_MAX) { // OAM ID is not supported on all devices - printf("\tOAM ID: %"PRIu32"\n", asic_info.oam_id); + printf("\tOAM ID: %" PRIu32"\n", asic_info.oam_id); } else { // OAM ID is not supported on this device printf("\tOAM ID: N/A\n"); @@ -999,7 +999,7 @@ int main() { printf(" Output of amdsmi_get_power_info:\n"); if (ret != AMDSMI_STATUS_NOT_SUPPORTED) { CHK_AMDSMI_RET(ret) - printf("\tCurrent GFX Voltage: %d\n", power_measure.gfx_voltage); + printf("\tCurrent GFX Voltage: %ld\n", power_measure.gfx_voltage); printf("\tAverage socket power: %d\n", power_measure.average_socket_power); printf("\tGPU Power limit: %d\n\n", power_measure.power_limit); } else { diff --git a/projects/amdsmi/src/CMakeLists.txt b/projects/amdsmi/src/CMakeLists.txt index 01a67a97e1..2f22b7d854 100644 --- a/projects/amdsmi/src/CMakeLists.txt +++ b/projects/amdsmi/src/CMakeLists.txt @@ -41,8 +41,8 @@ set(INC_LIST "${PROJECT_SOURCE_DIR}/rocm_smi/include/rocm_smi/rocm_smi_utils.h") set(ACA_SRC_DIR "aca-decode") -set(SRC_LIST ${SRC_LIST} ${ACA_SRC_DIR}/aca_api.c ${ACA_SRC_DIR}/aca_decode.c ${ACA_SRC_DIR}/aca_fields.c ${ACA_SRC_DIR}/aca_tables.c - ${ACA_SRC_DIR}/error_map.c) +set(SRC_LIST ${SRC_LIST} ${ACA_SRC_DIR}/aca_api.c ${ACA_SRC_DIR}/aca_decode.c ${ACA_SRC_DIR}/aca_fields.c + ${ACA_SRC_DIR}/aca_tables.c ${ACA_SRC_DIR}/error_map.c) set(ACA_INC_DIR "${PROJECT_SOURCE_DIR}/include/aca-decode") set(INC_LIST ${INC_LIST} ${ACA_INC_DIR}/aca_decode.h ${ACA_INC_DIR}/aca_fields.h ${ACA_INC_DIR}/aca_tables.h ${ACA_INC_DIR}/error_map.h) @@ -76,8 +76,6 @@ message("SOVERSION: ${SO_VERSION_STRING}") # Create a configure file to get version info from within library configure_file("amd_smiConfig.in" "${PROJECT_SOURCE_DIR}/include/amd_smi/amd_smiConfig.h") -add_executable(amd_smi_ex "../example/amd_smi_drm_example.cc") -target_link_libraries(amd_smi_ex ${AMD_SMI}) add_library(${AMD_SMI} ${SRC_LIST} ${INC_LIST}) target_link_libraries(${AMD_SMI} pthread rt dl ${DRM_LIBRARIES} ${AMDGPU_DRM_LIBRARIES}) target_include_directories(${AMD_SMI} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/rocm_smi/include