diff --git a/projects/amdsmi/CMakeLists.txt b/projects/amdsmi/CMakeLists.txt index 18b11617fd..f94195ae7f 100755 --- a/projects/amdsmi/CMakeLists.txt +++ b/projects/amdsmi/CMakeLists.txt @@ -70,7 +70,7 @@ include(GNUInstallDirs) option(BUILD_TESTS "Build test suite" OFF) option(ENABLE_ASAN_PACKAGING "" OFF) -option(ENABLE_ESMI_LIB "" ON) +option(ENABLE_ESMI_LIB "Build ESMI Library" ON) include(CMakeDependentOption) # these options don't work without BUILD_SHARED_LIBS diff --git a/projects/amdsmi/amdsmi_cli/amdsmi_init.py b/projects/amdsmi/amdsmi_cli/amdsmi_init.py index e5b7484422..a5852293a4 100644 --- a/projects/amdsmi/amdsmi_cli/amdsmi_init.py +++ b/projects/amdsmi/amdsmi_cli/amdsmi_init.py @@ -63,8 +63,8 @@ def check_amd_hsmp_driver(): return False -def init_amdsmi(): - """ Initializes AMDSMI +def amdsmi_cli_init(): + """ Initializes AMDSMI Library for the CLI Checks for the presence of the amdgpu and amd_hsmp drivers and initializes the AMD SMI library based on the live drivers found. @@ -119,7 +119,7 @@ def init_amdsmi(): return init_flag -def shut_down_amdsmi(): +def amdsmi_cli_shutdown(): """Shutdown AMDSMI instance Raises: @@ -138,8 +138,8 @@ def signal_handler(sig, frame): if not AMDSMI_INITIALIZED: - AMDSMI_INIT_FLAG = init_amdsmi() + AMDSMI_INIT_FLAG = amdsmi_cli_init() AMDSMI_INITIALIZED = True signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) - atexit.register(shut_down_amdsmi) + atexit.register(amdsmi_cli_shutdown) diff --git a/projects/amdsmi/src/amd_smi/amd_smi_system.cc b/projects/amdsmi/src/amd_smi/amd_smi_system.cc index efdb698329..3a1149b810 100644 --- a/projects/amdsmi/src/amd_smi/amd_smi_system.cc +++ b/projects/amdsmi/src/amd_smi/amd_smi_system.cc @@ -56,6 +56,7 @@ namespace smi { #define AMD_SMI_INIT_FLAG_RESRV_TEST1 0x800000000000000 //!< Reserved for test +#ifdef ENABLE_ESMI_LIB amdsmi_status_t AMDSmiSystem::get_cpu_family(uint32_t *cpu_family) { amdsmi_status_t ret; ret = static_cast(esmi_cpu_family_get(cpu_family)); @@ -111,6 +112,7 @@ static amdsmi_status_t get_nr_cpu_sockets(uint32_t *num_socks) { } return AMDSMI_STATUS_SUCCESS; } +#endif amdsmi_status_t AMDSmiSystem::init(uint64_t flags) { init_flag_ = flags; @@ -120,9 +122,8 @@ amdsmi_status_t AMDSmiSystem::init(uint64_t flags) { amd_smi_status = populate_amd_gpu_devices(); if (amd_smi_status != AMDSMI_STATUS_SUCCESS) return amd_smi_status; -#ifdef ENABLE_ESMI_LIB } - +#ifdef ENABLE_ESMI_LIB if (flags & AMDSMI_INIT_AMD_CPUS) { amd_smi_status = populate_amd_cpus(); if (amd_smi_status != AMDSMI_STATUS_SUCCESS) @@ -130,6 +131,7 @@ amdsmi_status_t AMDSmiSystem::init(uint64_t flags) { } #endif return AMDSMI_STATUS_SUCCESS; + } #ifdef ENABLE_ESMI_LIB @@ -175,8 +177,6 @@ amdsmi_status_t AMDSmiSystem::populate_amd_cpus() { return AMDSMI_STATUS_SUCCESS; } - - #endif amdsmi_status_t AMDSmiSystem::populate_amd_gpu_devices() { diff --git a/projects/amdsmi/tools/amdsmi_quick_start.py b/projects/amdsmi/tools/amdsmi_quick_start.py new file mode 100644 index 0000000000..2108e29f91 --- /dev/null +++ b/projects/amdsmi/tools/amdsmi_quick_start.py @@ -0,0 +1,50 @@ +# +# Copyright (C) 2024 Advanced Micro Devices. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +# This script is used to quickly debug and check amdsmi Python APIs. +# This is not meant to serve best practices for development. +# Run this post install with python3 -i quick_start.py + + +from amdsmi import * +from pathlib import Path + +import atexit +import logging +import signal +import sys + + +# Make exit & quit work without parens because it's annoying +type(exit).__repr__ = sys.exit + +def signal_handler(sig, frame): + logging.debug(f"Handling signal: {sig}") + sys.exit(0) + +amdsmi_init() +signal.signal(signal.SIGINT, signal_handler) +signal.signal(signal.SIGTERM, signal_handler) +atexit.register(amdsmi_shut_down) + +devices = amdsmi_get_processor_handles() + +print(f"devices variable populated with:{devices}")