Skip to content

Commit

Permalink
Merge pull request xtensor-stack#2438 from DerThorsten/new_xsimd
Browse files Browse the repository at this point in the history
upgraded to xsimd 8
  • Loading branch information
JohanMabille authored Oct 18, 2021
2 parents 68ac1ed + 77658e1 commit bcf9e7b
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 86 deletions.
6 changes: 1 addition & 5 deletions .azure-pipelines/azure-pipelines-linux-clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ jobs:
- job: 'Linux_0'
strategy:
matrix:
clang_4:
llvm_version: '4.0'
clang_5:
llvm_version: '5.0'
clang_6:
llvm_version: '6.0'
clang_7:
Expand All @@ -18,7 +14,7 @@ jobs:
llvm_version: '10'
disable_xsimd: 1
pool:
vmImage: ubuntu-16.04
vmImage: ubuntu-18.04
variables:
CC: clang-$(llvm_version)
CXX: clang++-$(llvm_version)
Expand Down
14 changes: 7 additions & 7 deletions .azure-pipelines/azure-pipelines-linux-gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ jobs:
- job: 'Linux_1'
strategy:
matrix:
gcc_4:
gcc_version: '4.9'
check_cyclic_includes: 1
gcc_5_disable_xsimd:
gcc_version: '5'
gcc_6_disable_xsimd:
gcc_version: '6'
disable_xsimd: 1
gcc_6_disable_exception:
gcc_version: '6'
Expand All @@ -22,6 +19,9 @@ jobs:
gcc_7_openmp:
gcc_version: '7'
enable_openmp: 1
gcc_8:
gcc_version: '8'
check_cyclic_includes: 1
gcc_8_bound_checks:
gcc_version: '8'
bound_checks: 1
Expand All @@ -33,15 +33,15 @@ jobs:
gcc_9:
gcc_version: '9'
pool:
vmImage: ubuntu-16.04
vmImage: ubuntu-18.04
variables:
CC: gcc-$(gcc_version)
CXX: g++-$(gcc_version)
timeoutInMinutes: 360
steps:

- script: |
if [[ $(gcc_version) == '4.9' || $(gcc_version) == '6' || $(gcc_version) == '7' || $(gcc_version) == '8' ]]; then
if [[ $(gcc_version) == '6' || $(gcc_version) == '7' || $(gcc_version) == '8' ]]; then
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get --no-install-suggests --no-install-recommends install g++-$(gcc_version)
Expand Down
2 changes: 1 addition & 1 deletion .azure-pipelines/azure-pipelines-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
doctest ^
nlohmann_json ^
xtl==0.7.0 ^
xsimd==7.4.8 ^
xsimd==8.0.3 ^
python=3.6
conda list
displayName: "Install conda packages"
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ if(XTENSOR_USE_TBB AND XTENSOR_USE_OPENMP)
endif()

if(XTENSOR_USE_XSIMD)
set(xsimd_REQUIRED_VERSION 7.4.4)
set(xsimd_REQUIRED_VERSION 8.0.2)
if(TARGET xsimd)
set(xsimd_VERSION ${XSIMD_VERSION_MAJOR}.${XSIMD_VERSION_MINOR}.${XSIMD_VERSION_PATCH})
# Note: This is not SEMVER compatible comparison
Expand Down
4 changes: 2 additions & 2 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ channels:
dependencies:
- cmake
- xtl=0.7.0
- xsimd=7.4.9
- xsimd=8.0.3
- nlohmann_json
- doctest
- doctest
32 changes: 7 additions & 25 deletions include/xtensor/xcomplex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,35 +160,17 @@ namespace xt
return std::complex<T>(c.real(), -c.imag());
}

#ifdef XTENSOR_USE_XSIMD
template <class X>
constexpr X conj_impl(const xsimd::simd_complex_batch<X>& z)
{
return xsimd::conj(z);
}

template <class T>
struct not_complex_batch
: xtl::negation<std::is_base_of<xsimd::simd_complex_batch<T>, T>>
constexpr std::complex<T> conj_impl(const T & real)
{
};

