Skip to content

Commit e0062b0

Browse files
authored
SparseLib Code format (#199)
* SparseLib code reformat * workaround for benchmark code format
1 parent f9a2f6a commit e0062b0

39 files changed

+209
-145
lines changed

nlp_toolkit/backends/neural_engine/SparseLib/include/amx_utils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
#ifndef ENGINE_SPARSELIB_INCLUDE_AMX_UTILS_HPP_
1616
#define ENGINE_SPARSELIB_INCLUDE_AMX_UTILS_HPP_
17+
#include <omp.h>
1718
#include <immintrin.h>
1819
#include <mutex> // NOLINT
1920
#include <cstdint>
20-
#include <omp.h>
2121
#include <vector>
2222

2323
#include "jit_domain/jit_amx_configure.hpp"

nlp_toolkit/backends/neural_engine/SparseLib/include/benchmark_utils.hpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@
2121

2222
#include "interface.hpp"
2323

24-
namespace jd{
24+
namespace jd {
2525

2626
/*
2727
* @brief Run benchmark of kernel. Currently this mainly contains 3 parts:
2828
* 1. Run kernel for multiple iterations to get its execution time.
2929
* 2. Parse primitive and use execution time to calculate GFLOPS.
3030
* 3. Refresh some parts of runtime data for kernel before each execution.
31-
*
31+
*
3232
* To enable benchmark for a new kernel xxxx, you just need 2 steps:
3333
* 1. Implement calc_flop_xxxx and get_refresh_data_idx_xxxx for it.
34-
* 2. Simply add a case for it in calc_flop and get_refresh_data_idx in benchmark_utils.cpp
34+
* 2. Simply add a case for it in calc_flop and get_refresh_data_idx in benchmark_utils.cpp
3535
*/
3636
void benchmarkOrExecute(kernel_proxy* kp, const std::vector<const void*>& rt_data);
3737

@@ -53,17 +53,19 @@ std::vector<int> get_refresh_data_idx(const kernel_kind ker_kind);
5353
/*
5454
* @brief Allocate new memory for some parts of runtime data for kernel.
5555
*/
56-
bool alloc_new_mem(const std::vector<tensor_desc>& ts_descs, std::vector<const void*>& rt_data, std::vector<void*>& new_data, const std::vector<int>& idx);
56+
bool alloc_new_mem(const std::vector<tensor_desc>& ts_descs, std::vector<const void*>& rt_data, // NOLINT
57+
std::vector<void*>& new_data, const std::vector<int>& idx); // NOLINT
5758

5859
/*
5960
* @brief Free new memory for some parts of runtime data for kernel.
6061
*/
61-
void free_new_mem(std::vector<void*>& new_data);
62+
void free_new_mem(std::vector<void*>& new_data); // NOLINT
6263

6364
/*
6465
* @brief Refresh some parts of runtime data for kernel.
6566
*/
66-
void refresh_data(const std::vector<tensor_desc>& ts_descs, std::vector<void*>& new_data, const std::vector<int>& idx, const std::vector<float>& ranges = {-10.0, 10.0});
67+
void refresh_data(const std::vector<tensor_desc>& ts_descs, std::vector<void*>& new_data, // NOLINT
68+
const std::vector<int>& idx, const std::vector<float>& ranges = {-10.0, 10.0});
6769

6870
// Since different kernels use different info to calculate FLOP,
6971
// please implement calc_flop_xxxx for each kernel.
@@ -79,7 +81,6 @@ std::vector<int> get_refresh_data_idx_sparse_matmul();
7981

8082
std::vector<int> get_refresh_data_idx_postop();
8183

82-
} // namespace jd
84+
} // namespace jd
8385

8486
#endif // ENGINE_SPARSELIB_INCLUDE_BENCHMARK_UTILS_HPP_
85-

nlp_toolkit/backends/neural_engine/SparseLib/include/interface.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,23 +103,23 @@ class sparse_matmul_desc : public kernel_desc_proxy {
103103

104104
class postop_desc : public kernel_desc_proxy {
105105
public:
106-
postop_desc(){};
106+
postop_desc() {}
107107
explicit postop_desc(const operator_desc& op_desc) : kernel_desc_proxy(op_desc) {}
108108
virtual ~postop_desc() {}
109109
};
110110

111111
class eltwiseop_desc : public kernel_desc_proxy {
112112
public:
113-
eltwiseop_desc(){};
113+
eltwiseop_desc() {}
114114
explicit eltwiseop_desc(const operator_desc& op_desc) : kernel_desc_proxy(op_desc) {}
115115
virtual ~eltwiseop_desc() {}
116116
};
117117

118118
class layernorm_ba_desc : public kernel_desc_proxy {
119119
public:
120-
layernorm_ba_desc(){};
120+
layernorm_ba_desc() {}
121121
explicit layernorm_ba_desc(const operator_desc& op_desc) : kernel_desc_proxy(op_desc) {}
122-
virtual ~layernorm_ba_desc(){};
122+
virtual ~layernorm_ba_desc() {}
123123
};
124124

125125
/**

nlp_toolkit/backends/neural_engine/SparseLib/include/jit_domain/jit_eltwise_injector.hpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
#ifndef ENGINE_SPARSELIB_INCLUDE_JIT_DOMAIN_JIT_ELTWISE_INJECTOR_HPP_
1616
#define ENGINE_SPARSELIB_INCLUDE_JIT_DOMAIN_JIT_ELTWISE_INJECTOR_HPP_
1717

18+
#include <vector>
19+
#include <unordered_map>
20+
#include <map>
21+
#include <set>
1822
#include "jit_generator.hpp"
1923
#include "utils.hpp"
2024
#include "param_types.hpp"
21-
#include <map>
22-
#include <set>
2325

2426
namespace jd {
2527
class jit_eltwise_injector {
@@ -28,7 +30,7 @@ class jit_eltwise_injector {
2830
using Xmm = Xbyak::Xmm;
2931

3032
public:
31-
explicit jit_eltwise_injector(){};
33+
jit_eltwise_injector() {}
3234
virtual ~jit_eltwise_injector() {}
3335

3436
void eltwise_injector_init(jit_generator* ptr, const std::vector<postop_attr>& postop_attrs);
@@ -37,9 +39,9 @@ class jit_eltwise_injector {
3739
void escape_regs(reg_type type, int reg_idx);
3840
void escape_erase(reg_type type, int reg_idx = -1);
3941
void init_tb_allocate_set(const std::vector<postop_attr>& postop_attrs);
40-
int max_zmm_allocate_num() { return zmm_tb_allocate.size(); };
41-
int max_mask_allocate_num() { return mask_tb_allocate.size(); };
42-
int max_reg64_allocate_num() { return reg64_tb_allocate.size(); };
42+
int max_zmm_allocate_num() { return zmm_tb_allocate.size(); }
43+
int max_mask_allocate_num() { return mask_tb_allocate.size(); }
44+
int max_reg64_allocate_num() { return reg64_tb_allocate.size(); }
4345
void prepare_table();
4446

4547
private:
@@ -53,7 +55,7 @@ class jit_eltwise_injector {
5355
void linear_compute_vector_fwd(const Xbyak::Zmm& zmm_src);
5456
void register_table_entries(const std::vector<postop_attr>& postop_attrs);
5557
void assert_check(const std::vector<postop_attr>& postop_attrs);
56-
void load_table_addr() { h->mov(p_table, l_table); };
58+
void load_table_addr() { h->mov(p_table, l_table); }
5759

5860
private:
5961
postop_attr cur_postop_attr_;
@@ -147,4 +149,4 @@ class jit_eltwise_injector {
147149
mapped_table_t entry_map;
148150
};
149151
} // namespace jd
150-
#endif
152+
#endif

nlp_toolkit/backends/neural_engine/SparseLib/include/jit_domain/jit_eltwiseop.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
#ifndef ENGINE_SPARSELIB_INCLUDE_JIT_DOMAIN_JIT_ELTWISEOP_HPP_
1616
#define ENGINE_SPARSELIB_INCLUDE_JIT_DOMAIN_JIT_ELTWISEOP_HPP_
1717

18-
#include "../jit_generator.hpp"
18+
#include <map>
19+
#include "jit_generator.hpp"
1920
#include "utils.hpp"
2021
#include "kernels/eltwiseop_types.hpp"
21-
#include "jit_eltwise_injector.hpp"
22-
#include <map>
22+
#include "jit_domain/jit_eltwise_injector.hpp"
2323

2424
#define ELT_GET_OFF(field) offsetof(ssd::eltwiseop_data_t, field)
2525

@@ -77,7 +77,7 @@ class jit_eltwiseop_t : public jit_generator {
7777
case data_type::bf16:
7878
return 2u;
7979
}
80-
};
80+
}
8181

8282
size_t load_offset() {
8383
auto head_dt = param_.postop_attrs.front().dt;
@@ -120,4 +120,4 @@ class jit_eltwiseop_t : public jit_generator {
120120
}
121121
};
122122
} // namespace jd
123-
#endif
123+
#endif

nlp_toolkit/backends/neural_engine/SparseLib/include/jit_domain/jit_layernorm_ba.hpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@
1515
#ifndef ENGINE_SPARSELIB_INCLUDE_JIT_DOMAIN_JIT_LAYERNORM_BA_HPP_
1616
#define ENGINE_SPARSELIB_INCLUDE_JIT_DOMAIN_JIT_LAYERNORM_BA_HPP_
1717

18-
#include "../jit_generator.hpp"
18+
#include <utility>
19+
#include <vector>
20+
#include <map>
21+
#include <set>
22+
#include "jit_generator.hpp"
1923
#include "utils.hpp"
2024
#include "kernels/layernorm_ba_types.hpp"
21-
#include "jit_eltwise_injector.hpp"
25+
#include "jit_domain/jit_eltwise_injector.hpp"
2226

2327
#define LNBA_GET_OFF(field) offsetof(ssd::layernorm_ba_data_t, field)
2428

@@ -64,7 +68,7 @@ class jit_layernorm_ba_t : public jit_generator {
6468
mov(one_div_n, ptr[reg_param + LNBA_GET_OFF(one_div_n)]);
6569
mov(one, ptr[reg_param + LNBA_GET_OFF(one)]);
6670
mov(eps, ptr[reg_param + LNBA_GET_OFF(eps)]);
67-
};
71+
}
6872

6973
private:
7074
ssd::layernorm_ba_param_t param_;
@@ -85,4 +89,4 @@ class jit_layernorm_ba_t : public jit_generator {
8589
Opmask remain_task_mask;
8690
}; // namespace jd
8791
} // namespace jd
88-
#endif
92+
#endif

nlp_toolkit/backends/neural_engine/SparseLib/include/jit_domain/jit_postop_default.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
#ifndef ENGINE_SPARSELIB_INCLUDE_JIT_DOMAIN_JIT_POSTOP_DEFAULT_HPP_
1616
#define ENGINE_SPARSELIB_INCLUDE_JIT_DOMAIN_JIT_POSTOP_DEFAULT_HPP_
1717

18+
#include <map>
1819
#include "jit_generator.hpp"
1920
#include "utils.hpp"
2021
#include "kernels/postop_types.hpp"
21-
#include <map>
2222

2323
#define GET_OFF(field) offsetof(ssd::postop_data_t, field)
2424

@@ -48,7 +48,7 @@ class jit_postop_default_t : public jit_generator {
4848
bool is_bf16() {
4949
if (param_.dt == ssd::data_type::bf16) return true;
5050
return false;
51-
};
51+
}
5252

5353
size_t vlen() {
5454
switch (param_.dt) {
@@ -58,7 +58,7 @@ class jit_postop_default_t : public jit_generator {
5858
return 32u;
5959
}
6060
return 0;
61-
};
61+
}
6262

6363
size_t dtype_size() {
6464
switch (param_.dt) {
@@ -68,7 +68,7 @@ class jit_postop_default_t : public jit_generator {
6868
return 2u;
6969
}
7070
return 0;
71-
};
71+
}
7272

7373
private:
7474
ssd::postop_param_t param_;
@@ -161,7 +161,7 @@ class jit_postop_default_t : public jit_generator {
161161
};
162162
using table_t = std::multimap<key_t, table_entry_t>;
163163
using mapped_table_t = std::multimap<key_t, mapped_table_entry_t>;
164-
void load_table_addr() { mov(p_table, l_table); };
164+
void load_table_addr() { mov(p_table, l_table); }
165165
void register_table_entries();
166166
void prepare_table();
167167
void prepare_bf16_mask();
@@ -175,4 +175,4 @@ class jit_postop_default_t : public jit_generator {
175175
mapped_table_t entry_map;
176176
};
177177
} // namespace jd
178-
#endif
178+
#endif

nlp_toolkit/backends/neural_engine/SparseLib/include/jit_domain/jit_spmm_amx_bf16_x16.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ class jit_spmm_amx_bf16_x16_t : public jit_generator {
9999
dim_t tileM;
100100
bool bf16_out;
101101
dim_t size_of_dst_t;
102-
dim_t size_of_src_t = sizeof(src_t); // size of bfloat16
103-
dim_t size_of_out_t = sizeof(dst_t); // size of float since bf16 x bd16 = fp32
102+
dim_t size_of_src_t = sizeof(src_t); // size of bfloat16
103+
dim_t size_of_out_t = sizeof(dst_t); // size of float since bf16 x bd16 = fp32
104104

105105
static constexpr int stack_space_needed_ = 5120;
106106

nlp_toolkit/backends/neural_engine/SparseLib/include/jit_domain/jit_spmm_avx512f.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class jit_spmm_avx512f_t : public jit_generator {
6868
// Register allocator of load activation. TW = 1
6969
Xbyak::Zmm TW_Vmm = Xbyak::Zmm(VREG_NUMS - 1 - USED_VREGS - TH_);
7070
// Reg alloc of DST tile.
71-
Xbyak::Zmm dst_tile_Vmm(int i = 0) { return Xbyak::Zmm(i); };
71+
Xbyak::Zmm dst_tile_Vmm(int i = 0) { return Xbyak::Zmm(i); }
7272

7373
static constexpr int stack_space_needed_ = 256;
7474
static constexpr int BYTE8 = 8;

nlp_toolkit/backends/neural_engine/SparseLib/include/jit_domain/jit_spmm_vnni.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace jd {
3232
*/
3333
class jit_spmm_vnni_t : public jit_generator {
3434
public:
35-
explicit jit_spmm_vnni_t(const ssd::vnni_param_t& param) : jit_generator(), param_(param){};
35+
explicit jit_spmm_vnni_t(const ssd::vnni_param_t& param) : jit_generator(), param_(param) {}
3636
virtual ~jit_spmm_vnni_t() {}
3737

3838
public:
@@ -80,7 +80,7 @@ class jit_spmm_vnni_t : public jit_generator {
8080
inline int mt_size() const { return TH(); }
8181
inline int n_tiles() const { return param_.BN / nt_size(); }
8282
inline int m_tiles() const { return param_.BM / mt_size(); }
83-
inline data_type output_type() const { return param_.output_type; };
83+
inline data_type output_type() const { return param_.output_type; }
8484
inline int ld_dst() const { return param_.BN; } // leading dimension of dst matrix
8585

8686
private:

0 commit comments

Comments
 (0)