iOS framework is being built without optimization. (Bug #2232)


Added by John Brewer over 12 years ago. Updated over 12 years ago.


Status:Done Start date:2012-08-03
Priority:Normal Due date:
Assignee:Vadim Pisarevsky % Done:

0%

Category:ios
Target version:2.4.3
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

Description

The iOS OpenCV 2.42. iOS framework as built by the included build scripts, as well as the prebuilt opencv2.framework available from the opencv.org home page are build without optimization. I first noticed this when I rebuilt a project of mine using the prebuilt opencv2.framework. My app started running about 1/5 the speed of the old version, where I included the OpenCV sources directly, and was compiled everything with -Os.

Steps to reproduce:

1. Download OpenCV-2.4.2.tar.bz2 by clicking on the "OpenCV for Linux/Mac" link on the opencv.org homepage.
2. tar -xzvf OpenCV-2.4.2.tar.bz2
3. ln -s OpenCV-2.4.2 opencv # so scripts will run

Using the Python script:

4. mkdir opencv-python-build
5. cd opencv/ios
6. ./build_framework.py ../../opencv-python-build
7. Note compiler commands generated include -O0

Using the shell script (per the readme.txt file in the opencv/ios directory):

8. cd ../..
9. mkdir opencv-shell-build
10. cd opencv-shell-build
11. ../opencv/ios/configure-device_xcode.sh
12. xcodebuild -sdk iphoneos -configuration Release -target ALL_BUILD
13. Note that compiler commands generated include -O0

This is using Cmake 2.8.8 and Xcode 4.3.3.


Associated revisions

Revision 9db42aca
Added by Philipp Wagner over 12 years ago

Issue #2232: Bugfixes for 64bit Python-compability.

Revision 8efb84b5
Added by Vadim Pisarevsky over 12 years ago

added ios camera support in highgui. turned on optimization in opencv2.framework (ticket #2232)

Revision b0befeb1
Added by Andrey Pavlenko about 11 years ago

Merge pull request #2232 from ilya-lavrenov:ABF_drop

History

Updated by Daniil Osokin over 12 years ago

John, here is no Bug. You can profile your app and find, that routine started to consume more time as usual. If it's because OpenCV, you can ask about changes at http://answers.opencv.org/questions/.

Updated by John Brewer over 12 years ago

Here's a hack to opencv/ios/build_framework.py to delete the offending code:

53a54,55

os.system("sed -i bak '/GCC_OPTIMIZATION_LEVEL/d' OpenCV.xcodeproj/project.pbxproj")

Obviously it would be better to fix the Cmake scripts, but this at least gets my frame rate back up to where it should be.

Updated by John Brewer over 12 years ago

Daniil Osokin wrote:

John, here is no Bug. You can profile your app and find, that routine started to consume more time as usual. If it's because OpenCV, you can ask about changes at http://answers.opencv.org/questions/.

It is a real and genuine bug. OpenCV is building without optimization in release mode for iOS. If it were otherwise, my sed hack wouldn't drastically increase my frame rate.

Updated by John Brewer over 12 years ago

Looks like the actual bug is in Cmake. The "ALL_BUILD" target for even a simple "Hello, world" project forces "-O0" for all build configurations, although the actual "Hello" target does not.

It appears that the Cmake-generated "ALL_BUILD" target in Xcode doesn't work in general. See for example:

"Note: ALL_BUILD does not work properly with Xcode 4."
http://www.ogre3d.org/tikiwiki/CMake+Quick+Start+Guide?tikiversion=Mac+OS+X

I'll look at patching the build_framework.py script to use a different build target tomorrow.

Updated by Daniil Osokin over 12 years ago

Ok, looking forward to a patch.

Updated by Jesus Nuevo-Chiquero over 12 years ago

Hi all,

I don't know if this has already been solved, but my solution was to include a file "iOS-gcc.cmake" in ${OPENCV_ROOT}/ios/cmake/Modules/Platform, with the following contents:

SET (CMAKE_C_FLAGS_RELEASE_INIT "-O3 -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELEASE_INIT "-O3 -DNDEBUG")

SET (CMAKE_C_FLAGS_DEBUG_INIT "-O0 -gdwarf-2")
SET (CMAKE_CXX_FLAGS_DEBUG_INIT "-O0 -gdwarf-2")

According to the CMake wiki (http://www.cmake.org/Wiki/CMake_Cross_Compiling), CMake will look for this file when crosscompiling. The variables are then set to the usual CMAKE_*_FLAGS_RELEASE or _DEBUG by CMake.

Cheers,
J.

Updated by Jesus Nuevo-Chiquero over 12 years ago

My apologies for replying to myself.

After a cleanup it seems that setting this variables overwrites the CMAKE_CXX_FLAGS that are currently set in iOS.cmake. A solution is moving those values to the iOS-gcc.cmake file. My file looks like this, finally:

SET (CMAKE_CXX_FLAGS_INIT "-fvisibility=hidden -fvisibility-inlines-hidden")
SET (CMAKE_CXX_FLAGS_RELEASE_INIT "-O3 -DNDEBUG")
SET (CMAKE_CXX_FLAGS_DEBUG_INIT "-O0 -gdwarf-2")

Other variables for other CMAKE_BUILD_TYPE can be set that way too. (Maybe a better option would be to use a macro as in ${CMAKE_ROOT}/share/cmake-2.8/Modules/Compiler/GNU.cmake, but this does the trick for me.)
Regards,
J.

Updated by Andrey Kamaev over 12 years ago

  • Assignee set to Vadim Pisarevsky

Updated by Reto Grieder over 12 years ago

Usually, when dealing with compiler flags and CMake, it's a good idea to leave them as they are and only add new stuff because CMake already has a good set of default flags for Debug and Release.
However, I don't know about cross compiling here. Maybe the flags are wrong to start with.

Anyway, for now I just employed a hack with "-O3 -DNDEBUG -ffast-math" in the CMake files.

Updated by Vadim Pisarevsky over 12 years ago

thanks! fixed in d8b69d7

  • Status changed from Open to Done
  • Target version set to 2.4.3

Also available in: Atom PDF