// libc++ (OSX) conj is unfortunately broken and returns
// std::complex<T> instead of T.
// This function must be deactivated for complex batches,
// otherwise it will be a better match than the previous one.
template <class T, XTL_REQUIRES(not_complex_batch<T>)>
constexpr T conj_impl(const T& c)
{
return c;
return std::complex<T>(real, 0);
}
#else
// libc++ (OSX) conj is unfortunately broken and returns
// std::complex<T> instead of T.
template <class T>
constexpr T conj_impl(const T& c)

#ifdef XTENSOR_USE_XSIMD
template <class T, class A>
xsimd::complex_batch_type_t< xsimd::batch<T, A>> conj_impl(const xsimd::batch<T, A>& z)
{
return c;
return xsimd::conj(z);
}
#endif
}
Expand Down
5 changes: 2 additions & 3 deletions include/xtensor/xcontainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,17 +725,16 @@ namespace xt
inline void xcontainer<D>::store_simd(size_type i, const simd& e)
{
using align_mode = driven_align_mode_t<alignment, data_alignment>;
xt_simd::store_simd<value_type, typename simd::value_type>(std::addressof(storage()[i]), e, align_mode());
xt_simd::store_as(std::addressof(storage()[i]), e, align_mode());
}

template <class D>
template <class alignment, class requested_type, std::size_t N>
inline auto xcontainer<D>::load_simd(size_type i) const
-> container_simd_return_type_t<storage_type, value_type, requested_type>
//-> simd_return_type<requested_type>
{
using align_mode = driven_align_mode_t<alignment, data_alignment>;
return xt_simd::load_simd<value_type, requested_type>(std::addressof(storage()[i]), align_mode());
return xt_simd::load_as<requested_type>(std::addressof(storage()[i]), align_mode());
}

template <class D>
Expand Down
4 changes: 2 additions & 2 deletions include/xtensor/xiterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,8 @@ namespace xt
static R apply(const It& it)
{
R reg;
reg.load_unaligned(&(*it));
return reg;
return reg.load_unaligned(&(*it));
//return reg;
}
};

Expand Down
14 changes: 7 additions & 7 deletions include/xtensor/xmath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,21 +266,21 @@ XTENSOR_INT_SPECIALIZATION_IMPL(FUNC_NAME, RETURN_VAL, unsigned long long);
// VS2015 STL defines isnan, isinf and isfinite as template
// functions, breaking ADL.
#if defined(_WIN32) && defined(XTENSOR_USE_XSIMD)
template <class T, std::size_t N>
inline xsimd::batch_bool<T, N> isinf(const xsimd::batch<T, N>& b)
/*template <class T, class A>
inline xsimd::batch_bool<T, A> isinf(const xsimd::batch<T, A>& b)
{
return xsimd::isinf(b);
}
template <class T, std::size_t N>
inline xsimd::batch_bool<T, N> isnan(const xsimd::batch<T, N>& b)
template <class T, class A>
inline xsimd::batch_bool<T, A> isnan(const xsimd::batch<T, A>& b)
{
return xsimd::isnan(b);
}
template <class T, std::size_t N>
inline xsimd::batch_bool<T, N> isfinite(const xsimd::batch<T, N>& b)
template <class T, class A>
inline xsimd::batch_bool<T, A> isfinite(const xsimd::batch<T, A>& b)
{
return xsimd::isfinite(b);
}
}*/
#endif
// The following specializations are needed to avoid 'ambiguous overload' errors,
// whereas 'unsigned char' and 'unsigned short' are automatically converted to 'int'.
Expand Down
2 changes: 1 addition & 1 deletion include/xtensor/xscalar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ namespace xt
inline auto xscalar<CT>::load_simd(size_type) const
-> xt_simd::simd_return_type<value_type, requested_type>
{
return xt_simd::set_simd<value_type, requested_type>(m_value);
return xt_simd::broadcast_as<requested_type>(m_value);
}

