Skip to content

Commit 6f80c0d

Browse files
committed
style: 格式化所有文件
Signed-off-by: YdrMaster <[email protected]>
1 parent 87936b1 commit 6f80c0d

File tree

509 files changed

+18077
-17727
lines changed

Some content is hidden

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

509 files changed

+18077
-17727
lines changed

.github/workflows/build.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
name: Build and test cpu
22
on:
3+
pull_request:
34
push:
45
paths-ignore:
56
- '**.md'
67
- 'LICENSE'
7-
pull_request:
8-
paths:
9-
- '**.md'
10-
- 'LICENSE'
118

129
jobs:
1310
build:
@@ -23,6 +20,9 @@ jobs:
2320
with:
2421
submodules: recursive
2522

23+
- name: check format
24+
run: python3 format.py --path src --check
25+
2626
- name: build ${{ matrix.type }}
2727
run: make TYPE=${{ matrix.type }}
2828

src/00common/include/common.h

+21-19
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,29 @@
1313
#include <sstream>
1414

1515
namespace refactor {
16-
/// @brief 用于表示维度/形状的差的数值,主要是一些属性。
17-
using ddim_t = int16_t;
18-
/// @brief 用于表示形状的数值。
19-
using dim_t = uint32_t;
20-
/// @brief 用于表示带符号的形状的数值。
21-
using sdim_t = int32_t;
22-
/// @brief 用于表示对象的数量。
23-
using count_t = uint32_t;
16+
/// @brief 用于表示维度/形状的差的数值,主要是一些属性。
17+
using ddim_t = int16_t;
18+
/// @brief 用于表示形状的数值。
19+
using dim_t = uint32_t;
20+
/// @brief 用于表示带符号的形状的数值。
21+
using sdim_t = int32_t;
22+
/// @brief 用于表示对象的数量。
23+
using count_t = uint32_t;
2424

25-
template<class T> using Arc = std::shared_ptr<T>;
25+
template <class T>
26+
using Arc = std::shared_ptr<T>;
2627

27-
template<class Container> std::string vec2str(Container const &vec) {
28-
std::stringstream ss;
29-
ss << "[ ";
30-
for (auto d : vec) {
31-
ss << d << ' ';
32-
}
33-
ss << ']';
34-
return ss.str();
28+
template <class Container>
29+
std::string vec2str(Container const &vec) {
30+
std::stringstream ss;
31+
ss << "[ ";
32+
for (auto d : vec) {
33+
ss << d << ' ';
3534
}
35+
ss << ']';
36+
return ss.str();
37+
}
3638

37-
}// namespace refactor
39+
} // namespace refactor
3840

39-
#endif// COMMON_TYPES
41+
#endif // COMMON_TYPES

src/00common/include/common/bf16_t.h

+57-54
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,62 @@
77

88
namespace refactor {
99

10-
class bf16_t final {
11-
uint16_t code;
12-
13-
union converter {
14-
float f32;
15-
uint16_t u16[2];
16-
};
17-
18-
constexpr static uint16_t MASK_SIGN16 = 0b1'00000'00000'00000;
19-
20-
public:
21-
constexpr bf16_t(uint16_t code) noexcept : code(code) {}
22-
constexpr bf16_t(float value) noexcept : bf16_t(converter{value}.u16[1]) {}
23-
constexpr bf16_t() noexcept : bf16_t(0.f) {}
24-
constexpr bf16_t(bf16_t const &) noexcept = default;
25-
constexpr bf16_t(bf16_t &&) noexcept = default;
26-
27-
constexpr uint16_t as_code() const noexcept {
28-
return code;
29-
}
30-
31-
constexpr float to_f32() const noexcept {
32-
converter c{};
33-
c.u16[1] = code;
34-
c.u16[0] = 0;
35-
return c.f32;
36-
}
37-
38-
constexpr bool is_inf() const noexcept {
39-
return std::isinf(to_f32());
40-
}
41-
42-
constexpr bool is_nan() const noexcept {
43-
return std::isnan(to_f32());
44-
}
45-
46-
constexpr bf16_t operator-() const noexcept {
47-
return static_cast<decltype(code)>(code ^ (code | MASK_SIGN16));
48-
}
49-
50-
constexpr bool operator==(bf16_t const &others) const noexcept {
51-
return code == others.code && !is_nan();
52-
}
53-
54-
constexpr bool operator!=(bf16_t const &others) const noexcept {
55-
return !operator==(others);
56-
}
57-
58-
std::string to_string() const noexcept {
59-
return std::to_string(to_f32());
60-
}
61-
};
10+
class bf16_t final {
11+
uint16_t code;
6212

63-
}// namespace refactor
13+
union converter {
14+
float f32;
15+
uint16_t u16[2];
16+
};
6417

65-
#endif// BF16_H
18+
constexpr static uint16_t MASK_SIGN16 = 0b1'00000'00000'00000;
19+
20+
public:
21+
constexpr bf16_t(uint16_t code) noexcept
22+
: code(code) {}
23+
constexpr bf16_t(float value) noexcept
24+
: bf16_t(converter{value}.u16[1]) {}
25+
constexpr bf16_t() noexcept
26+
: bf16_t(0.f) {}
27+
constexpr bf16_t(bf16_t const &) noexcept = default;
28+
constexpr bf16_t(bf16_t &&) noexcept = default;
29+
30+
constexpr uint16_t as_code() const noexcept {
31+
return code;
32+
}
33+
34+
constexpr float to_f32() const noexcept {
35+
converter c{};
36+
c.u16[1] = code;
37+
c.u16[0] = 0;
38+
return c.f32;
39+
}
40+
41+
constexpr bool is_inf() const noexcept {
42+
return std::isinf(to_f32());
43+
}
44+
45+
constexpr bool is_nan() const noexcept {
46+
return std::isnan(to_f32());
47+
}
48+
49+
constexpr bf16_t operator-() const noexcept {
50+
return static_cast<decltype(code)>(code ^ (code | MASK_SIGN16));
51+
}
52+
53+
constexpr bool operator==(bf16_t const &others) const noexcept {
54+
return code == others.code && !is_nan();
55+
}
56+
57+
constexpr bool operator!=(bf16_t const &others) const noexcept {
58+
return !operator==(others);
59+
}
60+
61+
std::string to_string() const noexcept {
62+
return std::to_string(to_f32());
63+
}
64+
};
65+
66+
} // namespace refactor
67+
68+
#endif // BF16_H

