Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
sbaldu committed Feb 7, 2025
1 parent 3d16e6f commit 5eba84c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 67 deletions.
8 changes: 2 additions & 6 deletions include/CLUEstering/CLUE/CLUEAlpakaKernels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {
TilesAlpaka<Ndim>* tiles,
PointsAlpakaView* dev_points,
const KernelType& kernel,
/* const VecArray<VecArray<float, 2>, Ndim>& domains, */
const float* coords_i,
float* rho_i,
float dc,
Expand Down Expand Up @@ -72,7 +71,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {
}

} // end of interate inside this bin

return;
} else {
for (unsigned int i{search_box[search_box.capacity() - N_][0]};
Expand All @@ -99,7 +97,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {
TilesAlpaka<Ndim>* dev_tiles,
PointsAlpakaView* dev_points,
const KernelType& kernel,
/* const VecArray<VecArray<float, 2>, Ndim>& domains, */
float dc,
uint32_t n_points) const {
for (auto i : alpaka::uniformElements(acc, n_points)) {
Expand Down Expand Up @@ -143,9 +140,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {
const TAcc& acc,
VecArray<uint32_t, Ndim>& base_vec,
const VecArray<VecArray<uint32_t, 2>, Ndim>& s_box,
TilesAlpaka<Ndim>* tiles,
TilesAlpakaView<Ndim>* tiles,
PointsAlpakaView* dev_points,
/* const VecArray<VecArray<float, 2>, Ndim>& domains, */
const float* coords_i,
float rho_i,
float* delta_i,
Expand Down Expand Up @@ -211,8 +207,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {
template <typename TAcc, uint8_t Ndim>
ALPAKA_FN_ACC void operator()(const TAcc& acc,
TilesAlpaka<Ndim>* dev_tiles,
TilesAlpakaView<Ndim>* dev_tiles,
PointsAlpakaView* dev_points,
/* const VecArray<VecArray<float, 2>, Ndim>& domains, */
float dm,
float,
uint32_t n_points) const {
Expand Down
8 changes: 2 additions & 6 deletions include/CLUEstering/CLUEstering.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {
alpaka::memset(queue_, *d_seeds, 0x00);
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::exec<Acc1D>(queue_,

working_div,
KernelResetFollowers{},
m_followers,
h_points.nPoints());
alpaka::exec<Acc1D>(
queue_, working_div, KernelResetFollowers{}, m_followers, h_points.nPoints());

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
}

template <uint8_t Ndim>
Expand Down
99 changes: 49 additions & 50 deletions include/CLUEstering/DataFormats/alpaka/AssociationMap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ namespace clue {
*nbins = max + 1;
}
template <typename TAcc>
ALPAKA_FN_ACC void operator()(
const TAcc& acc, size_t size, uint32_t* associations, uint32_t* nbins, TFunc func) const {
ALPAKA_FN_ACC void operator()(const TAcc& acc,
size_t size,
uint32_t* associations,
uint32_t* nbins,
TFunc func) const {
auto max = 0;
for (auto i : alpaka::uniformElements(acc, size)) {
associations[i] = func(acc, i);
Expand Down Expand Up @@ -93,72 +96,68 @@ namespace clue {
};

struct AssociationMapView {
uint32_t* m_indexes;
uint32_t* m_offsets;
uint32_t m_size;
uint32_t m_nbins;

ALPAKA_FN_ACC Span<uint32_t> indexes(size_t assoc_id) {
auto size = m_offsets[assoc_id + 1] - m_offsets[assoc_id];
auto* buf_ptr = m_indexes + m_offsets[assoc_id];
return Span<uint32_t>{buf_ptr, size};
}
ALPAKA_FN_ACC uint32_t offsets(size_t assoc_id) {
return m_offsets[assoc_id];
}
ALPAKA_FN_ACC Span<uint32_t> operator[](size_t assoc_id) {
auto size = m_offsets[assoc_id + 1] - m_offsets[assoc_id];
auto* buf_ptr = m_indexes + m_offsets[assoc_id];
return Span<uint32_t>{buf_ptr, size};
}
uint32_t* m_indexes;
uint32_t* m_offsets;
uint32_t m_size;
uint32_t m_nbins;

ALPAKA_FN_ACC Span<uint32_t> indexes(size_t assoc_id) {
auto size = m_offsets[assoc_id + 1] - m_offsets[assoc_id];

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 10.4 rule Note

MISRA 10.4 rule
auto* buf_ptr = m_indexes + m_offsets[assoc_id];

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 18.4 rule Note

MISRA 18.4 rule
return Span<uint32_t>{buf_ptr, size};
}
ALPAKA_FN_ACC uint32_t offsets(size_t assoc_id) { return m_offsets[assoc_id]; }
ALPAKA_FN_ACC Span<uint32_t> operator[](size_t assoc_id) {
auto size = m_offsets[assoc_id + 1] - m_offsets[assoc_id];

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 10.4 rule Note

MISRA 10.4 rule
auto* buf_ptr = m_indexes + m_offsets[assoc_id];

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 18.4 rule Note

MISRA 18.4 rule
return Span<uint32_t>{buf_ptr, size};
}
};

template <typename TDev, typename = std::enable_if_t<alpaka::isDevice<TDev>>>

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
class AssociationMap {
private:
device_buffer<TDev, uint32_t[]> m_indexes;
device_buffer<TDev, uint32_t[]> m_offsets;
device_buffer<TDev, AssociationMapView> m_view;
// TODO: the names of this variables are a bit ambiguous
device_buffer<TDev, AssociationMapView> m_view;
// TODO: the names of this variables are a bit ambiguous
size_t m_size;

public:
AssociationMap() = default;

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 16.3 rule Note

MISRA 16.3 rule
// TODO: see above
// TODO: see above
AssociationMap(size_t size, size_t nbins, const TDev& dev)
: m_indexes{make_device_buffer<uint32_t[]>(dev, size)},
m_offsets{make_device_buffer<uint32_t[]>(dev, nbins + 1)},

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 10.4 rule Note

MISRA 10.4 rule
m_view{make_device_buffer<AssociationMapView>(dev)},
m_view{make_device_buffer<AssociationMapView>(dev)},
m_size{nbins} {
auto h_view = make_host_buffer<AssociationMapView>(dev);
h_view->m_indexes = m_indexes.data();
h_view->m_offsets = m_offsets.data();
h_view->m_size = size;
h_view->m_nbins = m_size;

auto queue(dev);
alpaka::memcpy(queue, m_view, h_view);
}
auto h_view = make_host_buffer<AssociationMapView>(dev);
h_view->m_indexes = m_indexes.data();
h_view->m_offsets = m_offsets.data();
h_view->m_size = size;
h_view->m_nbins = m_size;

auto queue(dev);
alpaka::memcpy(queue, m_view, h_view);

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.
}

// TODO: see above
// TODO: see above
template <typename TQueue, typename = std::enable_if_t<alpaka::isQueue<TQueue>>>
AssociationMap(size_t size, size_t nbins, TQueue queue)
: m_indexes{make_device_buffer<uint32_t[]>(queue, size)},
m_offsets{make_device_buffer<uint32_t[]>(queue, nbins + 1)},

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 10.4 rule Note

MISRA 10.4 rule
m_view{make_device_buffer<AssociationMapView>(queue)},
m_view{make_device_buffer<AssociationMapView>(queue)},
m_size{nbins} {
auto h_view = make_host_buffer<AssociationMapView>(queue);
h_view->m_indexes = m_indexes.data();
h_view->m_offsets = m_offsets.data();
h_view->m_size = size;
h_view->m_nbins = m_size;
auto h_view = make_host_buffer<AssociationMapView>(queue);
h_view->m_indexes = m_indexes.data();
h_view->m_offsets = m_offsets.data();
h_view->m_size = size;
h_view->m_nbins = m_size;

alpaka::memcpy(queue, m_view, h_view);
}
alpaka::memcpy(queue, m_view, h_view);

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.
}

AssociationMapView* view() {
return m_view.data();
}
AssociationMapView* view() { return m_view.data(); }

template <typename TQueue, typename = std::enable_if_t<alpaka::isQueue<TQueue>>>
ALPAKA_FN_HOST void initialize(size_t size, size_t nbins, const TQueue& queue) {
Expand All @@ -175,13 +174,14 @@ namespace clue {

auto size() const { return m_size; }

ALPAKA_FN_HOST device_buffer<TDev, uint32_t[]> indexes() { return m_indexes; }
ALPAKA_FN_HOST device_buffer<TDev, uint32_t[]> indexes() { return m_indexes; }
ALPAKA_FN_ACC Span<uint32_t> indexes(size_t assoc_id) {
auto size = m_offsets[assoc_id + 1] - m_offsets[assoc_id];

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 10.4 rule Note

MISRA 10.4 rule

Check warning

Code scanning / Cppcheck (reported by Codacy)

Local variable 'size' shadows outer function Warning

Local variable 'size' shadows outer function
auto* buf_ptr = m_indexes.data() + m_offsets[assoc_id];
return Span<uint32_t>{buf_ptr, size};
}
ALPAKA_FN_HOST device_view<TDev, uint32_t[]> indexes(const TDev& dev, size_t assoc_id) {
ALPAKA_FN_HOST device_view<TDev, uint32_t[]> indexes(const TDev& dev,
size_t assoc_id) {
auto size = m_offsets[assoc_id + 1] - m_offsets[assoc_id];

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 10.4 rule Note

MISRA 10.4 rule

Check warning

Code scanning / Cppcheck (reported by Codacy)

Local variable 'size' shadows outer function Warning

Local variable 'size' shadows outer function
auto* buf_ptr = m_indexes.data() + m_offsets[assoc_id];
return make_device_view<uint32_t[], TDev>(dev, buf_ptr, size);

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
Expand Down Expand Up @@ -263,7 +263,7 @@ namespace clue {

/* template <typename TFunc> */
/* ALPAKA_FN_HOST void fill(size_t size, TFunc func, TDev dev) { */
/* std::cout << "nbins = " << m_size << std::endl; */
/* std::cout << "nbins = " << m_size << std::endl; */
/* auto bin_buffer = make_device_buffer<uint32_t[]>(dev, size); */

/* auto queue(dev); */
Expand Down Expand Up @@ -323,7 +323,7 @@ namespace clue {
ALPAKA_FN_HOST void fill(size_t size, TFunc func, Queue queue) {
auto bin_buffer = make_device_buffer<uint32_t[]>(queue, size);

const auto dev = alpaka::getDev(queue);
const auto dev = alpaka::getDev(queue);
const auto blocksize = 512;
const auto gridsize = divide_up_by(size, blocksize);
const auto workdiv = make_workdiv<Acc1D>(gridsize, blocksize);
Expand Down Expand Up @@ -374,7 +374,6 @@ namespace clue {
temp_offsets.data(),
size);
}

};

/* template <typename TFunc, */
Expand Down
10 changes: 5 additions & 5 deletions include/CLUEstering/DataFormats/alpaka/TilesAlpaka.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {
template <uint8_t Ndim>
class TilesAlpaka {
public:
TilesAlpaka(Queue queue, uint32_t n_points, int32_t n_perdim, uint32_t n_tiles)
: m_ntiles{n_tiles},
m_nperdim{n_perdim},
TilesAlpaka(Queue queue, uint32_t n_points, int32_t n_perdim, int32_t n_tiles)
: m_assoc{clue::AssociationMap<Device>(n_points, n_tiles, queue)},
m_minmax{clue::make_device_buffer<CoordinateExtremes<Ndim>>(queue)},
m_tilesizes{clue::make_device_buffer<float[Ndim]>(queue)},
m_assoc{clue::AssociationMap<Device>(n_points, n_tiles, queue)},
m_ntiles{n_tiles},
m_nperdim{n_perdim},
m_view{clue::make_device_buffer<TilesAlpakaView<Ndim>>(queue)} {
auto host_view = clue::make_host_buffer<TilesAlpakaView<Ndim>>(queue);
host_view->indexes = m_assoc.indexes().data();
Expand Down Expand Up @@ -182,9 +182,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE {
clue::AssociationMap<Device> m_assoc;
clue::device_buffer<Device, CoordinateExtremes<Ndim>> m_minmax;
clue::device_buffer<Device, float[Ndim]> m_tilesizes;
clue::device_buffer<Device, TilesAlpakaView<Ndim>> m_view;
int32_t m_ntiles;
int32_t m_nperdim;
clue::device_buffer<Device, TilesAlpakaView<Ndim>> m_view;
};

} // namespace ALPAKA_ACCELERATOR_NAMESPACE_CLUE

0 comments on commit 5eba84c

Please sign in to comment.