Skip to content

Commit 53b81d0

Browse files
committed
examples,src: Handle and fix more recent clang-tidy warnings
1 parent 53d9419 commit 53b81d0

8 files changed

Lines changed: 126 additions & 112 deletions

File tree

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ hicpp-*,\
2323
misc-*,\
2424
-misc-const-correctness,\
2525
-misc-include-cleaner,\
26+
-misc-use-internal-linkage,\
2627
modernize-*,\
2728
-modernize-avoid-c-arrays,\
2829
-modernize-use-auto,\

examples/createAndDestroyDeviceObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Image
6969
STDGPU_HOST_DEVICE std::uint8_t&
7070
operator()(const stdgpu::index_t x, const stdgpu::index_t y)
7171
{
72-
return _values[y * _width + x];
72+
return _values[(y * _width) + x];
7373
}
7474

7575
STDGPU_HOST_DEVICE stdgpu::index_t

src/stdgpu/impl/algorithm_detail.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ template <class T>
2929
constexpr STDGPU_HOST_DEVICE const T&
3030
min(const T& a, const T& b)
3131
{
32-
return (b < a) ? b : a;
32+
return (b < a) ? b : a; // NOLINT(bugprone-return-const-ref-from-parameter)
3333
}
3434

3535
template <class T>
3636
constexpr STDGPU_HOST_DEVICE const T&
3737
max(const T& a, const T& b)
3838
{
39-
return (a < b) ? b : a;
39+
return (a < b) ? b : a; // NOLINT(bugprone-return-const-ref-from-parameter)
4040
}
4141

4242
template <class T>
@@ -45,7 +45,8 @@ clamp(const T& v, const T& lower, const T& upper)
4545
{
4646
STDGPU_EXPECTS(!(upper < lower));
4747

48-
return v < lower ? lower : upper < v ? upper : v; // NOLINT(readability-avoid-nested-conditional-operator)
48+
// NOLINTNEXTLINE(bugprone-return-const-ref-from-parameter,readability-avoid-nested-conditional-operator)
49+
return v < lower ? lower : upper < v ? upper : v;
4950
}
5051

5152
template <typename IndexType,
@@ -58,7 +59,7 @@ for_each_index(ExecutionPolicy&& policy, IndexType size, UnaryFunction f)
5859
thrust::for_each(std::forward<ExecutionPolicy>(policy),
5960
thrust::counting_iterator<IndexType>(0),
6061
thrust::counting_iterator<IndexType>(size),
61-
f);
62+
std::move(f));
6263
}
6364

6465
namespace detail

src/stdgpu/impl/bitset_detail.cuh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define STDGPU_BITSET_DETAIL_H
1818

1919
#include <limits>
20+
#include <type_traits>
2021

2122
#include <stdgpu/algorithm.h>
2223
#include <stdgpu/atomic.cuh>
@@ -119,7 +120,7 @@ div_up(const index_t a, const index_t b) noexcept
119120
STDGPU_EXPECTS(a >= 0);
120121
STDGPU_EXPECTS(b > 0);
121122

122-
index_t result = (a % b != 0) ? (a / b + 1) : (a / b);
123+
index_t result = (a % b != 0) ? ((a / b) + 1) : (a / b);
123124

124125
STDGPU_ENSURES(result * b >= a);
125126

