CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
134 lines
5.6 KiB
Markdown
134 lines
5.6 KiB
Markdown
# hipDNN Python Bindings
|
|
|
|
> [!CAUTION]
|
|
> **This is a POC of python bindings for hipdnn. It likely has bugs and features missing. Making this not a POC has been planned for a future date**
|
|
|
|
|
|
This project provides Python bindings for the hipDNN frontend library using the nanobind library. The bindings allow users to access the functionalities of the hipDNN library directly from Python, enabling seamless integration of deep learning operations.
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
python/
|
|
├── README.md
|
|
├── download_third_party_deps.py # Downloads pinned CI third-party source archives
|
|
├── frontend_bindings/
|
|
│ ├── CMakeLists.txt # Standalone CMake build for bindings
|
|
│ └── src/
|
|
│ ├── module.cpp # Main nanobind module entry point
|
|
│ ├── bindings.hpp # Shared binding declarations
|
|
│ ├── graph_bindings.cpp
|
|
│ ├── handle_bindings.cpp
|
|
│ ├── memory_bindings.cpp
|
|
│ ├── tensor_bindings.cpp
|
|
│ ├── attributes_bindings.cpp
|
|
│ ├── hip_bindings.cpp
|
|
│ └── types_bindings.cpp
|
|
└── frontend_wheel_package/
|
|
├── src/
|
|
│ └── hipdnn_frontend/
|
|
│ └── __init__.py # Runtime package initializer
|
|
├── samples/ # Source-tree sample scripts
|
|
├── tests/ # Source-tree tests
|
|
├── pyproject.toml # Wheel metadata and pytest config
|
|
└── pack_frontend_wheel.py # Stages and packs the wheel package
|
|
```
|
|
|
|
## Prerequisites
|
|
|
|
- CMake 3.26 or higher
|
|
- Ninja or another CMake generator
|
|
- A C++ compiler with C++17 support (e.g. clang++)
|
|
- Python 3.12 or higher, including development headers
|
|
- ROCm/HIP runtime and libraries
|
|
- Installed hipDNN development artifacts with `hipdnn_frontendConfig.cmake`,
|
|
`hipdnn_backendConfig.cmake`, headers, and the backend shared library
|
|
- `nanobind` and `tsl-robin-map` CMake packages, or network access during
|
|
configure so CMake can fetch the pinned source archives
|
|
- The `build` Python package when creating a wheel
|
|
- The `numpy` and `pytest` Python packages when running source-tree tests or samples
|
|
|
|
## Building
|
|
|
|
The Python bindings are a standalone CMake project. Build and install hipDNN
|
|
first, then point `CMAKE_PREFIX_PATH` at that install or nightly artifact prefix.
|
|
The extension uses installed hipDNN package metadata for headers and compile
|
|
definitions, and links the installed `hipdnn_frontend` and `hipdnn_backend`
|
|
package targets directly.
|
|
|
|
From the repository root:
|
|
|
|
```bash
|
|
cmake -S projects/hipdnn/python/frontend_bindings -B build/hipdnn-python -GNinja \
|
|
-DCMAKE_PREFIX_PATH=/path/to/hipdnn/install
|
|
cmake --build build/hipdnn-python
|
|
```
|
|
|
|
`CMAKE_PREFIX_PATH` is required. Point it at the installed hipDNN artifact prefix
|
|
or set the `CMAKE_PREFIX_PATH` environment variable before configuring.
|
|
|
|
The default build builds only the nanobind extension into the CMake build tree.
|
|
CMake does not know about wheel packaging, does not configure
|
|
`hipdnn_frontend/__init__.py`, and has no install rules.
|
|
|
|
Run the wheel packer to create the staged import package under
|
|
`build/hipdnn-python/wheel_package/hipdnn_frontend`; downstream environment
|
|
wiring should use that staged package tree.
|
|
|
|
For a source-tree development import after staging the package, put the staged
|
|
wheel package root on `PYTHONPATH`:
|
|
|
|
```bash
|
|
PYTHONPATH=build/hipdnn-python/wheel_package python -c "import hipdnn_frontend"
|
|
```
|
|
|
|
The backend shared library must also be discoverable at runtime: use
|
|
`LD_LIBRARY_PATH=/path/to/hipdnn/install/lib` on Linux, or set `ROCM_PATH` to the
|
|
artifact prefix on Windows so `hipdnn_frontend/__init__.py` can register `bin/`.
|
|
|
|
## Creating a Wheel
|
|
|
|
After building the bindings, run the packer script:
|
|
|
|
```bash
|
|
python projects/hipdnn/python/frontend_wheel_package/pack_frontend_wheel.py \
|
|
--build-dir build/hipdnn-python \
|
|
--wheel-dir build/hipdnn-python/wheel_package
|
|
```
|
|
|
|
The wheel is written to `build/hipdnn-python/wheel_package/`, beside the
|
|
`hipdnn_frontend/` package directory. The script packs
|
|
`wheel_package/hipdnn_frontend` into a temporary setuptools project. The wheel
|
|
contains only `hipdnn_frontend/__init__.py` and the native extension. It does
|
|
not include samples or tests, and it does not bundle `libhipdnn_backend`; users
|
|
still need ROCm and hipDNN runtime libraries discoverable through ROCm wheels,
|
|
`ROCM_PATH`, or the platform loader path.
|
|
|
|
## Testing the Wheel
|
|
|
|
The `hipDNN Superbuild CI` workflow validates the wheel end-to-end inside the
|
|
matching Linux and Windows superbuild jobs after installing the superbuild
|
|
outputs into the ROCm SDK path. The workflow calls
|
|
`projects/hipdnn/python/download_third_party_deps.py` to download and verify
|
|
pinned third-party source archives from `rocm-third-party-deps`, then passes
|
|
those source directories to CMake FetchContent. It then builds the nanobind
|
|
extension, packs the wheel, installs that wheel into the same venv, and runs:
|
|
|
|
```bash
|
|
python -m pytest -q projects/hipdnn/python/frontend_wheel_package/tests
|
|
```
|
|
|
|
The wheel package uses a `src/` layout, so running pytest from
|
|
`frontend_wheel_package/` does not accidentally import the source package.
|
|
|
|
## Running the Samples
|
|
|
|
Sample scripts are source-tree utilities and are not included in the wheel.
|
|
|
|
```bash
|
|
python projects/hipdnn/python/frontend_wheel_package/samples/conv_fprop.py
|
|
python projects/hipdnn/python/frontend_wheel_package/samples/conv_dgrad.py
|
|
python projects/hipdnn/python/frontend_wheel_package/samples/conv_wgrad.py
|
|
python projects/hipdnn/python/frontend_wheel_package/samples/matmul.py
|
|
```
|