src/00common/include/common/data_type.h

+56-53
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
namespace refactor {
1010

11-
using fp32_t = float;
12-
using fp64_t = double;
11+
using fp32_t = float;
12+
using fp64_t = double;
1313

14-
struct DataType {
15-
/// @brief 数据类型。
16-
/// @see <https://onnx.ai/onnx/api/mapping.html#l-onnx-types-mapping>
17-
enum : uint8_t {
18-
// clang-format off
14+
struct DataType {
15+
/// @brief 数据类型。
16+
/// @see <https://onnx.ai/onnx/api/mapping.html#l-onnx-types-mapping>
17+
enum : uint8_t {
18+
// clang-format off
1919
F32 = 1,
2020
U8 = 2,
2121
I8 = 3,
@@ -32,57 +32,60 @@ namespace refactor {
3232
Complex64 = 14,
3333
Complex128 = 15,
3434
BF16 = 16,
35-
// clang-format on
36-
} internal;
35+
// clang-format on
36+
} internal;
3737

38-
constexpr DataType(decltype(internal) i) noexcept : internal(i) {}
39-
constexpr operator decltype(internal)() const noexcept { return internal; }
38+
constexpr DataType(decltype(internal) i) noexcept
39+
: internal(i) {}
40+
constexpr operator decltype(internal)() const noexcept { return internal; }
4041

41-
static std::optional<DataType> parse(uint8_t) noexcept;
42+
static std::optional<DataType> parse(uint8_t) noexcept;
4243

43-
std::string_view name() const noexcept;
44-
bool isIeee754() const noexcept;
45-
bool isFloat() const noexcept;
46-
bool isSignedLarge() const noexcept;
47-
bool isSigned() const noexcept;
48-
bool isUnsigned() const noexcept;
49-
bool isNumberic() const noexcept;
50-
bool isCpuNumberic() const noexcept;
51-
bool isBool() const noexcept;
52-
size_t size() const noexcept;
53-
};
44+
std::string_view name() const noexcept;
45+
bool isIeee754() const noexcept;
46+
bool isFloat() const noexcept;
47+
bool isSignedLarge() const noexcept;
48+
bool isSigned() const noexcept;
49+
bool isUnsigned() const noexcept;
50+
bool isNumberic() const noexcept;
51+
bool isCpuNumberic() const noexcept;
52+
bool isBool() const noexcept;
53+
size_t size() const noexcept;
54+
};
5455

55-
constexpr bool operator==(DataType const &lhs, DataType const &rhs) noexcept {
56-
return lhs.internal == rhs.internal;
57-
}
58-
constexpr bool operator!=(DataType const &lhs, DataType const &rhs) noexcept {
59-
return !operator==(lhs, rhs);
60-
}
61-
constexpr bool operator==(DataType const &lhs, decltype(DataType::internal) const &rhs) noexcept {
62-
return lhs.internal == rhs;
63-
}
64-
constexpr bool operator!=(DataType const &lhs, decltype(DataType::internal) const &rhs) noexcept {
65-
return !operator==(lhs, rhs);
66-
}
67-
constexpr bool operator==(decltype(DataType::internal) const &lhs, DataType const &rhs) noexcept {
68-
return lhs == rhs.internal;
69-
}
70-
constexpr bool operator!=(decltype(DataType::internal) const &lhs, DataType const &rhs) noexcept {
71-
return !operator==(lhs, rhs);
72-
}
56+
constexpr bool operator==(DataType const &lhs, DataType const &rhs) noexcept {
57+
return lhs.internal == rhs.internal;
58+
}
59+
constexpr bool operator!=(DataType const &lhs, DataType const &rhs) noexcept {
60+
return !operator==(lhs, rhs);
61+
}
62+
constexpr bool operator==(DataType const &lhs, decltype(DataType::internal) const &rhs) noexcept {
63+
return lhs.internal == rhs;
64+
}
65+
constexpr bool operator!=(DataType const &lhs, decltype(DataType::internal) const &rhs) noexcept {
66+
return !operator==(lhs, rhs);
67+
}
68+
constexpr bool operator==(decltype(DataType::internal) const &lhs, DataType const &rhs) noexcept {
69+
return lhs == rhs.internal;
70+
}
71+
constexpr bool operator!=(decltype(DataType::internal) const &lhs, DataType const &rhs) noexcept {
72+
return !operator==(lhs, rhs);
73+
}
7374

74-
template<class T>
75-
DataType dataType();
75+
template <class T>
76+
DataType dataType();
7677

77-
template<decltype(DataType::internal) t>
78-
struct primitive;
78+
template <decltype(DataType::internal) t>
79+
struct primitive;
7980

80-
#define PRIMITIVE(T, U) \
81-
template<> inline DataType dataType<U>() { return DataType::T; } \
82-
template<> struct primitive<DataType::T> { \
83-
using type = U; \
81+
#define PRIMITIVE(T, U) \
82+
template <> \
83+
inline DataType dataType<U>() { return DataType::T; } \
84+
template <> \
85+
struct primitive<DataType::T> { \
86+
using type = U; \
8487
}
85-
// clang-format off
88+
// clang-format off
8689
PRIMITIVE(F32 , fp32_t );
8790
PRIMITIVE(U8 , uint8_t );
8891
PRIMITIVE(I8 , int8_t );
@@ -99,7 +102,7 @@ namespace refactor {
99102
PRIMITIVE(Complex64 , std::complex<fp32_t>);
100103
PRIMITIVE(Complex128 , std::complex<fp64_t>);
101104
PRIMITIVE(BF16 , bf16_t );
102-
// clang-format on
103-
}// namespace refactor
105+
// clang-format on
106+
} // namespace refactor
104107

105-
#endif// REFACTOR_DATA_TYPE
108+
#endif // REFACTOR_DATA_TYPE

src/00common/include/common/error_handler.h

+14-13
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
#include <stdexcept>
66

77
namespace refactor {
8-
struct UnimplementError : public std::logic_error {
9-
explicit UnimplementError(std::string msg)
10-
: std::logic_error(std::move(msg)) {}
11-
};
8+
struct UnimplementError : public std::logic_error {
9+
explicit UnimplementError(std::string msg)
10+
: std::logic_error(std::move(msg)) {}
11+
};
1212

13-
struct UnreachableError : public std::logic_error {
14-
explicit UnreachableError(std::string msg)
15-
: std::logic_error(std::move(msg)) {}
16-
};
17-
}// namespace refactor
13+
struct UnreachableError : public std::logic_error {
14+
explicit UnreachableError(std::string msg)
15+
: std::logic_error(std::move(msg)) {}
16+
};
17+
} // namespace refactor
1818

1919
#define ERROR_MSG(MSG) fmt::format("{} Source {}:{}", (MSG), __FILE__, __LINE__)
2020
#define RUNTIME_ERROR(MSG) throw std::runtime_error(ERROR_MSG(MSG))
@@ -30,12 +30,13 @@ namespace refactor {
3030
std::abort()
3131

3232
#ifndef DISABLE_ASSERT
33-
#define ASSERT(CONDITION, F, ...) \
34-
{ \
35-
if (!(CONDITION)) RUNTIME_ERROR(fmt::format("Assertion: " F, ##__VA_ARGS__)); \
33+
#define ASSERT(CONDITION, F, ...) \
34+
{ \
35+
if (!(CONDITION)) \
36+
RUNTIME_ERROR(fmt::format("Assertion: " F, ##__VA_ARGS__)); \
3637
}
3738
#else
3839
#define ASSERT(CONDITION, F)
3940
#endif
4041

41-
#endif// ERROR_HANDLER_H
42+
#endif // ERROR_HANDLER_H

0 commit comments

Comments
 (0)