Skip to content

Commit

Permalink
overload of make_cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraPerego committed Jan 27, 2025
1 parent e5ec0fd commit 777a9b1
Showing 1 changed file with 138 additions and 0 deletions.
138 changes: 138 additions & 0 deletions include/CLUEstering/CLUEstering.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {
Queue queue_,

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
std::size_t block_size);

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule

template <typename KernelType>
void make_clusters(PointsSoA<Ndim>& h_points,

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
PointsAlpaka<Ndim>& dev_points,

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
const KernelType& kernel,
Queue queue_,

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
std::size_t block_size);

std::map<int, std::vector<int>> getClusters(const PointsSoA<Ndim>& h_points);

private:
Expand All @@ -62,6 +69,10 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {
void setup(const PointsSoA<Ndim>& h_points,
Queue queue_,
std::size_t block_size);
void setup(const PointsSoA<Ndim>& h_points,
PointsAlpaka<Ndim>& dev_points,
Queue queue_,
std::size_t block_size);

// Construction of the tiles
void calculate_tile_size(CoordinateExtremes<Ndim>& min_max,
Expand Down Expand Up @@ -106,9 +117,52 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {

template <uint8_t Ndim>
void CLUEAlgoAlpaka<Ndim>::setup(const PointsSoA<Ndim>& h_points,
PointsAlpaka<Ndim>& dev_points,

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
Queue queue_,
std::size_t block_size) {
// calculate the number of tiles and their size

Check warning

Code scanning / Flawfinder (reported by Codacy)

Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. Warning

Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data.
const auto nTiles{std::ceil(h_points.nPoints() / static_cast<float>(pointsPerTile_))};
const auto nPerDim{std::ceil(std::pow(nTiles, 1. / Ndim))};

CoordinateExtremes<Ndim> min_max;
float tile_size[Ndim];
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)->minMax(), 2 * Ndim),
clue::make_host_view(min_max.data(), 2 * Ndim));
alpaka::memcpy(queue_,

Check warning

Code scanning / Flawfinder (reported by Codacy)

Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. Warning

Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data.
clue::make_device_view(device, (*d_tiles)->tileSize(), Ndim),
clue::make_host_view(tile_size, Ndim));
alpaka::wait(queue_);

Check notice

Code scanning / Cppcheck (reported by Codacy)

memset() called to fill 0 bytes. Note

memset() called to fill 0 bytes.
const Idx tiles_grid_size = clue::divide_up_by(nTiles, block_size);
const auto tiles_working_div = clue::make_workdiv<Acc1D>(tiles_grid_size, block_size);
alpaka::enqueue(queue_,
alpaka::createTaskKernel<Acc1D>(
tiles_working_div, KernelResetTiles{}, m_tiles, nTiles, nPerDim));

const auto copyExtent = (Ndim + 1) * h_points.nPoints();
alpaka::memcpy(queue_,

Check warning

Code scanning / Flawfinder (reported by Codacy)

Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. Warning

Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data.
dev_points.input_buffer,
clue::make_host_view(h_points.coords(), copyExtent),
copyExtent);
alpaka::memset(queue_, *d_seeds, 0x00);

// Define the working division
const Idx grid_size = clue::divide_up_by(h_points.nPoints(), block_size);
const auto working_div = clue::make_workdiv<Acc1D>(grid_size, block_size);
alpaka::enqueue(
queue_,
alpaka::createTaskKernel<Acc1D>(
working_div, KernelResetFollowers{}, m_followers, h_points.nPoints()));
}

template <uint8_t Ndim>
void CLUEAlgoAlpaka<Ndim>::setup(const PointsSoA<Ndim>& h_points,
Queue queue_,
std::size_t block_size) {
d_points = PointsAlpaka<Ndim>(queue_, h_points.nPoints());

// calculate the number of tiles and their size
Expand Down Expand Up @@ -234,6 +288,90 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {
// Wait for all the operations in the queue to finish
alpaka::wait(queue_);
}
template <uint8_t Ndim>
template <typename KernelType>
void CLUEAlgoAlpaka<Ndim>::make_clusters(PointsSoA<Ndim>& h_points,
PointsAlpaka<Ndim>& dev_points,
const KernelType& kernel,
Queue queue_,
std::size_t block_size) {
setup(h_points, dev_points, queue_, block_size);

const auto nPoints = h_points.nPoints();

const Idx grid_size = clue::divide_up_by(nPoints, block_size);
auto working_div = clue::make_workdiv<Acc1D>(grid_size, block_size);
alpaka::enqueue(
queue_,
alpaka::createTaskKernel<Acc1D>(
working_div, KernelFillTiles{}, dev_points.view(), m_tiles, nPoints));

alpaka::enqueue(queue_,
alpaka::createTaskKernel<Acc1D>(working_div,
KernelCalculateLocalDensity{},
m_tiles,
dev_points.view(),
kernel,
/* m_domains.data(), */
dc_,
nPoints));
alpaka::enqueue(queue_,
alpaka::createTaskKernel<Acc1D>(working_div,
KernelCalculateNearestHigher{},
m_tiles,
dev_points.view(),
/* m_domains.data(), */
dm_,
dc_,
nPoints));
alpaka::enqueue(queue_,
alpaka::createTaskKernel<Acc1D>(working_div,
KernelFindClusters<Ndim>{},
m_seeds,
m_followers,
dev_points.view(),
dm_,
dc_,
rhoc_,
nPoints));

// We change the working division when assigning the clusters
const Idx grid_size_seeds = clue::divide_up_by(reserve, block_size);
auto working_div_seeds = clue::make_workdiv<Acc1D>(grid_size_seeds, block_size);

alpaka::enqueue(queue_,
alpaka::createTaskKernel<Acc1D>(working_div_seeds,
KernelAssignClusters<Ndim>{},
m_seeds,
m_followers,
dev_points.view()));

// Wait for all the operations in the queue to finish
alpaka::wait(queue_);

const auto device = alpaka::getDev(queue_);
#ifdef DEBUG
alpaka::memcpy(queue_,
clue::make_host_view(h_points.debugInfo().rho.data(), nPoints),
clue::make_device_view(device, dev_points.view()->rho, nPoints));
alpaka::memcpy(queue_,

Check warning

Code scanning / Flawfinder (reported by Codacy)

Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. Warning

Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data.
clue::make_host_view(h_points.debugInfo().rho.data(), nPoints),
clue::make_device_view(device, dev_points.view()->delta, nPoints));
alpaka::memcpy(
queue_,
clue::make_host_view(h_points.debugInfo().nearestHigher.data(), nPoints),
clue::make_device_view(device, dev_points.view()->nearest_higher, nPoints));
#endif

alpaka::memcpy(queue_,
clue::make_host_view(h_points.clusterIndexes(), 2 * nPoints),

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 10.4 rule Note

MISRA 10.4 rule
clue::make_device_view(
device, dev_points.result_buffer.data() + nPoints, 2 * nPoints),

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 10.4 rule Note

MISRA 10.4 rule
2 * nPoints);

// Wait for all the operations in the queue to finish
alpaka::wait(queue_);
}

template <uint8_t Ndim>
std::map<int, std::vector<int>> CLUEAlgoAlpaka<Ndim>::getClusters(
Expand Down

0 comments on commit 777a9b1

Please sign in to comment.