Skip to content

Commit 64375f8

Browse files
cyyeverfacebook-github-bot
authored andcommitted
Use static functions/variables if possible (pytorch#4432)
Summary: Pull Request resolved: pytorch#4432 X-link: facebookresearch/FBGEMM#1497 There are two changes: 1. Marks in-file templates and other inner functions as static; this provides more opportunities to optimise code, i.e. followed by enabling link time optimization. An unused function in test code is removed. 2. Enables `misc-use-internal-linkage` check. Pull Request resolved: pytorch#4423 Reviewed By: cthi Differential Revision: D77635949 Pulled By: q10 fbshipit-source-id: 3ce5cfd435be216ccc48c5be9eb30e91dcfcfbb5
1 parent 0dbd1bc commit 64375f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+99
-149
lines changed

.clang-tidy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
# Get options for config files in parent directories,
55
# but override them if there's a conflict.
66
InheritParentConfig: true
7+
# @nolint
78
Checks: '
89
bugprone-argument-comment,
10+
misc-use-internal-linkage,
911
'
1012
CheckOptions:
1113
- key: facebook-cuda-safe-api-call-check.HandlerName

bench/BenchUtils.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
namespace fbgemm {
2121

22-
std::default_random_engine eng;
22+
static std::default_random_engine eng;
2323

2424
template <typename T>
2525
void randFill(aligned_vector<T>& vec, T low, T high, std::true_type) {

bench/ConvUnifiedBenchmark.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ using namespace fbgemm;
2828

2929
// clang-format off
3030
// 1D conv shapes
31-
vector<conv_param_t<1>> shapes_1d = {
31+
static vector<conv_param_t<1>> shapes_1d = {
3232
// MB, IC, OC, IW, G, KW, stride_w, pad_w_left, pad_w_right,
3333
// (dilation, output_padding_w, tranpose)
3434
// regular
@@ -46,7 +46,7 @@ vector<conv_param_t<1>> shapes_1d = {
4646
};
4747

4848
// 2D conv shapes
49-
vector<conv_param_t<2>> shapes_2d = {
49+
static vector<conv_param_t<2>> shapes_2d = {
5050
// MB, IC, OC, IH, IW, G, KH, KW, stride_h, stride_w,
5151
// pad_h_top, pad_w_left, pad_h_bottom, pad_w_right,
5252
// (dilation_h, dilation_w, output_padding_h, output_padding_w, tranpose)
@@ -84,7 +84,7 @@ vector<conv_param_t<2>> shapes_2d = {
8484
{1, 1}, {0, 0, 0, 0})
8585
};
8686

87-
vector<conv_param_t<2>> shapes_2d_resnext_101 = {
87+
static vector<conv_param_t<2>> shapes_2d_resnext_101 = {
8888
// ResNext-101 (unique shapes only)
8989
// conv_param_t<>(N, C, M, H, W, groups, /* kern */ {KH, KW}, /* stride */
9090
// {stride_h, stride_w}, /* padding pad_l = pad_h */ {pad_l, pad_l, pad_l, pad_l}, /* dialation */
@@ -143,7 +143,7 @@ vector<conv_param_t<2>> shapes_2d_resnext_101 = {
143143
};
144144

145145
// 3D conv shapes
146-
vector<conv_param_t<3>> shapes_3d = {
146+
static vector<conv_param_t<3>> shapes_3d = {
147147
// MB, IC, OC, {IT, IH, IW}, G, {KT, KH, KW}, {stride_t, stride_h,
148148
// stride_w},
149149
// {pad_prev, pad_h_top, pad_w_left, pad_next, pad_h_bottom, pad_w_right},
@@ -216,7 +216,7 @@ vector<conv_param_t<3>> shapes_3d = {
216216
// clang-format on
217217

218218
template <int SPATIAL_DIM, typename Acc_t>
219-
void performance_test(
219+
static void performance_test(
220220
const vector<conv_param_t<SPATIAL_DIM>>& shapes,
221221
bool flush,
222222
int repetitions) {

bench/ConvertBenchmark.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
using namespace std;
2222
using namespace fbgemm;
2323

24-
void performance_test() {
24+
static void performance_test() {
2525
constexpr int NWARMUP = 4;
2626
constexpr int NITER = 256;
2727

bench/EmbeddingIndexRemappingBenchmark.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static vector<vector<int>> GetInputs_() {
3737
return input_dims;
3838
}
3939

40-
int run_benchmark(
40+
static int run_benchmark(
4141
int batch_size,
4242
int num_rows,
4343
int average_len,

bench/EmbeddingQuantizeBenchmark.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using namespace fbgemm;
2525

2626
// T is the type of scale and bias
2727
template <typename T>
28-
void performance_test() {
28+
static void performance_test() {
2929
constexpr int NWARMUP = 4;
3030
constexpr int NITER = 256;
3131

bench/EmbeddingQuantizeFloatToFloatOrHalfBenchmark.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using namespace fbgemm;
2525

2626
// T is the type of scale and bias
2727
template <typename T>
28-
void performance_test() {
28+
static void performance_test() {
2929
constexpr int NWARMUP = 4;
3030
constexpr int NITER = 256;
3131

bench/EmbeddingSpMDM8BitBenchmark.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@
3030
using namespace std;
3131
using namespace fbgemm;
3232

33-
void print_fused_table(int rows, int embedding_dim, const uint8_t* table) {
34-
for (int i = 0; i < rows; i++) {
35-
cout << "row: " << i << " : " << endl;
36-
for (int ii = 0; ii < embedding_dim; ii++) {
37-
cout << (int)table[i * (embedding_dim + 2 * sizeof(float)) + ii] << ",";
33+
/*
34+
static void print_fused_table(int rows, int embedding_dim, const uint8_t* table)
35+
{ for (int i = 0; i < rows; i++) { cout << "row: " << i << " : " << endl; for
36+
(int ii = 0; ii < embedding_dim; ii++) { cout << (int)table[i * (embedding_dim +
37+
2 * sizeof(float)) + ii] << ",";
3838
}
3939
cout << endl;
4040
}
4141
}
42+
*/
4243

4344
static vector<vector<int>> GetInputs_() {
4445
vector<vector<int>> input_dims = {
@@ -58,10 +59,10 @@ static vector<vector<int>> GetInputs_() {
5859
return input_dims;
5960
}
6061

61-
vector<double> benchmarkTimes;
62+
static vector<double> benchmarkTimes;
6263

6364
template <typename OutType>
64-
int run_benchmark(
65+
static int run_benchmark(
6566
int batch_size,
6667
int num_rows,
6768
int embedding_dim,

bench/EmbeddingSpMDMBenchmark.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static vector<vector<int>> GetInputs_() {
4949
return input_dims;
5050
}
5151

52-
void run_benchmark(
52+
static void run_benchmark(
5353
int batch_size,
5454
int num_rows,
5555
int embedding_dim,

bench/EmbeddingSpMDMNBit2Benchmark.cc

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,6 @@ static void print_benchmark_results() {
171171
}
172172
}
173173

174-
void print_fused_table(int rows, int embedding_dim, const uint8_t* table) {
175-
for (int i = 0; i < rows; i++) {
176-
std::cout << "row: " << i << " : " << std::endl;
177-
for (int ii = 0; ii < embedding_dim; ii++) {
178-
std::cout << (int)table[i * (embedding_dim + 2 * sizeof(float)) + ii]
179-
<< ",";
180-
}
181-
std::cout << std::endl;
182-
}
183-
}
184-
185174
static vector<vector<int>> GetInputs_() {
186175
vector<vector<int>> input_dims = {
187176
// batch size, number of rows of table, emb dim , avg lengthl
@@ -200,7 +189,7 @@ static vector<vector<int>> GetInputs_() {
200189
return input_dims;
201190
}
202191

203-
int run_benchmark(
192+
static int run_benchmark(
204193
int bit_rate,
205194
int batch_size,
206195
int num_rows,
@@ -488,7 +477,7 @@ int run_benchmark(
488477
return 0;
489478
}
490479

491-
void sweep_benchmark(KernelType kern_type) {
480+
static void sweep_benchmark(KernelType kern_type) {
492481
int batch_size;
493482
int num_rows;
494483
int embedding_dim;

0 commit comments

Comments
 (0)