Search code examples
androidcudaandroid-ndkgoogle-project-tangoabi

Can't get CUDA working on Tango, or: how do I mangle code for another ARM EABI?


First of all, sorry for the probably misleading title, but I can't think of a better short description.

For my Bachelor thesis I write a Tango app that requires CUDA for performance reasons. Unfortunately, I'm not a experienced Android dev, so 90% of all tutorials and guides regarding CUDA, JNI or Tango are not quite basic enough.

From what I gather, NVCC always generates code for the armeabi-v7a-hard ABI. Therefore, from what I understand, my "normal" C++ code must be compiled for this ABI as well. Although I then can't debug my C++ code, I can live with that and also got that working after many hours of reading and trial and error.

However, today I ran into this issue: https://stackoverflow.com/questions/35399927/how-can-i-use-armeabi-v7a-hard-in-my-tango-jni-app. libtango_client_api.so is not compiled for armeabi-v7a-hard. I don't understand why my linking process doesn't fail, but it is what it is.

From my point of view, I have several options now:

  1. Compile the entire project for armeabi-v7a. I believe this would be the best solution but requires that NVCC provides matching code. There seems to be the possibility to pass a -mfloat-abi=hard-switch to g++ but I can't find any documentation about what that does and causes and if it would work.

  2. In the mentioned StackOverflow-article they mentioned "mangling" the tango_client_api.h. I found two hints: 1 and 2, section 3.10, p. 12, so I tried changing each function declaration in the header from (e.g.)

    void TangoConfig_free(TangoConfig config)
    

    to

    void TangoConfig_free(TangoConfig config) __attribute__((pcs("aapcs-vpf"))) ;
    

    and

    __hardfp void TangoConfig_free(TangoConfig config);
    

    The former crashes with Error:error: 'pcs' attribute ignored [-Werror=attributes], the latter doesn't compile at all (Error:error: '__hardfp' does not name a type). So, either I'm doing something wrong or this is an attribute that is ignored by g++ and only honored by armcc.

  3. Recompile libtango_client_api.so. I can't find any source code on Google's website though.

  4. Not use the TangoService_getPoseAtTime-function. That wouldn't be a big issue, but I am afraid that I might find additional broken functions or get weird behaviour because it's apparently only working accidentally.

  5. Use a Java Wrapper for CUDA. Can't imagine that's a good idea, though...

Any help is much appreciated!


Solution

  • Why do you gather that nvcc only generates armeabi-v7a-hard code? You can compile CUDA code to regular armeabi-v7a binaries.

    As far as I know, nvcc depends on the toolchain you compile the code with (using the -ccbin parameter), and armeabi-v7a is supported with the flags -march=armv7-a -mfloat-abi=softfp.