Skip to content

Commit dfb43a9

Browse files
committed
DRAFT initial circle-mlir project
on-going draft to introduce initial circle-mlir project. Signed-off-by: SaeHie Park <[email protected]>
1 parent 2350ddb commit dfb43a9

File tree

29 files changed

+1828
-22
lines changed

29 files changed

+1828
-22
lines changed

.github/workflows/run-circle-mlir-build.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
include:
3636
- ubuntu_code: jammy
3737
ubuntu_vstr: u2204
38+
one_comp_ver: 1.29.0
3839

3940
runs-on: ubuntu-latest
4041

@@ -45,11 +46,19 @@ jobs:
4546
name: circle-mlir ${{ matrix.ubuntu_vstr }} ${{ matrix.type }} test
4647

4748
steps:
49+
# TODO prepare circle-interpreter Debian package and install
50+
- name: Install one-compiler
51+
run: |
52+
cd /var/tmp
53+
ONE_COMPILER=one-compiler-${{ matrix.ubuntu_code }}_${{ matrix.one_comp_ver }}_amd64.deb
54+
wget https://github.com/Samsung/ONE/releases/download/${{ matrix.one_comp_ver }}/${ONE_COMPILER}
55+
ls -al .
56+
dpkg -i ${ONE_COMPILER}
57+
ls -al /usr/share/one/bin
58+
4859
- name: Checkout
4960
uses: actions/checkout@v4
5061

51-
# TODO download circle-interpreter
52-
5362
# NOTE Docker image has pre-installed submodules in /workdir
5463
# NOTE Docker image has pre-installed python packages
5564
- name: Configure

circle-mlir/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,10 @@ if(CIRCLE_MLIR_LOCALINST)
4343
endif()
4444

4545
set(RES_CIRCLE_SCHEMA "${CMAKE_SOURCE_DIR}/../res/CircleSchema")
46+
if(NOT CIRCLE_MLIR_EXTERNALS)
47+
set(EXTERNALS_BIN_DIR "${CMAKE_BINARY_DIR}/externals")
48+
else()
49+
set(EXTERNALS_BIN_DIR "${CMAKE_SOURCE_DIR}/${CIRCLE_MLIR_EXTERNALS}")
50+
endif()
4651

4752
add_subdirectory(circle-mlir)

circle-mlir/Makefile.aa

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
all: cfg debug test install
2+
3+
cfg:
4+
Python3_ROOT_DIR=/usr/bin cmake -B build/debug -S ./ \
5+
-DCMAKE_INSTALL_PREFIX=build/debug.install \
6+
-DCMAKE_BUILD_TYPE=Debug \
7+
-DCIRCLE_MLIR_WORKDIR=/workdir
8+
9+
cc:
10+
Python3_ROOT_DIR=/usr/bin cmake -B build/debug -S ./ \
11+
-DCMAKE_INSTALL_PREFIX=build/debug.install \
12+
-DCMAKE_BUILD_TYPE=Debug
13+
14+
debug:
15+
cmake --build build/debug -j4
16+
17+
test:
18+
CTEST_OUTPUT_ON_FAILURE=1 cmake --build build/debug --verbose -- test
19+
20+
install:
21+
cmake --build build/debug -j4 -- install
22+

circle-mlir/Makefile.sample

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ endif
1515
# TODO error handle if not found
1616
PYTHON3_PATH=$(shell dirname $(PYTHON3_CMD))
1717

18+
# NOTE CIRCLEM_LIR_XXX is used for CMakeLists
19+
# CIRCLEMLIR_XXX is used in this Makefile
20+
1821
CIRCLEMLIR_BUILD_DEBUG?=build/debug
1922
CIRCLEMLIR_BUILD_REL?=build/release
23+
CIRCLEMLIR_BUILD_COV?=build/coverage
24+
CIRCLEMLIR_EXTS_DEBUG?=build/externals/debug
25+
CIRCLEMLIR_EXTS_REL?=build/externals/release
2026

