From be1bb3fc35973d1abddc29778cf2f7ff6103d6c0 Mon Sep 17 00:00:00 2001 From: Simone Balducci Date: Sat, 2 Nov 2024 21:46:12 +0100 Subject: [PATCH 1/5] Fix seeds container --- CLUEstering/alpaka/CLUE/CLUEAlgoAlpaka.h | 21 +++++++++------------ CLUEstering/alpaka/CLUE/CLUEAlpakaKernels.h | 4 ++-- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/CLUEstering/alpaka/CLUE/CLUEAlgoAlpaka.h b/CLUEstering/alpaka/CLUE/CLUEAlgoAlpaka.h index 9b46918..0e1cfd9 100644 --- a/CLUEstering/alpaka/CLUE/CLUEAlgoAlpaka.h +++ b/CLUEstering/alpaka/CLUE/CLUEAlgoAlpaka.h @@ -35,7 +35,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { } TilesAlpaka* m_tiles; - clue::Vector* m_seeds; + VecArray* m_seeds; VecArray* m_followers; template @@ -56,8 +56,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { // Buffers std::optional>> d_tiles; - std::optional> d_seeds; - std::optional>> seeds; + std::optional>> + d_seeds; std::optional[]>> @@ -108,17 +108,14 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { template void CLUEAlgoAlpaka::init_device(Queue queue_) { d_tiles = cms::alpakatools::make_device_buffer>(queue_); - d_seeds = cms::alpakatools::make_device_buffer(queue_, reserve); - d_followers = cms::alpakatools::make_device_buffer< - cms::alpakatools::VecArray[]>(queue_, reserve); - - seeds = cms::alpakatools::make_device_buffer>(queue_); - // resize the seeds vector - (*seeds)->resize((*d_seeds).data(), reserve); + d_seeds = cms::alpakatools::make_device_buffer>(queue_); + d_followers = + cms::alpakatools::make_device_buffer[]>(queue_, + reserve); // Copy to the public pointers m_tiles = (*d_tiles).data(); - m_seeds = (*seeds).data(); + m_seeds = (*d_seeds).data(); m_followers = (*d_followers).data(); } @@ -221,7 +218,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { const Idx grid_size_seeds = cms::alpakatools::divide_up_by(reserve, block_size); auto working_div_seeds = cms::alpakatools::make_workdiv(grid_size_seeds, block_size); - + alpaka::enqueue(queue_, alpaka::createTaskKernel(working_div_seeds, KernelAssignClusters{}, diff --git a/CLUEstering/alpaka/CLUE/CLUEAlpakaKernels.h b/CLUEstering/alpaka/CLUE/CLUEAlpakaKernels.h index 30546e5..38a3224 100644 --- a/CLUEstering/alpaka/CLUE/CLUEAlpakaKernels.h +++ b/CLUEstering/alpaka/CLUE/CLUEAlpakaKernels.h @@ -278,7 +278,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { struct KernelFindClusters { template ALPAKA_FN_ACC void operator()(const TAcc& acc, - clue::Vector* seeds, + VecArray* seeds, VecArray* followers, PointsView* dev_points, float dm, @@ -313,7 +313,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { struct KernelAssignClusters { template ALPAKA_FN_ACC void operator()(const TAcc& acc, - clue::Vector* seeds, + VecArray* seeds, VecArray* followers, PointsView* dev_points) const { const auto& seeds_0{*seeds}; From 942017299c55f4f67d77fd567a49186f5025c93d Mon Sep 17 00:00:00 2001 From: Simone Balducci Date: Sat, 2 Nov 2024 21:46:52 +0100 Subject: [PATCH 2/5] Remove Vector header --- .../alpaka/DataFormats/alpaka/Vector.h | 85 ------------------- 1 file changed, 85 deletions(-) delete mode 100644 CLUEstering/alpaka/DataFormats/alpaka/Vector.h diff --git a/CLUEstering/alpaka/DataFormats/alpaka/Vector.h b/CLUEstering/alpaka/DataFormats/alpaka/Vector.h deleted file mode 100644 index f3ed59a..0000000 --- a/CLUEstering/alpaka/DataFormats/alpaka/Vector.h +++ /dev/null @@ -1,85 +0,0 @@ - -#pragma once - -// -// Author: Simone Balducci -// Note: Based on Felice's VecArray -// - -namespace clue { - - // TODO: Use a caching allocator to improve dynamic allocation - template - class Vector { - private: - T* m_data; - uint32_t m_size; - uint32_t m_capacity; - - public: - Vector() = default; - Vector(uint32_t size) : m_data(new T[size]), m_size{0}, m_capacity{size} {} - Vector(T* data, uint32_t size) : m_data(data), m_size{0}, m_capacity{size} {} - - inline constexpr int push_back_unsafe(const T& element) { - auto previousSize = m_size; - m_size++; - if (previousSize < m_capacity) { - m_data[previousSize] = element; - return previousSize; - } else { - --m_size; - return -1; - } - } - - // thread-safe version of the vector, when used in a CUDA kernel - template - ALPAKA_FN_ACC int push_back(const TAcc& acc, const T& element) { - auto previousSize = - alpaka::atomicAdd(acc, &m_size, 1u, alpaka::hierarchy::Blocks{}); - if (previousSize < m_capacity) { - m_data[previousSize] = element; - return previousSize; - } else { - alpaka::atomicSub(acc, &m_size, 1u, alpaka::hierarchy::Blocks{}); - assert(("Too few elemets reserved")); - return -1; - } - } - - inline constexpr T const* begin() const { return m_data; } - inline constexpr T const* end() const { return m_data + m_size; } - inline constexpr T* begin() { return m_data; } - inline constexpr T* end() { return m_data + m_size; } - - inline constexpr T const* data() const { return m_data; } - inline constexpr T* data() { return m_data; } - - inline constexpr const T& operator[](int i) const { return m_data[i]; } - inline constexpr T& operator[](int i) { return m_data[i]; } - - inline constexpr size_t size() const { return m_size; } - inline constexpr size_t capacity() const { return m_capacity; } - - inline constexpr bool empty() const { return 0 == m_size; } - inline constexpr bool full() const { return m_capacity == m_size; } - - inline constexpr void reset() { m_size = 0; } - inline constexpr void resize(T* data, int size) { - m_data = data; - m_size = 0; - m_capacity = size; - } - inline constexpr void resize(int size) { m_size = size; } - inline constexpr void reserve(uint32_t size) { - m_capacity = size; - m_size = 0; - - // move data to new location - T* new_data = new T[size]; - m_data = new_data; - new_data = nullptr; - } - }; -}; // namespace clue From 944bf0adba1b7f168d44020b325c857f4fa7870a Mon Sep 17 00:00:00 2001 From: Simone Balducci Date: Sat, 2 Nov 2024 21:47:37 +0100 Subject: [PATCH 3/5] Update package version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ae464dc..6d4e902 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import setup import subprocess -__version__ = "2.2.10" +__version__ = "2.2.11" this_directory = Path(__file__).parent long_description = (this_directory/'README.md').read_text() From f5806c2d08f3fd0f468c8f0fc48786287798c9bd Mon Sep 17 00:00:00 2001 From: Simone Balducci Date: Sat, 2 Nov 2024 21:49:45 +0100 Subject: [PATCH 4/5] Remove include --- CLUEstering/alpaka/CLUE/CLUEAlgoAlpaka.h | 1 - 1 file changed, 1 deletion(-) diff --git a/CLUEstering/alpaka/CLUE/CLUEAlgoAlpaka.h b/CLUEstering/alpaka/CLUE/CLUEAlgoAlpaka.h index 0e1cfd9..7b199dc 100644 --- a/CLUEstering/alpaka/CLUE/CLUEAlgoAlpaka.h +++ b/CLUEstering/alpaka/CLUE/CLUEAlgoAlpaka.h @@ -17,7 +17,6 @@ #include "../DataFormats/Points.h" #include "../DataFormats/alpaka/PointsAlpaka.h" #include "../DataFormats/alpaka/TilesAlpaka.h" -#include "../DataFormats/alpaka/Vector.h" #include "CLUEAlpakaKernels.h" #include "ConvolutionalKernel.h" From 12e2099d5c5aecaeff843f8e9b2262bf3d175f7b Mon Sep 17 00:00:00 2001 From: Simone Balducci Date: Sat, 2 Nov 2024 21:50:06 +0100 Subject: [PATCH 5/5] Remove include --- CLUEstering/alpaka/CLUE/CLUEAlpakaKernels.h | 1 - 1 file changed, 1 deletion(-) diff --git a/CLUEstering/alpaka/CLUE/CLUEAlpakaKernels.h b/CLUEstering/alpaka/CLUE/CLUEAlpakaKernels.h index 38a3224..dd1ce91 100644 --- a/CLUEstering/alpaka/CLUE/CLUEAlpakaKernels.h +++ b/CLUEstering/alpaka/CLUE/CLUEAlpakaKernels.h @@ -9,7 +9,6 @@ #include "../DataFormats/alpaka/PointsAlpaka.h" #include "../DataFormats/alpaka/TilesAlpaka.h" #include "../DataFormats/alpaka/AlpakaVecArray.h" -#include "../DataFormats/alpaka/Vector.h" #include "ConvolutionalKernel.h" using cms::alpakatools::VecArray;