Skip to content

Enable bugprone, misc and readability checks of tidy #4479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 48 additions & 7 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,60 @@ Checks: '
clang-analyzer*,
clang-diagnostic-missing-prototypes,
cppcoreguidelines-init-variables,
bugprone-argument-comment,
misc-use-internal-linkage,
bugprone*,
-bugprone-crtp-constructor-accessibility,
-bugprone-easily-swappable-parameters,
-bugprone-exception-escape,
-bugprone-implicit*,
-bugprone-macro-parentheses,
-bugprone-narrowing-conversions,
-bugprone-reserved-identifier,
-bugprone-signed-char-misuse,
-bugprone-switch-missing-default-case,
misc-*,
-misc-confusable-identifiers,
-misc-const-correctness,
-misc-include-cleaner,
-misc-no-recursion,
-misc-non-private-member-variables-in-classes,
-misc-use-anonymous-namespace,
-misc-unused-parameters,
modernize*,
-modernize-use-auto,
-modernize-use-constraints,
-modernize-use-trailing-return-type,
-modernize-avoid-c-arrays,
-modernize-avoid-bind,
-modernize-return-braced-init-list,
-modernize-use-auto,
-modernize-use-constraints,
-modernize-use-designated-initializers,
-modernize-use-ranges,
-modernize-use-integer-sign-comparison
-modernize-use-integer-sign-comparison,
-modernize-use-nodiscard,
-modernize-use-ranges,
-modernize-use-trailing-return-type,
-modernize-use-transparent-functors,
performance*,
-performance-enum-size,
readability*,
-readability-avoid-nested-conditional-operator,
-readability-avoid-const-params-in-decls,
-readability-avoid-unconditional-preprocessor-if,
-readability-braces-around-statements,
-readability-container-contains,
-readability-convert-member-functions-to-static,
-readability-else-after-return,
-readability-function-cognitive-complexity,
-readability-identifier-length,
-readability-implicit-bool-conversion,
-readability-isolate-declaration,
-readability-make-member-function-const,
-readability-magic-numbers,
-readability-math-missing-parentheses,
-readability-non-const-parameter,
-readability-qualified-auto,
-readability-uppercase-literal-suffix,
-readability-redundant-access-specifiers,
-readability-redundant-control-flow,
-readability-simplify-boolean-expr,
-readability-suspicious-call-argument,
'
CheckOptions:
- key: facebook-cuda-safe-api-call-check.HandlerName
Expand Down
6 changes: 3 additions & 3 deletions bench/BenchUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ namespace fbgemm {
static std::default_random_engine eng;

template <typename T>
void randFill(aligned_vector<T>& vec, T low, T high, std::true_type) {
void randFill(aligned_vector<T>& vec, T low, T high, std::true_type /*unused*/) {
std::uniform_int_distribution<int> dis(low, high);
std::generate(vec.begin(), vec.end(), [&] { return dis(eng); });
}

template <typename T>
void randFill(aligned_vector<T>& vec, T low, T high, std::false_type) {
void randFill(aligned_vector<T>& vec, T low, T high, std::false_type /*unused*/) {
std::uniform_real_distribution<T> dis(low, high);
std::generate(vec.begin(), vec.end(), [&] { return dis(eng); });
}
Expand Down Expand Up @@ -124,7 +124,7 @@ bool parseArgumentBool(
}

#if defined(USE_MKL)
void test_xerbla(char* srname, const int* info, int) {
void test_xerbla(char* srname, const int* info, int /*unused*/) {
// srname - name of the function that called xerbla
// info - position of the invalid parameter in the parameter list
// len - length of the name in bytes
Expand Down
1 change: 1 addition & 0 deletions bench/BenchUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once
#include <chrono>
#include <functional>
#include <memory>
#include <vector>

#if defined(__x86_64__) || defined(__i386__) || \
Expand Down
4 changes: 2 additions & 2 deletions bench/EmbeddingSpMDMBenchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ int main() {
cout << "Mean ";
}
cout << input_dtype << " inputs";
bool use_fp16_inputs = input_dtype == "fp16" ? true : false;
bool use_bf16_inputs = input_dtype == "fp16" ? true : false;
bool use_fp16_inputs = input_dtype == "fp16";
bool use_bf16_inputs = input_dtype == "fp16";
cout << (use_32_bit_indices ? " 32" : " 64") << " bit indices";
if (prefetch) {
cout << " with prefetching";
Expand Down
4 changes: 2 additions & 2 deletions bench/GEMMsBenchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ performance_test(const int M, const int N, const int K, const bool timebreak) {
}
}
if (flush) {
((volatile char*)(llc.data()))[0] = llc.data()[0] + 1;
((volatile char*)(llc.data()))[0] = llc[0] + 1;
}
// printMatrix(matrix_op_t::NoTranspose, Bint8.data(), k, n, n, "B
// unpacked");
Expand Down Expand Up @@ -312,7 +312,7 @@ performance_test(const int M, const int N, const int K, const bool timebreak) {
}
}
if (flush) {
((volatile char*)(llc.data()))[0] = llc.data()[0] + 1;
((volatile char*)(llc.data()))[0] = llc[0] + 1;
}
// printMatrix(matrix_op_t::NoTranspose, Bint8.data(), k, n, n, "B
// unpacked");
Expand Down
2 changes: 1 addition & 1 deletion bench/GEMMsTunableBenchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static void performance_test(
}
}
if (flush) {
((volatile char*)(llc.data()))[0] = llc.data()[0] + 1;
((volatile char*)(llc.data()))[0] = llc[0] + 1;
}

#ifdef FBGEMM_MEASURE_TIME_BREAKDOWN
Expand Down
2 changes: 1 addition & 1 deletion bench/GroupwiseConvRequantizeBenchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ static void performance_test() {
}

if (flush) {
((volatile char*)(llc.data()))[0] = llc.data()[0] + 1;
((volatile char*)(llc.data()))[0] = llc[0] + 1;
}

// packedB.printPackedMatrix("bench B Packed");
Expand Down
2 changes: 1 addition & 1 deletion bench/Im2ColFusedRequantizeBenchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ static void performance_test() {
}

if (flush) {
((volatile char*)(llc.data()))[0] = llc.data()[0] + 1;
((volatile char*)(llc.data()))[0] = llc[0] + 1;
}

// packedB.printPackedMatrix("bench B Packed");
Expand Down
4 changes: 2 additions & 2 deletions bench/PackedFloatInOutBenchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ static void performance_test() {
ttot *= 1e9; // convert to ns

if (flush) {
((volatile char*)(llc.data()))[0] = llc.data()[0] + 1;
((volatile char*)(llc.data()))[0] = llc[0] + 1;
}

cout << setw(6) << m << ", " << setw(6) << n << ", " << setw(6) << k
Expand Down Expand Up @@ -269,7 +269,7 @@ static void performance_test() {
}
}
if (flush) {
((volatile char*)(llc.data()))[0] = llc.data()[0] + 1;
((volatile char*)(llc.data()))[0] = llc[0] + 1;
}
// printMatrix(matrix_op_t::NoTranspose, Bint8.data(), k, n, n, "B
// unpacked");
Expand Down
4 changes: 2 additions & 2 deletions bench/PackedRequantizeAcc16Benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static void performance_test() {
ttot *= 1e9; // convert to ns

if (flush) {
((volatile char*)(llc.data()))[0] = llc.data()[0] + 1;
((volatile char*)(llc.data()))[0] = llc[0] + 1;
}
cout << setw(16) << runType << ", " << fixed << setw(5) << setprecision(1)
<< nops / ttot << '\n';
Expand Down Expand Up @@ -414,7 +414,7 @@ static void performance_test() {
}

if (flush) {
((volatile char*)(llc.data()))[0] = llc.data()[0] + 1;
((volatile char*)(llc.data()))[0] = llc[0] + 1;
}
// printMatrix(matrix_op_t::NoTranspose, Bint8.data(), k, n, n, "B
// unpacked");
Expand Down
4 changes: 2 additions & 2 deletions bench/PackedRequantizeAcc32Benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ static void performance_test() {
ttot *= 1e9; // convert to ns

if (flush) {
((volatile char*)(llc.data()))[0] = llc.data()[0] + 1;
((volatile char*)(llc.data()))[0] = llc[0] + 1;
}

cout << setw(6) << m << ", " << setw(6) << n << ", " << setw(6) << k
Expand Down Expand Up @@ -300,7 +300,7 @@ static void performance_test() {
}
}
if (flush) {
((volatile char*)(llc.data()))[0] = llc.data()[0] + 1;
((volatile char*)(llc.data()))[0] = llc[0] + 1;
}
// printMatrix(matrix_op_t::NoTranspose, Bint8.data(), k, n, n, "B
// unpacked");
Expand Down
4 changes: 2 additions & 2 deletions bench/RowwiseAdagradBenchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,14 @@ static void run_benchmark(
for (size_t i = 0; i < w.size(); ++i) {
assert(fabs(w[i] - w_ref[i]) < 1e-5);
if (fabs(w[i] - w_ref[i]) >= 1e-5) {
fprintf(stderr, "%ld %f %f\n", i, w[i], w_ref[i]);
fprintf(stderr, "%zu %f %f\n", i, w[i], w_ref[i]);
}
}

for (size_t i = 0; i < h.size(); ++i) {
assert(fabs(h[i] - h_ref[i]) < 1e-5);
if (fabs(h[i] - h_ref[i]) >= 1e-5) {
fprintf(stderr, "%ld %f %f\n", i, h[i], h_ref[i]);
fprintf(stderr, "%zu %f %f\n", i, h[i], h_ref[i]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion bench/RowwiseAdagradFusedBenchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

#include <algorithm>
#include <cassert>
#include <chrono>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <map>
#include <random>
#include <set>
Expand Down
4 changes: 2 additions & 2 deletions bench/SparseAdagradBenchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,14 @@ static void run_benchmark(
for (size_t i = 0; i < w.size(); ++i) {
assert(fabs(w[i] - w_ref[i]) < 1e-5);
if (fabs(w[i] - w_ref[i]) >= 1e-5) {
fprintf(stderr, "%ld %f %f\n", i, w[i], w_ref[i]);
fprintf(stderr, "%zu %f %f\n", i, w[i], w_ref[i]);
}
}

for (size_t i = 0; i < h.size(); ++i) {
assert(fabs(h[i] - h_ref[i]) < 1e-5);
if (fabs(h[i] - h_ref[i]) >= 1e-5) {
fprintf(stderr, "%ld %f %f\n", i, h[i], h_ref[i]);
fprintf(stderr, "%zu %f %f\n", i, h[i], h_ref[i]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion bench/SparseDenseMMInt8Benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
using namespace std;
using namespace fbgemm;

int main(int, char**) {
int main(int /*unused*/, char** /*unused*/) {
vector<vector<int>> shapes = getSparseMatrixShapes();

// C is MxN -> CT is NxM
Expand Down
6 changes: 3 additions & 3 deletions include/fbgemm/ConvUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ struct conv_param_t {
std::string toString() const {
std::string dim_string[3] = {"T", "H", "W"};

std::string out = "";
std::string out;
out += "MB:" + std::to_string(MB) + ", ";
out += "IC:" + std::to_string(IC) + ", ";
out += "OC:" + std::to_string(OC) + ", ";
if (SPATIAL_DIM <= 3) {
if constexpr (SPATIAL_DIM <= 3) {
for (int d = 0; d < SPATIAL_DIM; ++d) {
out += "I" + dim_string[3 - SPATIAL_DIM + d] + ":" +
std::to_string(IN_DIM[d]) + ", ";
Expand All @@ -139,7 +139,7 @@ struct conv_param_t {
}
}
out += "G:" + std::to_string(G) + ", ";
if (SPATIAL_DIM <= 3) {
if constexpr (SPATIAL_DIM <= 3) {
for (int d = 0; d < SPATIAL_DIM; ++d) {
out += "K" + dim_string[3 - SPATIAL_DIM + d] + ":" +
std::to_string(K[d]) + ", ";
Expand Down
12 changes: 6 additions & 6 deletions include/fbgemm/Fbgemm.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class PackMatrix {
/**
* @brief Print the packed block.
*/
void printPackedMatrix(std::string name) {
void printPackedMatrix(const std::string& name) {
static_cast<PT*>(this)->printPackedMatrix(name);
}

Expand Down Expand Up @@ -482,7 +482,7 @@ class FBGEMM_API PackBMatrix final
*/
void unpack(T* origin_buf, const BlockingFactors* params = nullptr);

~PackBMatrix() {}
~PackBMatrix() override = default;

private:
matrix_op_t trans_;
Expand Down Expand Up @@ -752,7 +752,7 @@ class FBGEMM_API PackAWithIm2Col
*/
static int rowOffsetBufferSize(const BlockingFactors* params = nullptr);

~PackAWithIm2Col() {
~PackAWithIm2Col() override {
if (rowOffsetAllocatedHere) {
fbgemmAlignedFree(row_offset_);
}
Expand Down Expand Up @@ -842,7 +842,7 @@ class FBGEMM_API PackAWithRowOffset final
*/
static int rowOffsetBufferSize(const BlockingFactors* params = nullptr);

~PackAWithRowOffset() {
~PackAWithRowOffset() override {
if (rowOffsetAllocatedHere) {
fbgemmAlignedFree(row_offset_);
}
Expand Down Expand Up @@ -934,7 +934,7 @@ class FBGEMM_API PackAWithQuantRowOffset final
*/
static int rowOffsetBufferSize(const BlockingFactors* params = nullptr);

~PackAWithQuantRowOffset() {
~PackAWithQuantRowOffset() override {
if (rowOffsetAllocatedHere) {
fbgemmAlignedFree(row_offset_);
}
Expand Down Expand Up @@ -967,7 +967,7 @@ class FBGEMM_API DoNothing {
public:
using outType = outT;
using inpType = inT;
DoNothing() {}
DoNothing() = default;
template <inst_set_t instSet>
int f(
outType* /* unused */,
Expand Down
1 change: 0 additions & 1 deletion include/fbgemm/FbgemmConvert.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#pragma once

#include <stdexcept>
#include "fbgemm/Types.h"
#include "fbgemm/Utils.h"

Expand Down
4 changes: 0 additions & 4 deletions include/fbgemm/FbgemmFP16.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@

#include <cpuinfo.h>
#include <cassert>
#include <cstdlib>
#include <memory>
#include <stdexcept>
#include <vector>

#include "./FbgemmPackMatrixB.h" // @manual
#include "./FloatConversion.h" // @manual
Expand Down
Loading
Loading