EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
EBGeometry_PointSoA.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Robert Marskar <robert.marskar@sintef.no>
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
11#ifndef EBGEOMETRY_POINTSOA_HPP
12#define EBGEOMETRY_POINTSOA_HPP
13
14// Std includes
15#include <cstddef>
16#include <cstdint>
17#include <type_traits>
18
19#if defined(__SSE4_1__) || defined(__AVX__) || defined(__AVX512F__)
20#include <immintrin.h>
21#endif
22
23// Our includes
24#include "EBGeometry_Array.hpp"
25#include "EBGeometry_Vec.hpp"
26
27namespace EBGeometry {
28
32namespace PointSoA {
33
49template <typename T>
50[[nodiscard]] constexpr size_t
51DefaultWidth() noexcept
52{
53 static_assert(std::is_floating_point_v<T>, "EBGeometry::PointSoA::DefaultWidth requires a floating-point T");
54
55 return 4;
56}
57
75template <typename T>
76[[nodiscard]] constexpr size_t
77HostWidth() noexcept
78{
79 static_assert(std::is_floating_point_v<T>, "EBGeometry::PointSoA::HostWidth requires a floating-point T");
80#if defined(__AVX512F__)
81 if constexpr (std::is_same_v<T, double>) {
82 return 8;
83 }
84 else {
85 return 16;
86 }
87#elif defined(__AVX__)
88 if constexpr (std::is_same_v<T, double>) {
89 return 4;
90 }
91 else {
92 return 8;
93 }
94#else
95 return 4;
96#endif
97}
98
99} // namespace PointSoA
100
126template <class T, size_t W = PointSoA::DefaultWidth<T>()>
128{
129 static_assert(W > 0, "W must be positive");
130 static_assert(std::is_floating_point_v<T>, "PointSoAT requires a floating-point type T");
131
132public:
141 void
142 pack(const Vec3T<T>* a_positions, uint32_t a_count) noexcept;
143
156 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
158 getDistances2(const Vec3T<T>& a_point) const noexcept;
159
167 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
169 getDistances(const Vec3T<T>& a_point) const noexcept;
170
178 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
179 T
180 getMinimumDistance2(const Vec3T<T>& a_point) const noexcept;
181
188 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
189 T
190 getMinimumDistance(const Vec3T<T>& a_point) const noexcept;
191
199 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
200 T
201 getMaximumDistance2(const Vec3T<T>& a_point) const noexcept;
202
209 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
210 T
211 getMaximumDistance(const Vec3T<T>& a_point) const noexcept;
212
220 template <class BV>
221 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
222 BV
223 computeBoundingVolume() const noexcept;
224
231 [[nodiscard]] EBGEOMETRY_HOST_DEVICE
232 uint32_t
233 numValid() const noexcept
234 {
235 return m_validCount;
236 }
237
238protected:
242 alignas(W * sizeof(T)) T m_x[W];
243
247 T m_y[W];
248
252 T m_z[W];
253
260 uint32_t m_validCount = 0;
261};
262
263static_assert(std::is_trivially_copyable_v<PointSoAT<float>>, "PointSoAT<float> must be trivially copyable");
264static_assert(std::is_trivially_copyable_v<PointSoAT<double>>, "PointSoAT<double> must be trivially copyable");
265
266} // namespace EBGeometry
267
268#include "EBGeometry_PointSoAImplem.hpp"
269
270#endif
A fixed-size array that compiles for both host and device.
#define EBGEOMETRY_HOST_DEVICE
Mark a function as callable from both host and device code (no-op on host compilers).
Definition EBGeometry_GPU.hpp:80
#define EBGEOMETRY_HOST
Mark a function as callable from host code only (no-op on host compilers).
Definition EBGeometry_GPU.hpp:83
Declaration of 2D and 3D point/vector classes with templated precision, and free functions on them.
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:258
constexpr size_t HostWidth() noexcept
The SoA width W (points per PointSoAT group) that fills one SIMD register for type T under the compil...
Definition EBGeometry_PointSoA.hpp:77
constexpr size_t DefaultWidth() noexcept
The default SoA width W (points per PointSoAT group): 4, for both float and double,...
Definition EBGeometry_PointSoA.hpp:51
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
Fixed-size array with host- and device-callable members.
Definition EBGeometry_Array.hpp:33
True SoA (Structure of Arrays) layout for W point positions, enabling SIMD distance evaluation agains...
Definition EBGeometry_PointSoA.hpp:128
BV computeBoundingVolume() const noexcept
Compute the bounding volume enclosing all valid positions in this group.
T m_z[W]
z-coordinates of point positions.
Definition EBGeometry_PointSoA.hpp:252
Array< T, W > getDistances2(const Vec3T< T > &a_point) const noexcept
Squared unsigned distances from a_point to every one of the W lane positions.
void pack(const Vec3T< T > *a_positions, uint32_t a_count) noexcept
Pack a_count positions from a_positions[0..a_count-1] into this SoA group.
Array< T, W > getDistances(const Vec3T< T > &a_point) const noexcept
Unsigned distances from a_point to every one of the W lane positions.
T getMaximumDistance2(const Vec3T< T > &a_point) const noexcept
Largest squared unsigned distance from a_point to the farthest position in this group.
T getMinimumDistance2(const Vec3T< T > &a_point) const noexcept
Shortest squared unsigned distance from a_point to the closest position in this group.
T getMaximumDistance(const Vec3T< T > &a_point) const noexcept
Largest unsigned distance from a_point to the farthest position in this group.
uint32_t numValid() const noexcept
Number of real (non-padded) positions in this group.
Definition EBGeometry_PointSoA.hpp:233
T m_y[W]
y-coordinates of point positions.
Definition EBGeometry_PointSoA.hpp:247
uint32_t m_validCount
Number of valid (non-padded) positions in this group (1..W).
Definition EBGeometry_PointSoA.hpp:260
T m_x[W]
x-coordinates of point positions. m_x[j] = x-coord of point j.
Definition EBGeometry_PointSoA.hpp:242
T getMinimumDistance(const Vec3T< T > &a_point) const noexcept
Shortest unsigned distance from a_point to the closest position in this group.