2127
CIRCLEMLIR_PY3_ROOT?=$(PYTHON3_PATH)
2228
CIRCLEMLIR_BUILD_JOBS?=4
@@ -38,7 +44,16 @@ help:
3844
@echo "make prepr : prepare externals for release (needed only once)"
3945
@echo "make cfgr : configure circle-mlir for release build"
4046
@echo "make rel : build for release"
47+
@echo "make prepcov : prepare submodules for coverage test (needed only once)"
48+
@echo "make cfgcov : configure circle-mlir for debug build with coverage test"
49+
@echo "make debugcov : build for test coverage"
50+
@echo "make testcov : run coverage test"
51+
@echo "make gencov : generate test coverage report"
52+
@echo "make cleancov : clean test coverage build"
4153
@echo "make testr : test for release"
54+
@echo "make cfgdi : configure circle-mlir for debug build in Docker image"
55+
@echo "make cfgcovdi : configure circle-mlir for debug build with coverage test in Docker image"
56+
@echo "make cfgri : configure circle-mlir for release build in Docker image"
4257
@echo "make cleanr : clean release build"
4358
@echo "make cleanall : clean all build including overlay, externals"
4459

@@ -64,11 +79,12 @@ overlay:
6479

6580
prep: _mkbuild
6681
Python3_ROOT_DIR=$(CIRCLEMLIR_PY3_ROOT) \
67-
cmake -B $(CIRCLEMLIR_BUILD_DEBUG)/externals -S ./externals -DCMAKE_BUILD_TYPE=Debug
68-
cmake --build $(CIRCLEMLIR_BUILD_DEBUG)/externals -j$(CIRCLEMLIR_BUILD_JOBS)
82+
cmake -B $(CIRCLEMLIR_EXTS_DEBUG) -S ./externals -DCMAKE_BUILD_TYPE=Debug
83+
cmake --build $(CIRCLEMLIR_EXTS_DEBUG) -j$(CIRCLEMLIR_BUILD_JOBS)
6984

7085
cfg: _mkbuild
7186
cmake -B $(CIRCLEMLIR_BUILD_DEBUG) -S ./ \
87+
-DCIRCLE_MLIR_EXTERNALS=$(CIRCLEMLIR_EXTS_DEBUG) \
7288
-DONNX2CIRCLE_TEST_MODELS_SINGLE=ON
7389

7490
debug:
@@ -83,16 +99,49 @@ clean:
8399
rm -f $(CIRCLEMLIR_BUILD_DEBUG)/CMakeCache.txt
84100
rm -rf $(CIRCLEMLIR_BUILD_DEBUG)/circle-mlir/
85101

102+
#-------------------------------------------------------------------------------
103+
# for debug test coverage
104+
105+
prepcov: _mkbuildcov
106+
Python3_ROOT_DIR=$(CIRCLEMLIR_PY3_ROOT) \
107+
cmake -B $(CIRCLEMLIR_EXTS_DEBUG) -S ./externals -DCMAKE_BUILD_TYPE=Release
108+
cmake --build $(CIRCLEMLIR_EXTS_DEBUG) -j$(CIRCLEMLIR_BUILD_JOBS)
109+
110+
cfgcov: _mkbuildcov
111+
cmake -B $(CIRCLEMLIR_BUILD_COV) -S ./ \
112+
-DCIRCLE_MLIR_EXTERNALS=$(CIRCLEMLIR_EXTS_DEBUG) \
113+
-DONNX2CIRCLE_TEST_MODELS_SINGLE=ON \
114+
-DENABLE_COVERAGE=ON
115+
116+
debugcov:
117+
CM_PASS_DUMP=2 \
118+
cmake --build $(CIRCLEMLIR_BUILD_COV) -j$(CIRCLEMLIR_BUILD_JOBS)
119+
120+
# NOTE to configure in Docker, use "make cfgcovdi"
121+
122+
testcov:
123+
CM_PASS_DUMP=2 \
124+
CTEST_OUTPUT_ON_FAILURE=1 \
125+
cmake --build $(CIRCLEMLIR_BUILD_COV) --verbose -- test
126+
127+
gencov:
128+
bash infra/tools/gen-coverage-report circle-mlir
129+
130+
cleancov:
131+
rm -f $(CIRCLEMLIR_BUILD_COV)/CMakeCache.txt
132+
rm -rf $(CIRCLEMLIR_BUILD_COV)/circle-mlir/
133+
86134
#-------------------------------------------------------------------------------
87135
# for release
88136

