Skip to content

Building Python bindings for ADLX

Navigation: Programming with ADLX → ADLX Programming Guide → Quick Start

This guide outlines the steps to build and use the Python binding for ADLX, a prerequisite to programming with ADLX in a Python application. The ADLX Python binding (ADLXPybind) is built on pybind11 and is distributed as a Python wheel that can be installed with pip. For details regarding pybind11’s core functionalities, search online for the “official pybind11 documentation.”

Prerequisite(s)

  • ADLX SDK is installed.
  • Visual Studio 2022 with the C and C++ desktop components is installed.
  • Python 3.12 is installed.
  • pybind11 is installed.
  • The path to the Python installation is added to the PYHOME system environment variable.

Note: The ADLX library is installed along with the AMD display driver.

To build the ADLX Python binding

Each ADLX C++ interface is exposed to Python through three parts: a trampoline class that lets pybind11 override the interface’s virtual methods, a binding definition that registers the class and its methods with Python, and a type stub (ADLX.pyi) that provides type hints and docstrings.

  • Open the ADLXPybind project in Visual Studio 2022.
  • Build the project to produce the ADLX.pyd Python extension module.

Note: Refer to the Python samples ADLXPybind for an example of how the binding is used.

To package the binding into a wheel

  • Copy the compiled ADLX.pyd into the wheel package folder.
  • Run the wheel build script.

Result: A wheel file (for example, adlx-1.0.0-py312-none-win_amd64.whl) is generated in the wheel dist folder.

To use the binding in a Python application

  • Install the wheel into your Python environment:
pip install adlx-1.0.0-py312-none-win_amd64.whl
  • Import the binding and use it to initialize ADLX and access ADLX features:
from typing import List
from adlx import ADLX
def main():
helper = ADLX.ADLXHelper()
ret = helper.Initialize()
assert ret == ADLX.ADLX_RESULT.ADLX_OK
system: ADLX.IADLXSystem = helper.GetSystemServices()
gpus: List[ADLX.IADLXGPU] = system.GetGPUs()
for gpu in gpus:
print(gpu.Name())
ret = helper.Terminate()
assert ret == ADLX.ADLX_RESULT.ADLX_OK
if __name__ == "__main__":
main()

See Also: ADLXPybind