Unity crash when loading ncnn model compiled with NCNN_OPENMP=ON
by DllImport(C++ library) .
The error occurs when calling load_model
. load_param
is fine.
Once set NCNN_OPENMP
as OFF
when compiling ncnn, ncnn model including load_model
and forword
is fine.
As reference, load and run libtorch is ok with same unity-c++dll way. Libtorch Example cod is from https://pytorch.org/cppdocs/installing.html .
By now, have no idea whether libtorch is compiled with openmp or not.
error log | 日志或报错信息 | ログ
Unity Editor.log shows crash error.
context | 编译/运行环境 | バックグラウンド
unity version:2020.3.2f1
ncnn version: e9a61b3
os version: macOS catalina 10.15.7
how to reproduce | 复现步骤 | 再現方法
- In C++: write and compile c++ code as dll (bundle in my mac pc)
example.h
extern "C" {
ncnn::Net * net_point;
void InitNetwork() {};
}
example.cpp
#include <example.h>
void InitNetwork() {
net_point = new ncnn::Net;
ncnn::Net net& = *net_point;
net_point->load_param(param_path);
net->load_model(model_path);
}
- In unity: load c++ dll in unity c# code and call in
Start
funtion
[DllImport("torch_unity", CallingConvention = CallingConvention.Cdecl)]
private static extern void InitNetwork();
2条答案
按热度按时间1rhkuytd1#
I ran recently in a similar issue, probably you are using another library built with OpenMP too.
I also had issues running OpenMP together with other libraries that make use of parallel processing (like
multiprocessing
in python). But in that case the program hangs forever, doesn't crash.Try to set
omp_set_dynamic(false);
andomp_set_num_threads(1);
before loading your model, if that doesn't fix anything, you are probably in the first case and I didn't find any workaround other than building NCNN without OpenMP support.4sup72z82#
Same problems. When NCNN compilde with opnemp support I get error on this project GPGAN-ncnn
Without OpenMP it work fine.