Python bindings for the Moore Threads Management Library (MTML) - a C-based API for monitoring and managing Moore Threads GPU devices.
MTML provides programmatic access to GPU metrics and configuration, similar to nvidia-smi for NVIDIA GPUs. This library (pymtml.py) wraps the native MTML C library for Python usage.
Moore Threads GPUs use MUSA (Meta-computing Unified System Architecture) as their compute platform, analogous to NVIDIA's CUDA.
- Python 3.7+
- Moore Threads GPU driver with MTML library installed
- The
libmtml.soshared library must be in the library path
pip install mthreads-ml-py
# Or install from source
git clone https://github.com/MooreThreads/mthreads-ml-py.git
cd mthreads-ml-py
pip install -e .from pymtml import *
# Initialize the library
mtmlLibraryInit()
# Get device count
device_count = mtmlLibraryCountDevice()
print(f"Found {device_count} GPU(s)")
# Query each device
for i in range(device_count):
device = mtmlLibraryInitDeviceByIndex(i)
# Basic info
name = mtmlDeviceGetName(device)
uuid = mtmlDeviceGetUUID(device)
print(f"Device {i}: {name} ({uuid})")
# Memory info
with mtmlMemoryContext(device) as memory:
total = mtmlMemoryGetTotal(memory)
used = mtmlMemoryGetUsed(memory)
print(f" Memory: {used / 1024**3:.2f} / {total / 1024**3:.2f} GB")
# GPU utilization
with mtmlGpuContext(device) as gpu:
util = mtmlGpuGetUtilization(gpu)
temp = mtmlGpuGetTemperature(gpu)
print(f" GPU Util: {util}%, Temp: {temp}°C")
# Shutdown
mtmlLibraryShutDown()mtmlLibraryInit()- Initialize the librarymtmlLibraryShutDown()- Shutdown the librarymtmlLibraryGetVersion()- Get library versionmtmlLibraryCountDevice()- Get device countmtmlLibraryInitDeviceByIndex(index)- Get device handle by indexmtmlLibraryInitDeviceByUuid(uuid)- Get device handle by UUID
mtmlDeviceGetIndex(device)- Get device indexmtmlDeviceGetName(device)- Get device namemtmlDeviceGetUUID(device)- Get device UUIDmtmlDeviceGetBrand(device)- Get device brandmtmlDeviceGetSerialNumber(device)- Get serial numbermtmlDeviceGetPciInfo(device)- Get PCI informationmtmlDeviceGetPowerUsage(device)- Get power usage (mW)mtmlDeviceGetVbiosVersion(device)- Get VBIOS versionmtmlDeviceCountGpuCores(device)- Get GPU core count
mtmlDeviceInitGpu(device)- Initialize GPU handlemtmlGpuGetUtilization(gpu)- Get GPU utilization (%)mtmlGpuGetTemperature(gpu)- Get GPU temperature (°C)mtmlGpuGetClock(gpu)- Get current GPU clock (MHz)mtmlGpuGetMaxClock(gpu)- Get max GPU clock (MHz)mtmlGpuGetEngineUtilization(gpu, engine)- Get engine utilization
mtmlDeviceInitMemory(device)- Initialize memory handlemtmlMemoryGetTotal(memory)- Get total memory (bytes)mtmlMemoryGetUsed(memory)- Get used memory (bytes)mtmlMemoryGetUtilization(memory)- Get memory utilization (%)mtmlMemoryGetClock(memory)- Get memory clock (MHz)mtmlMemoryGetBusWidth(memory)- Get memory bus width (bits)mtmlMemoryGetBandwidth(memory)- Get memory bandwidth (GB/s)
mtmlDeviceGetMtLinkSpec(device)- Get MtLink specificationmtmlDeviceGetMtLinkState(device, link)- Get link statemtmlDeviceGetMtLinkRemoteDevice(device, link)- Get remote devicemtmlDeviceCountMtLinkLayouts(dev1, dev2)- Count link layouts between devices
mtmlDeviceGetTopologyLevel(dev1, dev2)- Get topology level between devicesmtmlDeviceGetP2PStatus(dev1, dev2, cap)- Get P2P statusmtmlDeviceCountDeviceByTopologyLevel(device, level)- Count devices at topology levelmtmlDeviceGetDeviceByTopologyLevel(device, level, count)- Get devices at topology level
mtmlMemoryGetEccMode(memory)- Get ECC mode (current, pending)mtmlMemoryGetEccErrorCounter(memory, errorType, counterType, location)- Get ECC error countmtmlMemoryGetRetiredPagesCount(memory)- Get retired pages countmtmlMemoryGetRetiredPagesPendingStatus(memory)- Get pending status
mtmlDeviceInitVpu(device)- Initialize VPU handlemtmlVpuGetClock(vpu)- Get VPU clock (MHz)mtmlVpuGetUtilization(vpu)- Get VPU utilizationmtmlVpuGetCodecCapacity(vpu)- Get codec capacity
MTML_TOPOLOGY_INTERNAL = 0 # Same GPU
MTML_TOPOLOGY_SINGLE = 1 # Single PCIe switch
MTML_TOPOLOGY_MULTIPLE = 2 # Multiple PCIe switches
MTML_TOPOLOGY_HOSTBRIDGE = 3 # Host bridge
MTML_TOPOLOGY_NODE = 4 # Same NUMA node
MTML_TOPOLOGY_SYSTEM = 5 # Different NUMA nodesMTML_P2P_CAPS_READ = 0 # P2P read capability
MTML_P2P_CAPS_WRITE = 1 # P2P write capabilityAll functions raise MTMLError exceptions on failure:
try:
device = mtmlLibraryInitDeviceByIndex(99)
except MTMLError as e:
print(f"Error: {e}")# Run comprehensive MTML API tests
python test_pymtml.py
# Run sglang compatibility tests
python test_sglang_compat.pyMIT License