Skip to content

Commit

Permalink
[examples] Fix LeNet CPU/GPU library dependency issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanghb97 committed Dec 24, 2024
1 parent 835453e commit 1c338ba
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/BuddyLeNet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ target_link_directories(buddy-lenet-run PRIVATE ${LLVM_LIBRARY_DIR})
if(NOT DEFINED BUDDY_ENABLE_PNG)
message(FATAL_ERROR "To run LeNet inference, the png library is required. Please define BUDDY_ENABLE_PNG for CMake.")
endif()
set(BUDDY_LENET_LIBS LENET mlir_c_runner_utils mlir_async_runtime mlir_runner_utils mlir_cuda_runtime ${PNG_LIBRARIES})
set(BUDDY_LENET_LIBS LENET mlir_c_runner_utils mlir_async_runtime mlir_runner_utils ${PNG_LIBRARIES})

target_link_libraries(buddy-lenet-run ${BUDDY_LENET_LIBS})

Expand Down
46 changes: 41 additions & 5 deletions examples/BuddyLeNet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,47 @@ $ python pytorch-lenet-train.py

## LeNet Model Inference

0. Activate your python environment.
### Activate your python environment.

1. Build buddy-mlir
```bash
$ conda activate <your env>
```

### Build LLVM

```bash
$ cd buddy-mlir
$ mkdir llvm/build
$ cd llvm/build

// CPU
$ cmake -G Ninja ../llvm \
-DLLVM_ENABLE_PROJECTS="mlir;clang;openmp" \
-DLLVM_TARGETS_TO_BUILD="host;RISCV" \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DOPENMP_ENABLE_LIBOMPTARGET=OFF \
-DCMAKE_BUILD_TYPE=RELEASE \
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \
-DPython3_EXECUTABLE=$(which python3)

// GPU
$ cmake -G Ninja ../llvm \
-DLLVM_ENABLE_PROJECTS="mlir;clang;openmp" \
-DLLVM_TARGETS_TO_BUILD="host;RISCV;NVPTX" \
-DMLIR_ENABLE_CUDA_RUNNER=ON \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DOPENMP_ENABLE_LIBOMPTARGET=OFF \
-DCMAKE_BUILD_TYPE=RELEASE \
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \
-DPython3_EXECUTABLE=$(which python3)

$ ninja check-clang check-mlir omp
```

### Build buddy-mlir

```bash
$ cd buddy-mlir
$ mkdir build && cd build
$ cmake -G Ninja .. \
-DMLIR_DIR=$PWD/../llvm/build/lib/cmake/mlir \
Expand All @@ -31,7 +67,7 @@ $ ninja
$ ninja check-buddy
```

2. Set the `PYTHONPATH` environment variable.
### Set the `PYTHONPATH` environment variable.

Make sure you are in the build directory.

Expand All @@ -41,13 +77,13 @@ $ export LLVM_MLIR_BUILD_DIR=$PWD/../llvm/build
$ export PYTHONPATH=${LLVM_MLIR_BUILD_DIR}/tools/mlir/python_packages/mlir_core:${BUDDY_MLIR_BUILD_DIR}/python_packages:${PYTHONPATH}
```

3. Set the `LENET_EXAMPLE_PATH` environment variable.
### Set the `LENET_EXAMPLE_PATH` environment variable.

```bash
$ export LENET_EXAMPLE_PATH=${BUDDY_MLIR_BUILD_DIR}/../examples/BuddyLeNet/
```

4. Build and run the LeNet example
### Build and run the LeNet example

```bash
$ cmake -G Ninja .. -DBUDDY_LENET_EXAMPLES=ON
Expand Down

0 comments on commit 1c338ba

Please sign in to comment.