|
1 | 1 | # circle-mlir |
2 | 2 |
|
3 | 3 | Circle MLIR dialect and tools |
| 4 | + |
| 5 | +## Tools provided |
| 6 | + |
| 7 | +_onnx2circle_ |
| 8 | +- conversion tool of ONNX to Circle model for `compiler` |
| 9 | +- to replace not-maintained-anymore onnx-tensorflow package |
| 10 | + |
| 11 | +## How to build |
| 12 | + |
| 13 | +Use provided `Makefile.sample` or create your own `Makefile` |
| 14 | +``` |
| 15 | +ln -s Makefile.sample Makefile |
| 16 | +``` |
| 17 | +- `Makefile` is in `.gitignore` to let developers use own Makefile. |
| 18 | + |
| 19 | +### Prerequisite |
| 20 | + |
| 21 | +``` |
| 22 | +sudo apt-get install build-essential cmake git fakeroot |
| 23 | +sudo apt-get install autoconf automake libtool unzip wget |
| 24 | +sudo apt-get install devscripts debmake debhelper lcov |
| 25 | +sudo apt-get install python3 python3-pip python3-venv python3-dev python3-all dh-python |
| 26 | +
|
| 27 | +python3 -m pip install --upgrade pip setuptools |
| 28 | +python3 -m pip install numpy h5py==3.8.0 |
| 29 | +``` |
| 30 | + |
| 31 | +### Prepare externals |
| 32 | + |
| 33 | +### Debug build |
| 34 | + |
| 35 | +Prepare overlay |
| 36 | +``` |
| 37 | +make overlay |
| 38 | +``` |
| 39 | + |
| 40 | +Build submodules in venv |
| 41 | +``` |
| 42 | +source infra/overlay/venv/bin/activate |
| 43 | +make prep |
| 44 | +``` |
| 45 | +NOTE `llvm-project` is built as `Debug` which may require 32G or more RAM. |
| 46 | +- if build fails for some reason, please change back to |
| 47 | + `-DCMAKE_BUILD_TYPE=Release` in `prep:` target in `Makefile.sample` file. |
| 48 | +- build and test needs venv python packages. |
| 49 | + |
| 50 | +NOTE `overlay` and `submodules` builds are needed only once. |
| 51 | + |
| 52 | +Configure and build |
| 53 | +``` |
| 54 | +make cfg |
| 55 | +make debug |
| 56 | +``` |
| 57 | + |
| 58 | +Test build |
| 59 | +``` |
| 60 | +make test |
| 61 | +``` |
| 62 | +- optionally, set `ONE_COMPILER_ROOT` to alternate PATH for local ONE build |
| 63 | + ``` |
| 64 | + ONE_COMPILER_ROOT=/home/user/one/build/install make test |
| 65 | + ``` |
| 66 | + |
| 67 | +To clean up existing build results |
| 68 | +``` |
| 69 | +make clean |
| 70 | +``` |
| 71 | + |
| 72 | +To clean up also `overlay` and `submodules` |
| 73 | +``` |
| 74 | +make cleanall |
| 75 | +``` |
| 76 | +- NOTE when using `CIRCLE_MLIR_LOCALINST`, need to manually clean up this folder |
| 77 | + |
| 78 | +### Release build |
| 79 | + |
| 80 | +Release build is available as follows. |
| 81 | +Others not mentioned are same as above Debug build. |
| 82 | + |
| 83 | +Build submodules in venv |
| 84 | +``` |
| 85 | +source infra/overlay/venv/bin/activate |
| 86 | +make prepr |
| 87 | +deactivate |
| 88 | +``` |
| 89 | + |
| 90 | +Configure and build |
| 91 | +``` |
| 92 | +make cfgr |
| 93 | +make rel |
| 94 | +``` |
| 95 | + |
| 96 | +Test build |
| 97 | +``` |
| 98 | +make testr |
| 99 | +``` |
| 100 | + |
| 101 | +### Test coverage |
| 102 | + |
| 103 | +To get test coverage report, run as following commands. |
| 104 | +- assume you already have done `make overlay` and `make prepcov` |
| 105 | +- you can skip `make prepcov` step if you are using local installation with `CIRCLE_MLIR_LOCALINST` |
| 106 | +- or you can reuse `CIRCLE_MLIR_LOCALINST` for existing debug or release build submodules with |
| 107 | +`cfgcov` target such as `CIRCLE_MLIR_LOCALINST=$(pwd)/build/debug/submodules make cfgcov` |
| 108 | +``` |
| 109 | +source infra/overlay/venv/bin/activate |
| 110 | +make cfgcov |
| 111 | +deactivate |
| 112 | +
|
| 113 | +make debugcov |
| 114 | +make testcov |
| 115 | +make gencov |
| 116 | +``` |
| 117 | + |
| 118 | +Open `converage/html/index.html` file in web browser to see the reports. |
| 119 | + |
| 120 | +To generate from second run and so on in your local machine, you will have to |
| 121 | +remove existing files before running `gencov` |
| 122 | +``` |
| 123 | +rm -rf coverage |
| 124 | +make gencov |
| 125 | +``` |
| 126 | + |
| 127 | +To run this with Docker image, use `cfgcovdi` target instead of `cfgcov`. |
| 128 | +``` |
| 129 | +make cfgcovdi |
| 130 | +make debugcov |
| 131 | +make testcov |
| 132 | +make gencov |
| 133 | +``` |
| 134 | + |
| 135 | + |
| 136 | +## Local format check |
| 137 | + |
| 138 | +Install prerequiste package. |
| 139 | +``` |
| 140 | +sudo apt-get install clang-format-12 python3 python3-pip |
| 141 | +python3 -m pip install yapf==0.32.0 |
| 142 | +``` |
| 143 | + |
| 144 | +Run format checker. |
| 145 | +``` |
| 146 | +bash ./infra/tools/format |
| 147 | +``` |
| 148 | +or with `Makefile` from `Makefile.sample` |
| 149 | +``` |
| 150 | +make format |
| 151 | +``` |
| 152 | + |
| 153 | +## Dump debug logs |
| 154 | + |
| 155 | +To see logs during conversion with `onnx2circle` tool, set `CM_PASS_DUMP=1` for |
| 156 | +preprocessing ONNX and ONNX to circle conversion, or set `CM_PASS_DUMP=2` to see |
| 157 | +additional logs for circle rewrite. |
| 158 | + |
| 159 | +``` |
| 160 | +CM_PASS_DUMP=2 onnx2circle input.onnx output.circle |
| 161 | +``` |
| 162 | + |
| 163 | +You can give `-debug` option to see general MLIR logs or `-debug-only=o2c` |
| 164 | +option to see only logs from onnx2circle. |
| 165 | + |
| 166 | +``` |
| 167 | +onnx2circle -debug-only=o2c input.onnx output.circle |
| 168 | +``` |
| 169 | + |
| 170 | +## TensorFlow source code |
| 171 | + |
| 172 | +Some source codes are referenced from TensorFlow and the file path is added to |
| 173 | +inside our source. |
| 174 | + |
| 175 | +Current codes are from `v2.12.1` tag. |
0 commit comments