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

Ambiguous fma/fnma calls #1071

Open
Martmists-GH opened this issue Dec 14, 2024 · 4 comments
Open

Ambiguous fma/fnma calls #1071

Martmists-GH opened this issue Dec 14, 2024 · 4 comments

Comments

@Martmists-GH
Copy link

Seems to only happen on exp and log, error:

/home/mart/git/kotlin/kt-ndarray-simd/xsimd/include/xsimd/types/xsimd_api.hpp:958:16: error: call to 'fnma' is ambiguous
        return kernel::fnma<A>(x, y, z, A {});
               ^~~~~~~~~~~~~~~
/home/mart/git/kotlin/kt-ndarray-simd/xsimd/include/xsimd/arch/./generic/xsimd_generic_math.hpp:816:26: note: in instantiation of function template specialization 'xsimd::fnma<double, xsimd::fma4>' requested here
                    hi = fnma(k, constants::log_2hi<batch_type>(), a);
                         ^
/home/mart/git/kotlin/kt-ndarray-simd/xsimd/include/xsimd/arch/./generic/xsimd_generic_math.hpp:903:43: note: in instantiation of member function 'xsimd::kernel::detail::exp_reduction<double, xsimd::fma4, xsimd::kernel::detail::exp_tag>::reduce' requested here
                batch_type k = reducer_t::reduce(self, hi, lo, x);
                                          ^
/home/mart/git/kotlin/kt-ndarray-simd/xsimd/include/xsimd/arch/./generic/xsimd_generic_math.hpp:915:28: note: in instantiation of function template specialization 'xsimd::kernel::detail::exp<xsimd::kernel::detail::exp_tag, xsimd::fma4>' requested here
            return detail::exp<detail::exp_tag>(self);
                           ^
/home/mart/git/kotlin/kt-ndarray-simd/xsimd/include/xsimd/types/xsimd_api.hpp:720:24: note: in instantiation of function template specialization 'xsimd::kernel::exp<xsimd::fma4, double>' requested here
        return kernel::exp<A>(x, A {});
                       ^
/home/mart/git/kotlin/kt-ndarray-simd/src/lib/arch/../cpp/math_priv.h:96:27: note: in instantiation of function template specialization 'xsimd::exp<double, xsimd::fma4>' requested here
        auto res = xsimd::exp(va);
                          ^
/home/mart/git/kotlin/kt-ndarray-simd/xsimd/include/xsimd/arch/./xsimd_fma4.hpp:32:39: note: candidate function [with A = xsimd::fma4]
        XSIMD_INLINE batch<double, A> fnma(simd_register<double, A> const& x, simd_register<double, A> const& y, simd_register<double, A> const& z, requires_arch<fma4>) noexcept
                                      ^
/home/mart/git/kotlin/kt-ndarray-simd/xsimd/include/xsimd/arch/./generic/xsimd_generic_arithmetic.hpp:102:34: note: candidate function [with A = xsimd::fma4, T = double]
        XSIMD_INLINE batch<T, A> fnma(batch<T, A> const& x, batch<T, A> const& y, batch<T, A> const& z, requires_arch<generic>) noexcept
                                 ^

Code:

struct _vec_exp { template <class Arch> void operator()(Arch, double* a, int n); };
static auto _vec_exp_dispatcher = xsimd::dispatch<arch_list>(_vec_exp{});
// extern for each arch here
template <class Arch> void _vec_exp::operator()(Arch, double* a, int n) {
    using batch = xsimd::batch<double, Arch>;

    std::size_t size = n - n % batch::size;

    for (std::size_t i = 0; i < size; i += batch::size) {
        auto va = batch::load_unaligned(&a[i]);
        auto res = xsimd::exp(va);
        xsimd::store_unaligned(&a[i], res);
    }

    for (std::size_t i = size; i < n; ++i) {
        a[i] = std::exp(a[i]);
    }
}

xsimd version 13.0.0

@Martmists-GH
Copy link
Author

Martmists-GH commented Dec 14, 2024

Seems to happen when compiling for fma4, fma3+sse4.2 works fine.

generated clang invocation:

/home/mart/.konan/dependencies/llvm-16.0.0-x86_64-linux-essentials-80/bin/clang 
  -B/home/mart/.konan/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2/x86_64-unknown-linux-gnu/bin 
  -fno-stack-protector
  --gcc-toolchain=/home/mart/.konan/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2
  -target x86_64-unknown-linux-gnu
  --sysroot=/home/mart/.konan/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2/x86_64-unknown-linux-gnu/sysroot
  -fPIC 
  /home/mart/git/kotlin/kt-ndarray-simd/src/lib/arch/fma4.cpp
  -c
  -o /home/mart/git/kotlin/kt-ndarray-simd/build/cinterop/linuxX64/fma4.o
  -O2 
  -mfma4 -msse4.2 -msse4.1 -mssse3 -msse3 -msse2
  -I/home/mart/git/kotlin/kt-ndarray-simd/src/lib/public 
  -I/home/mart/git/kotlin/kt-ndarray-simd/xsimd/include

@Martmists-GH
Copy link
Author

Reproducer: https://godbolt.org/z/dsYx3rWPr

serge-sans-paille added a commit that referenced this issue Dec 14, 2024
@serge-sans-paille
Copy link
Contributor

Can you confirm #1072 fixes your issue?

@Martmists-GH
Copy link
Author

That does seem to fix it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants