onnx-mlir: onnx-mlir killed while generating .so file for onnx.CategoryMapper with 65537+ string constants
On my environment, onnx-mlir is killed while generating .so file for onnx.CategoryMapper with 100K string constants.
$ ./test_categorymapper.sh
**** Generating test_categorymapper_100000-onnxbasic.mlir
**** Compiling test_categorymapper_100000-onnxbasic.mlir
time /home1/negishi/src/dlc.git/onnx-mlir.opt/build/Debug/bin/onnx-mlir -v -mcpu=z14 --EmitLib --preserveBitcode --preserveLLVMIR test_categorymapper_100000-onnxbasic.mlir
./test_categorymapper.sh: line 28: 4051033 Killed /home1/negishi/src/dlc.git/onnx-mlir.opt/build/Debug/bin/onnx-mlir -v -mcpu=z14 --EmitLib --preserveBitcode --preserveLLVMIR test_categorymapper_100000-onnxbasic.mlir
real 11m39.898s
user 7m16.200s
sys 1m33.217s
Please reproduce the issue by the following sh script, which generates the input file and compile it by onnx-mlir. (Please fix the line beginning with “ONNXMLIR=” to specify the onnx-mlir command in your environment.)
ELEMENTNUM=100000
INPUTFILE="test_categorymapper_$ELEMENTNUM-onnxbasic.mlir"
TIME="time"
ONNXMLIR="./build/Debug/bin/onnx-mlir"
ONNXMLIR="/home/negishi/src/dlc.git/onnx-mlir.opt/build/Debug/bin/onnx-mlir"
COMPILEOPTION="-v -mcpu=z14 --EmitLib --preserveBitcode --preserveLLVMIR"
echo "**** Generating $INPUTFILE"
(
echo "module attributes {} {"
echo " func.func @main_graph(%arg0: tensor<?x!onnx.String>) -> (tensor<*xi64>) {"
echo -n " %0 = \"onnx.CategoryMapper\"(%arg0) {cats_int64s = [0"
for a in `seq 1 $ELEMENTNUM`; do echo -n ", $a"; done
echo -n "], cats_strings = [\"0\""
for a in `seq 1 $ELEMENTNUM`; do echo -n ", \"$a\""; done
echo "], default_int64 = 74353 : si64, default_string = \"_Unused\", onnx_node_name = \"CategoryMapper_4\"} : (tensor<?x!onnx.String>) -> tensor<*xi64>"
echo " return %0 : tensor<*xi64>"
echo " }"
echo " \"onnx.EntryPoint\"() {func = @main_graph} : () -> ()"
echo "}"
) > $INPUTFILE
echo "**** Compiling $INPUTFILE"
CMD="$TIME $ONNXMLIR $COMPILEOPTION $INPUTFILE"
echo "$CMD"
eval "$CMD"
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 19
Created a patch in LLVM to fix this issue: https://reviews.llvm.org/D148487
Good news: I can fix the memory issue. Bad news: we need to modify LLVM.
It is related to constant folding of
InsertValue. If an array has N string, there would be NInsertValueto insert constant addresses in the the array… Each timeInsertValueis folded, a new constant array of N elements are created and not freed. This issue is like the memory consumption issue in our compiler when doing constant propagation.I temporarily fix this issue by this patch:
By this patch we can compile @negiyas’s example in 9 minutes with around 1.6 GB memory comsumption:
Will prepare a patch to LLVM.