SWDEV-361376 - Add python wrapper

- Add generator for python wrapper
- Add interface, exception and init files
- Add CMake custom targets

Change-Id: I63c1d94fbb587387c22f559a3db79987eb214a2e
Signed-off-by: Dejan Andjelkovic <Dejan.Andjelkovic@amd.com>


[ROCm/amdsmi commit: 6064f160a3]
This commit is contained in:
Dejan Andjelkovic
2022-10-11 16:06:32 +02:00
committed by Bill(Shuzhou) Liu
parent c68caedcbd
commit 14d9160565
16 changed files with 5805 additions and 72 deletions
File diff suppressed because it is too large Load Diff
+114
View File
@@ -0,0 +1,114 @@
#
# Copyright (C) 2022 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.
#
# Library Initialization
from .amdsmi_interface import amdsmi_init
from .amdsmi_interface import amdsmi_fini
# Device Descovery
from .amdsmi_interface import amdsmi_get_device_type
from .amdsmi_interface import amdsmi_get_device_handles
from .amdsmi_interface import amdsmi_get_device_bdf
from .amdsmi_interface import amdsmi_get_device_uuid
from .amdsmi_interface import amdsmi_get_device_handle_from_bdf
# # SW Version Information
from .amdsmi_interface import amdsmi_get_driver_version
# # ASIC and Bus Static Information
from .amdsmi_interface import amdsmi_get_asic_info
from .amdsmi_interface import amdsmi_get_power_info
from .amdsmi_interface import amdsmi_get_caps_info
# # Microcode and VBIOS Information
from .amdsmi_interface import amdsmi_get_vbios_info
from .amdsmi_interface import amdsmi_get_fw_info
# # GPU Monitoring
from .amdsmi_interface import amdsmi_get_gpu_activity
from .amdsmi_interface import amdsmi_get_vram_usage
from .amdsmi_interface import amdsmi_get_power_measure
from .amdsmi_interface import amdsmi_get_clock_measure
from .amdsmi_interface import amdsmi_get_temperature_measure
from .amdsmi_interface import amdsmi_get_pcie_link_status
from .amdsmi_interface import amdsmi_get_pcie_link_caps
from .amdsmi_interface import amdsmi_get_power_limit
from .amdsmi_interface import amdsmi_get_temperature_limit
from .amdsmi_interface import amdsmi_get_bad_page_info
# # Power Management
from .amdsmi_interface import amdsmi_get_target_frequency_range
# # Process Information
from .amdsmi_interface import amdsmi_get_process_list
from .amdsmi_interface import amdsmi_get_process_info
# # ECC Error Information
from .amdsmi_interface import amdsmi_get_ecc_error_count
# # Board Information
from .amdsmi_interface import amdsmi_get_board_info
# # Ras Information
from .amdsmi_interface import amdsmi_get_ras_block_features_enabled
# # Events
# from .smi_interface import EventListen
# # Enums
from .amdsmi_interface import AmdSmiInitFlags
from .amdsmi_interface import AmdSmiContainerTypes
from .amdsmi_interface import AmdSmiDeviceType
from .amdsmi_interface import AmdSmiMmIp
from .amdsmi_interface import AmdSmiFWBlock
from .amdsmi_interface import AmdSmiClockType
from .amdsmi_interface import AmdSmiTemperatureType
from .amdsmi_interface import AmdSmiDevPerfLevel
from .amdsmi_interface import AmdSmiSwComponent
from .amdsmi_interface import AmdSmiEventGroup
from .amdsmi_interface import AmdSmiEventType
from .amdsmi_interface import AmdSmiCounterCommand
from .amdsmi_interface import AmdSmiEvtNotificationType
from .amdsmi_interface import AmdSmiTemperatureMetric
from .amdsmi_interface import AmdSmiVoltageMetric
from .amdsmi_interface import AmdSmiVoltageType
from .amdsmi_interface import AmdSmiPowerProfilePresetMasks
from .amdsmi_interface import AmdSmiGpuBlock
from .amdsmi_interface import AmdSmiRasErrState
from .amdsmi_interface import AmdSmiMemoryType
from .amdsmi_interface import AmdSmiFreqInd
from .amdsmi_interface import AmdSmiXgmiStatus
from .amdsmi_interface import AmdSmiMemoryPageStatus
from .amdsmi_interface import AmdSmiIoLinkType
from .amdsmi_interface import AmdSmiUtilizationCounterType
# Exceptions
from .amdsmi_exception import AmdSmiLibraryException
from .amdsmi_exception import AmdSmiRetryException
from .amdsmi_exception import AmdSmiParameterException
from .amdsmi_exception import AmdSmiKeyException
from .amdsmi_exception import AmdSmiBdfFormatException
from .amdsmi_exception import AmdSmiTimeoutException
from .amdsmi_exception import AmdSmiException
from .amdsmi_exception import AmdSmiRetCode
@@ -0,0 +1,172 @@
#
# Copyright (C) 2022 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.
#
from enum import IntEnum
from . import amdsmi_wrapper
class AmdSmiRetCode(IntEnum):
SUCCESS = amdsmi_wrapper.AMDSMI_STATUS_SUCCESS
ERR_INVAL = amdsmi_wrapper.AMDSMI_STATUS_INVAL
ERR_NOT_SUPPORTED = amdsmi_wrapper.AMDSMI_STATUS_NOT_SUPPORTED
FILE_ERROR = amdsmi_wrapper.AMDSMI_STATUS_FILE_ERROR
ERR_NO_PERM = amdsmi_wrapper.AMDSMI_STATUS_NO_PERM
ERR_OUT_OF_RESOURCES = amdsmi_wrapper.AMDSMI_STATUS_OUT_OF_RESOURCES
INTERNAL_EXCEPTION = amdsmi_wrapper.AMDSMI_STATUS_INTERNAL_EXCEPTION
INPUT_OUT_OF_BOUNDS = amdsmi_wrapper.AMDSMI_STATUS_INPUT_OUT_OF_BOUNDS
INIT_ERROR = amdsmi_wrapper.AMDSMI_STATUS_INIT_ERROR
NOT_IMPLEMENTED = amdsmi_wrapper.AMDSMI_STATUS_NOT_YET_IMPLEMENTED
ERR_NOT_FOUND = amdsmi_wrapper.AMDSMI_STATUS_NOT_FOUND
INSUFFICIENT_SIZE = amdsmi_wrapper.AMDSMI_STATUS_INSUFFICIENT_SIZE
INTERRUPT = amdsmi_wrapper.AMDSMI_STATUS_INTERRUPT
UNEXPECTED_SIZE = amdsmi_wrapper.AMDSMI_STATUS_UNEXPECTED_SIZE
NO_DATA = amdsmi_wrapper.AMDSMI_STATUS_NO_DATA
UNEXPECTED_DATA = amdsmi_wrapper.AMDSMI_STATUS_UNEXPECTED_DATA
ERR_BUSY = amdsmi_wrapper.AMDSMI_STATUS_BUSY
REFCOUNT_OVERFLOW = amdsmi_wrapper.AMDSMI_STATUS_REFCOUNT_OVERFLOW
LIB_START = amdsmi_wrapper.AMDSMI_LIB_START
FAIL_LOAD_MODULE = amdsmi_wrapper.AMDSMI_STATUS_FAIL_LOAD_MODULE
FAIL_LOAD_SYMBOL = amdsmi_wrapper.AMDSMI_STATUS_FAIL_LOAD_SYMBOL
DRM_ERROR = amdsmi_wrapper.AMDSMI_STATUS_DRM_ERROR
ERR_IO = amdsmi_wrapper.AMDSMI_STATUS_IO
FAULT = amdsmi_wrapper.AMDSMI_STATUS_FAULT
API_FAILED = amdsmi_wrapper.AMDSMI_STATUS_API_FAILED
TIMEOUT = amdsmi_wrapper.AMDSMI_STATUS_TIMEOUT
NO_SLOT = amdsmi_wrapper.AMDSMI_STATUS_NO_SLOT
RETRY = amdsmi_wrapper.AMDSMI_STATUS_RETRY
NOT_INIT = amdsmi_wrapper.AMDSMI_STATUS_NOT_INIT
UNKNOWN_ERROR = amdsmi_wrapper.AMDSMI_STATUS_UNKNOWN_ERROR
class AmdSmiException(Exception):
"""Base smi exception class"""
pass
class AmdSmiLibraryException(AmdSmiException):
def __init__(self, err_code):
err_code = abs(err_code)
super().__init__(err_code)
self.err_code = err_code
self.set_err_info()
def __str__(self):
return "An error occured with code: {err_code}({err_info})".format(
err_code=self.err_code, err_info=self.err_info
)
def get_error_code(self):
return self.err_code
def set_err_info(self):
switch = {
AmdSmiRetCode.ERR_INVAL: "AMDSMI_STATUS_INVAL - Invalid parameters",
AmdSmiRetCode.ERR_NOT_SUPPORTED: "AMDSMI_STATUS_NOT_SUPPORTED - Feature not supported",
AmdSmiRetCode.FILE_ERROR: "AMDSMI_STATUS_FILE_ERROR - Error opening file",
AmdSmiRetCode.ERR_OUT_OF_RESOURCES: "AMDSMI_STATUS_OUT_OF_RESOURCES - Not enough memory",
AmdSmiRetCode.INTERNAL_EXCEPTION: "AMDSMI_STATUS_INTERNAL_EXCEPTION - Internal error",
AmdSmiRetCode.ERR_NO_PERM: "AMDSMI_STATUS_NO_PERM - Permission Denied",
AmdSmiRetCode.INPUT_OUT_OF_BOUNDS: "AMDSMI_STATUS_INPUT_OUT_OF_BOUNDS - Out of bounds",
AmdSmiRetCode.INIT_ERROR: "AMDSMI_STATUS_INIT_ERROR - Initialization error",
AmdSmiRetCode.ERR_BUSY: "AMDSMI_STATUS_BUSY - Device busy",
AmdSmiRetCode.ERR_NOT_FOUND: "AMDSMI_STATUS_NOT_FOUND - Device Not found",
AmdSmiRetCode.ERR_IO: "AMDSMI_STATUS_IO - I/O Error",
AmdSmiRetCode.NOT_IMPLEMENTED: "AMDSMI_STATUS_NOT_YET_IMPLEMENTED - Feature not yet implemented",
AmdSmiRetCode.INSUFFICIENT_SIZE: "AMDSMI_STATUS_INSUFFICIENT_SIZE - Insufficient size for operation",
AmdSmiRetCode.INTERRUPT: "AMDSMI_STATUS_INTERRUPT - Interrupt ocurred during execution",
AmdSmiRetCode.UNEXPECTED_SIZE: "AMDSMI_STATUS_UNEXPECTED_SIZE - unexpected size of data was read",
AmdSmiRetCode.NO_DATA: "AMDSMI_STATUS_NO_DATA - No data was found for given input",
AmdSmiRetCode.UNEXPECTED_DATA: "AMDSMI_STATUS_UNEXPECTED_DATA - The data read or provided was unexpected",
AmdSmiRetCode.REFCOUNT_OVERFLOW: "AMDSMI_STATUS_REFCOUNT_OVERFLOW - Internal reference counter exceeded INT32_MAX",
AmdSmiRetCode.LIB_START: "AMDSMI_LIB_START - Lib start status",
AmdSmiRetCode.FAIL_LOAD_MODULE: "AMDSMI_STATUS_FAIL_LOAD_MODULE - Fail to load lib",
AmdSmiRetCode.FAIL_LOAD_SYMBOL: "AMDSMI_STATUS_FAIL_LOAD_SYMBOL - Fail to load symbol",
AmdSmiRetCode.DRM_ERROR: "AMDSMI_STATUS_DRM_ERROR - Error when called libdrm",
AmdSmiRetCode.FAULT: "AMDSMI_STATUS_FAULT - Bad address",
AmdSmiRetCode.API_FAILED: "AMDSMI_STATUS_API_FAILED - API call failed",
AmdSmiRetCode.TIMEOUT: "AMDSMI_STATUS_TIMEOUT - Timeout in API call",
AmdSmiRetCode.NO_SLOT: "AMDSMI_STATUS_NO_SLOT - No more free slot",
AmdSmiRetCode.RETRY: "AMDSMI_STATUS_RETRY - Retry operation",
AmdSmiRetCode.NOT_INIT: "AMDSMI_STATUS_NOT_INIT - Device not initialized",
}
self.err_info = switch.get(self.err_code, "AMDSMI_STATUS_UNKNOWN_ERROR - An unknown error occurred")
class AmdSmiRetryException(AmdSmiLibraryException):
def __init__(self):
super().__init__(AmdSmiRetCode.RETRY)
class AmdSmiTimeoutException(AmdSmiLibraryException):
def __init__(self):
super().__init__(AmdSmiRetCode.TIMEOUT)
class AmdSmiParameterException(AmdSmiException):
def __init__(self, receivedValue, expectedType, msg=None):
super().__init__(msg)
self.actualType = type(receivedValue)
self.expectedType = expectedType
self.set_err_msg()
if msg is not None:
self.err_msg = msg
def set_err_msg(self):
self.err_msg = (
"Invalid parameter:\n"
+ "Actual type: {actualType}\n".format(actualType=self.actualType)
+ "Expected type: {expectedType}".format(expectedType=self.expectedType)
)
def __str__(self):
return self.err_msg
class AmdSmiKeyException(AmdSmiException):
def __init__(self, key):
super().__init__()
self.key = key
self.set_err_msg()
def set_err_msg(self):
self.err_msg = "Key " + self.key + " is missing from dictionary"
def __str__(self):
return self.err_msg
class AmdSmiBdfFormatException(AmdSmiException):
def __init__(self, bdf):
super().__init__()
self.bdf = bdf
def __str__(self):
return (
"Wrong BDF format: {}. \n"
+ "BDF string should be: <domain>:<bus>:<device>.<function>\n"
+ " or <bus>:<device>.<function> in hexcode format.\n"
+ "Where:\n\t<domain> is 4 hex digits long from 0000-FFFF interval\n"
+ "\t<bus> is 2 hex digits long from 00-FF interval\n"
+ "\t<device> is 2 hex digits long from 00-1F interval\n"
+ "\t<function> is 1 hex digit long from 0-7 interval"
).format(self.bdf)
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+16
View File
@@ -0,0 +1,16 @@
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",
)