diff --git a/include/CLUEstering/data_structures/detail/PointsDevice.hpp b/include/CLUEstering/data_structures/detail/PointsDevice.hpp index a5ee90949..5582b9a69 100644 --- a/include/CLUEstering/data_structures/detail/PointsDevice.hpp +++ b/include/CLUEstering/data_structures/detail/PointsDevice.hpp @@ -26,10 +26,12 @@ namespace clue { template inline PointsDevice::PointsDevice(TQueue& queue, int32_t n_points) : m_buffer{make_device_buffer( - queue, soa::device::computeSoASize(n_points))}, + queue, + soa::device::computeSoASize(computeAlignSoASize(n_points)))}, m_view{}, m_size{n_points} { - soa::device::partitionSoAView(m_view, m_buffer.data(), n_points); + soa::device::partitionSoAView(m_view, m_buffer.data(), computeAlignSoASize(n_points)); + m_view.m_n = n_points; } template diff --git a/include/CLUEstering/data_structures/detail/PointsHost.hpp b/include/CLUEstering/data_structures/detail/PointsHost.hpp index 6b25f47f0..7912d1ad8 100644 --- a/include/CLUEstering/data_structures/detail/PointsHost.hpp +++ b/include/CLUEstering/data_structures/detail/PointsHost.hpp @@ -23,10 +23,12 @@ namespace clue { template inline PointsHost::PointsHost(TQueue& queue, int32_t n_points) : m_buffer{make_host_buffer( - queue, soa::host::computeSoASize(n_points))}, + queue, + soa::host::computeSoASize(computeAlignSoASize(n_points)))}, m_view{}, m_size{n_points} { - soa::host::partitionSoAView(m_view, m_buffer->data(), n_points); + soa::host::partitionSoAView(m_view, m_buffer->data(), computeAlignSoASize(n_points)); + m_view.m_n = n_points; } template diff --git a/include/CLUEstering/data_structures/internal/PointsCommon.hpp b/include/CLUEstering/data_structures/internal/PointsCommon.hpp index f99808487..1a1636c1b 100644 --- a/include/CLUEstering/data_structures/internal/PointsCommon.hpp +++ b/include/CLUEstering/data_structures/internal/PointsCommon.hpp @@ -168,8 +168,13 @@ namespace clue { } }; - // TODO: implement for better cache use + // Round n_points up to the next multiple of 32 so that each sub-array in a + // SoA layout starts at a 128-byte–aligned address for 4-byte types (float, + // int32), matching the GPU L2 cache line size. template - int32_t computeAlignSoASize(int32_t n_points); + inline int32_t computeAlignSoASize(int32_t n_points) { + constexpr int32_t alignment = 32; + return ((n_points + alignment - 1) / alignment) * alignment; + } } // namespace clue