apache / mxnet

Lightweight, Portable, Flexible Distributed/Mobile Deep Learning with Dynamic, Mutation-aware Dataflow Dep Scheduler; for Python, R, Julia, Scala, Go, Javascript and more
https://mxnet.apache.org
Apache License 2.0
20.79k stars 6.79k forks source link

mxnet-cpp package cross-compilation fails with OSError: "wrong ELF class: ELFCLASS32" #13303

Open TeXniKK opened 6 years ago

TeXniKK commented 6 years ago

Description

mxnet-cpp package cross-compilation fails with OSError: "wrong ELF class: ELFCLASS32"

Environment info (Required)

Host system: Ubuntu 18.04.1 LTS 4.15.0-38-generic x86_64 Target system: ARM Cortex-A9 CPU

What to do:
1. Configure Buildroot for target system

2. Add MxNet as a CMake Buildroot package

3. Compile package

Build info (Required if built from source)

Compiler (gcc/clang/mingw/visual studio): arm-buildroot-linux-gnueabihf-gcc-7.3.0

MXNet commit hash: 85fefa8c7291b556057ae685a5883c3f6a175c18

Build config: -DBUILD_CPP_EXAMPLES=OFF -DUSE_MKLDNN=OFF \ -DTHREADS_PTHREAD_ARG=OFF -DUSE_OPENCV=OFF \ -DUSE_OPENMP=OFF -DUSE_CUDA=OFF -DUSE_CUDNN=OFF \ -DUSE_SSE=OFF -DUSE_CPP_PACKAGE=ON -DUSE_LIBJPEG_TURBO=OFF \ -DENABLE_CUDA_RTC=OFF

Error Message:

mxnet 1.3.0 Building .... [ 86%] Building C object CMakeFiles/mxnet.dir/dummy.c.o [ 93%] Built target mxnet_unit_tests [ 93%] Linking CXX shared library libmxnet.so [ 93%] Built target mxnet Scanning dependencies of target cpp_package_op_h Running: OpWrapperGenerator.py Traceback (most recent call last): File "OpWrapperGenerator.py", line 428, in raise(e) OSError: buildroot/output/build/mxnet-1.3.0/libmxnet.so: wrong ELF class: ELFCLASS32 cpp-package/CMakeFiles/cpp_package_op_h.dir/build.make:58: recipe for target 'cpp-package/CMakeFiles/cpp_package_op_h' failed make[4]: [cpp-package/CMakeFiles/cpp_package_op_h] Error 1 CMakeFiles/Makefile2:541: recipe for target 'cpp-package/CMakeFiles/cpp_package_op_h.dir/all' failed make[3]: [cpp-package/CMakeFiles/cpp_package_op_h.dir/all] Error 2

Minimum reproducible example + Steps to reproduce

  1. Configure Buildroot for target system

  2. Add MxNet as a CMake Buildroot package: MXNET_VERSION:=1.3.0 MXNET_SITE:=https://github.com/apache/incubator-mxnet.git MXNET_SITE_METHOD = git MXNET_GIT_SUBMODULES = YES MXNET_INSTALL_STAGING = YES MXNET_CONF_OPTS = -DBUILD_CPP_EXAMPLES=OFF -DUSE_MKLDNN=OFF \ -DTHREADS_PTHREAD_ARG=OFF -DUSE_OPENCV=OFF \ -DUSE_OPENMP=OFF -DUSE_CUDA=OFF -DUSE_CUDNN=OFF \ -DUSE_SSE=OFF -DUSE_CPP_PACKAGE=ON -DUSE_LIBJPEG_TURBO=OFF \ -DENABLE_CUDA_RTC=OFF $(eval $(cmake-package))

  3. Compile package

What have you tried to solve it?

  1. Checked OpWrapperGenerator.py source code. It tries to invoke Python of the host system (x86_64) and perform cdll.libmxnet = cdll.LoadLibrary(sys.argv[1]) for library built for target. Eventually host Python know nothing about ARM library format.
zachgk commented 6 years ago

@mxnet-label-bot add [Build, CMake, ARM]

Thank you for submitting the issue! I'm labeling it so the MXNet community members can help resolve it.

lebeg commented 6 years ago

Yes, interesting issue. @leleamol

@TeXniKK try to do the following as a workaround:

TeXniKK commented 6 years ago

@lebeg , thanks for suggestion. I've slightly modified it, because removal of whole section will cause dependency failure of several MXNet modules.

This patch helped as a workaround:

index adff533..df8fa39 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -299,6 +299,8 @@ include_directories("3rdparty/tvm/include")
 include_directories("3rdparty/dmlc-core/include")
 include_directories("3rdparty/dlpack/include")

+install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/nnvm/include/nnvm DESTINATION ${CMAKE_INSTALL_INCLUDEDI$
+
 # commented out until PR goes through
 #if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/dlpack)
 # add_subdirectory(3rdparty/dlpack)
diff --git a/cpp-package/CMakeLists.txt b/cpp-package/CMakeLists.txt
index f7fbc77..fbe8c86 100644
--- a/cpp-package/CMakeLists.txt
+++ b/cpp-package/CMakeLists.txt
@@ -12,10 +12,12 @@ if(USE_CPP_PACKAGE)
     MAIN_DEPENDENCY mxnet
     DEPENDS mxnet ${CMAKE_CURRENT_SOURCE_DIR}/scripts/OpWrapperGenerator.py
     COMMAND echo "Running: OpWrapperGenerator.py"
-    COMMAND python OpWrapperGenerator.py $<TARGET_FILE:mxnet>
+#    COMMAND python OpWrapperGenerator.py $<TARGET_FILE:mxnet>
     WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts
   )

+  install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/mxnet-cpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+
   if(NOT DO_NOT_BUILD_EXAMPLES)
     add_subdirectory(example)
   endif()
diff --git a/cpp-package/include/mxnet-cpp/op.h b/cpp-package/include/mxnet-cpp/op.h
new file mode 100644
index 0000000..69409cd
--- /dev/null
+++ b/cpp-package/include/mxnet-cpp/op.h
.... Copied code here.....
lebeg commented 6 years ago

I'm glad you nailed it.

TeXniKK commented 6 years ago

@lebeg yep, but still it will be nice to generate some permanent fix for it )