diff --git a/projects/rocm-smi-lib/CMakeLists.txt b/projects/rocm-smi-lib/CMakeLists.txt index 561a035b35..c9ed159b6b 100755 --- a/projects/rocm-smi-lib/CMakeLists.txt +++ b/projects/rocm-smi-lib/CMakeLists.txt @@ -53,6 +53,9 @@ set(ROCM_SMI_PACKAGE rocm-smi-lib) project(${AMD_SMI_LIBS_TARGET}) set(COMMON_PROJ_ROOT ${PROJECT_SOURCE_DIR}) +# Set default libdir to be "lib" for ROCm, distros/users can override this +set(CMAKE_INSTALL_LIBDIR "lib" CACHE STRING "Library install directory") +include(GNUInstallDirs) ## Verbose output. set(CMAKE_VERBOSE_MAKEFILE on) @@ -149,19 +152,17 @@ option(FILE_REORG_BACKWARD_COMPATIBILITY "Enable File Reorg with backward compat if(FILE_REORG_BACKWARD_COMPATIBILITY) include(rocm_smi-backward-compat.cmake) endif() -#TODO: Should use GNUInstallDirs to match distro standards -#This need fix in subdirectory CMakefile as well -#include(GNUInstallDirs) -set(LIB_INSTALL_DIR "lib") -set(INCLUDE_INSTALL_DIR "include") -set(BIN_INSTALL_DIR "bin") + +set(LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}") +set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}") +set(BIN_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}") include(CMakePackageConfigHelpers) configure_package_config_file( rocm_smi-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/rocm_smi-config.cmake - INSTALL_DESTINATION ${LIB_INSTALL_DIR}/cmake/rocm_smi + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/rocm_smi PATH_VARS LIB_INSTALL_DIR INCLUDE_INSTALL_DIR BIN_INSTALL_DIR ) @@ -175,7 +176,7 @@ install( FILES ${CMAKE_CURRENT_BINARY_DIR}/rocm_smi-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/rocm_smi-config-version.cmake DESTINATION - lib/cmake/${ROCM_SMI} + ${CMAKE_INSTALL_LIBDIR}/cmake/${ROCM_SMI} COMPONENT dev ) @@ -190,11 +191,11 @@ export(PACKAGE rocm_smi) # Create the rocm_smiConfig.cmake and rocm_smiConfigVersion files # ... for the build tree install(EXPORT rocm_smiTargets DESTINATION - "lib/cmake/${ROCM_SMI}" COMPONENT dev) + "${CMAKE_INSTALL_LIBDIR}/cmake/${ROCM_SMI}" COMPONENT dev) #License file set(CPACK_RPM_PACKAGE_LICENSE "NCSA") -install( FILES ${CPACK_RESOURCE_FILE_LICENSE} DESTINATION share/doc/${ROCM_SMI} RENAME LICENSE.txt) +install( FILES ${CPACK_RESOURCE_FILE_LICENSE} DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/${ROCM_SMI} RENAME LICENSE.txt) ########################### # Packaging directives diff --git a/projects/rocm-smi-lib/DEBIAN/postinst.in b/projects/rocm-smi-lib/DEBIAN/postinst.in index 5fda052286..d916aa7b85 100755 --- a/projects/rocm-smi-lib/DEBIAN/postinst.in +++ b/projects/rocm-smi-lib/DEBIAN/postinst.in @@ -5,7 +5,7 @@ set -e do_ldconfig() { # left-hand term originates from ENABLE_LDCONFIG = ON/OFF at package build if [ "@ENABLE_LDCONFIG@" == "ON" ]; then - echo @CPACK_PACKAGING_INSTALL_PREFIX@/lib > /etc/ld.so.conf.d/x86_64-librocm_smi_lib.conf + echo @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ > /etc/ld.so.conf.d/x86_64-librocm_smi_lib.conf ldconfig fi } diff --git a/projects/rocm-smi-lib/DEBIAN/prerm.in b/projects/rocm-smi-lib/DEBIAN/prerm.in index 65ec3de3ad..bc9cc2ef33 100755 --- a/projects/rocm-smi-lib/DEBIAN/prerm.in +++ b/projects/rocm-smi-lib/DEBIAN/prerm.in @@ -12,7 +12,7 @@ rm_ldconfig() { rm_pyc() { # remove pyc file generated by python - rm -rf @CPACK_PACKAGING_INSTALL_PREFIX@/libexec/rocm_smi/__pycache__ + rm -rf @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBEXECDIR@/rocm_smi/__pycache__ } case "$1" in diff --git a/projects/rocm-smi-lib/RPM/post.in b/projects/rocm-smi-lib/RPM/post.in index df1074537a..a7f518b81d 100755 --- a/projects/rocm-smi-lib/RPM/post.in +++ b/projects/rocm-smi-lib/RPM/post.in @@ -1,5 +1,5 @@ # left-hand term originates from ENABLE_LDCONFIG = ON/OFF at package build if [ "@ENABLE_LDCONFIG@" == "ON" ]; then - echo -e "@CPACK_PACKAGING_INSTALL_PREFIX@/lib\n@CPACK_PACKAGING_INSTALL_PREFIX@/lib64" > /etc/ld.so.conf.d/x86_64-librocm_smi_lib.conf + echo -e "@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@" > /etc/ld.so.conf.d/x86_64-librocm_smi_lib.conf ldconfig fi diff --git a/projects/rocm-smi-lib/RPM/postun.in b/projects/rocm-smi-lib/RPM/postun.in index d54cd9b2ea..72f4c565e2 100755 --- a/projects/rocm-smi-lib/RPM/postun.in +++ b/projects/rocm-smi-lib/RPM/postun.in @@ -4,3 +4,6 @@ if [ $1 -le 1 ] && [ "@ENABLE_LDCONFIG@" == "ON" ]; then rm -f /etc/ld.so.conf.d/x86_64-librocm_smi_lib.conf ldconfig fi + +# remove pyc file generated by python +rm -rf @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBEXECDIR@/rocm_smi/__pycache__ diff --git a/projects/rocm-smi-lib/oam/CMakeLists.txt b/projects/rocm-smi-lib/oam/CMakeLists.txt index 8cbf9dd918..7e96c85a49 100644 --- a/projects/rocm-smi-lib/oam/CMakeLists.txt +++ b/projects/rocm-smi-lib/oam/CMakeLists.txt @@ -101,12 +101,12 @@ target_include_directories(${OAM_TARGET} ## Add the install directives for the runtime library. install(TARGETS ${OAM_TARGET} EXPORT rocm_smiTargets - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${OAM_COMPONENT}) install(FILES ${COMMON_SRC_ROOT}/oam/include/oam/oam_mapi.h ${COMMON_SRC_ROOT}/oam/include/oam/amd_oam.h - DESTINATION include/oam) + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/oam) # Generate Doxygen documentation if (DOXYGEN_FOUND) diff --git a/projects/rocm-smi-lib/python_smi_tools/rocm_smi.py b/projects/rocm-smi-lib/python_smi_tools/rocm_smi.py index 73d88fd010..b20200d2c2 100755 --- a/projects/rocm-smi-lib/python_smi_tools/rocm_smi.py +++ b/projects/rocm-smi-lib/python_smi_tools/rocm_smi.py @@ -509,7 +509,6 @@ def printLog(device, metricName, value): logstr = 'GPU[%s]\t\t: %s' % (device, metricName) if device is None: logstr = logstr[13:] - logging.debug(logstr) # Force thread safe printing print(logstr + '\n', end='') @@ -791,11 +790,13 @@ def setClockRange(deviceList, clkType, minvalue, maxvalue, autoRespond): printLogSpacer(' Set Valid %s Range ' % (clkType)) for device in deviceList: ret = rocmsmi.rsmi_dev_clk_range_set(device, int(minvalue), int(maxvalue), rsmi_clk_names_dict[clkType]) - if rsmi_ret_ok(ret, device): + if rsmi_ret_ok(ret, device, silent=True): printLog(device, 'Successfully set %s from %s(MHz) to %s(MHz)' % (clkType, minvalue, maxvalue), None) else: printErrLog(device, 'Unable to set %s from %s(MHz) to %s(MHz)' % (clkType, minvalue, maxvalue)) RETCODE = 1 + if ret == rsmi_status_t.RSMI_STATUS_NOT_SUPPORTED: + printLog(device, 'Setting %s range is not supported for this device.' % (clkType), None) def setVoltageCurve(deviceList, point, clk, volt, autoRespond): @@ -2043,7 +2044,7 @@ def showProfile(deviceList): status = rsmi_power_profile_status_t() for device in deviceList: ret = rocmsmi.rsmi_dev_power_profile_presets_get(device, 0, byref(status)) - if rsmi_ret_ok(ret, device, 'profiles'): + if rsmi_ret_ok(ret, device, 'profiles', silent=False): binaryMaskString = str(format(status.available_profiles, '07b'))[::-1] bitMaskPosition = 0 profileNumber = 0 @@ -2075,7 +2076,7 @@ def showRange(deviceList, rangeType): odvf = rsmi_od_volt_freq_data_t() for device in deviceList: ret = rocmsmi.rsmi_dev_od_volt_info_get(device, byref(odvf)) - if rsmi_ret_ok(ret, device, 'od volt'): + if rsmi_ret_ok(ret, device, 'od volt', silent=False): if rangeType == 'sclk': printLog(device, 'Valid sclk range: %sMhz - %sMhz' % ( int(odvf.curr_sclk_range.lower_bound / 1000000), int(odvf.curr_sclk_range.upper_bound / 1000000)), None) @@ -2097,8 +2098,6 @@ def showRange(deviceList, rangeType): None) else: printLog(device, 'Unable to display %s range' % (rangeType), None) - else: - printLog(device, 'Unable to display %s range' % (rangeType), None) printLogSpacer() @@ -2181,6 +2180,10 @@ def showSerialNumber(deviceList): for device in deviceList: sn = create_string_buffer(256) ret = rocmsmi.rsmi_dev_serial_number_get(device, sn, 256) + if not str(sn).isalnum(): + printErrLog(device, "FRU Serial Number contains non-alphanumeric characters. FRU is likely corrupted") + continue + if rsmi_ret_ok(ret, device) and sn.value.decode(): printLog(device, 'Serial Number', sn.value.decode()) else: @@ -2311,13 +2314,11 @@ def showVoltageCurve(deviceList): odvf = rsmi_od_volt_freq_data_t() for device in deviceList: ret = rocmsmi.rsmi_dev_od_volt_info_get(device, byref(odvf)) - if rsmi_ret_ok(ret, device, 'od volt'): + if rsmi_ret_ok(ret, device, 'od volt', silent=False): for position in range(3): printLog(device, 'Voltage point %d: %sMhz %smV' % ( position, int(list(odvf.curve.vc_points)[position].frequency / 1000000), int(list(odvf.curve.vc_points)[position].voltage)), None) - else: - printLog(device, 'Voltage Curve is not supported', None) printLogSpacer() @@ -2807,10 +2808,10 @@ def rsmi_ret_ok(my_ret, device=None, metric=None, silent=False): returnString += ' %s: ' % (metric) returnString += '%s\t' % (err_str.value.decode()) if not PRINT_JSON: - if silent: - logging.info('%s', returnString) - else: - logging.error('%s', returnString) + logging.debug('%s', returnString) + if not silent: + if my_ret in rsmi_status_verbose_err_out: + printLog(device, rsmi_status_verbose_err_out[my_ret], None) RETCODE = my_ret return False return True diff --git a/projects/rocm-smi-lib/python_smi_tools/rsmiBindings.py b/projects/rocm-smi-lib/python_smi_tools/rsmiBindings.py index 090b85c3d8..7da7c2bc8c 100644 --- a/projects/rocm-smi-lib/python_smi_tools/rsmiBindings.py +++ b/projects/rocm-smi-lib/python_smi_tools/rsmiBindings.py @@ -69,6 +69,27 @@ class rsmi_status_t(c_int): RSMI_STATUS_UNKNOWN_ERROR = 0xFFFFFFFF +#Dictionary of rsmi ret codes and it's verbose output +rsmi_status_verbose_err_out = { + rsmi_status_t.RSMI_STATUS_SUCCESS: 'Operation was successful', + rsmi_status_t.RSMI_STATUS_INVALID_ARGS: 'Invalid arguments provided', + rsmi_status_t.RSMI_STATUS_NOT_SUPPORTED: 'Not supported on the given system', + rsmi_status_t.RSMI_STATUS_FILE_ERROR: 'Problem accessing a file', + rsmi_status_t.RSMI_STATUS_PERMISSION: 'Permission denied', + rsmi_status_t.RSMI_STATUS_OUT_OF_RESOURCES: 'Unable to acquire memory or other resource', + rsmi_status_t.RSMI_STATUS_INTERNAL_EXCEPTION: 'An internal exception was caught', + rsmi_status_t.RSMI_STATUS_INPUT_OUT_OF_BOUNDS: 'Provided input is out of allowable or safe range', + rsmi_status_t.RSMI_INITIALIZATION_ERROR: 'Error occured during rsmi initialization', + rsmi_status_t.RSMI_STATUS_NOT_YET_IMPLEMENTED: 'Requested function is not implemented on this setup', + rsmi_status_t.RSMI_STATUS_NOT_FOUND: 'Item searched for but not found', + rsmi_status_t.RSMI_STATUS_INSUFFICIENT_SIZE: 'Insufficient resources available', + rsmi_status_t.RSMI_STATUS_INTERRUPT: 'Interrupt occured during execution', + rsmi_status_t.RSMI_STATUS_UNEXPECTED_SIZE: 'Unexpected amount of data read', + rsmi_status_t.RSMI_STATUS_NO_DATA: 'No data found for the given input', + rsmi_status_t.RSMI_STATUS_UNKNOWN_ERROR: 'Unknown error occured' +} + + class rsmi_init_flags_t(c_int): RSMI_INIT_FLAG_ALL_GPUS = 0x1 diff --git a/projects/rocm-smi-lib/rocm_smi-backward-compat.cmake b/projects/rocm-smi-lib/rocm_smi-backward-compat.cmake index 8d31ebf087..aa8fd9c49e 100644 --- a/projects/rocm-smi-lib/rocm_smi-backward-compat.cmake +++ b/projects/rocm-smi-lib/rocm_smi-backward-compat.cmake @@ -72,7 +72,7 @@ function(generate_wrapper_header) set(include_guard "${include_guard}COMGR_WRAPPER_INCLUDE_${INC_GAURD_NAME}_H") #set #include statement get_filename_component(file_name ${header_file} NAME) - set(include_statements "${include_statements}#include \"../../../include/${ROCM_SMI}/${file_name}\"\n") + set(include_statements "${include_statements}#include \"../../../${CMAKE_INSTALL_INCLUDEDIR}/${ROCM_SMI}/${file_name}\"\n") configure_file(${RSMI_WRAPPER_DIR}/header.hpp.in ${RSMI_WRAPPER_INC_DIR}/${file_name}) unset(include_guard) unset(include_statements) @@ -90,7 +90,7 @@ function(generate_wrapper_header) set(include_guard "${include_guard}COMGR_WRAPPER_INCLUDE_${INC_GAURD_NAME}_H") #set #include statement get_filename_component(file_name ${header_file} NAME) - set(include_statements "${include_statements}#include \"../../../include/${OAM_TARGET_NAME}/${file_name}\"\n") + set(include_statements "${include_statements}#include \"../../../${CMAKE_INSTALL_INCLUDEDIR}/${OAM_TARGET_NAME}/${file_name}\"\n") configure_file(${RSMI_WRAPPER_DIR}/header.hpp.in ${OAM_WRAPPER_INC_DIR}/${file_name}) unset(include_guard) unset(include_statements) @@ -127,7 +127,7 @@ function(create_library_symlink) add_custom_target(link_${file_name} ALL WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E create_symlink - ../../lib/${file_name} ${RSMI_WRAPPER_LIB_DIR}/${file_name}) + ../../${CMAKE_INSTALL_LIBDIR}/${file_name} ${RSMI_WRAPPER_LIB_DIR}/${file_name}) endforeach() file(MAKE_DIRECTORY ${OAM_WRAPPER_LIB_DIR}) @@ -155,7 +155,7 @@ function(create_library_symlink) add_custom_target(link_${file_name} ALL WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E create_symlink - ../../lib/${file_name} ${OAM_WRAPPER_LIB_DIR}/${file_name}) + ../../${CMAKE_INSTALL_LIBDIR}/${file_name} ${OAM_WRAPPER_LIB_DIR}/${file_name}) endforeach() endfunction() diff --git a/projects/rocm-smi-lib/rocm_smi/CMakeLists.txt b/projects/rocm-smi-lib/rocm_smi/CMakeLists.txt index 862199d3e3..c594eeb8af 100755 --- a/projects/rocm-smi-lib/rocm_smi/CMakeLists.txt +++ b/projects/rocm-smi-lib/rocm_smi/CMakeLists.txt @@ -108,29 +108,29 @@ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin) add_custom_target(link-rocm-smi ALL WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E create_symlink - ../libexec/${ROCM_SMI}/rocm_smi.py ${CMAKE_CURRENT_BINARY_DIR}/bin/rocm-smi) + ../${CMAKE_INSTALL_LIBEXECDIR}/${ROCM_SMI}/rocm_smi.py ${CMAKE_CURRENT_BINARY_DIR}/bin/rocm-smi) ## Add the install directives for the runtime library. install(TARGETS ${ROCM_SMI_TARGET} EXPORT rocm_smiTargets - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${ROCM_SMI_COMPONENT}) install(FILES ${COMMON_SRC_ROOT}/include/rocm_smi/rocm_smi.h - DESTINATION include/rocm_smi) + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rocm_smi) install(FILES ${COMMON_SRC_ROOT}/include/rocm_smi/${ROCM_SMI_TARGET}Config.h - DESTINATION include/rocm_smi) + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rocm_smi) install(FILES ${COMMON_SRC_ROOT}/include/rocm_smi/kfd_ioctl.h - DESTINATION include/rocm_smi) + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/rocm_smi) install(FILES ${COMMON_SRC_ROOT}/python_smi_tools/rsmiBindings.py - DESTINATION libexec/${ROCM_SMI}) + DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/${ROCM_SMI}) install(FILES ${COMMON_SRC_ROOT}/python_smi_tools/rocm_smi.py PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_EXECUTE - DESTINATION libexec/${ROCM_SMI}) + DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/${ROCM_SMI}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/bin/rocm-smi - DESTINATION bin) + DESTINATION ${CMAKE_INSTALL_BINDIR}) # Generate Doxygen documentation find_package(Doxygen) @@ -157,9 +157,9 @@ if (DOXYGEN_FOUND AND LATEX_FOUND) add_dependencies(${ROCM_SMI_TARGET} docs) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/latex/refman.pdf - DESTINATION share/doc/${ROCM_SMI} RENAME ${RSMI_MANUAL_NAME}.pdf) + DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/${ROCM_SMI} RENAME ${RSMI_MANUAL_NAME}.pdf) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../README.md - DESTINATION share/doc/${ROCM_SMI}/) + DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/${ROCM_SMI}/) else() message("Doxygen or Latex is not found. Will not generate documents.") endif(DOXYGEN_FOUND AND LATEX_FOUND)