Skip to content
Snippets Groups Projects
Commit 0d25368e authored by Wiebe van Breukelen's avatar Wiebe van Breukelen
Browse files

Fixed AVX2 support for radec2lmn.

We have to make sure that SmartVector is actually aligned. Then we
can switch back to the aligned mode. The current implementation does not
guarantee that the data is aligned.
parent 9bb73a49
No related branches found
No related tags found
1 merge request!24Fixed AVX2 support for radec2lmn.
Pipeline #116803 passed
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <common/SmartVector.h> #include <common/SmartVector.h>
#include <vector> #include <vector>
#include <xsimd/types/xsimd_avx512f_register.hpp>
#include <xtensor/xmath.hpp> #include <xtensor/xmath.hpp>
#include <xtensor/xview.hpp> #include <xtensor/xview.hpp>
...@@ -145,16 +146,18 @@ struct radec2lmn { ...@@ -145,16 +146,18 @@ struct radec2lmn {
template <class C, class Tag, class Arch> template <class C, class Tag, class Arch>
void radec2lmn::operator()(Arch, const Direction &reference, const C &ra, void radec2lmn::operator()(Arch, const Direction &reference, const C &ra,
const C &dec, xt::xtensor<double, 2> &lmn, Tag) { const C &dec, xt::xtensor<double, 2> &lmn, Tag) {
using b_type = xsimd::batch<double, Arch>; using b_type = xsimd::batch<double>;
std::size_t inc = b_type::size; std::size_t inc = b_type::size;
std::size_t size = ra.size(); std::size_t size = ra.size();
double sin_dec0 = std::sin(reference.dec); const double sin_dec0 = std::sin(reference.dec);
double cos_dec0 = std::cos(reference.dec); const double cos_dec0 = std::cos(reference.dec);
const ConstSmartVectorView<double> ra_view = ra.view();
// size for which the vectorization is possible // size for which the vectorization is possible
std::size_t vec_size = size - size % inc; std::size_t vec_size = size - size % inc;
for (std::size_t i = 0; i < vec_size; i += inc) { for (std::size_t i = 0; i < vec_size; i += inc) {
const b_type ra_vec = b_type::load(&ra[i], Tag()); const b_type ra_vec = b_type::load(&(ra_view[i]), Tag());
const b_type dec_vec = b_type::load(&dec[i], Tag()); const b_type dec_vec = b_type::load(&(dec[i]), Tag());
const b_type delta_ra = ra_vec - reference.ra; const b_type delta_ra = ra_vec - reference.ra;
...@@ -196,8 +199,22 @@ template <> ...@@ -196,8 +199,22 @@ template <>
inline void Directions::radec2lmn<Directions::computation_strategy::MULTI_SIMD>( inline void Directions::radec2lmn<Directions::computation_strategy::MULTI_SIMD>(
const Direction &reference, xt::xtensor<double, 2> &lmn) { const Direction &reference, xt::xtensor<double, 2> &lmn) {
xt::xtensor<double, 2> lmn_tmp({3, ra.size()}); xt::xtensor<double, 2> lmn_tmp({3, ra.size()});
xsimd::dispatch(xsimd::radec2lmn{})(reference, ra, dec, lmn_tmp,
xsimd::aligned_mode()); // FIXME: we have to make sure that SmartVector is actually aligned. Then we
// can switch back to the aligned mode. The current implementation does not
// guarantee that the data is aligned.
if (reinterpret_cast<std::uintptr_t>(ra.data()) %
xsimd::arch_list<xsimd::avx2>::alignment() !=
0) {
std::cerr << "Warning: ra is not aligned. Using unaligned mode."
<< std::endl;
xsimd::dispatch<xsimd::arch_list<xsimd::avx2>>(xsimd::radec2lmn{})(
reference, ra, dec, lmn_tmp, xsimd::unaligned_mode{});
} else {
xsimd::dispatch<xsimd::arch_list<xsimd::avx2>>(xsimd::radec2lmn{})(
reference, ra, dec, lmn_tmp, xsimd::aligned_mode{});
}
lmn = xt::transpose(lmn_tmp); lmn = xt::transpose(lmn_tmp);
} }
#endif #endif
\ No newline at end of file
...@@ -18,6 +18,10 @@ using SmartVectorView = ...@@ -18,6 +18,10 @@ using SmartVectorView =
decltype(::xt::adapt(std::add_pointer_t<T>{}, std::array<size_t, 1UL>{})); decltype(::xt::adapt(std::add_pointer_t<T>{}, std::array<size_t, 1UL>{}));
; ;
template <typename T>
using ConstSmartVectorView =
decltype(::xt::adapt(std::declval<const T *>(), std::array<size_t, 1>{}));
template <typename T> class SmartVector : public std::vector<T> { template <typename T> class SmartVector : public std::vector<T> {
public: public:
SmartVector() : std::vector<T>() {} SmartVector() : std::vector<T>() {}
...@@ -25,7 +29,7 @@ public: ...@@ -25,7 +29,7 @@ public:
SmartVector(const std::initializer_list<T> &vec) : std::vector<T>(vec) {} SmartVector(const std::initializer_list<T> &vec) : std::vector<T>(vec) {}
SmartVectorView<T> view() { return xt::adapt(this->data(), {this->size()}); } SmartVectorView<T> view() { return xt::adapt(this->data(), {this->size()}); }
const SmartVectorView<T> view() const { ConstSmartVectorView<T> view() const {
return xt::adapt(this->data(), {this->size()}); return xt::adapt(this->data(), {this->size()});
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment