Skip to content

Commit

Permalink
Merge pull request #427 from astro-informatics/cg_onnxrt_dynamic
Browse files Browse the repository at this point in the history
Updates from MSSL meeting
  • Loading branch information
20DM authored Sep 13, 2024
2 parents 6c5c8f1 + 90159c9 commit db06770
Show file tree
Hide file tree
Showing 17 changed files with 155 additions and 371 deletions.
86 changes: 25 additions & 61 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
OMP_NUM_THREADS: 2
CONAN_PRINT_RUN_COMMANDS: 1
CONAN_CPU_COUNT: 2
USE_CONAN: 0

jobs:
build:
Expand Down Expand Up @@ -47,11 +44,11 @@ jobs:
- g++-10
- clang++
mpi:
- "on"
- "off"
- "ON"
- "OFF"
omp:
- "on"
- "off"
- "ON"
- "OFF"
exclude:
- cc: gcc-10
cxx: clang++
Expand All @@ -61,7 +58,7 @@ jobs:
cc: clang
cxx: clang++
- os: macos-14
mpi: "on"
mpi: "ON"
# This doesn't seem to work with ONNXrt yet:
- os: macos-14
cxx: g++-10
Expand All @@ -75,18 +72,21 @@ jobs:
if: ${{ contains(matrix.os, 'ubuntu') }}
run: |
sudo apt update
sudo apt install openmpi-bin libopenmpi-dev libyaml-cpp-dev ccache
if [[ "$USE_CONAN" = 1 ]]; then
pip install conan
else
sudo apt install libeigen3-dev libtiff-dev
git clone https://github.com/catchorg/Catch2.git -b v3.4.0
mkdir Catch2/build
cd Catch2/build
cmake .. -DBUILD_TESTING=OFF -DCMAKE_INSTALL_PREFIX=${PWD}
make -j$(nproc --ignore 1) install
cd -
fi
sudo apt install openmpi-bin libopenmpi-dev libyaml-cpp-dev ccache libeigen3-dev libtiff-dev
- name: Checkout Catch2
uses: actions/checkout@v4
with:
repository: catchorg/Catch2.git
path: Catch2
ref: v3.4.0

- name: Build Catch2
run: |
mkdir Catch2/build
cd Catch2/build
cmake .. -DBUILD_TESTING=OFF -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local
make -j$(nproc --ignore 1) install
- name: Install Dependencies on MacOS
if: ${{ contains(matrix.os, 'macos') }}
Expand All @@ -95,9 +95,6 @@ jobs:
echo "CMAKE_PREFIX_PATH=/opt/homebrew/opt/libomp" >> $GITHUB_ENV
echo "/opt/homebrew/opt/ccache/libexec" >> $GITHUB_PATH
#echo "/opt/homebrew/opt/libomp" >> $GITHUB_PATH
if [[ "$USE_CONAN" = 1 ]]; then
brew install conan
fi
#- name: Install gcc on MacOS
# if: ${{ contains(matrix.os, 'macos') && contains(matrix.cxx, 'g++10') }}
Expand All @@ -109,28 +106,6 @@ jobs:
uses: mxschmitt/action-tmate@v3
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}

#- name: Install Tensorflow API on Ubuntu
# # TODO could this be combined with mac version somehow? if/else?
# if: ${{ contains(matrix.os, 'ubuntu') }}
# uses: UCL/install-tensorflow-action@main
# with:
# version: 2.11.0
# os: linux

#- name: Install Tensorflow API on MacOS
# if: ${{ contains(matrix.os, 'macos') }}
# uses: UCL/install-tensorflow-action@main
# with:
# version: 2.11.0
# os: darwin

