pytorch / executorch

On-device AI across mobile, embedded and edge for PyTorch
https://pytorch.org/executorch/
Other
2.21k stars 368 forks source link

error: 'realpath' was not declared in this scope when building ExecuTorch on ARM #6593

Open AIWintermuteAI opened 3 weeks ago

AIWintermuteAI commented 3 weeks ago

🐛 Describe the bug

Following the instructions https://github.com/pytorch/executorch/tree/main/examples/arm after successfully completing

# Step [1] - setup necessary tools
$ ./setup.sh --i-agree-to-the-contained-eula build-dir

then

# Step [2] - build + run ExecuTorch and executor_runner baremetal application
# suited for Corstone300 to run a simple PyTorch model.
$ ./run.sh --build-only --scratch-dir=build-dir

gets to building flatc and outputs the following error

/root/app/executorch/third-party/flatbuffers/src/util.cpp: In function 'std::string flatbuffers::AbsolutePath(const std::string&)':
/root/app/executorch/third-party/flatbuffers/src/util.cpp:353:29: error: 'realpath' was not declared in this scope
  353 |       char *abs_path_temp = realpath(filepath.c_str(), nullptr);

Full output of the command is

root@127cbb8410e1:~/app/executorch/examples/arm# ./run.sh --build-only --scratch-dir=build-dir
+ [[ -d /root/app/executorch/cmake-out ]]
+ mkdir -p /root/app/executorch/cmake-out
+ cd /root/app/executorch
++ which flatc
+ cmake -DCMAKE_INSTALL_PREFIX=/root/app/executorch/cmake-out -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=OFF -DCMAKE_BUILD_TYPE=Release -DEXECUTORCH_ENABLE_LOGGING=ON -DEXECUTORCH_BUILD_ARM_BAREMETAL=ON -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON -DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON -DFLATC_EXECUTABLE= -DCMAKE_TOOLCHAIN_FILE=/root/app/executorch/examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake -B/root/app/executorch/cmake-out /root/app/executorch
-- The C compiler identification is GNU 12.3.1
-- The CXX compiler identification is GNU 12.3.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /root/app/executorch/examples/arm/build-dir/arm-gnu-toolchain-12.3.rel1-aarch64-arm-none-eabi/bin/arm-none-eabi-gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /root/app/executorch/examples/arm/build-dir/arm-gnu-toolchain-12.3.rel1-aarch64-arm-none-eabi/bin/arm-none-eabi-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using python executable 'python3'
-- Resolved buck2 as /root/app/executorch/cmake-out/buck2-bin/buck2-49670bee56a7d8a7696409ca6fbf7551d2469787.
-- Killing buck2 daemon
'/root/app/executorch/cmake-out/buck2-bin/buck2-49670bee56a7d8a7696409ca6fbf7551d2469787 kill'
-- executorch: Generating source lists
-- executorch: Generating source file list /root/app/executorch/cmake-out/executorch_srcs.cmake
-- executorch: Using sources file /root/app/executorch/cmake-out/executorch_srcs.cmake
-- Proceeding with version: 24.3.25.0
-- Looking for strtof_l
-- Looking for strtof_l - not found
-- Looking for strtoull_l
-- Looking for strtoull_l - not found
-- Looking for realpath
-- Looking for realpath - found
-- CMAKE_CXX_FLAGS: 
-- executorch: Using PAL default 'posix'
-- Generating operator lib:
--   LIB_NAME: portable_ops_lib
--   OPS_SCHEMA_YAML: /root/app/executorch/kernels/portable/functions.yaml
--   ROOT_OPS: 
--   INCLUDE_ALL_OPS: 
Command - python3;-m;codegen.tools.gen_oplist;--output_path=/root/app/executorch/cmake-out/kernels/portable/portable_ops_lib/selected_operators.yaml;--ops_schema_yaml_path="/root/app/executorch/kernels/portable/functions.yaml"
-- Generating kernel bindings:
--   LIB_NAME: portable_ops_lib
--   FUNCTIONS_YAML: /root/app/executorch/kernels/portable/functions.yaml
--   CUSTOM_OPS_YAML: 
Generated files /root/app/executorch/cmake-out/kernels/portable/portable_ops_lib/RegisterCodegenUnboxedKernelsEverything.cpp;/root/app/executorch/cmake-out/kernels/portable/portable_ops_lib/Functions.h;/root/app/executorch/cmake-out/kernels/portable/portable_ops_lib/NativeFunctions.h
-- Generating operator lib:
--   LIB_NAME: portable_ops_lib
--   KERNEL_LIBS: portable_kernels
--   DEPS: executorch
CMake Deprecation Warning at third-party/gflags/CMakeLists.txt:73 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

