| 1 |
# Origami Python Bindings |
| 2 |
|
| 3 |
This directory provides Python bindings for the C++ Origami project. |
| 4 |
The bindings allow you to use Origami's functionality directly from Python. |
| 5 |
|
| 6 |
## Installation |
| 7 |
|
| 8 |
First, install `nanobind` using pip: |
| 9 |
|
| 10 |
```bash |
| 11 |
pip install nanobind |
| 12 |
``` |
| 13 |
|
| 14 |
Make sure `ROCM_PATH` is set (e.g. `export ROCM_PATH=/opt/rocm`). Then, build the bindings using the following command: |
| 15 |
|
| 16 |
```bash |
| 17 |
python setup.py build_ext --inplace |
| 18 |
export PYTHONPATH=$(pwd):$PYTHONPATH |
| 19 |
``` |
| 20 |
|
| 21 |
## Testing |
| 22 |
|
| 23 |
After building the bindings, you can test them using the provided test file: |
| 24 |
|
| 25 |
```bash |
| 26 |
python ./origami_test.py |
| 27 |
``` |
| 28 |
|
| 29 |
## Usage |
| 30 |
|
| 31 |
Once the bindings are built and tested, you can import and use them in your Python scripts: |
| 32 |
|
| 33 |
```python |
| 34 |
import origami |
| 35 |
|
| 36 |
hardware = origami.getHardwareForDevice(args.device) |
| 37 |
|
| 38 |
result = origami.select_best_macro_tile_size( |
| 39 |
args.m, args.n, args.k, args.transA, args.transB, hardware, tile_list, args.element_size, args.miDataType, 0.8, args.debug, args.print, args.wgm |
| 40 |
) |
| 41 |
``` |
| 42 |
|
| 43 |
## Modifying `origami_module.cpp` |
| 44 |
|
| 45 |
To expose more C++ functionality to Python, you can modify the `origami_module.cpp` file. |
| 46 |
This involves adding new functions or classes to the module and ensuring they are properly wrapped for Python. |
| 47 |
After making your changes, rebuild the bindings using the installation command above. |