Skip to content

Commit b2808c9

Browse files
cyyeverfacebook-github-bot
authored andcommitted
Modernize C++ code by clang-tidy (pytorch#4415)
Summary: Pull Request resolved: pytorch#4415 X-link: facebookresearch/FBGEMM#1486 Apply several modernize checks. Pull Request resolved: pytorch#4413 Reviewed By: cthi, spcyppt Differential Revision: D77493248 Pulled By: q10 fbshipit-source-id: fd3c05913d1db5919ab37e2dc9141c72f11240c8
1 parent 49422df commit b2808c9

28 files changed

+137
-226
lines changed

src/EmbeddingSpMDM.cc

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ template <
9191
bool THREAD_LOCAL = false>
9292
class GenEmbeddingSpMDMLookup {
9393
public:
94-
GenEmbeddingSpMDMLookup() {}
94+
GenEmbeddingSpMDMLookup() = default;
9595
typename ReturnFunctionSignature<
9696
inType,
9797
indxType,
@@ -235,15 +235,15 @@ GenEmbeddingSpMDMLookup<
235235
offsetType,
236236
outType,
237237
ROWWISE_SPARSE>::jit_embedding_kernel {
238-
bool is_8bit_in = std::is_same<inType, uint8_t>::value;
239-
bool is_16bit_in = std::is_same<inType, uint16_t>::value;
240-
bool is_16bit_out = std::is_same<outType, uint16_t>::value;
238+
bool is_8bit_in = std::is_same_v<inType, uint8_t>;
239+
bool is_16bit_in = std::is_same_v<inType, uint16_t>;
240+
bool is_16bit_out = std::is_same_v<outType, uint16_t>;
241241
bool is_fp16_in = is_16bit_in && !is_bf16_in;
242242
bool is_fp16_out = is_16bit_out && !is_bf16_out;
243243

244244
// TODO: Make this tunable
245245
int pref_dist = prefetch;
246-
bool areIndices64b = std::is_same<indxType, int64_t>::value;
246+
bool areIndices64b = std::is_same_v<indxType, int64_t>;
247247

248248
asmjit::CodeHolder code;
249249
code.init(runtime().environment());
@@ -410,7 +410,7 @@ GenEmbeddingSpMDMLookup<
410410
constexpr int NUM_VEC_REG = simd_info<instSet>::NUM_VEC_REGS;
411411
int unroll_factor = NUM_VEC_REG;
412412

413-
typedef typename simd_info<instSet>::vec_reg_t vec_reg_t;
413+
using vec_reg_t = typename simd_info<instSet>::vec_reg_t;
414414

415415
int num_vec_regs_per_block = (block_size + vlen - 1) / vlen;
416416
int remainder = block_size % vlen;
@@ -862,7 +862,7 @@ GenEmbeddingSpMDMLookup<
862862
a->vmulps(out_vreg, out_vreg, vlen_inv_vreg);
863863
}
864864

865-
if (std::is_same<outType, float>::value) {
865+
if (std::is_same_v<outType, float>) {
866866
if (remainder && vec_idx + v == num_vec_regs_per_block - 1) {
867867
if (instSet == inst_set_t::avx2) {
868868
a->vmaskmovps(dst_addr, mask_vreg, out_vreg.ymm());
@@ -1042,7 +1042,7 @@ typename EmbeddingSpMDMKernelSignature<inType, indxType, offsetType, outType>::
10421042
output_stride = block_size;
10431043
}
10441044
if (input_stride == -1) {
1045-
if (std::is_same<inType, uint8_t>::value) {
1045+
if (std::is_same_v<inType, uint8_t>) {
10461046
const auto scale_bias_offset =
10471047
2 * (scale_bias_last ? sizeof(float) : sizeof(uint16_t));
10481048
input_stride = block_size + scale_bias_offset;
@@ -1057,10 +1057,9 @@ typename EmbeddingSpMDMKernelSignature<inType, indxType, offsetType, outType>::
10571057
throw std::runtime_error("Failed to initialize cpuinfo!");
10581058
}
10591059
const inst_set_t isa = fbgemmInstructionSet();
1060-
if ((std::is_same<inType, float>::value ||
1061-
std::is_same<inType, uint16_t>::value) &&
1060+
if ((std::is_same_v<inType, float> || std::is_same_v<inType, uint16_t>) &&
10621061
block_size == 1 && isYmm(isa) && output_stride == block_size &&
1063-
input_stride == block_size && std::is_same<outType, float>::value &&
1062+
input_stride == block_size && std::is_same_v<outType, float> &&
10641063
!is_asmjit_disabled()) {
10651064
return [=](int64_t output_size,
10661065
int64_t index_size,
@@ -1352,7 +1351,7 @@ GenerateEmbeddingSpMDMRowWiseSparse(
13521351
bool use_offsets) {
13531352
#if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
13541353
int64_t input_stride = block_size;
1355-
if (std::is_same<inType, uint8_t>::value) {
1354+
if (std::is_same_v<inType, uint8_t>) {
13561355
const auto scale_bias_offset = 2 * sizeof(float);
13571356
input_stride = block_size + scale_bias_offset;
13581357
}

src/EmbeddingSpMDMAutovec.cc

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ static inline void fill_output(
5454
const float* src,
5555
const int64_t block_size,
5656
const bool is_bf16_out) {
57-
if (std::is_same<OutType, float>::value) {
57+
if (std::is_same_v<OutType, float>) {
5858
for (int j = 0; j < block_size; ++j) {
5959
out[j] = src[j];
6060
}
61-
} else if (std::is_same<OutType, uint16_t>::value && is_bf16_out) {
61+
} else if (std::is_same_v<OutType, uint16_t> && is_bf16_out) {
6262
for (int j = 0; j < block_size; ++j) {
6363
out[j] = cpu_float2bfloat16(src[j]);
6464
}
@@ -72,9 +72,9 @@ static inline void fill_output(
7272
template <typename OutType>
7373
static inline EmbeddingStatsTracker::DataType get_output_type(
7474
const bool is_bf16_out) {
75-
if (std::is_same<OutType, float>::value) {
75+
if (std::is_same_v<OutType, float>) {
7676
return EmbeddingStatsTracker::DataType::FP32;
77-
} else if (std::is_same<OutType, uint16_t>::value && is_bf16_out) {
77+
} else if (std::is_same_v<OutType, uint16_t> && is_bf16_out) {
7878
return EmbeddingStatsTracker::DataType::BF16;
7979
} else {
8080
return EmbeddingStatsTracker::DataType::FP16;
@@ -100,7 +100,7 @@ static bool ALWAYS_INLINE EmbeddingSpMDM8Bit_autovec(
100100
const bool scale_bias_last,
101101
const bool no_bag,
102102
const bool is_bf16_out) {
103-
constexpr bool isOutput8bit = std::is_same<OutType, uint8_t>::value;
103+
constexpr bool isOutput8bit = std::is_same_v<OutType, uint8_t>;
104104
if (data_size < 0) {
105105
return false;
106106
}
@@ -736,7 +736,7 @@ static bool ALWAYS_INLINE EmbeddingSpMDMRowWiseSparse_autovec(
736736
float* out,
737737
const bool is_weight_positional,
738738
const bool use_offsets) {
739-
bool is8bit = std::is_same<InType, uint8_t>::value;
739+
bool is8bit = std::is_same_v<InType, uint8_t>;
740740

741741
if (is8bit) {
742742
// block_size is the number of elements and fused_block_size is the size
@@ -860,17 +860,15 @@ static bool ALWAYS_INLINE EmbeddingSpMDMRowWiseSparse_autovec(
860860
const InType* inptr = input_row++;
861861
out[j] = std::fma(
862862
weight,
863-
std::is_same<InType, float16>::value ? cpu_half2float(*inptr)
864-
: *inptr,
863+
std::is_same_v<InType, float16> ? cpu_half2float(*inptr) : *inptr,
865864
out[j]);
866865
}
867866
#endif
868867
for (; j < block_size; ++j) {
869868
const InType* inptr = input_row++;
870869
out[j] = std::fma(
871870
weight,
872-
std::is_same<InType, float16>::value ? cpu_half2float(*inptr)
873-
: *inptr,
871+
std::is_same_v<InType, float16> ? cpu_half2float(*inptr) : *inptr,
874872
out[j]);
875873
}
876874
}
@@ -1141,7 +1139,7 @@ template <typename InType>
11411139
static int64_t stride_SpMDMWithStrides(
11421140
int64_t block_size,
11431141
bool scale_bias_last) {
1144-
if (std::is_same<InType, uint8_t>::value) {
1142+
if (std::is_same_v<InType, uint8_t>) {
11451143
const size_t scale_bias_offset =
11461144
2 * (scale_bias_last ? sizeof(float) : sizeof(uint16_t));
11471145
return block_size + scale_bias_offset;

src/EmbeddingSpMDMAvx2.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
#include "RefImplementations.h"
1212
#include "fbgemm/FbgemmEmbedding.h"
1313

14-
namespace fbgemm {
15-
namespace internal {
14+
namespace fbgemm::internal {
1615

1716
template <typename InType, typename IndexType, typename OffsetType>
1817
bool EmbeddingSpMDMBlockSize1_(
@@ -158,5 +157,4 @@ INSTANTIATE_SPMDM_INDEX_T(std::uint8_t)
158157
#undef INSTANTIATE_SPMDM_OFFSET_T
159158
#undef INSTANTIATE_SPMDM_BASE
160159

161-
} // namespace internal
162-
} // namespace fbgemm
160+
} // namespace fbgemm::internal

0 commit comments

Comments
 (0)