-- Looking for C++ include unistd.h
-- Looking for C++ include unistd.h - found
-- Looking for C++ include stdint.h
-- Looking for C++ include stdint.h - found
-- Looking for C++ include inttypes.h
-- Looking for C++ include inttypes.h - found
-- Looking for C++ include sys/types.h
-- Looking for C++ include sys/types.h - found
-- Looking for C++ include sys/stat.h
-- Looking for C++ include sys/stat.h - found
-- Looking for C++ include fnmatch.h
-- Looking for C++ include fnmatch.h - found
-- Looking for C++ include stddef.h
-- Looking for C++ include stddef.h - found
-- Check size of uint32_t
-- Check size of uint32_t - done
-- Looking for strtoll
-- Looking for strtoll - found
-- Generating operator lib:
--   LIB_NAME: quantized_ops_lib
--   OPS_SCHEMA_YAML: /root/app/executorch/kernels/quantized/quantized.yaml
--   ROOT_OPS: 
--   INCLUDE_ALL_OPS: 
Command - python3;-m;codegen.tools.gen_oplist;--output_path=/root/app/executorch/cmake-out/kernels/quantized/quantized_ops_lib/selected_operators.yaml;--ops_schema_yaml_path="/root/app/executorch/kernels/quantized/quantized.yaml"
-- Generating kernel bindings:
--   LIB_NAME: quantized_ops_lib
--   FUNCTIONS_YAML: 
--   CUSTOM_OPS_YAML: /root/app/executorch/kernels/quantized/quantized.yaml
Generated files /root/app/executorch/cmake-out/kernels/quantized/quantized_ops_lib/RegisterCodegenUnboxedKernelsEverything.cpp;/root/app/executorch/cmake-out/kernels/quantized/quantized_ops_lib/Functions.h;/root/app/executorch/cmake-out/kernels/quantized/quantized_ops_lib/NativeFunctions.h;/root/app/executorch/cmake-out/kernels/quantized/quantized_ops_lib/RegisterCPUCustomOps.cpp;/root/app/executorch/cmake-out/kernels/quantized/quantized_ops_lib/RegisterSchema.cpp;/root/app/executorch/cmake-out/kernels/quantized/quantized_ops_lib/CustomOpsNativeFunctions.h
-- Generating operator lib:
--   LIB_NAME: quantized_ops_lib
--   KERNEL_LIBS: quantized_kernels
--   DEPS: executorch
-- 
-- ******** Summary ********
--   CMAKE_BUILD_TYPE              : Release
--   CMAKE_CXX_STANDARD            : 17
--   CMAKE_CXX_COMPILER_ID         : GNU
--   CMAKE_TOOLCHAIN_FILE          : /root/app/executorch/examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake
--   BUCK2                         : /root/app/executorch/cmake-out/buck2-bin/buck2-49670bee56a7d8a7696409ca6fbf7551d2469787
--   PYTHON_EXECUTABLE             : python3
--   FLATC_EXECUTABLE              : flatc
--   EXECUTORCH_ENABLE_LOGGING              : ON
--   EXECUTORCH_ENABLE_PROGRAM_VERIFICATION : OFF
--   EXECUTORCH_LOG_LEVEL                   : Info
--   EXECUTORCH_BUILD_ANDROID_JNI           : OFF
--   EXECUTORCH_BUILD_ARM_BAREMETAL         : ON
--   EXECUTORCH_BUILD_COREML                : OFF
--   EXECUTORCH_BUILD_KERNELS_CUSTOM        : OFF
--   EXECUTORCH_BUILD_EXECUTOR_RUNNER       : OFF
--   EXECUTORCH_BUILD_EXTENSION_DATA_LOADER : OFF
--   EXECUTORCH_BUILD_EXTENSION_MODULE      : OFF
--   EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL : ON
--   EXECUTORCH_BUILD_EXTENSION_TENSOR      : OFF
--   EXECUTORCH_BUILD_EXTENSION_TRAINING      : OFF
--   EXECUTORCH_BUILD_FLATC                 : ON
--   EXECUTORCH_BUILD_GFLAGS                : ON
--   EXECUTORCH_BUILD_GTESTS                : OFF
--   EXECUTORCH_BUILD_HOST_TARGETS          : ON
--   EXECUTORCH_BUILD_MPS                   : OFF
--   EXECUTORCH_BUILD_PYBIND                : OFF
--   EXECUTORCH_BUILD_QNN                   : OFF
--   EXECUTORCH_BUILD_KERNELS_OPTIMIZED     : OFF
--   EXECUTORCH_BUILD_KERNELS_QUANTIZED     : ON
--   EXECUTORCH_BUILD_DEVTOOLS              : OFF
--   EXECUTORCH_BUILD_SIZE_TEST             : OFF
--   EXECUTORCH_BUILD_XNNPACK               : OFF
--   EXECUTORCH_BUILD_VULKAN                : OFF
--   EXECUTORCH_BUILD_PTHREADPOOL           : OFF
--   EXECUTORCH_BUILD_CPUINFO               : OFF
-- Configuring done (5.4s)
-- Generating done (0.1s)
-- Build files have been written to: /root/app/executorch/cmake-out
+ echo '[build_executorch] Configured CMAKE'
[build_executorch] Configured CMAKE
+ cmake --build /root/app/executorch/cmake-out --parallel --target install --config Release
[  0%] Building CXX object third-party/gflags/CMakeFiles/gflags_nothreads_static.dir/src/gflags.cc.obj
[  1%] Building CXX object backends/arm/CMakeFiles/executorch_delegate_ethos_u.dir/runtime/ArmBackendEthosU.cpp.obj
[  1%] Building CXX object third-party/gflags/CMakeFiles/gflags_nothreads_static.dir/src/gflags_reporting.cc.obj
[  2%] Building CXX object backends/arm/CMakeFiles/executorch_delegate_ethos_u.dir/runtime/VelaBinStream.cpp.obj
[  2%] Building CXX object third-party/gflags/CMakeFiles/gflags_nothreads_static.dir/src/gflags_completions.cc.obj
[  3%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_parser.cpp.obj
[  3%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_text.cpp.obj
[  3%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/reflection.cpp.obj
[  4%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/util.cpp.obj
[  4%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_binary.cpp.obj
[  5%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_cpp.cpp.obj
[  5%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_csharp.cpp.obj
[  5%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_dart.cpp.obj
[  6%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_kotlin.cpp.obj
[  6%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_kotlin_kmp.cpp.obj
[  6%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_go.cpp.obj
[  7%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_java.cpp.obj
[  8%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_ts.cpp.obj
[  8%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_php.cpp.obj
[  8%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_lobster.cpp.obj
[  8%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_python.cpp.obj
[  9%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_rust.cpp.obj
[  9%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_fbs.cpp.obj
[ 10%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_grpc.cpp.obj
[ 10%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_swift.cpp.obj
[ 11%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/file_binary_writer.cpp.obj
[ 11%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/idl_gen_json_schema.cpp.obj
[ 11%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/file_name_saving_file_manager.cpp.obj
[ 11%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/file_writer.cpp.obj
[ 12%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/flatc.cpp.obj
[ 12%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/flatc_main.cpp.obj
[ 13%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/binary_annotator.cpp.obj
[ 13%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/annotated_binary_text_gen.cpp.obj
[ 13%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/bfbs_gen_lua.cpp.obj
[ 13%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/code_generators.cpp.obj
[ 14%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/src/bfbs_gen_nim.cpp.obj
[ 14%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/grpc/src/compiler/cpp_generator.cc.obj
[ 15%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/grpc/src/compiler/go_generator.cc.obj
[ 15%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/grpc/src/compiler/java_generator.cc.obj
[ 16%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/grpc/src/compiler/python_generator.cc.obj
[ 16%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/grpc/src/compiler/swift_generator.cc.obj
[ 16%] Building CXX object third-party/flatbuffers/CMakeFiles/flatc.dir/grpc/src/compiler/ts_generator.cc.obj
/root/app/executorch/third-party/flatbuffers/src/util.cpp: In function 'std::string flatbuffers::AbsolutePath(const std::string&)':
/root/app/executorch/third-party/flatbuffers/src/util.cpp:353:29: error: 'realpath' was not declared in this scope
  353 |       char *abs_path_temp = realpath(filepath.c_str(), nullptr);
      |                             ^~~~~~~~
[ 16%] Linking CXX static library libexecutorch_delegate_ethos_u.a
[ 16%] Built target executorch_delegate_ethos_u
gmake[2]: *** [third-party/flatbuffers/CMakeFiles/flatc.dir/build.make:118: third-party/flatbuffers/CMakeFiles/flatc.dir/src/util.cpp.obj] Error 1
gmake[2]: *** Waiting for unfinished jobs....
[ 16%] Linking CXX static library libgflags_nothreads.a
[ 16%] Built target gflags_nothreads_static
gmake[1]: *** [CMakeFiles/Makefile2:287: third-party/flatbuffers/CMakeFiles/flatc.dir/all] Error 2
gmake: *** [Makefile:136: all] Error 2

Versions

root@127cbb8410e1:~/app/executorch/examples/arm# python collect_env.py Collecting environment information... PyTorch version: N/A Is debug build: N/A CUDA used to build PyTorch: N/A ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.5 LTS (aarch64) GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 Clang version: Could not collect CMake version: version 3.30.5 Libc version: glibc-2.35

Python version: 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0] (64-bit runtime) Python platform: Linux-6.6.32-linuxkit-aarch64-with-glibc2.35 Is CUDA available: N/A CUDA runtime version: Could not collect CUDA_MODULE_LOADING set to: N/A GPU models and configuration: Could not collect Nvidia driver version: Could not collect cuDNN version: Could not collect HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: N/A

CPU: Architecture: aarch64 CPU op-mode(s): 64-bit Byte Order: Little Endian CPU(s): 10 On-line CPU(s) list: 0-9 Vendor ID: Apple Model: 0 Thread(s) per core: 1 Core(s) per cluster: 10 Socket(s): - Cluster(s): 1 Stepping: 0x0 BogoMIPS: 48.00 Flags: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm ssbs sb paca pacg dcpodp flagm2 frint Vulnerability Gather data sampling: Not affected Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Not affected Vulnerability Reg file data sampling: Not affected Vulnerability Retbleed: Not affected Vulnerability Spec rstack overflow: Not affected Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl Vulnerability Spectre v1: Mitigation; __user pointer sanitization Vulnerability Spectre v2: Not affected Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected

Versions of relevant libraries: [pip3] No relevant packages [conda] Could not collect

AIWintermuteAI commented 3 weeks ago

Same result for running in MacOS (above the results from Ubuntu 22.04 container on MacOS host created specifically to tests executorch). Could that be the realpath is present in the host system, but absent in the toolchain used for cross-compilation (here arm-gnu-toolchain-12.3.rel1-aarch64-arm-none-eabi/bin/arm-none-eabi-gcc)?

JacobSzwejbka commented 3 weeks ago

cc @digantdesai

zingo commented 1 week ago

I got this error during my build and I tried a lot of different combination of rm/rebuild and got passed it. Unfortunately my tests where a bit messy as I along the way ended up with another build error and I'm not sure what fixed it in the end. Looking in my bash history it mighe have been removing all cmake-out folders e.g.

rm -Rf cmake-out cmake-out-aot-lib/ examples/arm/executor_runner/cmake-out/

So that could be something to try.

Also as a note I'm not sure realpath() should be used in the embeded compilation (but are not 100% sure) and there is a flag detecting if its available, I kind of wonder if we both ended up in a mixed local gcc/target gcc problem where the wrong compiler was used/picked when config/building some stuff and then another when rerunning the build of flatc?

I'm sorry I don't have a solution for you but hope this might work out or at least give us some more clues.

AIWintermuteAI commented 1 week ago

Mixed local gcc / target gcc problem sounds very probable. Removing cmake-out does not fix the issue. Still waiting for response from PyTorch team, @digantdesai

zingo commented 1 week ago

Other things I did was to remove pip-out and a cmake folder under third party flatc , not sure if one of those also fixed something.

zingo commented 1 week ago

Another thing to check could be the python version used, I got the error with Python 3.12.3 (ubuntu 24.04) and and think the Executotch setup guide recommend Python 3.10. Since I not getting the error anymore Ill cant test if python 3.10 helps.

AIWintermuteAI commented 1 week ago

I have used Python 3.10.12 - you can see it in my python collect_env.py dump.

AdrianLundell commented 5 days ago

Hi, if you are still having this error I resolved it by running build/install_flatc.sh. Would be nice to find this path automatically or at least catch this with a better error though.

digantdesai commented 18 hours ago

IIUC is this because we shouldn't cross compile flatc in the first place?