Skip to content

Commit

Permalink
src,tests: Handle and fix recent clang-tidy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
stotko committed Nov 16, 2024
1 parent 1523669 commit 7b08673
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 54 deletions.
6 changes: 6 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,34 @@ cppcoreguidelines-*,\
-cppcoreguidelines-avoid-c-arrays,\
-cppcoreguidelines-avoid-non-const-global-variables,\
-cppcoreguidelines-macro-usage,\
-cppcoreguidelines-missing-std-forward,\
-cppcoreguidelines-owning-memory,\
-cppcoreguidelines-pro-bounds-pointer-arithmetic,\
-cppcoreguidelines-pro-type-const-cast,\
-cppcoreguidelines-pro-type-vararg,\
-cppcoreguidelines-rvalue-reference-param-not-moved,\
hicpp-*,\
-hicpp-avoid-c-arrays,\
-hicpp-vararg,\
-hicpp-use-auto,\
misc-*,\
-misc-const-correctness,\
-misc-include-cleaner,\
modernize-*,\
-modernize-avoid-c-arrays,\
-modernize-use-auto,\
-modernize-use-nodiscard,\
-modernize-use-trailing-return-type,\
performance-*,\
-performance-avoid-endl,\
portability-*,\
readability-*,\
-readability-avoid-const-params-in-decls,\
-readability-const-return-type,\
-readability-function-cognitive-complexity,\
-readability-identifier-length,\
-readability-redundant-casting,\
-readability-redundant-member-init,\
"
HeaderFilterRegex: 'src|benchmark/stdgpu|test/stdgpu'
...
51 changes: 44 additions & 7 deletions src/stdgpu/atomic.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/

#include <cstddef>
#include <cstdint>
#include <type_traits>

#include <stdgpu/execution.h>
Expand All @@ -42,16 +43,52 @@ namespace stdgpu
* \ingroup atomic
* \brief The memory order types for atomic operations
*/
enum memory_order
enum class memory_order : std::int8_t
{
memory_order_relaxed, /**< memory_order_relaxed */
memory_order_consume, /**< memory_order_consume */
memory_order_acquire, /**< memory_order_acquire */
memory_order_release, /**< memory_order_release */
memory_order_acq_rel, /**< memory_order_acq_rel */
memory_order_seq_cst /**< memory_order_seq_cst */
relaxed, /**< relaxed */
consume, /**< consume */
acquire, /**< acquire */
release, /**< release */
acq_rel, /**< acq_rel */
seq_cst /**< seq_cst */
};

/**
* \ingroup atomic
* \brief memory_order_relaxed
*/
inline constexpr memory_order memory_order_relaxed = memory_order::relaxed;

/**
* \ingroup atomic
* \brief memory_order_consume
*/
inline constexpr memory_order memory_order_consume = memory_order::consume;

/**
* \ingroup atomic
* \brief memory_order_acquire
*/
inline constexpr memory_order memory_order_acquire = memory_order::acquire;

/**
* \ingroup atomic
* \brief memory_order_release
*/
inline constexpr memory_order memory_order_release = memory_order::release;

/**
* \ingroup atomic
* \brief memory_order_acq_rel
*/
inline constexpr memory_order memory_order_acq_rel = memory_order::acq_rel;

/**
* \ingroup atomic
* \brief memory_order_seq_cst
*/
inline constexpr memory_order memory_order_seq_cst = memory_order::seq_cst;