template <class T>
Expand Down
4 changes: 2 additions & 2 deletions include/xtensor/xstrided_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ namespace xt
-> enable_simd_interface<T, void>
{
using align_mode = driven_align_mode_t<alignment, data_alignment>;
xt_simd::store_simd<value_type, typename simd::value_type>(&(storage()[i]), e, align_mode());
xt_simd::store_as(&(storage()[i]), e, align_mode());
}

template <class CT, class S, layout_type L, class FST>
Expand All @@ -625,7 +625,7 @@ namespace xt
-> enable_simd_interface<T, simd_return_type<requested_type>>
{
using align_mode = driven_align_mode_t<alignment, data_alignment>;
return xt_simd::load_simd<value_type, requested_type>(&(storage()[i]), align_mode());
return xt_simd::load_as<requested_type>(&(storage()[i]), align_mode());
}

template <class CT, class S, layout_type L, class FST>
Expand Down
8 changes: 7 additions & 1 deletion include/xtensor/xtensor_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
xt::svector<typename XTENSOR_DEFAULT_DATA_CONTAINER(T, EA)::size_type, 4, SA, true>
#endif

#ifdef XTENSOR_USE_XSIMD
#include <xsimd/xsimd.hpp>
#define XSIMD_DEFAULT_ALIGNMENT xsimd::default_arch::alignment()
#endif


#ifndef XTENSOR_DEFAULT_ALLOCATOR
#ifdef XTENSOR_ALLOC_TRACKING
#ifndef XTENSOR_ALLOC_TRACKING_POLICY
Expand All @@ -72,7 +78,7 @@
#endif
#else
#ifdef XTENSOR_USE_XSIMD
#include <xsimd/xsimd.hpp>

#define XTENSOR_DEFAULT_ALLOCATOR(T) \
xsimd::aligned_allocator<T, XSIMD_DEFAULT_ALIGNMENT>
#else
Expand Down
37 changes: 19 additions & 18 deletions include/xtensor/xtensor_simd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
#ifdef XTENSOR_USE_XSIMD

#include <xsimd/xsimd.hpp>
//#include <xsimd/memory/xsimd_load_store.hpp>

#if defined(_MSV_VER) && (_MSV_VER < 1910)
template <class T, std::size_t N>
inline xsimd::batch_bool<T, N> isnan(const xsimd::batch<T, N>& b)
template <class T, class A>
inline xsimd::batch_bool<T, A> isnan(const xsimd::batch<T, A>& b)
{
return xsimd::isnan(b);
}
Expand Down Expand Up @@ -62,15 +63,15 @@ namespace xt_simd
template <class T>
using revert_simd_type = xsimd::revert_simd_type<T>;

using xsimd::set_simd;
using xsimd::load_simd;
using xsimd::store_simd;
using xsimd::select;
using xsimd::get_alignment_offset;

template <class T1, class T2>
using simd_return_type = xsimd::simd_return_type<T1, T2>;

using xsimd::load_as;
using xsimd::store_as;
using xsimd::broadcast_as;
using xsimd::select;
using xsimd::get_alignment_offset;

template <class V>
using is_batch_bool = xsimd::is_batch_bool<V>;

Expand Down Expand Up @@ -139,32 +140,32 @@ namespace xt_simd
template <class T>
using revert_simd_type = typename revert_simd_traits<T>::type;

template <class T, class V>
inline simd_type<T> set_simd(const T& value)
template <class R, class T>
inline simd_type<R> broadcast_as(const T& value)
{
return value;
}

template <class T, class V>
inline simd_type<T> load_simd(const T* src, aligned_mode)
template <class R, class T>
inline simd_type<R> load_as(const T* src, aligned_mode)
{
return *src;
}

template <class T, class V>
inline simd_type<T> load_simd(const T* src, unaligned_mode)
template <class R, class T>
inline simd_type<R> load_as(const T* src, unaligned_mode)
{
return *src;
}

template <class T>
inline void store_simd(T* dst, const simd_type<T>& src, aligned_mode)
template <class R, class T>
inline void store_as(R* dst, const simd_type<T>& src, aligned_mode)
{
*dst = src;
}

