ashvardanian / SimSIMD

Up to 200x Faster Dot Products & Similarity Metrics — for Python, Rust, C, JS, and Swift, supporting f64, f32, f16 real & complex, i8, and bit vectors using SIMD for both AVX2, AVX-512, NEON, SVE, & SVE2 📐
https://ashvardanian.com/posts/simsimd-faster-scipy/
Apache License 2.0
956 stars 56 forks source link

`__ARM_ARCH` redefinition warning #158

Closed ashvardanian closed 1 month ago

ashvardanian commented 2 months ago
#pragma GCC push_options
#pragma GCC target("arch=armv8.6-a+simd+bf16")
#pragma clang attribute push(__attribute__((target("arch=armv8.6-a+simd+bf16"))), apply_to = function)

void simsimd_kernel(...) { ... }

#pragma clang attribute pop
#pragma GCC pop_options

When compiling for Arm, pushing and popping attributes like we do causes warnings like:

In file included from /home/ubuntu/usearch/simsimd/include/simsimd/simsimd.h:107:
/home/ubuntu/usearch/simsimd/include/simsimd/spatial.h:311:46: warning: "__ARM_ARCH" redefined
  311 | #pragma GCC target("arch=armv8.6-a+simd+bf16")
      |                                              ^
/home/ubuntu/usearch/simsimd/include/simsimd/spatial.h:311:46: note: this is the location of the previous definition
/home/ubuntu/usearch/simsimd/include/simsimd/spatial.h:434:9: warning: "__ARM_ARCH" redefined
  434 | #pragma GCC pop_options
      |         ^~~
/home/ubuntu/usearch/simsimd/include/simsimd/spatial.h:434:9: note: this is the location of the previous definition
/home/ubuntu/usearch/simsimd/include/simsimd/spatial.h:439:49: warning: "__ARM_ARCH" redefined
  439 | #pragma GCC target("arch=armv8.2-a+dotprod+i8mm")
      |                                                 ^
/home/ubuntu/usearch/simsimd/include/simsimd/spatial.h:439:49: note: this is the location of the previous definition
/home/ubuntu/usearch/simsimd/include/simsimd/spatial.h:589:9: warning: "__ARM_ARCH" redefined
  589 | #pragma GCC pop_options
      |         ^~~
/home/ubuntu/usearch/simsimd/include/simsimd/spatial.h:589:9: note: this is the location of the previous definition
/home/ubuntu/usearch/simsimd/include/simsimd/simsimd.h:306:40: warning: "__ARM_ARCH" redefined
  306 | #pragma GCC target("arch=armv8.5-a+sve")
      |                                        ^
/home/ubuntu/usearch/simsimd/include/simsimd/simsimd.h:306:40: note: this is the location of the previous definition
/home/ubuntu/usearch/simsimd/include/simsimd/simsimd.h:411:9: warning: "__ARM_ARCH" redefined
  411 | #pragma GCC pop_options
      |         ^~~
/home/ubuntu/usearch/simsimd/include/simsimd/simsimd.h:411:9: note: this is the location of the previous definition
MarkReedZ commented 1 month ago

I'm not seeing these warnings building usearch on a c7g instance. The only warning I see is unused-function:

In file included from /home/ubuntu/usearch/simsimd/include/simsimd/simsimd.h:106:
/home/ubuntu/usearch/simsimd/include/simsimd/probability.h:71:21: warning: ‘simsimd_kl_f16_haswell’ declared ‘static’ but never defined [-Wunused-function]
   71 | SIMSIMD_PUBLIC void simsimd_kl_f16_haswell(simsimd_f16_t const* a, simsimd_f16_t const* b, simsimd_size_t n, simsimd_distance_t* divergence);
ashvardanian commented 1 month ago

Which GCC version are you running? Can you also try building the Python bindings, @MarkReedZ?

MarkReedZ commented 1 month ago

Was this a compiler bug perhaps?

PR with the warning workaround removed: https://github.com/ashvardanian/SimSIMD/pull/164

I've removed the warning workaround for __ARM_ARCH and I no longer see any warnings. If it was a bug on an older compiler and we want to keep the warning workaround we can alternatively just add #undef __ARM_ARCH each time that we set __ARM_ARCH:

Alternative fix if we want to keep the warning workaround:

#if defined(SIMSIMD_DEFAULT_TARGET_ARM)
#undef __ARM_ARCH
#define __ARM_ARCH SIMSIMD_DEFAULT_TARGET_ARM
#undef SIMSIMD_DEFAULT_TARGET_ARM
#endif

I was able to reproduce and confirm both fixes with a new c7g instance and the following commands. Note I did not build usearch this time.

    sudo apt-get update && sudo apt-get install cmake build-essential libjemalloc-dev g++-13 gcc-13
    git clone https://github.com/ashvardanian/SimSIMD.git
    cd SimSIMD/
    git checkout main-dev
    sudo apt install libopenblas-dev
    cmake -D CMAKE_BUILD_TYPE=Release -D SIMSIMD_BUILD_TESTS=1 -D SIMSIMD_BUILD_BENCHMARKS=1 -D SIMSIMD_BUILD_BENCHMARKS_WITH_CBLAS=1  -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -B bld
    cmake --build bld --config Release
MarkReedZ commented 1 month ago

I'm happy to try different setups if you have a suggestion as to what to try. I just noticed you added this recently - do you recall the setup? https://github.com/ashvardanian/SimSIMD/commit/e975cc9e

e975cc9e include/simsimd/simsimd.h (Ash Vardanian   2024-08-26 18:06:17 +0000  107) #define SIMSIMD_DEFAULT_TARGET_ARM __ARM_ARCH
ashvardanian commented 1 month ago

It could be Clang or Apple Clang or GCC 12/13. Can try again in a couple of days.

MarkReedZ commented 1 month ago

I'll play around Sunday. Adding the undefs has to be the answer then, but I'd like to see the original issue. Has to be a bug, but I don't see anyone else hitting anything like it. The gnu code looks fine to me - I can't see it throwing this warning on push/pop.

MarkReedZ commented 1 month ago

No warnings with my branch on Graviton3 with clang 18.1, gcc 12, or gcc 13. Will revisit this when I have more test environments setup.

    git clone https://github.com/MarkReedZ/SimSIMD.git
    cd SimSIMD/
    git fetch && git checkout redefinition_fix
ashvardanian commented 1 month ago

Let's close this for now and re-open if someone complains 😉