kendryte / nncase

Open deep learning compiler stack for Kendryte AI accelerators ✨
Apache License 2.0
752 stars 184 forks source link

'Fatal: Allocator has ran out of memory' - intermediate tensors less than 2M #49

Closed tjmc closed 5 years ago

tjmc commented 5 years ago

nncase is failing when using a graph with intermediate tensors in: 32x128x128 out: 64x128x128.

Sample tflite graph

./ncc compile detect.tflite detect.kmodel --dataset images/ -i tflite --dump-ir Fatal: Allocator has ran out of memory

32x128x128 + 64x128x128 = 1048576 + 524288 = 1,572,864

I'd expect this to work since it's less than 2,097,152 bytes.

ir_optimize_2: ir_optimize_2

ir_import: ir_import

sunnycase commented 5 years ago

You have encountered a memory fragment issue. Currently nncase uses a first-fit allocator. The 2nd conv2d's output occupies the middle range of the KPU memory, neither of the rest 2 free memory slices are enough to be allocated for the 3rd conv2d's output.

nncase now has a experimental allocator (https://github.com/kendryte/nncase/tree/features/best-alloc) which uses a CP solver to solve the NP-hard allocation problem. You can compile from sources or download prebuilt binaries from CI (https://dev.azure.com/sunnycase/nncase/_build?definitionId=1).

tjmc commented 5 years ago

I think there might be a dependency problem. best-alloc build is failing https://dev.azure.com/sunnycase/nncase/_build/results?buildId=23

/home/vsts/.conan/data/cbc/2.10/sunnycase/testing/package/346b7f78d3e4c19940cf936de17de5c2948ede92/lib/libCbcSolver.a(CbcSolver.cpp.o): In function CbcMain1(int, char const**, CbcModel&, int (*)(CbcModel*, int), CbcSolverUsefulData&)': CbcSolver.cpp:(.text+0xcd27): undefined reference toCbcHeuristicGreedyCover::CbcHeuristicGreedyCover(CbcModel&)' CbcSolver.cpp:(.text+0xcd76): undefined reference to `CbcHeuristicGreedyEquality::CbcHeuristicGreedyEquality(CbcModel&)'

I see the same error when I build locally.

sunnycase commented 5 years ago

@tjmc The build issue has been solved now.

tjmc commented 5 years ago

Thanks! I'm able to generate the kmodel with the latest changes.