Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compilation error: array subscript 5 is above array bounds with aarch64-none-linux-gnu-g++ 12.2.Rel1 #727

Open
maxmarsc opened this issue May 25, 2023 · 2 comments
Labels
Build issue This problem was about building ArmNN or one of its dependencies.

Comments

@maxmarsc
Copy link

maxmarsc commented May 25, 2023

I'm trying to cross compile ArmNN with Arm Compute Library backend using the Arm GNU Toolchain 12.2.Rel1 and this compilation error occurs :

In file included from /home/mcoutant/work/armnn/include/armnn/Types.hpp:7,
                 from /home/mcoutant/work/armnn/include/armnn/Tensor.hpp:9,
                 from /home/mcoutant/work/armnn/src/armnnUtils/Permute.cpp:6:
In static member function ‘static constexpr _Tp& std::__array_traits<_Tp, _Nm>::_S_ref(const _Tp (&)[_Nm], std::size_t) [with _Tp = unsigned int; long unsigned int _Nm = 5]’,
    inlined from ‘constexpr std::array<_Tp, _Nm>::value_type& std::array<_Tp, _Nm>::operator[](size_type) [with _Tp = unsigned int; long unsigned int _Nm = 5]’ at /usr/local/aarch64-none-linux-gnu/aarch64-none-linux-gnu/include/c++/12.2.1/array:209:25,
    inlined from ‘void {anonymous}::PermuteLoop::Unroll(size_type, const unsigned char*, unsigned char*, const unsigned char*, unsigned char*, size_t)’ at /home/mcoutant/work/armnn/src/armnnUtils/Permute.cpp:83:50,
    inlined from ‘void {anonymous}::PermuteLoop::Unroll(size_type, const unsigned char*, unsigned char*, const unsigned char*, unsigned char*, size_t)’ at /home/mcoutant/work/armnn/src/armnnUtils/Permute.cpp:80:23,
    inlined from ‘void {anonymous}::PermuteLoop::Unroll(size_type, const unsigned char*, unsigned char*, const unsigned char*, unsigned char*, size_t)’ at /home/mcoutant/work/armnn/src/armnnUtils/Permute.cpp:80:23,
    inlined from ‘void {anonymous}::PermuteLoop::Unroll(size_type, const unsigned char*, unsigned char*, const unsigned char*, unsigned char*, size_t)’ at /home/mcoutant/work/armnn/src/armnnUtils/Permute.cpp:80:23,
    inlined from ‘void {anonymous}::PermuteLoop::Unroll(size_type, const unsigned char*, unsigned char*, const unsigned char*, unsigned char*, size_t)’ at /home/mcoutant/work/armnn/src/armnnUtils/Permute.cpp:80:23,
    inlined from ‘void {anonymous}::PermuteLoop::Unroll(size_type, const unsigned char*, unsigned char*, const unsigned char*, unsigned char*, size_t)’ at /home/mcoutant/work/armnn/src/armnnUtils/Permute.cpp:80:23,
    inlined from ‘void {anonymous}::PermuteLoop::Unroll(const void*, void*, size_t)’ at /home/mcoutant/work/armnn/src/armnnUtils/Permute.cpp:55:15,
    inlined from ‘void armnnUtils::Permute(const armnn::TensorShape&, const armnn::PermutationVector&, const void*, void*, size_t)’ at /home/mcoutant/work/armnn/src/armnnUtils/Permute.cpp:134:43:
/usr/local/aarch64-none-linux-gnu/aarch64-none-linux-gnu/include/c++/12.2.1/array:61:36: error: array subscript 5 is above array bounds of ‘std::__array_traits<unsigned int, 5>::_Type’ {aka ‘const unsigned int [5]’} [-Werror=array-bounds]
   61 |       { return const_cast<_Tp&>(__t[__n]); }
      |                                 ~~~^

The CMake toolchain file I use for both ArmCL and ArmNN is :

# targets
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(triple aarch64-linux-gnu)