89137
prepr: _mkbuildr
90138
Python3_ROOT_DIR=$(CIRCLEMLIR_PY3_ROOT) \
91-
cmake -B $(CIRCLEMLIR_BUILD_REL)/externals -S ./externals -DCMAKE_BUILD_TYPE=Release
92-
cmake --build $(CIRCLEMLIR_BUILD_REL)/externals -j$(CIRCLEMLIR_BUILD_JOBS)
139+
cmake -B $(CIRCLEMLIR_EXTS_REL) -S ./externals -DCMAKE_BUILD_TYPE=Release
140+
cmake --build $(CIRCLEMLIR_EXTS_REL) -j$(CIRCLEMLIR_BUILD_JOBS)
93141

94142
cfgr: _mkbuildr
95-
cmake -B $(CIRCLEMLIR_BUILD_REL) -S ./ -DCMAKE_BUILD_TYPE=Release
143+
cmake -B $(CIRCLEMLIR_BUILD_REL) -S ./ -DCMAKE_BUILD_TYPE=Release \
144+
-DCIRCLE_MLIR_EXTERNALS=$(CIRCLEMLIR_EXTS_REL)
96145

97146
rel:
98147
cmake --build $(CIRCLEMLIR_BUILD_REL) -j$(CIRCLEMLIR_BUILD_JOBS)
@@ -105,6 +154,33 @@ cleanr:
105154
rm -f $(CIRCLEMLIR_BUILD_REL)/CMakeCache.txt
106155
rm -rf $(CIRCLEMLIR_BUILD_REL)/circle-mlir/
107156

157+
#-------------------------------------------------------------------------------
158+
# for debug build in Docker
159+
#
160+
# no need to make for overlay, prep as prepared in Docker image
161+
# run make for 'cfgdi'
162+
# then make for 'debug', 'test'
163+
164+
cfgdi: _mkbuild
165+
cmake -B $(CIRCLEMLIR_BUILD_DEBUG) -S ./ \
166+
-DONNX2CIRCLE_TEST_MODELS_SINGLE=ON \
167+
-DCMAKE_BUILD_TYPE=Debug \
168+
-DCIRCLE_MLIR_WORKDIR=/workdir
169+
170+
# for test converage build in Docker
171+
cfgcovdi: _mkbuildcov
172+
cmake -B $(CIRCLEMLIR_BUILD_COV) -S ./ \
173+
-DONNX2CIRCLE_TEST_MODELS_SINGLE=ON \
174+
-DCIRCLE_MLIR_WORKDIR=/workdir \
175+
-DENABLE_COVERAGE=ON
176+
177+
# for release build in Docker
178+
179+
cfgri: _mkbuild
180+
cmake -B $(CIRCLEMLIR_BUILD_REL) -S ./ \
181+
-DONNX2CIRCLE_TEST_MODELS_SINGLE=ON \
182+
-DCMAKE_BUILD_TYPE=Release \
183+
-DCIRCLE_MLIR_WORKDIR=/workdir
108184

109185
#-------------------------------------------------------------------------------
110186

circle-mlir/README.md

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,175 @@
11
# circle-mlir
22

33
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 yapf==0.43.0 numpy==1.26.4 h5py==3.8.0 einops
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.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
include(UseMLIR)
2+
include(UseAbseil)
3+
24
add_subdirectory(lib)
5+
add_subdirectory(tools)
36
add_subdirectory(tools-test)

circle-mlir/circle-mlir/lib/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ add_subdirectory(tools)
33
add_subdirectory(arser)
44
add_subdirectory(schema)
55
add_subdirectory(dialect)
6-
add_subdirectory(utils)
7-
add_subdirectory(export)
6+
#add_subdirectory(utils)
7+
#add_subdirectory(pass)
8+
#add_subdirectory(import)
9+
#add_subdirectory(export)

circle-mlir/circle-mlir/lib/dialect/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ target_include_directories(cirmlir_dialect PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/in
1818
# use generated files
1919
add_dependencies(cirmlir_dialect circle_mlir_gen_inc)
2020
target_include_directories(cirmlir_dialect PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
21+
target_link_libraries(cirmlir_dialect PUBLIC abseil_cpp)
2122
target_link_libraries(cirmlir_dialect PUBLIC circle_schema)
2223
target_link_libraries(cirmlir_dialect PUBLIC cirmlir_coverage)
2324

0 commit comments

Comments
 (0)