- name: Select Python 3.10
# otherwise turtlebrowser/[email protected] fails on macos-14
# ref: https://github.com/turtlebrowser/get-conan/issues/4
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Prepare ccache timestamp
id: ccache_cache_timestamp
run: echo "{date_and_time}={$(date +'%Y-%m-%d-%H;%M;%S')}" >> $GITHUB_OUTPUT
Expand All @@ -148,26 +123,15 @@ jobs:
${{ matrix.os }}-${{ matrix.cxx }}
${{ matrix.os }}
- name: Dependencies
run: |
if [[ "$USE_CONAN" = 1 ]]; then
conan profile detect
conan install ${{github.workspace}} -of ${{github.workspace}}/build --build missing -o dompi=${{matrix.mpi}} -o openmp=${{matrix.omp}} -o onnxrt=on -s compiler.cppstd=17
fi
- name: Build
# Build your program with the given configuration.
# The Github Actions machines are dual-core so we can build faster using 2 parallel processes
run: |
if [[ "$USE_CONAN" = 1 ]]; then
conan build ${{github.workspace}} -of ${{github.workspace}}/build -o dompi=${{matrix.mpi}} -o openmp=${{matrix.omp}} -o onnxrt=on -s compiler.cppstd=17
else
export CMAKE_PREFIX_PATH=${{github.workspace}}/Catch2/build/lib/cmake:$CMAKE_PREFIX_PATH
mkdir ${{github.workspace}}/build
cd ${{github.workspace}}/build
cmake .. --fresh -DCMAKE_INSTALL_PREFIX=${PWD}
make -j$(nproc --ignore 1) install
fi
export CMAKE_PREFIX_PATH=${{github.workspace}}/local:$CMAKE_PREFIX_PATH
mkdir ${{github.workspace}}/build
cd ${{github.workspace}}/build
cmake .. --fresh -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local -Ddompi=${{matrix.mpi}} -Dopenmp=${{matrix.omp}}
make -j$(nproc --ignore 1) install
- name: Test
Expand Down
59 changes: 23 additions & 36 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ on:
default: false

env:
CONAN_PRINT_RUN_COMMANDS: 1
CONAN_REVISIONS_ENABLED: 1
OMP_NUM_THREADS: 2
CONAN_CPU_COUNT: 2
USE_CONAN: 0

jobs:
make-documentation:
Expand All @@ -34,47 +30,38 @@ jobs:
uses: mxschmitt/action-tmate@v3
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}

# Note that we are installing doxygen with apt here, and with conan in the Configure step.
# This is because there is no easy way of extracting the path to the doxygen executable from conan.
# the apt installed doxygen is used in the Make Docweb step to build the html files,
# while the conan installed version is used in the build step.
# -> Is this still true for Conan v2?
- name: Install dependencies
run: |
sudo apt update
sudo apt install openmpi-bin libopenmpi-dev libyaml-cpp-dev doxygen graphviz ccache
if [[ "$USE_CONAN" = 1 ]]; then
pip install conan
else
sudo apt install libeigen3-dev libtiff-dev
git clone https://github.com/catchorg/Catch2.git -b v3.4.0
mkdir Catch2/build
cd Catch2/build
cmake .. -DBUILD_TESTING=OFF -DCMAKE_INSTALL_PREFIX=${PWD}
make -j$(nproc --ignore 1)
make -j$(nproc --ignore 1) install
cd -
fi
sudo apt install openmpi-bin libopenmpi-dev libyaml-cpp-dev doxygen graphviz ccache libeigen3-dev libtiff-dev
- name: Checkout Catch2
uses: actions/checkout@v4
with:
repository: catchorg/Catch2.git
path: Catch2
ref: v3.4.0