# misc settings
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
set(GNU_ROOT "/usr/local/aarch64-none-linux-gnu")
set(CMAKE_SYSROOT "${GNU_ROOT}/aarch64-none-linux-gnu/libc")

# find paths
set(CMAKE_FIND_ROOT_PATH "${GNU_ROOT}")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)

# compiler settings
set(CMAKE_C_COMPILER "${GNU_ROOT}/bin/aarch64-none-linux-gnu-gcc" CACHE INTERNAL "")
set(CMAKE_CXX_COMPILER "${GNU_ROOT}/bin/aarch64-none-linux-gnu-g++" CACHE INTERNAL "")

set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER_TARGET ${triple})

set(CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN "${GNU_ROOT}/lib/gcc")
set(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN "${GNU_ROOT}/lib/gcc")

# CPU tuning : the RPI 0 2W uses a Cortex a53
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mtune=cortex-a53" CACHE STRING "")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mtune=cortex-a53" CACHE STRING "")

# Qemu emulation setup
set(CMAKE_CROSSCOMPILING_EMULATOR "qemu-aarch64-static;-L;${CMAKE_SYSROOT}" CACHE FILEPATH "Path to the emulator for the target system.")

# Include settings
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES
  ${GNU_ROOT}/aarch64-none-linux-gnu/include/c++/12.2.1
  ${GNU_ROOT}/aarch64-none-linux-gnu/libc/usr/include
  ${GNU_ROOT}/include
  ${GNU_ROOT}/aarch64-none-linux-gnu/include/c++/12.2.1/aarch64-none-linux-gnu
  ${GNU_ROOT}/lib/gcc/aarch64-none-linux-gnu/12.2.1/include
)

set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES
  ${GNU_ROOT}/aarch64-none-linux-gnu/libc/usr/include
)

(with aarch64-none-linux-gnu installed under /usr/local)

I first compiled locally ArmCL with the following flags :

 -D CMAKE_TOOLCHAIN_FILE="myToolchainFile.cmake"
 -D BUILD_SHARED_LIBS=OFF
 -D ARM_COMPUTE_EXCEPTIONS=OFF

Then tried to build ArmNN like this :

export ARMCOMPUTE_LIBRARIES="${ARMCOMPUTE_BUILD_DIR}/libarm_compute_core.a;${ARMCOMPUTE_BUILD_DIR}/libarm_compute_graph.a;${ARMCOMPUTE_BUILD_DIR}/libarm_compute_sve.a;${ARMCOMPUTE_BUILD_DIR}/libarm_compute_sve2.a"

cmake -B build -D CMAKE_TOOLCHAIN_FILE="myToolchainFile.cmake" -D BUILD_CLASSIC_DELEGATE=OFF -D ARMCOMPUTENEON=ON -D BUILD_UNIT_TESTS=OFF -D BUILD_TESTS=OFF -D TOSA_REFERENCE_MODEL_OUTPUT=OFF -D BUILD_SHARED_LIBS=OFF . -D ARMCOMPUTE_ROOT="${ARMCOMPUTE_ROOT}" -D ARMCOMPUTE_LIBRARIES="${ARMCOMPUTE_LIBRARIES}"

Both ArmCL and ArmNN are on version 23.05

@maxmarsc
Copy link
Author

Update : I tried locally installing the GNU toolchain version 11.3.rel1 rather than 12.2.Rel1 and it seems to fix the compilation. I cannot tell if this is a compiler issue or an issue on your library though.

@maxmarsc maxmarsc changed the title compilation error: array subscript 5 is above array bounds with aarch64-none-linux-gnu-g++ 12.2.Rel1 compilation error: array subscript 5 is above array bounds with aarch64-none-linux-gnu-g++ 12.2.Rel1 May 30, 2023
@ghost ghost added the Build issue This problem was about building ArmNN or one of its dependencies. label Jun 1, 2023
@andyt9527
Copy link

andyt9527 commented Sep 16, 2023

meet the same issue building armnn 22.11.01 using gcc12.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Build issue This problem was about building ArmNN or one of its dependencies.
Projects
None yet
Development

No branches or pull requests

2 participants