@@ -146,7 +147,7 @@ private:
146147
STDGPU_HOST_DEVICE Block
147148
block_mask(const index_t i) const
148149
{
149-
index_t remaining_bits = _size - i * _bits_per_block;
150+
index_t remaining_bits = _size - (i * _bits_per_block);
150151
return (remaining_bits >= _bits_per_block)
151152
? ~static_cast<Block>(0)
152153
: (static_cast<Block>(1) << static_cast<Block>(remaining_bits)) - static_cast<Block>(1);
@@ -256,7 +257,7 @@ template <typename ExecutionPolicy,
256257
inline void
257258
bitset<Block, Allocator>::set(ExecutionPolicy&& policy)
258259
{
259-
fill(std::forward<ExecutionPolicy>(policy), device_begin(_bit_blocks), device_end(_bit_blocks), ~block_type(0));
260+
fill(std::decay_t<ExecutionPolicy>{ policy }, device_begin(_bit_blocks), device_end(_bit_blocks), ~block_type(0));
260261

261262
STDGPU_ENSURES(count(std::forward<ExecutionPolicy>(policy)) == size());
262263
}
@@ -284,7 +285,7 @@ template <typename ExecutionPolicy,
284285
inline void
285286
bitset<Block, Allocator>::reset(ExecutionPolicy&& policy)
286287
{
287-
fill(std::forward<ExecutionPolicy>(policy), device_begin(_bit_blocks), device_end(_bit_blocks), block_type(0));
288+
fill(std::decay_t<ExecutionPolicy>{ policy }, device_begin(_bit_blocks), device_end(_bit_blocks), block_type(0));
288289

289290
STDGPU_ENSURES(count(std::forward<ExecutionPolicy>(policy)) == 0);
290291
}

src/stdgpu/impl/deque_detail.cuh

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#ifndef STDGPU_DEQUE_DETAIL_H
1717
#define STDGPU_DEQUE_DETAIL_H
1818

19+
#include <type_traits>
20+
1921
#include <stdgpu/contract.h>
2022
#include <stdgpu/iterator.h>
2123
#include <stdgpu/memory.h>
@@ -42,19 +44,21 @@ deque<T, Allocator>::createDeviceObject(ExecutionPolicy&& policy, const index_t&
4244

4345
deque<T, Allocator> result(
4446
mutex_array<mutex_default_type, mutex_array_allocator_type>::createDeviceObject(
45-
std::forward<ExecutionPolicy>(policy),
47+
std::decay_t<ExecutionPolicy>{ policy },
4648
capacity,
4749
mutex_array_allocator_type(allocator)),
4850
bitset<bitset_default_type, bitset_allocator_type>::createDeviceObject(
49-
std::forward<ExecutionPolicy>(policy),
51+
std::decay_t<ExecutionPolicy>{ policy },
5052
capacity,
5153
bitset_allocator_type(allocator)),
52-
atomic<int, atomic_int_allocator_type>::createDeviceObject(std::forward<ExecutionPolicy>(policy),
54+
atomic<int, atomic_int_allocator_type>::createDeviceObject(std::decay_t<ExecutionPolicy>{ policy },
5355
atomic_int_allocator_type(allocator)),
54-
atomic<unsigned int, atomic_uint_allocator_type>::createDeviceObject(std::forward<ExecutionPolicy>(policy),
55-
atomic_uint_allocator_type(allocator)),
56-
atomic<unsigned int, atomic_uint_allocator_type>::createDeviceObject(std::forward<ExecutionPolicy>(policy),
57-
atomic_uint_allocator_type(allocator)),
56+
atomic<unsigned int, atomic_uint_allocator_type>::createDeviceObject(
57+
std::decay_t<ExecutionPolicy>{ policy },
58+
atomic_uint_allocator_type(allocator)),
59+
atomic<unsigned int, atomic_uint_allocator_type>::createDeviceObject(
60+
std::decay_t<ExecutionPolicy>{ policy },
61+
atomic_uint_allocator_type(allocator)),
5862
allocator);
5963
result._data = allocator_traits<allocator_type>::allocate(result._allocator, capacity);
6064
result._range_indices = allocator_traits<index_allocator_type>::allocate(result._index_allocator, capacity);
@@ -77,7 +81,7 @@ deque<T, Allocator>::destroyDeviceObject(ExecutionPolicy&& policy, deque<T, Allo
7781
{
7882
if (!detail::is_destroy_optimizable<value_type>())
7983
{
80-
device_object.clear(std::forward<ExecutionPolicy>(policy));
84+
device_object.clear(std::decay_t<ExecutionPolicy>{ policy });
8185
}
8286

8387
allocator_traits<allocator_type>::deallocate(device_object._allocator,
@@ -89,13 +93,13 @@ deque<T, Allocator>::destroyDeviceObject(ExecutionPolicy&& policy, deque<T, Allo
8993
device_object._data = nullptr;
9094
device_object._range_indices = nullptr;
9195
mutex_array<mutex_default_type, mutex_array_allocator_type>::destroyDeviceObject(
92-
std::forward<ExecutionPolicy>(policy),
96+
std::decay_t<ExecutionPolicy>{ policy },
9397
device_object._locks);
94-
bitset<bitset_default_type, bitset_allocator_type>::destroyDeviceObject(std::forward<ExecutionPolicy>(policy),
98+
bitset<bitset_default_type, bitset_allocator_type>::destroyDeviceObject(std::decay_t<ExecutionPolicy>{ policy },
9599
device_object._occupied);
96-
atomic<int, atomic_int_allocator_type>::destroyDeviceObject(std::forward<ExecutionPolicy>(policy),
100+
atomic<int, atomic_int_allocator_type>::destroyDeviceObject(std::decay_t<ExecutionPolicy>{ policy },
97101
device_object._size);
98-
atomic<unsigned int, atomic_uint_allocator_type>::destroyDeviceObject(std::forward<ExecutionPolicy>(policy),
102+
atomic<unsigned int, atomic_uint_allocator_type>::destroyDeviceObject(std::decay_t<ExecutionPolicy>{ policy },
99103
device_object._begin);
100104
atomic<unsigned int, atomic_uint_allocator_type>::destroyDeviceObject(std::forward<ExecutionPolicy>(policy),
101105
device_object._end);
@@ -550,48 +554,50 @@ template <typename ExecutionPolicy,
550554
inline void
551555
deque<T, Allocator>::clear(ExecutionPolicy&& policy)
552556
{
553-
if (empty(std::forward<ExecutionPolicy>(policy)))
557+
if (empty(std::decay_t<ExecutionPolicy>{ policy }))
554558
{
555559
return;
556560
}
557561

558562
if (!detail::is_destroy_optimizable<value_type>())
559563
{
560-
const index_t begin = static_cast<index_t>(_begin.load(std::forward<ExecutionPolicy>(policy)));
561-
const index_t end = static_cast<index_t>(_end.load(std::forward<ExecutionPolicy>(policy)));
564+
const index_t begin = static_cast<index_t>(_begin.load(std::decay_t<ExecutionPolicy>{ policy }));
565+
const index_t end = static_cast<index_t>(_end.load(std::decay_t<ExecutionPolicy>{ policy }));
562566

563567
// Full, i.e. one large block and begin == end
564-
if (full(std::forward<ExecutionPolicy>(policy)))
568+
if (full(std::decay_t<ExecutionPolicy>{ policy }))
565569
{
566-
detail::unoptimized_destroy(std::forward<ExecutionPolicy>(policy), device_begin(_data), device_end(_data));
570+
detail::unoptimized_destroy(std::decay_t<ExecutionPolicy>{ policy },
571+
device_begin(_data),
572+
device_end(_data));
567573
}
568574
// One large block
569575
else if (begin <= end)
570576
{
571-
detail::unoptimized_destroy(std::forward<ExecutionPolicy>(policy),
577+
detail::unoptimized_destroy(std::decay_t<ExecutionPolicy>{ policy },
572578
make_device(_data + begin),
573579
make_device(_data + end));
574580
}
575581
// Two disconnected blocks
576582
else
577583
{
578-
detail::unoptimized_destroy(std::forward<ExecutionPolicy>(policy),
584+
detail::unoptimized_destroy(std::decay_t<ExecutionPolicy>{ policy },
579585
device_begin(_data),
580586
make_device(_data + end));
581-
detail::unoptimized_destroy(std::forward<ExecutionPolicy>(policy),
587+
detail::unoptimized_destroy(std::decay_t<ExecutionPolicy>{ policy },
582588
make_device(_data + begin),
583589
device_end(_data));
584590
}
585591
}
586592

587-
_occupied.reset(std::forward<ExecutionPolicy>(policy));
593+
_occupied.reset(std::decay_t<ExecutionPolicy>{ policy });
588594

589-
_size.store(std::forward<ExecutionPolicy>(policy), 0);
595+
_size.store(std::decay_t<ExecutionPolicy>{ policy }, 0);
590596

591-
_begin.store(std::forward<ExecutionPolicy>(policy), 0);
592-
_end.store(std::forward<ExecutionPolicy>(policy), 0);
597+
_begin.store(std::decay_t<ExecutionPolicy>{ policy }, 0);
598+
_end.store(std::decay_t<ExecutionPolicy>{ policy }, 0);
593599

594-
STDGPU_ENSURES(empty(std::forward<ExecutionPolicy>(policy)));
600+
STDGPU_ENSURES(empty(std::decay_t<ExecutionPolicy>{ policy }));
595601
STDGPU_ENSURES(valid(std::forward<ExecutionPolicy>(policy)));
596602
}
597603

@@ -614,9 +620,9 @@ deque<T, Allocator>::valid(ExecutionPolicy&& policy) const
614620
return true;
615621
}
616622

617-
return (size_valid(std::forward<ExecutionPolicy>(policy)) &&
618-
occupied_count_valid(std::forward<ExecutionPolicy>(policy)) &&
619-
_locks.valid(std::forward<ExecutionPolicy>(policy)));
623+
return (size_valid(std::decay_t<ExecutionPolicy>{ policy }) &&
624+
occupied_count_valid(std::decay_t<ExecutionPolicy>{ policy }) &&
625+
_locks.valid(std::decay_t<ExecutionPolicy>{ policy }));
620626
}
621627

622628
template <typename T, typename Allocator>
@@ -632,30 +638,30 @@ template <typename ExecutionPolicy,
632638
stdgpu::device_indexed_range<T>
633639
deque<T, Allocator>::device_range(ExecutionPolicy&& policy)
634640
{
635-
const index_t begin = static_cast<index_t>(_begin.load(std::forward<ExecutionPolicy>(policy)));
636-
const index_t end = static_cast<index_t>(_end.load(std::forward<ExecutionPolicy>(policy)));
641+
const index_t begin = static_cast<index_t>(_begin.load(std::decay_t<ExecutionPolicy>{ policy }));
642+
const index_t end = static_cast<index_t>(_end.load(std::decay_t<ExecutionPolicy>{ policy }));
637643

638644
// Full, i.e. one large block and begin == end
639-
if (full(std::forward<ExecutionPolicy>(policy)))
645+
if (full(std::decay_t<ExecutionPolicy>{ policy }))
640646
{
641-
iota(std::forward<ExecutionPolicy>(policy), device_begin(_range_indices), device_end(_range_indices), 0);
647+
iota(std::decay_t<ExecutionPolicy>{ policy }, device_begin(_range_indices), device_end(_range_indices), 0);
642648
}
643649
// One large block, including empty block
644650
else if (begin <= end)
645651
{
646-
iota(std::forward<ExecutionPolicy>(policy),
652+
iota(std::decay_t<ExecutionPolicy>{ policy },
647653
device_begin(_range_indices),
648654
device_begin(_range_indices) + (end - begin),
649655
begin);
650656
}
651657
// Two disconnected blocks
652658
else
653659
{
654-
iota(std::forward<ExecutionPolicy>(policy),
660+
iota(std::decay_t<ExecutionPolicy>{ policy },
655661
device_begin(_range_indices),
656662
device_begin(_range_indices) + end,
657663
0);
658-
iota(std::forward<ExecutionPolicy>(policy),
664+
iota(std::decay_t<ExecutionPolicy>{ policy },
659665
device_begin(_range_indices) + end,
660666
device_begin(_range_indices) + (end + capacity() - begin),
661667
begin);
@@ -679,30 +685,30 @@ template <typename ExecutionPolicy,
679685
stdgpu::device_indexed_range<const T>
680686
deque<T, Allocator>::device_range(ExecutionPolicy&& policy) const
681687
{
682-
const index_t begin = static_cast<index_t>(_begin.load(std::forward<ExecutionPolicy>(policy)));
683-
const index_t end = static_cast<index_t>(_end.load(std::forward<ExecutionPolicy>(policy)));
688+
const index_t begin = static_cast<index_t>(_begin.load(std::decay_t<ExecutionPolicy>{ policy }));
689+
const index_t end = static_cast<index_t>(_end.load(std::decay_t<ExecutionPolicy>{ policy }));
684690

685691
// Full, i.e. one large block and begin == end
686-
if (full(std::forward<ExecutionPolicy>(policy)))
692+
if (full(std::decay_t<ExecutionPolicy>{ policy }))
687693
{
688-
iota(std::forward<ExecutionPolicy>(policy), device_begin(_range_indices), device_end(_range_indices), 0);
694+
iota(std::decay_t<ExecutionPolicy>{ policy }, device_begin(_range_indices), device_end(_range_indices), 0);
689695
}
690696
// One large block, including empty block
691697
else if (begin <= end)
692698
{
693-
iota(std::forward<ExecutionPolicy>(policy),
699+
iota(std::decay_t<ExecutionPolicy>{ policy },
694700
device_begin(_range_indices),
695701
device_begin(_range_indices) + (end - begin),
696702
begin);
697703
}
698704
// Two disconnected blocks
699705
else
700706
{
701-
iota(std::forward<ExecutionPolicy>(policy),
707+
iota(std::decay_t<ExecutionPolicy>{ policy },
702708
device_begin(_range_indices),
703709
device_begin(_range_indices) + end,
704710
0);
705-
iota(std::forward<ExecutionPolicy>(policy),
711+
iota(std::decay_t<ExecutionPolicy>{ policy },
706712
device_begin(_range_indices) + end,
707713
device_begin(_range_indices) + (end + capacity() - begin),
708714
begin);
@@ -726,7 +732,7 @@ template <typename ExecutionPolicy,
726732
bool
727733
deque<T, Allocator>::occupied_count_valid(ExecutionPolicy&& policy) const
728734
{
729-
index_t size_count = size(std::forward<ExecutionPolicy>(policy));
735+
index_t size_count = size(std::decay_t<ExecutionPolicy>{ policy });
730736
index_t size_sum = _occupied.count(std::forward<ExecutionPolicy>(policy));
731737

732738
return (size_count == size_sum);

src/stdgpu/impl/memory_detail.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ unoptimized_destroy(ExecutionPolicy&& policy, Iterator first, Iterator last)
174174

175175
template <typename T>
176176
T*
177-
createDeviceArray(const stdgpu::index64_t count, const T default_value)
177+
createDeviceArray(const stdgpu::index64_t count, const T default_value) // NOLINT(performance-unnecessary-value-param)
178178
{
179179
T* device_array = nullptr;
180180

@@ -441,8 +441,8 @@ template <typename ExecutionPolicy,
441441
typename... Args,
442442
STDGPU_DETAIL_OVERLOAD_DEFINITION_IF(is_execution_policy_v<remove_cvref_t<ExecutionPolicy>>)>
443443
device_unique_object<T>::device_unique_object(ExecutionPolicy&& policy, Args&&... args)
444-
: _object(new T(T::createDeviceObject(std::forward<ExecutionPolicy>(policy), std::forward<Args>(args)...)),
445-
[_policy = std::forward<ExecutionPolicy>(policy)](T* ptr)
444+
: _object(new T(T::createDeviceObject(std::decay_t<ExecutionPolicy>{ policy }, std::forward<Args>(args)...)),
445+
[_policy = std::decay_t<ExecutionPolicy>{ policy }](T* ptr)
446446
{
447447
T::destroyDeviceObject(_policy, *ptr);
448448
delete ptr;

0 commit comments

Comments
 (0)