diff --git a/CLUEstering/alpaka/CLUE/CLUEAlgoAlpaka.h b/CLUEstering/alpaka/CLUE/CLUEAlgoAlpaka.h index 9b46918..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" @@ -35,7 +34,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { } TilesAlpaka* m_tiles; - clue::Vector* m_seeds; + VecArray* m_seeds; VecArray* m_followers; template @@ -56,8 +55,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 +107,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 +217,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..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; @@ -278,7 +277,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 +312,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}; 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 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()