kalwalt / PTAM-GPL

PTAM (Parallel Tracking and Mapping) re-released under GPLv3.
GNU General Public License v3.0
2 stars 0 forks source link

Emscripten compilation #1

Open kalwalt opened 3 years ago

kalwalt commented 3 years ago

Compile PTAM with Emscripten

@Carnaux @ThorstenBux i created this issue to share our results. I'm testing under Ubuntu 20.04. Emscripten 1.38.15 (need to update to a newest version) Followed the instructions by @ThorstenBux in the Readme:

emcmake cmake .
emmake make

First issue i need to copy the file arith.h included in external/clapack-3.2.1/build-x86-vc12/F2CLIBS/libf2c" inside external/clapack-3.2.1/F2CLIBS/libf2c

then the cmake config is build and i can run emmake make but it fails with this error:

/home/walter/kalwalt-github/PTAM-GPL/external/clapack-3.2.1/BLAS/SRC/xerbla.c:70:2: error: 
      implicitly declaring library function 'printf' with type
      'int (const char *, ...)' [-Werror,-Wimplicit-function-declaration]
        printf("** On entry to %6s, parameter number %2i had an illegal ...
        ^
/home/walter/kalwalt-github/PTAM-GPL/external/clapack-3.2.1/BLAS/SRC/xerbla.c:70:2: note: 
      include the header <stdio.h> or explicitly provide a declaration for
      'printf'
/home/walter/kalwalt-github/PTAM-GPL/external/clapack-3.2.1/BLAS/SRC/xerbla.c:71:11: warning: 
      format specifies type 'int' but the argument has type 'integer'
      (aka 'long') [-Wformat]
                srname, *info);
                        ^~~~~
1 warning and 1 error generated.

i solved this issue adding inside /external/clapack-3.2.1/BLAS/SRC/xerbla.c a stdio.h include:

#include "f2c.h"
#include "blaswrap.h"
+ #include <stdio.h>
-

After that the build process continue and it fails at external/libcvd/cvd_src/get_time_of_day_ns.cc :

