Updated cli init functions to not intersect with lib init functions

Added Quick start script to quickly test python APIs
"python3 -i tools/amdsmi_quick_start.py"
Fixed ESMI lib macros

Signed-off-by: Maisam Arif <Maisam.Arif@amd.com>
Change-Id: I55370a0cb79d631f7f2f2b91568f089b503ebfad


[ROCm/amdsmi commit: 1efb5e9910]
This commit is contained in:
Maisam Arif
2024-08-29 12:35:16 -05:00
rodzic b276ae6c2b
commit adc9b69f39
4 zmienionych plików z 60 dodań i 10 usunięć
+1 -1
Wyświetl plik
@@ -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
@@ -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)
@@ -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<amdsmi_status_t>(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() {
@@ -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}")