Skip to content

Commit

Permalink
changes to simd
Browse files Browse the repository at this point in the history
  • Loading branch information
Llibert Areste Salo committed Feb 21, 2024
1 parent 86cfdbc commit 446aae8
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Examples/Fluid_Kerr/PerfectFluidLevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void PerfectFluidLevel::specificEvalRHS(GRLevelData &a_soln, GRLevelData &a_rhs,
BoxLoops::loop(make_compute_pack(TraceARemoval(), PositiveDensity(),
PositiveChiAndAlpha(),
PrimitiveRecovery()),
a_soln, a_soln, INCLUDE_GHOST_CELLS, disable_simd());
a_soln, a_soln, INCLUDE_GHOST_CELLS/*, disable_simd()*/);

// Calculate MatterCCZ4 right hand side with matter_t = ScalarField
EoS eos(m_p.eos_params);
Expand Down
6 changes: 4 additions & 2 deletions Examples/Fluid_Kerr/PrimitiveRecovery.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ class PrimitiveRecovery

int i = 0;

while (diff > tolerance)
// while (simd_compare_lt(tolerance, diff))
auto cond = simd_all_false(simd_compare_lt(diff, tolerance));
//while (simd_all_false(simd_compare_lt(diff, tolerance)))
while (i<20)
// while (simd_compare_lt(tolerance, diff))
{
i++;
Wa = sqrt(pow(xa, 2.) / (pow(xa, 2.) - r));
Expand Down
17 changes: 17 additions & 0 deletions Source/simd/arm/neon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ template <> struct simd<double> : public simd_base<double>
return vmaxq_f64(a, b);
}

friend ALWAYS_INLINE bool simd_all_false(const mask_t cond)
{
uint64x2_t high_bits = vshrq_n_u64(input, 63);
//Lanes are indexed like bits (big-endian)
int moved_mask = vgetq_lane_u64(high_bits, 0) | (vgetq_lane_u64(high_bits, 1) << 1);
return moved_mask == 0 ? true : false;
}

friend ALWAYS_INLINE simd simd_sqrt(const simd &a) { return vsqrtq_f64(a); }
};

Expand Down Expand Up @@ -170,6 +178,15 @@ template <> struct simd<float> : public simd_base<float>
return vmaxq_f32(a, b);
}

friend ALWAYS_INLINE bool simd_all_false(const mask_t cond)
{
uint32x4_t high_bits = vshrq_n_u32(input, 31);
//Lanes are indexed like bits (big-endian)
int moved_mask = vgetq_lane_u32(high_bits, 0) | (vgetq_lane_u32(high_bits, 1) << 1)
| (vgetq_lane_u32(high_bits, 2) << 2) (vgetq_lane_u32(high_bits, 3) << 3);
return moved_mask == 0 ? true : false;
}

friend ALWAYS_INLINE simd simd_sqrt(const simd &a) { return vsqrtq_f32(a); }
};

Expand Down
12 changes: 12 additions & 0 deletions Source/simd/arm/sve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ template <> struct simd<double> : public simd_base<double>
return svmax_f64_z(svptrue_b64(), a, b);
}

friend ALWAYS_INLINE bool simd_all_false(const mask_t cond)
{
//Would be nice to implement a movemask here, for extensions to lane-specific info
return !svptest_any(svptrue_b64(), cond);
}

friend ALWAYS_INLINE simd simd_sqrt(const simd &a)
{
return svsqrt_f64_z(svptrue_b64(), a);
Expand Down Expand Up @@ -206,6 +212,12 @@ template <> struct simd<float> : public simd_base<float>
return svmax_f32_z(svptrue_b32(), a, b);
}

friend ALWAYS_INLINE bool simd_all_false(const mask_t cond)
{
//Would be nice to implement a movemask here, for extensions to lane-specific info
return !svptest_any(svptrue_b32(), cond);
}

friend ALWAYS_INLINE simd simd_sqrt(const simd &a)
{
return svsqrt_f32_z(svptrue_b32(), a);
Expand Down
10 changes: 10 additions & 0 deletions Source/simd/simd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ template <typename t> struct simd
{
return (a > b) ? a : b;
}

friend ALWAYS_INLINE bool simd_all_false(const bool cond)
{
return !cond;
}
};

// Define all the simd-functions whose implementation does not depend on the
Expand Down Expand Up @@ -170,6 +175,11 @@ template <typename t> ALWAYS_INLINE t simd_max(const t &a, const t &b)
return (a > b) ? a : b;
}

template <typename t> ALWAYS_INLINE bool simd_all_false(const bool cond)
{
return !cond;
}

//<-- End: Defining the simd specific calls for non-simd datatypes.

#include "simdify.hpp"
Expand Down
12 changes: 12 additions & 0 deletions Source/simd/x64/avx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ template <> struct simd<double> : public simd_base<double>
return _mm256_max_pd(a, b);
}

friend ALWAYS_INLINE bool simd_all_false(const mask_t cond)
{
int mask = _mm256_movemask_pd(cond);
return mask == 0 ? true : false;
}

friend ALWAYS_INLINE simd simd_sqrt(const simd &a)
{
return _mm256_sqrt_pd(a);
Expand Down Expand Up @@ -193,6 +199,12 @@ template <> struct simd<float> : public simd_base<float>
return _mm256_max_ps(a, b);
}

friend ALWAYS_INLINE bool simd_all_false(const mask_t cond)
{
int mask = _mm256_movemask_ps(cond);
return mask == 0 ? true : false;
}

friend ALWAYS_INLINE simd simd_sqrt(const simd &a)
{
return _mm256_sqrt_ps(a);
Expand Down
12 changes: 12 additions & 0 deletions Source/simd/x64/avx512.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ template <> struct simd<double> : public simd_base<double>
return _mm512_max_pd(a, b);
}

friend ALWAYS_INLINE bool simd_all_false(const mask_t cond)
{
int mask = static_cast<int>(cond);
return mask == 0 ? true : false;
}

#ifdef __AVX512ER__
friend ALWAYS_INLINE simd exp2(const simd &a)
{
Expand Down Expand Up @@ -198,6 +204,12 @@ template <> struct simd<float> : public simd_base<float>
return _mm512_max_ps(a, b);
}

friend ALWAYS_INLINE bool simd_all_false(const mask_t cond)
{
int mask = static_cast<int>(cond);
return mask == 0 ? true : false;
}

#ifdef __AVX512ER__
friend ALWAYS_INLINE simd exp2(const simd &a)
{
Expand Down
12 changes: 12 additions & 0 deletions Source/simd/x64/sse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ template <> struct simd<double> : public simd_base<double>
return _mm_max_pd(a, b);
}

friend ALWAYS_INLINE bool simd_all_false(const mask_t cond)
{
int mask = _mm_movemask_pd(cond);
return mask == 0 ? true : false;
}

friend ALWAYS_INLINE simd simd_sqrt(const simd &a)
{
return _mm_sqrt_pd(a);
Expand Down Expand Up @@ -215,6 +221,12 @@ template <> struct simd<float> : public simd_base<float>
return _mm_max_ps(a, b);
}

friend ALWAYS_INLINE bool simd_all_false(const mask_t cond)
{
int mask = _mm_movemask_ps(cond);
return mask == 0 ? true : false;
}

friend ALWAYS_INLINE simd simd_sqrt(const simd &a)
{
return _mm_sqrt_ps(a);
Expand Down

0 comments on commit 446aae8

Please sign in to comment.