/home/walter/kalwalt-github/PTAM-GPL/external/libcvd/cvd_src/get_time_of_day_ns.cc:9:57: error: 
      no member named 'to_time_t' in 'std::__2::chrono::steady_clock'
  return (long long)std::chrono::high_resolution_clock::to_time_t(std::c...
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
1 error generated.
ERROR:root:compiler frontend failed to generate LLVM bitcode, halting

i excluded for now that line of code;

#include "cvd/timer.h"
#include <chrono>

namespace CVD {

long long get_time_of_day_ns()
{
 // i excluded this line of code from compilation
 // return (long long)std::chrono::high_resolution_clock::to_time_t(std::chrono::high_resolution_clock::now());
}

}

the build process continue but fails at external/libcvd/CMakeFiles/libcvd.dir/cvd_src/i686/convolve_gaussian.cc :

[ 96%] Building CXX object external/libcvd/CMakeFiles/libcvd.dir/cvd_src/i686/convolve_gaussian.cc.o
/home/walter/kalwalt-github/PTAM-GPL/external/libcvd/cvd_src/i686/convolve_gaussian.cc:260:30: error: 
      use of undeclared identifier '_mm_getcsr'
    unsigned int csr_state = _mm_getcsr();
                             ^
/home/walter/kalwalt-github/PTAM-GPL/external/libcvd/cvd_src/i686/convolve_gaussian.cc:261:29: error: 
      use of undeclared identifier '_MM_FLUSH_ZERO_ON'
    _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
                            ^
/home/walter/kalwalt-github/PTAM-GPL/external/libcvd/cvd_src/i686/convolve_gaussian.cc:374:5: error: 
      use of undeclared identifier '_mm_setcsr'; did you mean '_mm_set_ss'?
    _mm_setcsr(csr_state);
    ^~~~~~~~~~
    _mm_set_ss
/home/walter/emsdk/emscripten/1.38.15/system/include/SSE/xmmintrin.h:35:1: note: 
      '_mm_set_ss' declared here
_mm_set_ss(float __w)
^
3 errors generated.

This last issue i haven't solved...

Carnaux commented 3 years ago

Maybe we could create a standard setup(hardware-independent?) with Docker? One of the issues might be including different versions of the libraries. We will always get a new file error, at least I always got when trying to build ORB, then you get to a system file that should be there, but it isn't. If we can find a way to do that maybe we can compile it nicely. @thorsten @kalwalt did you compile it without emscripten?

kalwalt commented 3 years ago

Yes a Docker set up would be nice, haven't yet tested the standard compilation.

ThorstenBux commented 3 years ago

On one Mac I can compile it (the normal compile with make) on the other I get ioStream file not found.

ThorstenBux commented 3 years ago

Hm, now I can actually build it with EM successfully too. But only on that isolated case.

kalwalt commented 3 years ago

I can compile the static lib with gcc without problems, i will try to build also the apps.

Carnaux commented 3 years ago

I'm almost compiling it with emscripten, I solved the cvd issues @kalwalt was having, also needed to update the libcvd, use this repo, only copy the cvd and cvd_src folders, maintain the make instructions.

To use the new libcvd:

  1. Rename the config.h.in file
  2. Remove the "Video" folder from the cvd folder
  3. Remove the "ucvbuffer.cc" file from the cvd_src folder

Now I'm getting:

[100%] Building CXX object ptam/CMakeFiles/PTAM.dir/construct/small_blurry_image.cc.o
clang-13: warning: argument unused during compilation: '-stdlib=libstdc++' [-Wunused-command-line-argument]
/home/daniel/Desktop/emscriptenProjects/emsdk/ptam-projects/ptam_plus/thorsten/ptam_plus/ptam/construct/small_blurry_image.cc:122:10: error: no member named 'transform' in namespace 'CVD'
    CVD::transform(mimTemplate, imWarped, se2XForm.get_rotation().get_matrix(),
    ~~~~~^
1 error generated.

Also I'm using ptam_plus as base.

In case you want to use my changes I created this repo

kalwalt commented 3 years ago

@Carnaux i found this transform https://github.com/edrosten/libcvd/blob/b30062150f6a5f105df7d1d8a3899ef96170820e/cvd/distance_transform.h#L196-L200 but not seems to match the args.

kalwalt commented 3 years ago

no it is defined here https://github.com/edrosten/libcvd/blob/b30062150f6a5f105df7d1d8a3899ef96170820e/cvd/vision.h#L412 but why it fails? And: which libcvd branch did you used? the say master branch requires C++14.

kalwalt commented 3 years ago

Testing your ptam_plus.js, it is required to add a define #if defined(CVD_HAVE_TOON) https://github.com/edrosten/libcvd/blob/b30062150f6a5f105df7d1d8a3899ef96170820e/cvd/vision.h#L399 but not sure how is best to add.

kalwalt commented 3 years ago

running emcmake cmake -D=CVD_HAVE_TOON . doesn't change anything.

Carnaux commented 3 years ago

I was using the master, didn't notice it was c++14. I tried to add it too, but no luck

kalwalt commented 3 years ago

I was using the master, didn't notice it was c++14. I tried to add it too, but no luck

I think we are very close to a full build!

Carnaux commented 3 years ago

I was using the master, didn't notice it was c++14. I tried to add it too, but no luck

I think we are very close to a full build!

Yeah, it's already building the ptam files, if I find time I will work on it today.

Carnaux commented 3 years ago

@ThorstenBux did manage to get the build working on both Mac setups?

ThorstenBux commented 3 years ago

@ThorstenBux did manage to get the build working on both Mac setups?

No unfortunately only on one.

kalwalt commented 3 years ago

Hi Daniel @Carnaux have you made some progresses on this side?

Carnaux commented 3 years ago

Not yet :/