/**
* \ingroup atomic
* \brief A synchronization fence enforcing the given memory order
Expand Down
2 changes: 1 addition & 1 deletion src/stdgpu/impl/algorithm_detail.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ clamp(const T& v, const T& lower, const T& upper)
{
STDGPU_EXPECTS(!(upper < lower));

return v < lower ? lower : upper < v ? upper : v;
return v < lower ? lower : upper < v ? upper : v; // NOLINT(readability-avoid-nested-conditional-operator)
}

template <typename IndexType,
Expand Down
10 changes: 5 additions & 5 deletions src/stdgpu/impl/bitset_detail.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,20 @@ template <typename Block>
class count_block_bits
{
public:
inline count_block_bits(Block* bit_blocks, const index_t size)
count_block_bits(Block* bit_blocks, const index_t size)
: _bit_blocks(bit_blocks)
, _size(size)
{
}

inline STDGPU_HOST_DEVICE index_t
STDGPU_HOST_DEVICE index_t
operator()(const index_t i) const
{
return static_cast<index_t>(popcount(block_mask(i) & _bit_blocks[i]));
}

private:
inline STDGPU_HOST_DEVICE Block
STDGPU_HOST_DEVICE Block
block_mask(const index_t i) const
{
index_t remaining_bits = _size - i * _bits_per_block;
Expand All @@ -162,12 +162,12 @@ template <typename Block>
class flip_bits
{
public:
inline explicit flip_bits(Block* bit_blocks)
explicit flip_bits(Block* bit_blocks)
: _bit_blocks(bit_blocks)
{
}

inline STDGPU_HOST_DEVICE void
STDGPU_HOST_DEVICE void
operator()(const index_t i)
{
_bit_blocks[i] = ~_bit_blocks[i];
Expand Down
2 changes: 1 addition & 1 deletion src/stdgpu/impl/functional_detail.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct hash_base
template <typename T>
struct hash_base<T, true>
{
inline STDGPU_HOST_DEVICE std::size_t
STDGPU_HOST_DEVICE std::size_t
operator()(const T& key) const
{
return hash<std::underlying_type_t<T>>()(static_cast<std::underlying_type_t<T>>(key));
Expand Down
1 change: 1 addition & 0 deletions src/stdgpu/impl/iterator_detail.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ template <typename T>
index64_t
size(T* array)
{
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
index64_t array_size_bytes = size<void>(static_cast<void*>(const_cast<std::remove_cv_t<T>*>(array)));

if (array_size_bytes % static_cast<index64_t>(sizeof(T)) != 0) // NOLINT(bugprone-sizeof-expression)
Expand Down
1 change: 1 addition & 0 deletions src/stdgpu/impl/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include <stdgpu/memory.h>

#include <cstdint>
#include <cstdio>
#include <map>
#include <mutex>
Expand Down
76 changes: 48 additions & 28 deletions src/stdgpu/impl/memory_detail.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,15 @@ copyDevice2HostArray(const T* source_device_array,
T* destination_host_array,
const MemoryCopy check_safety)
{
stdgpu::detail::memcpy(destination_host_array,
source_device_array,
count * static_cast<stdgpu::index64_t>(sizeof(T)), // NOLINT(bugprone-sizeof-expression)
stdgpu::dynamic_memory_type::host,
stdgpu::dynamic_memory_type::device,
check_safety != MemoryCopy::RANGE_CHECK);
stdgpu::detail::memcpy(
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
static_cast<void*>(const_cast<std::remove_cv_t<T>*>(destination_host_array)),
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
static_cast<void*>(const_cast<std::remove_cv_t<T>*>(source_device_array)),
count * static_cast<stdgpu::index64_t>(sizeof(T)), // NOLINT(bugprone-sizeof-expression)
stdgpu::dynamic_memory_type::host,
stdgpu::dynamic_memory_type::device,
check_safety != MemoryCopy::RANGE_CHECK);
}

template <typename T>
Expand All @@ -392,12 +395,15 @@ copyHost2DeviceArray(const T* source_host_array,
T* destination_device_array,
const MemoryCopy check_safety)
{
stdgpu::detail::memcpy(destination_device_array,
source_host_array,
count * static_cast<stdgpu::index64_t>(sizeof(T)), // NOLINT(bugprone-sizeof-expression)
stdgpu::dynamic_memory_type::device,
stdgpu::dynamic_memory_type::host,
check_safety != MemoryCopy::RANGE_CHECK);
stdgpu::detail::memcpy(
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
static_cast<void*>(const_cast<std::remove_cv_t<T>*>(destination_device_array)),
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
static_cast<void*>(const_cast<std::remove_cv_t<T>*>(source_host_array)),
count * static_cast<stdgpu::index64_t>(sizeof(T)), // NOLINT(bugprone-sizeof-expression)
stdgpu::dynamic_memory_type::device,
stdgpu::dynamic_memory_type::host,
check_safety != MemoryCopy::RANGE_CHECK);
}

template <typename T>
Expand All @@ -407,12 +413,15 @@ copyHost2HostArray(const T* source_host_array,
T* destination_host_array,
const MemoryCopy check_safety)
{
stdgpu::detail::memcpy(destination_host_array,
source_host_array,
count * static_cast<stdgpu::index64_t>(sizeof(T)), // NOLINT(bugprone-sizeof-expression)
stdgpu::dynamic_memory_type::host,
stdgpu::dynamic_memory_type::host,
check_safety != MemoryCopy::RANGE_CHECK);
stdgpu::detail::memcpy(
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
static_cast<void*>(const_cast<std::remove_cv_t<T>*>(destination_host_array)),
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
static_cast<void*>(const_cast<std::remove_cv_t<T>*>(source_host_array)),
count * static_cast<stdgpu::index64_t>(sizeof(T)), // NOLINT(bugprone-sizeof-expression)
stdgpu::dynamic_memory_type::host,
stdgpu::dynamic_memory_type::host,
check_safety != MemoryCopy::RANGE_CHECK);
}

template <typename T>
Expand All @@ -422,12 +431,15 @@ copyDevice2DeviceArray(const T* source_device_array,
T* destination_device_array,
const MemoryCopy check_safety)
{
stdgpu::detail::memcpy(destination_device_array,
source_device_array,
count * static_cast<stdgpu::index64_t>(sizeof(T)), // NOLINT(bugprone-sizeof-expression)
stdgpu::dynamic_memory_type::device,
stdgpu::dynamic_memory_type::device,
check_safety != MemoryCopy::RANGE_CHECK);
stdgpu::detail::memcpy(
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
static_cast<void*>(const_cast<std::remove_cv_t<T>*>(destination_device_array)),
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
static_cast<void*>(const_cast<std::remove_cv_t<T>*>(source_device_array)),
count * static_cast<stdgpu::index64_t>(sizeof(T)), // NOLINT(bugprone-sizeof-expression)
stdgpu::dynamic_memory_type::device,
stdgpu::dynamic_memory_type::device,
check_safety != MemoryCopy::RANGE_CHECK);
}

namespace stdgpu
Expand Down Expand Up @@ -517,7 +529,8 @@ void
safe_device_allocator<T>::deallocate(T* p, index64_t n)
{
deregister_memory(p, n, memory_type);
detail::deallocate(static_cast<void*>(p),
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
detail::deallocate(static_cast<void*>(const_cast<std::remove_cv_t<T>*>(p)),
n * static_cast<index64_t>(sizeof(T)), // NOLINT(bugprone-sizeof-expression)
memory_type);
}
Expand All @@ -543,7 +556,8 @@ void
safe_host_allocator<T>::deallocate(T* p, index64_t n)
{
deregister_memory(p, n, memory_type);
detail::deallocate(static_cast<void*>(p),
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
detail::deallocate(static_cast<void*>(const_cast<std::remove_cv_t<T>*>(p)),
n * static_cast<index64_t>(sizeof(T)), // NOLINT(bugprone-sizeof-expression)
memory_type);
}
Expand All @@ -569,7 +583,8 @@ void
safe_managed_allocator<T>::deallocate(T* p, index64_t n)
{
deregister_memory(p, n, memory_type);
detail::deallocate(static_cast<void*>(p),
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
detail::deallocate(static_cast<void*>(const_cast<std::remove_cv_t<T>*>(p)),
n * static_cast<index64_t>(sizeof(T)), // NOLINT(bugprone-sizeof-expression)
memory_type);
}
Expand Down Expand Up @@ -695,7 +710,8 @@ template <typename T, typename... Args>
STDGPU_HOST_DEVICE T*
construct_at(T* p, Args&&... args)
{
return ::new (static_cast<void*>(p)) T(forward<Args>(args)...);
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
return ::new (static_cast<void*>(const_cast<std::remove_cv_t<T>*>(p))) T(forward<Args>(args)...);
}

template <typename T>
Expand Down Expand Up @@ -793,6 +809,7 @@ template <typename T>
dynamic_memory_type
get_dynamic_memory_type(T* array)
{
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
return get_dynamic_memory_type<void>(static_cast<void*>(const_cast<std::remove_cv_t<T>*>(array)));
}

Expand All @@ -804,6 +821,7 @@ template <typename T>
void
register_memory(T* p, index64_t n, dynamic_memory_type memory_type)
{
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
register_memory<void>(static_cast<void*>(const_cast<std::remove_cv_t<T>*>(p)),
n * static_cast<index64_t>(sizeof(T)), // NOLINT(bugprone-sizeof-expression)
memory_type);
Expand All @@ -817,6 +835,7 @@ template <typename T>
void
deregister_memory(T* p, index64_t n, dynamic_memory_type memory_type)
{
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
deregister_memory<void>(static_cast<void*>(const_cast<std::remove_cv_t<T>*>(p)),
n * static_cast<index64_t>(sizeof(T)), // NOLINT(bugprone-sizeof-expression)
memory_type);
Expand All @@ -830,6 +849,7 @@ template <typename T>
index64_t
size_bytes(T* array)
{
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
return size_bytes<void>(static_cast<void*>(const_cast<std::remove_cv_t<T>*>(array)));
}

Expand Down
4 changes: 3 additions & 1 deletion src/stdgpu/impl/unordered_base.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#ifndef STDGPU_UNORDERED_BASE_H
#define STDGPU_UNORDERED_BASE_H

#include <cstdint>

#include <stdgpu/atomic.cuh>
#include <stdgpu/bitset.cuh>
#include <stdgpu/cstddef.h>
Expand All @@ -35,7 +37,7 @@ namespace stdgpu::detail
/**
* \brief Status flags for try_insert and try_erase
*/
enum class operation_status
enum class operation_status : std::int8_t
{
success, /**< Operation succeeded */
failed_no_action_required, /**< Operation failed because no action is required */
Expand Down
7 changes: 4 additions & 3 deletions src/stdgpu/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* \file stdgpu/memory.h
*/

#include <cstdint>
#include <functional>
#include <memory>
#include <type_traits>
Expand All @@ -39,7 +40,7 @@
* \ingroup memory
* \brief The place to initialize the created array
*/
enum class Initialization
enum class Initialization : std::int8_t
{
HOST, /**< The array is initialized on the host (CPU) */
DEVICE /**< The array is initialized on the device (GPU) */
Expand Down Expand Up @@ -121,7 +122,7 @@ destroyManagedArray(T*& managed_array);
* \ingroup memory
* \brief The copy check states
*/
enum class MemoryCopy
enum class MemoryCopy : std::int8_t
{
NO_CHECK, /**< No checks should be performed. This is useful when copying from/to arrays not created by our API,
e.g. created by 3rd party libraries or pointers to local variables. */
Expand Down Expand Up @@ -356,7 +357,7 @@ class device_unique_object
* \ingroup memory
* \brief The types of a dynamically allocated array
*/
enum class dynamic_memory_type
enum class dynamic_memory_type : std::int8_t
{
host, /**< The array is allocated on the host (CPU) */
device, /**< The array is allocated on the device (GPU) */
Expand Down
Loading

0 comments on commit 7b08673

Please sign in to comment.