template <class T>
inline void store_simd(T* dst, const simd_type<T>& src, unaligned_mode)
template <class R, class T>
inline void store_as(R* dst, const simd_type<T>& src, unaligned_mode)
{
*dst = src;
}
Expand Down
6 changes: 5 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)

include(set_compiler_flag.cmake)



if(CPP17)
# User requested C++17, but compiler might not oblige.
set_compiler_flag(
Expand Down Expand Up @@ -69,12 +71,13 @@ endif()

OPTION(XTENSOR_ENABLE_WERROR "Turn on -Werror" OFF)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DXSIMD_ENABLE_XTL_COMPLEX=1")
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR (CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND NOT WIN32))
CHECK_CXX_COMPILER_FLAG(-march=native arch_native_supported)
if(arch_native_supported AND NOT CMAKE_CXX_FLAGS MATCHES "-march")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_cxx_std_flag} -Wunused-parameter -Wextra -Wreorder -Wconversion -Wsign-conversion")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_cxx_std_flag} -Wunused-parameter -Wextra -Wreorder -Wconversion -Wno-sign-conversion ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast -Wunused-variable -ftemplate-backtrace-limit=0")
if (XTENSOR_DISABLE_EXCEPTIONS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
Expand Down Expand Up @@ -163,6 +166,7 @@ set(COMMON_BASE
test_xview.cpp
test_xview_semantic.cpp
test_xutils.cpp
test_xsimd8.cpp
)

set(XTENSOR_TESTS
Expand Down
10 changes: 1 addition & 9 deletions test/test_xadaptor_semantic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,7 @@ namespace xt
{
#if defined(XTENSOR_USE_XSIMD)
std::cout << "Built with XSIMD" << std::endl;
#if defined(XSIMD_X86_INSTR_SET)
std::cout << "Using X86 Instruction set: " << XSIMD_INSTR_SET << std::endl;
#elif defined(XSIMD_X86_AMD_INSTR_SET)
std::cout << "Using AMD Instruction set: " << XSIMD_INSTR_SET << std::endl;
#elif defined(XSIMD_ARM_INSTR_SET)
std::cout << "Using ARM Instruction set: " << XSIMD_INSTR_SET << std::endl;
#else
std::cout << "Using unknown Instruction set: " << XSIMD_INSTR_SET << std::endl;
#endif
std::cout << " arch "<<xsimd::default_arch::name() << std::endl;
#else
std::cout << "Built without XSIMD" << std::endl;
#endif
Expand Down
10 changes: 9 additions & 1 deletion test/test_xcomplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ namespace xt
EXPECT_EQ(*(it.operator->()), 1.0);
}

TEST(xcomplex, arg)
{
xarray<std::complex<double>> cmplarg_0 = {{0.40101756 + 0.71233018i, 0.62731701 + 0.42786349i, 0.32415089 + 0.2977805i},
{0.24475928 + 0.49208478i, 0.69475518 + 0.74029639i, 0.59390240 + 0.35772892i},
{0.63179202 + 0.41720995i, 0.44025718 + 0.65472131i, 0.08372648 + 0.37380143i}};
xarray<double> res = xt::arg(cmplarg_0);

}
TEST(xcomplex, abs_angle_conj)
{
xarray<std::complex<double>> cmplarg_0 = {{0.40101756 + 0.71233018i, 0.62731701 + 0.42786349i, 0.32415089 + 0.2977805i},
Expand Down Expand Up @@ -195,7 +203,7 @@ namespace xt
xarray<double> A = {{0.81745298, 0.75933774, 0.44016704},
{0.54959488, 1.01524554, 0.69331814},
{0.75711643, 0.78897806, 0.38306348}};
xarray<double> B = xt::conj(A);
xarray<double> B = xt::real(xt::conj(A));
EXPECT_EQ(A, B);
}

Expand Down
Loading

0 comments on commit bcf9e7b

Please sign in to comment.