root-project / veccore

C++ Library for Portable SIMD Vectorization
https://root-project.github.io/veccore
Other
80 stars 22 forks source link

apple clang 16 (at least) needs -fexperimental-library #27

Open andresailer opened 3 hours ago

andresailer commented 3 hours ago

As far as I can tell building against veccore on apple clang 16 on macos needs -fexperimental-library

Otherwise there is going to be a lot of

/Users/sftnight/build/workspace/lcg_nightly_pipeline/install/veccore/0.8.1-f2b7a/arm64-mac14-clang160-opt/include/VecCore/Backend/SIMD.h:17:24: error: no member named 'experimental' in namespace 'std'
   17 | struct TypeTraits<std::experimental::simd_mask<T, Abi>> {
      |                   ~~~~~^
amadio commented 3 hours ago

You need to use -std=c++20 if you want to use std::simd. Are you using it? I've only ever tested with std::simd from GCC, even with Clang. So, if you have a recipe which I can use to reproduce the issue, I can change things in VecCore before I tag the next release, which is coming quite soon.

andresailer commented 3 hours ago

It is just a flag that has to be exported like an INTERFACE_COMPILE_OPTION LINK Option (?)

Yes, I am using c++20 otherwise I wouldn't reach this code

https://github.com/root-project/veccore/blob/b4b2bf3d33d07caa2318fa0308cac03cb8718635/include/VecCore/Backend/SIMD.h#L4-L18

Right?

andresailer commented 3 hours ago

Here is a simple reproducer, as long as you have a mac14 clang16 machine, I guess?

cat > test.cpp << EOF
#include <experimental/simd>
template <typename T, class Abi>
struct TypeTraits<std::experimental::simd_mask<T, Abi>> {
  using IndexType = typename std::experimental::simd_mask<T, Abi>::simd_type;
  using ScalarType = typename std::experimental::simd_mask<T, Abi>::value_type;
  static constexpr size_t Size = std::experimental::simd<T, Abi>::size();
};
int main() {
  return 0;
}
EOF

clang++ -std=c++20 test.cpp
clang++ -std=c++20 -fexperimental-library test.cpp
amadio commented 3 hours ago

The reproducer above doesn't work.

test.cpp:3:8: error: explicit specialization of undeclared template struct 'TypeTraits'

I guess just #include <VecCore> should do, though.

andresailer commented 3 hours ago

Please look at the difference between with and without -fexperimental-library

bash-3.2$ clang++ -fexperimental-library -std=c++20 test2.cpp 
test2.cpp:3:8: error: explicit specialization of undeclared template struct 'TypeTraits'
    3 | struct TypeTraits<std::experimental::simd_mask<T, Abi>> {
      |        ^         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
bash-3.2$ clang++ -std=c++20 test2.cpp 
test2.cpp:3:24: error: no member named 'experimental' in namespace 'std'
    3 | struct TypeTraits<std::experimental::simd_mask<T, Abi>> {
      |                   ~~~~~^
test2.cpp:3:48: error: 'T' does not refer to a value
    3 | struct TypeTraits<std::experimental::simd_mask<T, Abi>> {
      |                                                ^
test2.cpp:2:20: note: declared here
    2 | template <typename T, class Abi>
      |                    ^
test2.cpp:3:8: error: explicit specialization of undeclared template struct 'TypeTraits'
    3 | struct TypeTraits<std::experimental::simd_mask<T, Abi>> {
      |        ^         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test2.cpp:3:55: error: expected unqualified-id
    3 | struct TypeTraits<std::experimental::simd_mask<T, Abi>> {
      |                                                       ^
4 errors generated.
amadio commented 3 hours ago
gentoo ~ $ clang++ -std=c++20 test.cpp
test.cpp:3:8: error: explicit specialization of undeclared template struct 'TypeTraits'
    3 | struct TypeTraits<std::experimental::simd_mask<T, Abi>> {
      |        ^         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
gentoo ~ $ clang++ -std=c++20 -fexperimental-library test.cpp
test.cpp:3:8: error: explicit specialization of undeclared template struct 'TypeTraits'
    3 | struct TypeTraits<std::experimental::simd_mask<T, Abi>> {
      |        ^         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
andresailer commented 3 hours ago
clang++ --version
Apple clang version 16.0.0 (clang-1600.0.26.4)
Target: arm64-apple-darwin23.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
amadio commented 3 hours ago

I will try on macOS, the above is on Linux, and with clang-18, so might explain the differences.

amadio commented 3 hours ago

It might be easier if you give me access to one of your build nodes, I only have an old machine with macOS 11.7 available to me at the moment, and that has clang 13 installed.