mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[10/N] Fixes clang-tidy warnings in c10/util/*.h (#116326)
Still a continued work for clean up c10/util/*.h Pull Request resolved: https://github.com/pytorch/pytorch/pull/116326 Approved by: https://github.com/Skylion007
This commit is contained in:
@ -35,6 +35,7 @@ namespace c10 {
|
||||
|
||||
template <size_t Alignment, size_t Size>
|
||||
struct AlignedCharArray {
|
||||
// NOLINTNEXTLINE(*c-arrays)
|
||||
alignas(Alignment) char buffer[Size];
|
||||
};
|
||||
|
||||
@ -142,6 +143,7 @@ template <
|
||||
typename T9 = char,
|
||||
typename T10 = char>
|
||||
union SizerImpl {
|
||||
// NOLINTNEXTLINE(*c-arrays)
|
||||
char arr1[sizeof(T1)], arr2[sizeof(T2)], arr3[sizeof(T3)], arr4[sizeof(T4)],
|
||||
arr5[sizeof(T5)], arr6[sizeof(T6)], arr7[sizeof(T7)], arr8[sizeof(T8)],
|
||||
arr9[sizeof(T9)], arr10[sizeof(T10)];
|
||||
|
@ -5,8 +5,7 @@
|
||||
#include <intrin.h>
|
||||
#endif
|
||||
|
||||
namespace c10 {
|
||||
namespace utils {
|
||||
namespace c10::utils {
|
||||
|
||||
/**
|
||||
* This is a simple bitset class with sizeof(long long int) bits.
|
||||
@ -114,5 +113,4 @@ inline bool operator!=(bitset lhs, bitset rhs) noexcept {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
} // namespace c10
|
||||
} // namespace c10::utils
|
||||
|
@ -47,7 +47,7 @@ class once_flag {
|
||||
if (init_.load(std::memory_order_relaxed)) {
|
||||
return;
|
||||
}
|
||||
c10::guts::invoke(f, std::forward<Args>(args)...);
|
||||
c10::guts::invoke(std::forward<F>(f), std::forward<Args>(args)...);
|
||||
init_.store(true, std::memory_order_release);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <c10/core/TensorImpl.h>
|
||||
#include <c10/core/UndefinedTensorImpl.h>
|
||||
|
||||
#include <utility>
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
#include <c10/util/Float8_e4m3fn.h>
|
||||
#include <iostream>
|
||||
#include <type_traits>
|
||||
|
||||
namespace c10 {
|
||||
|
||||
static_assert(
|
||||
std::is_standard_layout<Float8_e4m3fn>::value,
|
||||
std::is_standard_layout_v<Float8_e4m3fn>,
|
||||
"c10::Float8_e4m3fn must be standard layout.");
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const Float8_e4m3fn& value) {
|
||||
|
@ -50,14 +50,15 @@ class function_ref<Ret(Params...)> {
|
||||
|
||||
template <typename Callable>
|
||||
function_ref(
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward)
|
||||
Callable&& callable,
|
||||
typename std::enable_if<!std::is_same<
|
||||
typename std::remove_reference<Callable>::type,
|
||||
function_ref>::value>::type* = nullptr,
|
||||
typename std::enable_if<std::is_convertible<
|
||||
std::enable_if_t<
|
||||
!std::is_same_v<std::remove_reference_t<Callable>, function_ref>>* =
|
||||
nullptr,
|
||||
std::enable_if_t<std::is_convertible_v<
|
||||
typename std::invoke_result_t<Callable, Params...>,
|
||||
Ret>::value>::type* = nullptr)
|
||||
: callback(callback_fn<typename std::remove_reference<Callable>::type>),
|
||||
Ret>>* = nullptr)
|
||||
: callback(callback_fn<std::remove_reference_t<Callable>>),
|
||||
callable(reinterpret_cast<intptr_t>(&callable)) {}
|
||||
|
||||
Ret operator()(Params... params) const {
|
||||
|
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <c10/util/TypeList.h>
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
namespace c10::guts {
|
||||
@ -207,6 +206,7 @@ constexpr auto tuple_slice(Tuple t) {
|
||||
namespace detail {
|
||||
template <class Mapper, class... Args, size_t... Indices>
|
||||
auto tuple_map(
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved)
|
||||
std::tuple<Args...>&& tuple,
|
||||
const Mapper& mapper,
|
||||
std::index_sequence<Indices...>) {
|
||||
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
|
||||
/** Helper class for allocating temporary fixed size arrays with SBO.
|
||||
@ -16,9 +18,7 @@ namespace c10 {
|
||||
|
||||
template <typename T, size_t N>
|
||||
class SmallBuffer {
|
||||
static_assert(
|
||||
std::is_trivial<T>::value,
|
||||
"SmallBuffer is intended for POD types");
|
||||
static_assert(std::is_trivial_v<T>, "SmallBuffer is intended for POD types");
|
||||
|
||||
std::array<T, N> storage_;
|
||||
size_t size_{};
|
||||
|
@ -201,7 +201,7 @@ struct all {
|
||||
};
|
||||
template <template <class> class Condition, class... Types>
|
||||
struct all<Condition, typelist<Types...>>
|
||||
: guts::conjunction<Condition<Types>...> {
|
||||
: std::conjunction<Condition<Types>...> {
|
||||
static_assert(
|
||||
is_type_condition<Condition>::value,
|
||||
"In typelist::all<Condition, TypeList>, the Condition argument must be a condition type trait, i.e. have a static constexpr bool ::value member.");
|
||||
@ -223,7 +223,7 @@ struct true_for_any_type final {
|
||||
};
|
||||
template <template <class> class Condition, class... Types>
|
||||
struct true_for_any_type<Condition, typelist<Types...>> final
|
||||
: guts::disjunction<Condition<Types>...> {
|
||||
: std::disjunction<Condition<Types>...> {
|
||||
static_assert(
|
||||
is_type_condition<Condition>::value,
|
||||
"In typelist::true_for_any_type<Condition, TypeList>, the Condition argument must be a condition type trait, i.e. have a static constexpr bool ::value member.");
|
||||
|
@ -5,8 +5,7 @@
|
||||
#include <cstring>
|
||||
#include <optional>
|
||||
|
||||
namespace c10 {
|
||||
namespace utils {
|
||||
namespace c10::utils {
|
||||
// Reads an environment variable and returns
|
||||
// - optional<true>, if set equal to "1"
|
||||
// - optional<false>, if set equal to "0"
|
||||
@ -39,5 +38,4 @@ inline std::optional<bool> check_env(const char* name) {
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
} // namespace utils
|
||||
} // namespace c10
|
||||
} // namespace c10::utils
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <c10/macros/Macros.h>
|
||||
#include <cstdint>
|
||||
|
||||
namespace c10::detail {
|
||||
|
@ -33,6 +33,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <c10/macros/Export.h>
|
||||
#include <cstdint>
|
||||
#include <iosfwd>
|
||||
|
||||
namespace c10 {
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
namespace c10 {
|
||||
namespace detail {
|
||||
|
||||
|
@ -14,16 +14,12 @@
|
||||
#pragma once
|
||||
#include <c10/macros/Macros.h>
|
||||
#include <c10/util/llvmMathExtras.h>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <climits>
|
||||
#include <cstring>
|
||||
#include <iterator>
|
||||
#include <list>
|
||||
|
||||
C10_CLANG_DIAGNOSTIC_PUSH()
|
||||
#if C10_CLANG_HAS_WARNING("-Wshorten-64-to-32")
|
||||
C10_CLANG_DIAGNOSTIC_IGNORE("-Wshorten-64-to-32")
|
||||
#endif
|
||||
#include <ostream>
|
||||
|
||||
namespace c10 {
|
||||
|
||||
@ -54,18 +50,12 @@ struct SparseBitVectorElement {
|
||||
private:
|
||||
// Index of Element in terms of where first bit starts.
|
||||
unsigned ElementIndex;
|
||||
BitWord Bits[BITWORDS_PER_ELEMENT];
|
||||
std::array<BitWord, BITWORDS_PER_ELEMENT> Bits{};
|
||||
|
||||
SparseBitVectorElement() {
|
||||
ElementIndex = ~0U;
|
||||
memset(&Bits[0], 0, sizeof(BitWord) * BITWORDS_PER_ELEMENT);
|
||||
}
|
||||
SparseBitVectorElement() : ElementIndex(~0U) {}
|
||||
|
||||
public:
|
||||
explicit SparseBitVectorElement(unsigned Idx) {
|
||||
ElementIndex = Idx;
|
||||
memset(&Bits[0], 0, sizeof(BitWord) * BITWORDS_PER_ELEMENT);
|
||||
}
|
||||
explicit SparseBitVectorElement(unsigned Idx) : ElementIndex(Idx) {}
|
||||
|
||||
// Comparison.
|
||||
bool operator==(const SparseBitVectorElement& RHS) const {
|
||||
@ -274,8 +264,10 @@ class SparseBitVector {
|
||||
// 'this' is always const in this particular function and we sort out the
|
||||
// difference in FindLowerBound and FindLowerBoundConst.
|
||||
ElementListIter Begin =
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
|
||||
const_cast<SparseBitVector<ElementSize>*>(this)->Elements.begin();
|
||||
ElementListIter End =
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
|
||||
const_cast<SparseBitVector<ElementSize>*>(this)->Elements.end();
|
||||
|
||||
if (Elements.empty()) {
|
||||
@ -313,7 +305,7 @@ class SparseBitVector {
|
||||
// than it would be, in order to be efficient.
|
||||
class SparseBitVectorIterator {
|
||||
private:
|
||||
bool AtEnd;
|
||||
bool AtEnd{false};
|
||||
|
||||
const SparseBitVector<ElementSize>* BitVector = nullptr;
|
||||
|
||||
@ -321,13 +313,13 @@ class SparseBitVector {
|
||||
ElementListConstIter Iter;
|
||||
|
||||
// Current bit number inside of our bitmap.
|
||||
unsigned BitNumber;
|
||||
unsigned BitNumber{0};
|
||||
|
||||
// Current word number inside of our element.
|
||||
unsigned WordNumber;
|
||||
unsigned WordNumber{0};
|
||||
|
||||
// Current bits from the element.
|
||||
typename SparseBitVectorElement<ElementSize>::BitWord Bits;
|
||||
typename SparseBitVectorElement<ElementSize>::BitWord Bits{0};
|
||||
|
||||
// Move our iterator to the first non-zero bit in the bitmap.
|
||||
void AdvanceToFirstNonZero() {
|
||||
@ -392,12 +384,10 @@ class SparseBitVector {
|
||||
SparseBitVectorIterator(
|
||||
const SparseBitVector<ElementSize>* RHS,
|
||||
bool end = false)
|
||||
: BitVector(RHS) {
|
||||
Iter = BitVector->Elements.begin();
|
||||
BitNumber = 0;
|
||||
Bits = 0;
|
||||
WordNumber = ~0;
|
||||
AtEnd = end;
|
||||
: AtEnd(end),
|
||||
BitVector(RHS),
|
||||
Iter(BitVector->Elements.begin()),
|
||||
WordNumber(~0) {
|
||||
AdvanceToFirstNonZero();
|
||||
}
|
||||
|
||||
@ -442,7 +432,7 @@ class SparseBitVector {
|
||||
|
||||
SparseBitVector(const SparseBitVector& RHS)
|
||||
: Elements(RHS.Elements), CurrElementIter(Elements.begin()) {}
|
||||
SparseBitVector(SparseBitVector&& RHS)
|
||||
SparseBitVector(SparseBitVector&& RHS) noexcept
|
||||
: Elements(std::move(RHS.Elements)), CurrElementIter(Elements.begin()) {}
|
||||
|
||||
// Clear.
|
||||
@ -459,7 +449,7 @@ class SparseBitVector {
|
||||
CurrElementIter = Elements.begin();
|
||||
return *this;
|
||||
}
|
||||
SparseBitVector& operator=(SparseBitVector&& RHS) {
|
||||
SparseBitVector& operator=(SparseBitVector&& RHS) noexcept {
|
||||
Elements = std::move(RHS.Elements);
|
||||
CurrElementIter = Elements.begin();
|
||||
return *this;
|
||||
@ -612,7 +602,7 @@ class SparseBitVector {
|
||||
if (Iter1->index() > Iter2->index()) {
|
||||
++Iter2;
|
||||
} else if (Iter1->index() == Iter2->index()) {
|
||||
bool BecameZero;
|
||||
bool BecameZero = false;
|
||||
changed |= Iter1->intersectWith(*Iter2, BecameZero);
|
||||
if (BecameZero) {
|
||||
ElementListIter IterTmp = Iter1;
|
||||
@ -666,7 +656,7 @@ class SparseBitVector {
|
||||
if (Iter1->index() > Iter2->index()) {
|
||||
++Iter2;
|
||||
} else if (Iter1->index() == Iter2->index()) {
|
||||
bool BecameZero;
|
||||
bool BecameZero = false;
|
||||
changed |= Iter1->intersectWithComplement(*Iter2, BecameZero);
|
||||
if (BecameZero) {
|
||||
ElementListIter IterTmp = Iter1;
|
||||
@ -900,5 +890,3 @@ std::ostream& operator<<(
|
||||
}
|
||||
|
||||
} // end namespace c10
|
||||
|
||||
C10_CLANG_DIAGNOSTIC_POP()
|
||||
|
@ -38,6 +38,7 @@ constexpr auto ssize(const C& c) -> std::
|
||||
}
|
||||
|
||||
template <typename T, std::ptrdiff_t N>
|
||||
// NOLINTNEXTLINE(*-c-arrays)
|
||||
constexpr auto ssize(const T (&array)[N]) noexcept -> std::ptrdiff_t {
|
||||
return N;
|
||||
}
|
||||
|
Reference in New Issue
Block a user