Skip to content

calib3d: some tests fails using clang on Raspberry Pi 3 #11056

Closed

Description

@tomoaki0705
System information (version)
  • OpenCV => master ( c729fbd )
  • Operating System / Platform => Debian (Raspbian) 9.3 / Raspberry Pi 3
  • Compiler => GCC 4.9.2 / Clang 3.7.0
Detailed description
  • The following tests fails from opencv_test_calib3d
[==========] 89 tests from 46 test cases ran. (472539 ms total)
[  PASSED  ] 86 tests.
[  FAILED  ] 3 tests, listed below:
[  FAILED  ] Calib3d_SolveP3P.accuracy
[  FAILED  ] Calib3d_SolvePnPRansac.accuracy
[  FAILED  ] Calib3d_SolvePnP.accuracy

 3 FAILED TESTS
  • On the other hand, when building with GCC, this doesn't happen
[==========] 89 tests from 46 test cases ran. (410682 ms total)
[  PASSED  ] 89 tests.
complex<double> complex2 = 2 * q4 / sqrt_2m;
  • I added some printf and found weird behvior of complex
GCC(expected behavior)   |Clang (weird behavior)
=========================|=========================
q4      :-0.00130684     |q4      :-0.00130684    
2 * q4  :(-0.00261369,0) |2 * q4  :(-0.00261369,0)
sqrt_2m :(0.00617747,0)  |sqrt_2m :(0.00617747,0) 
complex2:(-0.4231,0)     |complex2:(-0.00261369,0)
  • It seems division of complex<double> has something wrong.
  • From this part, the data was different, and concluded as a massive number of failure.
  • Just to make sure, I wrote a small code to check the behaviour.
  • Even for the simplest following code, the result differs between the compiler
#include <iostream>
#include <cmath>
#include <complex>

int main(int argc, char**argv)
{
    std::complex<double> a(-0.00261369, 0);
    std::complex<double> b(0.00617747, 0);

    std::complex<double> c = a / b;
    std::cout << "a" << a << std::endl;
    std::cout << "b" << b << std::endl;
    std::cout << "c" << c << std::endl;

    return 0;
}
=========GCC=========
a(-0.00261369,0)
b(0.00617747,0)
c(-0.4231,0)
=========Clang=======
a(-0.00261369,0)
b(0.00617747,0)
c(-0.00261369,0)
=====GCC Version=====
g++ (Raspbian 4.9.2-10) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

=====Clang Version===
Raspbian clang version 3.7.0-4~bpo8+1 (tags/RELEASE_370/final) (based on LLVM 3.7.0)
Target: arm-unknown-linux-gnueabihf
Thread model: posix
  • I also tried on wandbox but this issue did not reproduce. I didn't use any suspicious clang, I installed clang using apt
  • I added a workaround using ifdef in this code, and avoided the issue.
  • I'll send PR later.
Steps to reproduce
  • run opencv_test_calib3d on Raspbian on Raspberry Pi 3, using clang

Activity

  1. alalek commented on Mar 12, 2018

    @alalek
    Member

    BTW, Can't reproduce with Clang 3.8 on TX-1 (aarch64, Ubuntu 16.04).

    Output:
    $ clang++ -O3 main.cpp -o main
    $ ./main 
    a(-0.00261369,0)
    b(0.00617747,0)
    c(-0.4231,0)
    $ clang++ --version
    clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
    Target: aarch64-unknown-linux-gnu
    Thread model: posix
    InstalledDir: /usr/bin
    
  2. tomoaki0705 commented on Mar 12, 2018

    @tomoaki0705
    ContributorAuthor

    Yeah, that's one reason I raised this issue.
    Which approach should we take ?

    1. Fix from upstream (Clang)
    2. work around in OpenCV (My PR)
    3. Ignore this issue (It's really version dependent issue, so the impact of this issue is relatively small)

    Probably we need more information, and I'll take a look, but how do you think @alalek ?

  3. alalek commented on Mar 13, 2018

    @alalek
    Member

    Workaround is fine, but I believe we should adjust condition: simple "clang" is too wide.
    It would be nice to add clang version check and/or target platform ("defined(arm) && !defined(aarch64) && !defined(ANDROID)" ?)
    You could try to use some defines from this command (run it on RPi3):

    clang++ -dM -E - < /dev/null
    
  4. tomoaki0705 commented on Mar 13, 2018

    @tomoaki0705
    ContributorAuthor

    I added some of your suggestions

    #if defined(__clang__) && defined(__arm) && __clang_major__ <= 3 && __clang_minor__ <= 7
    

    I wasn't sure about ANDROID, does it get build using LLVM ? I'm not sure about that point.
    if so, I'll add ANDROID in the condition, too.

  5. alalek commented on Mar 13, 2018

    @alalek
    Member

    __arm looks strange and almost not used: __arm__ should be fine.
    Android NDK deprecates GCC toolchains - they switching to clang.

    Version condition doesn't look really good (2.0-2.7 pass, 2.8+ doesn't, 3.0-3.7 pass again), this would be better with less questions:

    __clang_major__ <= 3
    __clang_major__ == 3
  6. tomoaki0705 commented on Mar 13, 2018

    @tomoaki0705
    ContributorAuthor

    Thank you !
    I updated the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions