Skip to content

Commit

Permalink
fixes to wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraPerego committed Jan 28, 2025
1 parent 25924f2 commit 62a3592
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CLUEstering/BindingModules/Run.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {
float dm,
int pPBin,
std::tuple<float*, int*>&& pData,
const PointShape<Ndim>& shape,
const PointInfo<Ndim>& shape,
const Kernel& kernel,
Queue queue_,
size_t block_size) {
Expand Down
3 changes: 3 additions & 0 deletions include/CLUEstering/CLUEstering.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {
calculate_tile_size(min_max, tile_size, h_points, nPerDim);

const auto device = alpaka::getDev(queue_);
alpaka::memcpy(queue_,
clue::make_device_view(device, (*d_tiles)->wrapped(), Ndim),
clue::make_host_view(h_points.wrapped(), Ndim));
alpaka::memcpy(queue_,
clue::make_device_view(device, (*d_tiles)->minMax(), 2 * Ndim),
clue::make_host_view(min_max.data(), 2 * Ndim));
Expand Down
20 changes: 11 additions & 9 deletions include/CLUEstering/DataFormats/Points.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include <vector>

template <uint8_t Ndim>
struct PointShape {
struct PointInfo {
uint32_t nPoints;
static constexpr auto nDim = Ndim;
int wrapping[Ndim];
};

template <uint8_t Ndim>
Expand All @@ -34,16 +34,16 @@ struct PointsSoA {
#endif
};

PointsSoA(float* floatBuffer, int* intBuffer, const PointShape<Ndim>& shape)
PointsSoA(float* floatBuffer, int* intBuffer, const PointInfo<Ndim>& info)
: m_coordsBuffer{floatBuffer},
m_resultsBuffer{intBuffer},
m_view{std::make_unique<View>()},
m_shape{shape},
m_debugInfo{shape.nPoints} {
m_info{info},
m_debugInfo{info.nPoints} {
m_view->coords = floatBuffer;
m_view->weights = floatBuffer + m_shape.nPoints * m_shape.nDim;
m_view->weights = floatBuffer + m_info.nPoints * Ndim;
m_view->clusterIndexes = intBuffer;
m_view->isSeed = intBuffer + m_shape.nPoints;
m_view->isSeed = intBuffer + m_info.nPoints;
}

PointsSoA(const PointsSoA&) = delete;
Expand All @@ -52,11 +52,13 @@ struct PointsSoA {
PointsSoA& operator=(PointsSoA&&) = default;
~PointsSoA() = default;

uint32_t nPoints() const { return m_shape.nPoints; }
uint32_t nPoints() const { return m_info.nPoints; }

const float* coords() const { return m_view->coords; }
const float* weights() const { return m_view->weights; }

const int* wrapped() const { return m_info.wrapping; }

int* clusterIndexes() { return m_view->clusterIndexes; }
const int* clusterIndexes() const { return m_view->clusterIndexes; }
int* isSeed() { return m_view->isSeed; }
Expand All @@ -70,6 +72,6 @@ struct PointsSoA {
float* m_coordsBuffer;
int* m_resultsBuffer;
std::unique_ptr<View> m_view;
PointShape<Ndim> m_shape;
PointInfo<Ndim> m_info;
DebugInfo m_debugInfo;
};
25 changes: 12 additions & 13 deletions include/CLUEstering/DataFormats/alpaka/TilesAlpaka.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {
ALPAKA_FN_HOST_ACC float max(int i) const { return m_data[2 * i + 1]; }
ALPAKA_FN_HOST_ACC float& max(int i) { return m_data[2 * i + 1]; }
ALPAKA_FN_HOST_ACC float range(int i) const { return max(i) - min(i); }
ALPAKA_FN_HOST_ACC float& range(int i) {
auto tmp = max(i) - min(i);
return tmp;
}
};

template <uint8_t Ndim>
Expand All @@ -56,6 +52,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {
}
ALPAKA_FN_HOST_ACC inline constexpr float* tileSize() { return tile_size; }

ALPAKA_FN_HOST_ACC inline constexpr const int* wrapped() const { return m_wrapped; }
ALPAKA_FN_HOST_ACC inline constexpr int* wrapped() { return m_wrapped; }

ALPAKA_FN_HOST_ACC void resizeTiles(std::size_t nTiles, int nPerDim) {
this->n_tiles = nTiles;
this->n_tiles_per_dim = nPerDim;
Expand All @@ -68,7 +67,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {
float coord_,
int dim_) const {
int coord_Bin;
if (wrapped[dim_]) {
if (m_wrapped[dim_]) {
coord_Bin = static_cast<int>(
(normalizeCoordinate(coord_, dim_) - min_max.min(dim_)) / tile_size[dim_]);
} else {
Expand Down Expand Up @@ -99,11 +98,11 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {
const TAcc& acc, const VecArray<uint32_t, Ndim>& Bins) const {
uint32_t globalBin = 0;
for (int dim = 0; dim != Ndim - 1; ++dim) {
auto bin_i = wrapped[dim] ? (Bins[dim] % n_tiles_per_dim) : Bins[dim];
auto bin_i = m_wrapped[dim] ? (Bins[dim] % n_tiles_per_dim) : Bins[dim];
globalBin += alpaka::math::pow(acc, n_tiles_per_dim, Ndim - dim - 1) * bin_i;
}
globalBin +=
wrapped[Ndim - 1] ? (Bins[Ndim - 1] % n_tiles_per_dim) : Bins[Ndim - 1];
m_wrapped[Ndim - 1] ? (Bins[Ndim - 1] % n_tiles_per_dim) : Bins[Ndim - 1];
return globalBin;
}

Expand All @@ -123,7 +122,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {
VecArray<uint32_t, 2> dim_sb;
auto infBin = getBin(acc, sb_extremes[dim][0], dim);
auto supBin = getBin(acc, sb_extremes[dim][1], dim);
if (wrapped[dim] and infBin > supBin)
if (m_wrapped[dim] and infBin > supBin)
supBin += n_tiles_per_dim;
dim_sb.push_back_unsafe(infBin);
dim_sb.push_back_unsafe(supBin);
Expand All @@ -135,11 +134,11 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {
ALPAKA_FN_ACC inline float distance(const float* coord_i, const float* coord_j) {
float dist_sq = 0.f;
for (int dim = 0; dim != Ndim; ++dim) {
if (wrapped[dim])
dist_sq += normalizeCoordinate(coord_i - coord_j, dim) *
normalizeCoordinate(coord_i - coord_j, dim);
if (m_wrapped[dim])
dist_sq += normalizeCoordinate(coord_i[dim] - coord_j[dim], dim) *
normalizeCoordinate(coord_i[dim] - coord_j[dim], dim);
else
dist_sq += (coord_i - coord_j) * (coord_i - coord_j);
dist_sq += (coord_i[dim] - coord_j[dim]) * (coord_i[dim] - coord_j[dim]);
}
return dist_sq;
}
Expand Down Expand Up @@ -175,7 +174,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {

std::size_t n_tiles;
int n_tiles_per_dim;
int wrapped[Ndim];
int m_wrapped[Ndim];
CoordinateExtremes<Ndim> min_max;
float tile_size[Ndim];
VecArray<VecArray<uint32_t, max_tile_depth>, max_n_tiles> m_tiles;
Expand Down

0 comments on commit 62a3592

Please sign in to comment.