-
Notifications
You must be signed in to change notification settings - Fork 12
/
compile.sh
executable file
·26 lines (19 loc) · 1.14 KB
/
compile.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash
printf "[Compile Script]: Getting the ONNX model\n"
FILE=gpt2-lm-head-10.onnx
if [ -f "$FILE" ]; then
echo "$FILE exists."
else
echo "$FILE does not exist."
wget https://github.com/onnx/models/raw/main/text/machine_comprehension/gpt-2/model/gpt2-lm-head-10.onnx
fi
printf "\n[Compile Script]: Convert TF model to LLVM IR\n"
onnx-mlir --EmitLLVMIR --instrument-onnx-ops="ALL" --InstrumentBeforeAndAfterOp gpt2-lm-head-10.onnx
mlir-translate -mlir-to-llvmir gpt2-lm-head-10.onnx.mlir > model.mlir.ll
printf "\n[Compile Script]: Compile main driver program and link to TF model in LLVM IR\n"
clang++ -DONNX_ML=1 input.c -o main.ll -O0 -S -emit-llvm -lonnx_proto -lprotobuf -I$ONNX_MLIR_SRC/include
llvm-link -o model.ll -S main.ll model.mlir.ll
printf "\n[Compile Script]: Generate model.exe \n"
llc -filetype=obj -o model.o model.ll -O0 --relocation-model=pic
clang++ -o model.exe model.o -L$LLFI_BUILD_ROOT/bin/../runtime_lib -lllfi-rt -lpthread -L /Debug/lib -Wl,-rpath $LLFI_BUILD_ROOT/bin/../runtime_lib -I$ONNX_MLIR_SRC/include -O0 -lonnx_proto -lprotobuf -lcruntime -ljson-c
printf "\n[Compile Script]: Compilation complete\n"