ndk icon indicating copy to clipboard operation
ndk copied to clipboard

Using std::numeric_limits<__fp16>::lowest() causes a compilation error

Open AnthonyBarbier opened this issue 7 years ago • 1 comments

Description

|| In file included from /work/projects/jenkins/scripts/../toolchains//aarch64-linux-android-ndk-r18-beta1/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../include/c++/4.9.x/vector:270:
|| In file included from /work/projects/jenkins/scripts/../toolchains//aarch64-linux-android-ndk-r18-beta1/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../include/c++/4.9.x/__bit_reference:15:
|| In file included from /work/projects/jenkins/scripts/../toolchains//aarch64-linux-android-ndk-r18-beta1/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../include/c++/4.9.x/algorithm:644:
|| In file included from /work/projects/jenkins/scripts/../toolchains//aarch64-linux-android-ndk-r18-beta1/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../include/c++/4.9.x/memory:659:
/work/projects/jenkins/toolchains/aarch64-linux-android-ndk-r18-beta1/include/c++/4.9.x/limits|189 col 59| error: invalid operands to binary expression ('float' and 'int')
||     static _LIBCPP_CONSTEXPR const _Tp value = _Tp(_Tp(1) << __digits);
||                                                    ~~~~~~ ^  ~~~~~~~~
/work/projects/jenkins/toolchains/aarch64-linux-android-ndk-r18-beta1/include/c++/4.9.x/limits|210 col 49| note: in instantiation of template class 'std::__ndk1::__libcpp_compute_min<__fp16, 15, true>' requested here
||     static _LIBCPP_CONSTEXPR const type __min = __libcpp_compute_min<type, digits, is_signed>::value;
||                                                 ^
/work/projects/jenkins/toolchains/aarch64-linux-android-ndk-r18-beta1/include/c++/4.9.x/limits|443 col 15| note: in instantiation of template class 'std::__ndk1::__libcpp_numeric_limits<__fp16, true>' requested here
||     : private __libcpp_numeric_limits<typename remove_cv<_Tp>::type>
||               ^
src/core/NEON/kernels/NESoftmaxLayerKernel.cpp|395 col 54| note: in instantiation of template class 'std::__ndk1::numeric_limits<__fp16>' requested here
||         auto vec_max = vdup_n<vec_16_byte_t<T>>(std::numeric_limits<T>::lowest());

Environment Details

ndk r18-beta1 on Ubuntu 16.04 x86 64bit cross compiling for -march=armv8.2-a+fp16 Using a standalone toolchain generated by doing:

$NDK/build/tools/make_standalone_toolchain.py --arch arm64 --install-dir $TOOLCHAINS/aarch64-linux-android-ndk-r18-beta1 --stl libc++ --api 21

AnthonyBarbier avatar Aug 10 '18 16:08 AnthonyBarbier

I think the only issue is that libc++ is missing a specialization for this (technically the standard doesn't specify one, but neither does it specify that fp16 exists, so it shouldn't be hard to get added).

DanAlbert avatar Aug 10 '18 16:08 DanAlbert

Not sure when this was fixed upstream, but the following code compiles now:

#include <limits>

int main() {
  std::numeric_limits<__fp16>::lowest();
}

DanAlbert avatar Oct 02 '25 22:10 DanAlbert