Correlation 4.10.0
An Analysis Tool for Liquids and for Amorphous Solids
Loading...
Searching...
No Matches
SIMDScattering.hpp
Go to the documentation of this file.
1
9
10#pragma once
11
14#include "math/simd/detail/AVX512Kernels.hpp" // IWYU pragma: export
15#include "math/simd/detail/ScalarKernels.hpp" // IWYU pragma: export
16
17#include <cmath>
18
19namespace correlation::math {
20
25template <typename T>
26inline T simdDot(const T *CORRELATION_RESTRICT input_a, const T *CORRELATION_RESTRICT input_b,
27 std::size_t count) noexcept {
28#ifdef CORRELATION_SIMD_AVX512
29 return detail::avx512::simdDot(input_a, input_b, count);
30#elifdef CORRELATION_SIMD_AVX2
31 return detail::avx2::simdDot(input_a, input_b, count);
32#else
33 return detail::scalar::simdDot(input_a, input_b, count);
34#endif
35}
36
41template <typename T>
42inline void dotBlock(T v1x, T v1y, T v1z, const T *CORRELATION_RESTRICT v2x,
43 const T *CORRELATION_RESTRICT v2y, const T *CORRELATION_RESTRICT v2z,
44 T *CORRELATION_RESTRICT out_dot, std::size_t count) noexcept {
45#ifdef CORRELATION_SIMD_AVX512
46 detail::avx512::dotBlock(v1x, v1y, v1z, v2x, v2y, v2z, out_dot, count);
47#elifdef CORRELATION_SIMD_AVX2
48 detail::avx2::dotBlock(v1x, v1y, v1z, v2x, v2y, v2z, out_dot, count);
49#else
50 detail::scalar::dotBlock(v1x, v1y, v1z, v2x, v2y, v2z, out_dot, count);
51#endif
52}
53
58template <typename T>
59inline T debyeSum(T q_magnitude, const T *CORRELATION_RESTRICT distances,
60 T *CORRELATION_RESTRICT scratch, std::size_t count) noexcept {
61#ifdef CORRELATION_SIMD_AVX512
62 return detail::avx512::debyeSum(q_magnitude, distances, scratch, count);
63#elifdef CORRELATION_SIMD_AVX2
64 return detail::avx2::debyeSum(q_magnitude, distances, scratch, count);
65#else
66 return detail::scalar::debyeSum(q_magnitude, distances, scratch, count);
67#endif
68}
69
74template <typename T>
75inline void complexExpSum(T q_x, T q_y, T q_z, const T *CORRELATION_RESTRICT x_s,
76 const T *CORRELATION_RESTRICT y_s, const T *CORRELATION_RESTRICT z_s,
77 std::size_t count, ComplexExpSumResult<T> &result) noexcept {
78 result.cos_sum = static_cast<T>(0.0);
79 result.sin_sum = static_cast<T>(0.0);
80 for (std::size_t idx = 0; idx < count; ++idx) {
81 const T phase = q_x * x_s[idx] + q_y * y_s[idx] + q_z * z_s[idx];
82 result.cos_sum += std::cos(phase);
83 result.sin_sum += std::sin(phase);
84 }
85}
86
87template <typename T>
88inline void complexExpSum(const ComplexExpSumParams<T> &params,
89 ComplexExpSumResult<T> &result) noexcept {
90 complexExpSum(params.q_x, params.q_y, params.q_z, params.x_s, params.y_s, params.z_s,
91 params.count, result);
92}
93
94template <typename T = real_t>
95inline ComplexExpSumResult<T> complexExpSum(T q_x, T q_y, T q_z, const T *CORRELATION_RESTRICT x_s,
96 const T *CORRELATION_RESTRICT y_s,
97 const T *CORRELATION_RESTRICT z_s,
98 std::size_t count) noexcept {
100 complexExpSum(q_x, q_y, q_z, x_s, y_s, z_s, count, result);
101 return result;
102}
103
104template <typename T = real_t>
107 complexExpSum(params, result);
108 return result;
109}
110
115template <typename T>
116inline void millerPhaseSum(const MillerPhaseSumParams<T> &params,
117 MillerPhaseSumResult<T> &result) noexcept {
118#ifdef CORRELATION_SIMD_AVX512
119 detail::avx512::millerPhaseSum(params, result);
120#elifdef CORRELATION_SIMD_AVX2
121 detail::avx2::millerPhaseSum(params, result);
122#else
123 detail::scalar::millerPhaseSum(params, result);
124#endif
125}
126
127template <typename T = real_t>
130 millerPhaseSum(params, result);
131 return result;
132}
133
134template <typename T>
135inline void millerPhaseSum(const T *CORRELATION_RESTRICT cos1, const T *CORRELATION_RESTRICT sin1,
136 const T *CORRELATION_RESTRICT cos2, const T *CORRELATION_RESTRICT sin2,
137 const T *CORRELATION_RESTRICT cos3, const T *CORRELATION_RESTRICT sin3,
138 std::size_t count, MillerPhaseSumResult<T> &result) noexcept {
141 .cos1 = cos1,
142 .sin1 = sin1,
143 .cos2 = cos2,
144 .sin2 = sin2,
145 .cos3 = cos3,
146 .sin3 = sin3,
147 .count = count,
148 },
149 result);
150}
151
152template <typename T = real_t>
154millerPhaseSum(const T *CORRELATION_RESTRICT cos1, const T *CORRELATION_RESTRICT sin1,
155 const T *CORRELATION_RESTRICT cos2, const T *CORRELATION_RESTRICT sin2,
156 const T *CORRELATION_RESTRICT cos3, const T *CORRELATION_RESTRICT sin3,
157 std::size_t count) noexcept {
159 millerPhaseSum(cos1, sin1, cos2, sin2, cos3, sin3, count, result);
160 return result;
161}
162
163} // namespace correlation::math
Low-level AVX2 intrinsic kernel implementations.
Low-level AVX-512 intrinsic kernel implementations.
Common parameter containers, POD types, and scalar helpers for SIMD operations.
Low-level Scalar fallback kernel implementations.
void millerPhaseSum(const MillerPhaseSumParams< double > &params, MillerPhaseSumResult< double > &result) noexcept
Definition AVX2Kernels.hpp:375
void dotBlock(double v1x, double v1y, double v1z, const double *v2x, const double *v2y, const double *v2z, double *out_dot, std::size_t count) noexcept
Definition AVX2Kernels.hpp:145
double debyeSum(double q_magnitude, const double *distances, double *scratch, std::size_t count) noexcept
Definition AVX2Kernels.hpp:211
double simdDot(const double *input_a, const double *input_b, std::size_t count) noexcept
Definition AVX2Kernels.hpp:93
double debyeSum(double q_magnitude, const double *distances, double *scratch, std::size_t count) noexcept
Definition ScalarKernels.hpp:106
void dotBlock(double v1x, double v1y, double v1z, const double *v2x, const double *v2y, const double *v2z, double *out_dot, std::size_t count) noexcept
Definition ScalarKernels.hpp:76
double simdDot(const double *input_a, const double *input_b, std::size_t count) noexcept
Definition ScalarKernels.hpp:53
void millerPhaseSum(const MillerPhaseSumParams< double > &params, MillerPhaseSumResult< double > &result) noexcept
Definition ScalarKernels.hpp:203
Defines universal mathematical and physical constants.
MillerExpSumParams< T > ComplexExpSumParams
Alias for MillerExpSumParams used with complexExpSum kernel invocations.
Definition SIMDTypes.hpp:123
T simdDot(const T *input_a, const T *input_b, std::size_t count) noexcept
Computes the dot product of two array buffers.
Definition SIMDScattering.hpp:26
void dotBlock(T v1x, T v1y, T v1z, const T *v2x, const T *v2y, const T *v2z, T *out_dot, std::size_t count) noexcept
Computes dot products between a reference vector and a block of target vectors.
Definition SIMDScattering.hpp:42
void millerPhaseSum(const MillerPhaseSumParams< T > &params, MillerPhaseSumResult< T > &result) noexcept
Computes the Miller phase sum across angle blocks.
Definition SIMDScattering.hpp:116
void complexExpSum(T q_x, T q_y, T q_z, const T *x_s, const T *y_s, const T *z_s, std::size_t count, ComplexExpSumResult< T > &result) noexcept
Computes the sum of complex exponentials for a query q-vector.
Definition SIMDScattering.hpp:75
T debyeSum(T q_magnitude, const T *distances, T *scratch, std::size_t count) noexcept
Computes the Debye scattering equation sum across distances.
Definition SIMDScattering.hpp:59
ComplexExpSumResult< T > MillerPhaseSumResult
Alias for MillerPhaseSumResult used with millerPhaseSum kernel invocations.
Definition SIMDTypes.hpp:138
Output result container holding cosine and sine phase sums.
Definition SIMDTypes.hpp:129
Parameter container for millerExpSum / complexExpSum kernel invocations.
Definition SIMDTypes.hpp:112
Parameter container for millerPhaseSum kernel invocations.
Definition SIMDTypes.hpp:98