-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
Description
System information (version)
- OpenCV => 1a74de1 (4.2)
- Operating System / Platform => Android 4.4.4 amv7l
- Compiler => Android NDK r18b (clang, Android API level = 16)
- Optmization => -DCMAKE_BUILD_TYPE=Release (-Oz)
Detailed description
I'm getting a SIGBUS when loading an ONNX model on Android (armv7l), this problem only occurs when building with optimizations enabled, -O0 doesn't trigger the issue. I've nailed down the problem to these specific lines:
opencv/modules/dnn/src/onnx/onnx_importer.cpp
Lines 149 to 153 in d85e67d
| { | |
| char* val = const_cast<char*>(tensor_proto.raw_data().c_str()); | |
| int64_t* src = reinterpret_cast<int64_t*>(val); | |
| convertInt64ToInt32(src, dst, blob.total()); | |
| } |
The problem is that the pointer returned by std::string::c_str() doesn't have any guarantee that it is 8 bytes aligned, and sure enough when inspecting with GDB the val pointer isn't aligned, thus src.
I've workaround this by allocating a intermediate buffer and copying the data pointed by val:
{
char* val = const_cast<char*>(tensor_proto.raw_data().c_str());
int size = tensor_proto.raw_data().size();
int64_t* src = new int64_t[size];
memcpy(src, val, size);
convertInt64ToInt32(src, dst, blob.total());
delete[] src;
}I don't known if this is an good solution, please let me known.
Steps to reproduce
Build for Android armv7l, NDK r18b with optimizations. Call cv::dnn::readNetFromONNX() with a valid ONNX file.
Thanks,
Augusto.