Adjusted folder naming and moved amdsmi_cli into amdsmi project folder
Change-Id: I4b7c42161fc92450f496483e5b49c7def6810437
[ROCm/amdsmi commit: 3eadf3a216]
This commit is contained in:
@@ -12,3 +12,8 @@ DEBIAN/postinst
|
||||
DEBIAN/prerm
|
||||
RPM/
|
||||
docs/*.pdf
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*.egg-*
|
||||
|
||||
@@ -155,10 +155,10 @@ if(PYTHON3 AND PIP3)
|
||||
python3 ${CMAKE_CURRENT_BINARY_DIR}/amdsmi_wrapper/generator.py -o ${CMAKE_CURRENT_BINARY_DIR}/amdsmi_wrapper/amdsmi_wrapper.py
|
||||
-i ${CMAKE_CURRENT_BINARY_DIR}/amdsmi_wrapper/amdsmi.h -l ${CMAKE_CURRENT_BINARY_DIR}/src/libamd_smi.so
|
||||
COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/amdsmi_wrapper/amdsmi_wrapper.py
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/py-interface/
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/py_interface/
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/amdsmi_wrapper)
|
||||
|
||||
set(PY_INTERFACE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/py-interface")
|
||||
set(PY_INTERFACE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/py_interface")
|
||||
set(PACKAGE_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/python_package/amdsmi")
|
||||
|
||||
add_custom_target(
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import argparse
|
||||
import platform
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import traceback
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import BDF
|
||||
from amd_smi_init import *
|
||||
|
||||
class AMD_SMI_Modules(object):
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
|
||||
def get_socket_handles(self):
|
||||
### Returns tuple of (int, list of ctypes: socket_handles)
|
||||
socket_count = c_uint32(0)
|
||||
return_code = amdsmi.amdsmi_get_socket_handles(byref(socket_count), None)
|
||||
check_return(return_code=return_code, error_statment="Invalid get_socket_handles request")
|
||||
|
||||
sockets = [0] * socket_count.value # 1
|
||||
socket_handles = (c_void_p * socket_count.value)(*sockets) # That is a pointer, not a multiplication
|
||||
return_code = amdsmi.amdsmi_get_socket_handles(byref(socket_count), socket_handles)
|
||||
check_return(return_code=return_code, error_statment=f"Invalid get_socket_handles with {socket_count.value} sockets")
|
||||
return (socket_count.value, socket_handles)
|
||||
|
||||
|
||||
def get_device_handles(self, socket_handle):
|
||||
"""Gets the Device Handles that are in the current socket"""
|
||||
### Returns tuple of (int, list of ctypes: device_handles)
|
||||
device_count = c_uint32(0)
|
||||
return_code = amdsmi.amdsmi_get_device_handles(socket_handle, byref(device_count), None)
|
||||
check_return(return_code=return_code, error_statment="Invalid get_device_handles request")
|
||||
|
||||
devices = [0] * device_count.value
|
||||
device_handles = (c_void_p * len(devices))(*devices)
|
||||
return_code = amdsmi.amdsmi_get_device_handles(socket_handle, byref(device_count), byref(device_handles))
|
||||
check_return(return_code=return_code, error_statment=f"Invalid get_device_handles with {device_count.value} devices")
|
||||
return (device_count.value, device_handles)
|
||||
|
||||
|
||||
def get_socket_info(self, socket_handle):
|
||||
""" Given a socket_handle, return the socket_info, which is just a BDF object"""
|
||||
socket_info = create_string_buffer(128) # createstringbuffer or something??? c_char_p
|
||||
return_code = amdsmi.amdsmi_get_socket_info(socket_handle, byref(socket_info), c_size_t(128))
|
||||
check_return(return_code=return_code, error_statment="Invalid get_socket_info request")
|
||||
socket_bdf = BDF.BDF(socket_info.value.decode())
|
||||
return(socket_bdf)
|
||||
|
||||
|
||||
def get_device_type(self, device_handle, format=True):
|
||||
# format: True for string; False for int
|
||||
# Returns device_type string for the given device_handle
|
||||
dev_type = c_int(0)
|
||||
return_code = amdsmi.amdsmi_get_device_type(device_handle, byref(dev_type))
|
||||
check_return(return_code=return_code, error_statment="Invalid get_device_type request")
|
||||
|
||||
if format == True: # Return string
|
||||
return device_type__enumvalues[dev_type.value]
|
||||
|
||||
return dev_type.value # Return int
|
||||
|
||||
|
||||
def get_device_bdf(self, device_handle):
|
||||
|
||||
# class amdsmi_bdf_t (Union):
|
||||
# _fields_ = [
|
||||
# ('bdf_submodule', bdf_submodule),
|
||||
# ('as_uint', c_uint64)
|
||||
# ]
|
||||
bdf = amdsmi_bdf_t()
|
||||
# bdf.bdf_submodule
|
||||
|
||||
|
||||
|
||||
return_code = amdsmi.amdsmi_get_device_bdf(device_handle, bdf)
|
||||
check_return(return_code=return_code, error_statment="Invalid amdsmi_get_device_bdf request")
|
||||
return (bdf)
|
||||
|
||||
|
||||
def get_device_handle_from_bdf(self, bdf):
|
||||
pass
|
||||
|
||||
|
||||
def get_fan_speed(self, bdf):
|
||||
pass
|
||||
|
||||
def show_retired_pages(self):
|
||||
# num_pages = c_uint32()
|
||||
# records = rsmi_retired_page_record_t()
|
||||
pass
|
||||
@@ -177,7 +177,6 @@ from .amdsmi_interface import amdsmi_is_P2P_accessible
|
||||
from .amdsmi_interface import amdsmi_get_xgmi_info
|
||||
|
||||
# # Enums
|
||||
|
||||
from .amdsmi_interface import AmdSmiInitFlags
|
||||
from .amdsmi_interface import AmdSmiContainerTypes
|
||||
from .amdsmi_interface import AmdSmiDeviceType
|
||||
@@ -205,8 +204,8 @@ from .amdsmi_interface import AmdSmiIoLinkType
|
||||
from .amdsmi_interface import AmdSmiUtilizationCounterType
|
||||
from .amdsmi_interface import AmdSmiSwComponent
|
||||
from .amdsmi_interface import AmdSmiIoLinkType
|
||||
# Exceptions
|
||||
|
||||
# Exceptions
|
||||
from .amdsmi_exception import AmdSmiLibraryException
|
||||
from .amdsmi_exception import AmdSmiRetryException
|
||||
from .amdsmi_exception import AmdSmiParameterException
|
||||
Regular → Executable
+2
-3
@@ -2,9 +2,8 @@
|
||||
|
||||
# from amd_smi_init import *
|
||||
|
||||
from amd_smi_commands import AMD_SMI_Commands
|
||||
from amd_smi_parser import AMD_SMI_Parser
|
||||
|
||||
from amdsmi_commands import AMD_SMI_Commands
|
||||
from amdsmi_parser import AMD_SMI_Parser
|
||||
|
||||
# sudo /src/out/ubuntu-20.04/20.04/bin/rocm-smi -bc --json | python -m json.tool
|
||||
|
||||
+8
-6
@@ -13,9 +13,8 @@ from pathlib import Path
|
||||
from BDF import BDF
|
||||
from _version import __version__
|
||||
|
||||
from amd_smi_logger import AMD_SMI_Logger
|
||||
|
||||
|
||||
from amdsmi_logger import AMD_SMI_Logger
|
||||
from amdsmi_helpers import *
|
||||
|
||||
class AMD_SMI_Commands(object):
|
||||
# def __init__(self, amd_smi_logger) -> None:
|
||||
@@ -30,8 +29,10 @@ class AMD_SMI_Commands(object):
|
||||
|
||||
def version(self, args):
|
||||
kernel_version = 123
|
||||
print(f'AMD-SMI version: {__version__} | Kernel version: {kernel_version}')
|
||||
|
||||
amdsmi_lib_version = amdsmi_interface.amdsmi_get_version()
|
||||
{'major': 1, 'minor': 0, 'patch': 0, 'build': '0'}
|
||||
amdsmi_lib_version_str = f'{amdsmi_lib_version["major"]}.{amdsmi_lib_version["minor"]}.{amdsmi_lib_version["patch"]}'
|
||||
print(f'AMD-SMI Tool: {__version__} | AMD-SMI Library version: {amdsmi_lib_version_str} | Kernel version: {kernel_version}')
|
||||
|
||||
def discovery(self, args):
|
||||
print('discovery test')
|
||||
@@ -46,7 +47,8 @@ class AMD_SMI_Commands(object):
|
||||
|
||||
|
||||
def firmware(self, args):
|
||||
print('firmware test')
|
||||
for elem in range(100000):
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
def bad_pages(self, args):
|
||||
+1
-1
@@ -12,7 +12,7 @@ import logging
|
||||
from pathlib import Path
|
||||
|
||||
from BDF import BDF
|
||||
from amd_smi_init import *
|
||||
from amdsmi_init import *
|
||||
|
||||
|
||||
class AMD_SMI_Helpers(object):
|
||||
+8
-21
@@ -11,7 +11,8 @@ import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Handle bindings for windows, Hyper-v and KVM seperately
|
||||
from amdsmiBindings import *
|
||||
import amdsmi_interface
|
||||
|
||||
|
||||
# Using basic python logging for user errors and development
|
||||
# logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG) # Logging for Development
|
||||
@@ -20,11 +21,6 @@ logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.ERROR) #
|
||||
# On initial import set initialized variable
|
||||
amd_smi_initialized = False
|
||||
|
||||
def check_return(return_code, error_statment): #@TODO would raising an exception be better?
|
||||
if return_code != amdsmi_status.AMDSMI_STATUS_SUCCESS:
|
||||
logging.error(error_statment)
|
||||
sys.exit(return_code)
|
||||
|
||||
|
||||
def check_amdgpu_driver(): #@TODO Handle KVM logic
|
||||
""" Returns true if amdgpu is found in the list of initialized modules """
|
||||
@@ -37,29 +33,20 @@ def check_amdgpu_driver(): #@TODO Handle KVM logic
|
||||
return False
|
||||
|
||||
|
||||
def init_amd_smi(flag=amdsmi_init_flags.AMD_SMI_INIT_AMD_GPUS):
|
||||
def init_amd_smi(flag=amdsmi_interface.AmdSmiInitFlags.AMD_GPUS):
|
||||
""" Initializes AMD-SMI """
|
||||
# Check if amdgpu driver is up
|
||||
# Check if amdgpu driver is up & Handle error gracefully
|
||||
if check_amdgpu_driver():
|
||||
# Only init AMD GPUs for now, waiting for future support for AMD CPUs
|
||||
init_status = amdsmi.amdsmi_init(flag)
|
||||
check_return(return_code=init_status, error_statment=f'AMD SMI initialization returned {init_status} (the expected value is {amdsmi_status_t.AMDSMI_STATUS_SUCCESS})')
|
||||
logging.info('amd-smi initialized successfully')
|
||||
amdsmi_interface.amdsmi_init(flag)
|
||||
logging.info('amd-smi initialized successfully') # without errors really
|
||||
else:
|
||||
logging.error('Driver not initialized (amdgpu not found in modules)')
|
||||
exit(-1)
|
||||
|
||||
|
||||
def amdsmi_shut_down():
|
||||
""" Shutdown AMD-SMI """
|
||||
# Only init AMD GPUs for now, waiting for future support for AMD CPUs
|
||||
shut_down_status = amdsmi.amdsmi_shut_down()
|
||||
check_return(return_code=shut_down_status, error_statment=f'AMD SMI Shutdown code returned {shut_down_status} (the expected value is {amdsmi_status_t.AMDSMI_STATUS_SUCCESS})')
|
||||
logging.debug('amd-smi shutdown successfully')
|
||||
|
||||
|
||||
def signal_handler(sig, frame):
|
||||
logging.debug(f'Handling signal: {sig}')
|
||||
logging.info(f'Handling signal: {sig}')
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
@@ -68,4 +55,4 @@ if not amd_smi_initialized:
|
||||
amd_smi_initialized = True
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
signal.signal(signal.SIGTERM, signal_handler)
|
||||
atexit.register(amdsmi_shut_down)
|
||||
atexit.register(amdsmi_interface.amdsmi_shut_down)
|
||||
+2
-2
@@ -4,7 +4,7 @@ import argparse
|
||||
import platform
|
||||
|
||||
from _version import __version__
|
||||
from amd_smi_helpers import AMD_SMI_Helpers
|
||||
from amdsmi_helpers import AMD_SMI_Helpers
|
||||
|
||||
# sudo /src/out/ubuntu-20.04/20.04/bin/rocm-smi -bc --json | python -m json.tool
|
||||
|
||||
@@ -50,7 +50,7 @@ class AMD_SMI_Parser(argparse.ArgumentParser):
|
||||
# self.add_set_value_parser(subparsers, set_value)
|
||||
self.add_reset_parser(subparsers, reset)
|
||||
self.add_misc_parser(subparsers, misc)
|
||||
self.add_gpu_v_parser(subparsers, misc)
|
||||
# self.add_gpu_v_parser(subparsers, misc)
|
||||
|
||||
|
||||
def add_version_parser(self, subparsers, func):
|
||||
+1
-1
@@ -20,7 +20,7 @@
|
||||
#
|
||||
|
||||
from enum import IntEnum
|
||||
from . import amdsmi_wrapper
|
||||
import amdsmi_wrapper
|
||||
|
||||
|
||||
class AmdSmiRetCode(IntEnum):
|
||||
+11
-8
@@ -25,8 +25,8 @@ from typing import Union, Any, Dict, List, Tuple
|
||||
from enum import IntEnum
|
||||
from collections.abc import Iterable
|
||||
|
||||
from . import amdsmi_wrapper
|
||||
from .amdsmi_exception import *
|
||||
import amdsmi_wrapper
|
||||
from amdsmi_exception import *
|
||||
|
||||
|
||||
class AmdSmiInitFlags(IntEnum):
|
||||
@@ -498,8 +498,7 @@ def amdsmi_get_socket_handles() -> List[amdsmi_wrapper.amdsmi_socket_handle]:
|
||||
socket_count.value)()
|
||||
_check_res(
|
||||
amdsmi_wrapper.amdsmi_get_socket_handles(
|
||||
ctypes.byref(socket_count), socket_handles
|
||||
)
|
||||
ctypes.byref(socket_count), socket_handles)
|
||||
)
|
||||
sockets = [
|
||||
amdsmi_wrapper.amdsmi_socket_handle(socket_handles[sock_idx])
|
||||
@@ -513,12 +512,16 @@ def amdsmi_get_socket_info(socket_handle):
|
||||
if not isinstance(socket_handle, amdsmi_wrapper.amdsmi_socket_handle):
|
||||
raise AmdSmiParameterException(
|
||||
socket_handle, amdsmi_wrapper.amdsmi_socket_handle)
|
||||
socket_info = ctypes.create_string_buffer(128)
|
||||
|
||||
_check_res(
|
||||
amdsmi_wrapper.get_socket_info(
|
||||
socket_handle, ctypes.byref(socket_info), ctypes.c_size_t(128))
|
||||
)
|
||||
|
||||
return {
|
||||
"name": ""
|
||||
}
|
||||
|
||||
return socket_info.value.decode()
|
||||
|
||||
# This input is different, also this List defintion doesn't really work because you never return that, you return a list of lists
|
||||
def amdsmi_get_device_handles() -> List[amdsmi_wrapper.amdsmi_device_handle]:
|
||||
socket_handles = amdsmi_get_socket_handles()
|
||||
devices = []
|
||||
+3
-4
@@ -165,11 +165,10 @@ def char_pointer_cast(string, encoding='utf-8'):
|
||||
return ctypes.cast(string, ctypes.POINTER(ctypes.c_char))
|
||||
|
||||
|
||||
|
||||
# Change this to more dynamic later or in /opt/rocm/lib/libamd_smi64.so
|
||||
_libraries = {}
|
||||
_libraries['libamd_smi.so'] = ctypes.CDLL(os.path.join(os.path.dirname(__file__), 'libamd_smi.so'))
|
||||
|
||||
|
||||
amd_smi_lib_so_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../build/src/libamd_smi.so'))
|
||||
_libraries['libamd_smi.so'] = ctypes.CDLL(amd_smi_lib_so_path)
|
||||
|
||||
# values for enumeration 'c__EA_amdsmi_init_flags_t'
|
||||
c__EA_amdsmi_init_flags_t__enumvalues = {
|
||||
@@ -0,0 +1,21 @@
|
||||
from setuptools import setup, find_packages
|
||||
from _version import __version__
|
||||
|
||||
with open("README.md", "r", encoding="utf-8") as fh:
|
||||
long_description = fh.read()
|
||||
|
||||
setup(
|
||||
name='amdsmi',
|
||||
version=__version__,
|
||||
description="SMI LIB - AMD GPU Monitoring Library",
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
packages=find_packages(), # can be customized later, but works for now
|
||||
package_data={'': ['LICENSE']},
|
||||
include_package_data=True,
|
||||
python_requires=">=3.6",
|
||||
)
|
||||
|
||||
# To build wheel
|
||||
# python3 -m pip install -U wheel
|
||||
# python3 setup.py bdist_wheel
|
||||
@@ -1,16 +0,0 @@
|
||||
from setuptools import setup
|
||||
|
||||
with open("amdsmi/README.md", "r", encoding="utf-8") as fh:
|
||||
long_description = fh.read()
|
||||
|
||||
setup(
|
||||
name='amdsmi',
|
||||
version='0.1',
|
||||
description="SMI LIB - AMD GPU Monitoring Library",
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
packages=['amdsmi'],
|
||||
package_data={'': ['LICENSE']},
|
||||
include_package_data=True,
|
||||
python_requires=">=3.6",
|
||||
)
|
||||
Reference in New Issue
Block a user