- name: Build Catch2
run: |
mkdir Catch2/build
cd Catch2/build
cmake .. -DBUILD_TESTING=OFF -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local
make -j$(nproc --ignore 1) install
- name: Build
run: |
if [[ "$USE_CONAN" = 1 ]]; then
conan build ${{github.workspace}} -of ${{github.workspace}}/build
else
export CMAKE_PREFIX_PATH=${{github.workspace}}/Catch2/build/lib/cmake:$CMAKE_PREFIX_PATH
mkdir ${{github.workspace}}/build
cd ${{github.workspace}}/build
cmake .. --fresh -DCMAKE_INSTALL_PREFIX=${PWD} -Ddompi=OFF -Dopenmp=OFF -Ddocs=ON -Donnxrt=ON
make -j$(nproc --ignore 1)
make -j$(nproc --ignore 1) install
fi
export CMAKE_PREFIX_PATH=${{github.workspace}}/local:$CMAKE_PREFIX_PATH
mkdir ${{github.workspace}}/build
cd ${{github.workspace}}/build
cmake .. --fresh -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/local -Ddompi=OFF -Dopenmp=OFF -Ddocs=ON -Donnxrt=ON
make -j$(nproc --ignore 1)
make -j$(nproc --ignore 1) install
- name: Make Docweb
run: |
if [[ "$USE_CONAN" = 0 ]]; then
cd build
make docweb VERBOSE=1
fi
cd build
make docweb VERBOSE=1
- name: Deploy to GH pages
if: ${{github.event_name == 'push'}}
Expand Down
90 changes: 11 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,65 +27,17 @@ This documentation outlines the necessary and optional [dependencies](#dependenc
- [OpenMP](http://openmp.org/wp/) v4.8.4 (Trusty) - Optional - Speeds up some of the operations.
- [Eigen3](http://eigen.tuxfamily.org/index.php?title=Main_Page) v3.4.0 (Trusty) Modern `C++` linear algebra. Downloaded automatically if absent.
- [Catch2](https://github.com/catchorg/Catch2) v3.4.0 - Optional - A `C++`
unit-testing framework only needed for testing. Downloaded automatically if absent.
unit-testing framework only needed for testing.
- [google/benchmark](https://github.com/google/benchmark) - Optional - A `C++`
micro-benchmarking framework only needed for benchmarks. Downloaded automatically if absent.
micro-benchmarking framework only needed for benchmarks.
- [tiff](http://www.libtiff.org/) v4.5.1 (Trusty) Tag Image File Format library - only installed if needed.
- [ONNXruntime](https://onnxruntime.ai/) v1.17.1 - Optional - a cross-platform runtime engine based on the
Open Neural Network eXchange format.

## Installing and building SOPT

### Using Conan v2 (recommended)

[Conan](https://docs.conan.io/en/latest/installation.html) is a C++ package manager that helps deal with most of the C++ dependencies
as well as the **SOPT** installation:

1. Once the mandatory dependencies are present, `git clone` from the [GitHub repository](https://github.com/astro-informatics/sopt):

``` bash
git clone https://github.com/astro-informatics/sopt.git
```

1. Then, the program can be built using conan:

``` bash
cd /path/to/code
mkdir build
cd build
conan install .. -of . --build missing
conan build .. -of .
```

Things to note:

- To install in directory `INSTALL_FOLDER`, add the following options to the conan build command:

``` bash
conan build .. -of INSTALL_FOLDER
```

- CMake build options should be passed as options to `conan install` using the `-o` flag with a value `on` or `off`.
Possible options are:

- tests (default on)
- benchmarks (default off)
- examples (default on)
- openmp (default off)
- dompi (default off)
- docs (default off)
- coverage (default off)
- onnxrt (default off)

For example, to build with both MPI and OpenMP on you would use

``` bash
conan install .. -of . --build missing -o openmp=on -o dompi=on
conan build .. -of .
```


### Using CMake

If the dependencies are already available on your system, you can also install **SOPT** manually like so
If the dependencies are already available on your system, you can install **SOPT** manually like so

``` bash
cd /path/to/code
Expand All @@ -101,32 +53,8 @@ On MacOS, you can also install most of the dependencies with Homebrew e.g.
``` bash
brew install libtensorflow eigen tiff catch2
```
**Note that the ONNXruntime interface is currently only supported when compiling with Clang on MacOS, but not with g++**


## Conan tips
**Note that on MacOS, the ONNXruntime currently only support Clang but not g++**

You can set commonly used options, choices of compilers etc. in a
[conan profile](https://docs.conan.io/en/latest/reference/profiles.html).
You can list profiles available on your system using `conan profile list` and
select the profile you want to use with `conan install` with
`conan install .. -pr my_profile`.
CMake build options can also be added to the profile under `[options]`.
Here is an example of a conan profile for building with a homebrew installed gcc 11 on MacOS.

```
[settings]
os=Macos
os_build=Macos
arch=x86_64
arch_build=x86_64
compiler=gcc
compiler.version=11
compiler.libcxx=libstdc++11
build_type=Release
[options]
[build_requires]
```

## Testing

Expand Down Expand Up @@ -175,7 +103,6 @@ python -m tf2onnx.convert
--inputs input0:0
--extra_opset StatefulPartitionedCall:0
```
Unknown TF input dimensions can be specified e.g. using `--inputs 'input0:0[1,256,256,1]'`.
After the export, load the model and verify that it's well formed like so
```
Expand All @@ -184,6 +111,11 @@ onnx_model = onnx.load("model_name.onnx")
onnx.checker.check_model(onnx_model)
print( onnx_model.graph.input )
```
Hard-coded dimensions can be removed from the input/output tensor e.g. like so
```
print (onnx_model.graph.input[0].type.tensor_type.shape)
onnx_model.graph.input[0].type.tensor_type.shape.dim[1].ClearField('dim_value')
```
[Netron](https://netron.app/) is a useful online tool to help visualise the model.
Expand Down
Loading

0 comments on commit db06770

Please sign in to comment.