Skip to content

Commit 3c31dc6

Browse files
Merge pull request #45 from YdrMaster/main
issue/52 代码格式化:机制和效果
2 parents 16dad77 + e5ed9fa commit 3c31dc6

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

+1155
-713
lines changed

.clang-format

Lines changed: 17 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,30 @@
1-
# Generated from CLion C/C++ Code Style settings
1+
---
22
BasedOnStyle: LLVM
3-
AccessModifierOffset: -4
4-
AlignAfterOpenBracket: Align
5-
# AlignConsecutiveAssignments: None
6-
AlignOperands: Align
7-
AllowAllArgumentsOnNextLine: false
8-
AllowAllConstructorInitializersOnNextLine: false
9-
AllowAllParametersOfDeclarationOnNextLine: false
10-
AllowShortBlocksOnASingleLine: Always
11-
AllowShortCaseLabelsOnASingleLine: false
12-
AllowShortFunctionsOnASingleLine: All
13-
AllowShortIfStatementsOnASingleLine: Always
14-
AllowShortLambdasOnASingleLine: All
15-
AllowShortLoopsOnASingleLine: true
16-
AlwaysBreakAfterReturnType: None
17-
AlwaysBreakTemplateDeclarations: No
18-
BreakBeforeBraces: Custom
3+
IndentWidth: 4 # 缩进宽度,LLVM 默认值为 2,改为 4
4+
AccessModifierOffset: -4 # public/protected/private 访问控制符相对成员的偏移,与 IndentWidth 配合,LLVM 默认值为 -2
5+
AlignOperands: AlignAfterOperator # 双目运算符的行间对齐,LLVM 默认值为 Align,改为带符号一起换行
6+
BreakBeforeBinaryOperators: All # 在双目运算符之前换行,LLVM 默认值为 None,改为换行时总是把双目运算符放在行首,包括赋值(=)
7+
ColumnLimit: 0 # 列宽限制,LLVM 默认值为 80,改为不限制
8+
AllowShortBlocksOnASingleLine: Always # 是否允许短块(单个语句的块)不换行,LLVM 默认值为 Never,改为允许
9+
AllowShortLoopsOnASingleLine: true # 是否允许短循环不换行,LLVM 默认值为 false,改为允许
10+
InsertBraces: true # 是否在 if/for/while/switch 等语句后插入大括号,LLVM 默认值为 false,改为允许
11+
BreakBeforeBraces: Custom # 大括号换行配置,LLVM 默认值为 LLVM,改为自定义以使 BraceWrapping 生效
1912
BraceWrapping:
2013
AfterCaseLabel: false
2114
AfterClass: false
2215
AfterControlStatement: Never
2316
AfterEnum: false
2417
AfterFunction: false
2518
AfterNamespace: false
19+
AfterObjCDeclaration: false
20+
AfterStruct: false
2621
AfterUnion: false
22+
AfterExternBlock: false
2723
BeforeCatch: false
2824
BeforeElse: false
25+
BeforeLambdaBody: false
26+
BeforeWhile: false
2927
IndentBraces: false
30-
SplitEmptyFunction: false
28+
SplitEmptyFunction: true
3129
SplitEmptyRecord: true
32-
BreakBeforeBinaryOperators: None
33-
BreakBeforeTernaryOperators: true
34-
BreakConstructorInitializers: BeforeColon
35-
BreakInheritanceList: BeforeColon
36-
ColumnLimit: 0
37-
CompactNamespaces: true
38-
ContinuationIndentWidth: 4
39-
IndentCaseLabels: true
40-
IndentPPDirectives: None
41-
IndentWidth: 4
42-
KeepEmptyLinesAtTheStartOfBlocks: true
43-
MaxEmptyLinesToKeep: 2
44-
NamespaceIndentation: All
45-
ObjCSpaceAfterProperty: false
46-
ObjCSpaceBeforeProtocolList: true
47-
PointerAlignment: Right
48-
ReflowComments: false
49-
SpaceAfterCStyleCast: true
50-
SpaceAfterLogicalNot: false
51-
SpaceAfterTemplateKeyword: false
52-
SpaceBeforeAssignmentOperators: true
53-
SpaceBeforeCpp11BracedList: false
54-
SpaceBeforeCtorInitializerColon: true
55-
SpaceBeforeInheritanceColon: true
56-
SpaceBeforeParens: ControlStatements
57-
SpaceBeforeRangeBasedForLoopColon: true
58-
SpaceInEmptyParentheses: false
59-
SpacesBeforeTrailingComments: 0
60-
SpacesInAngles: false
61-
SpacesInCStyleCastParentheses: false
62-
SpacesInContainerLiterals: false
63-
SpacesInParentheses: false
64-
SpacesInSquareBrackets: false
65-
TabWidth: 4
66-
UseTab: Never
30+
SplitEmptyNamespace: true

.github/workflows/build.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Build and test
2+
on:
3+
pull_request:
4+
push:
5+
paths-ignore:
6+
- '**.md'
7+
- 'LICENSE'
8+
9+
jobs:
10+
build:
11+
name: Build
12+
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
type: [debug, release]
17+
steps:
18+
19+
- name: checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: install black
23+
run: pip install black
24+
25+
- name: check format
26+
run: python3 scripts/format.py --path src --check
27+
28+
- name: install xmake
29+
uses: xmake-io/github-action-setup-xmake@v1
30+
with:
31+
xmake-version: latest
32+
33+
- name: configure xmake
34+
run: xmake f -cv
35+
36+
- name: build with xmake
37+
run: xmake build && xmake install

README.md

Lines changed: 80 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,99 @@
11
# InfiniCore
22

3-
InfiniCore是一个跨平台统一编程工具集,为不同芯片平台的功能(包括计算、运行时、通信等)提供统一 C 语言接口。目前支持的芯片包括CPU、英伟达GPU、华为昇腾NPU、寒武纪MLU、摩尔线程GPU、天数智芯GPU、沐曦GPU、曙光DCU、昆仑芯。
3+
InfiniCore 是一个跨平台统一编程工具集,为不同芯片平台的功能(包括计算、运行时、通信等)提供统一 C 语言接口。目前支持的硬件和后端包括:
44

5-
## 一、使用说明
5+
- CPU;
6+
- CUDA
7+
- 英伟达 GPU;
8+
- 摩尔线程 GPU;
9+
- 天数智芯 GPU;
10+
- 沐曦 GPU;
11+
- 曙光 DCU;
12+
- 华为昇腾 NPU;
13+
- 寒武纪 MLU;
14+
- 昆仑芯 XPU;
615

7-
### 1. 配置
16+
## 配置和使用
817

9-
#### 查看当前配置
18+
1. 项目配置
1019

11-
```xmake
12-
xmake f -v
13-
```
20+
- 查看当前配置
1421

15-
#### 配置 CPU (默认配置)
22+
```shell
23+
xmake f -v
24+
```
1625

17-
```xmake
18-
xmake f -cv
19-
```
26+
- 配置 CPU(默认配置)
2027

21-
#### 配置加速卡
28+
```shell
29+
xmake f -cv
30+
```
2231

23-
```xmake
24-
# 英伟达
25-
# 可以指定 CUDA 路径, 一般环境变量为 `CUDA_HOME` 或者 `CUDA_ROOT`
26-
xmake f --nv-gpu=true --cuda=$CUDA_HOME -cv
32+
- 配置加速卡
2733

28-
# 寒武纪
29-
xmake f --cambricon-mlu=true -cv
34+
```shell
35+
# 英伟达
36+
# 可以指定 CUDA 路径, 一般环境变量为 `CUDA_HOME` 或者 `CUDA_ROOT`
37+
xmake f --nv-gpu=true --cuda=$CUDA_HOME -cv
3038
31-
# 华为昇腾
32-
xmake f --ascend-npu=true -cv
33-
```
39+
# 寒武纪
40+
xmake f --cambricon-mlu=true -cv
3441
35-
### 2. 编译安装
42+
# 华为昇腾
43+
xmake f --ascend-npu=true -cv
44+
```
3645

37-
```xmake
38-
xmake build && xmake install
39-
# 默认安装路径为 $HOME/.infini
40-
```
46+
2. 编译安装
47+
48+
默认安装路径为 `$HOME/.infini`
49+
50+
```shell
51+
xmake build && xmake install
52+
```
53+
54+
3. 设置环境变量
55+
56+
按输出提示设置 `INFINI_ROOT``LD_LIBRARY_PATH` 环境变量。
57+
58+
4. 运行算子测试
4159

42-
### 3. 设置环境变量
60+
```shell
61+
python test/infiniop/[operator].py [--cpu | --nvidia | --cambricon | --ascend]
62+
```
4363

44-
按输出提示设置 `INFINI_ROOT``LD_LIBRARY_PATH` 环境变量。
64+
## 开发指南
4565

46-
### 4. 运行算子测试
66+
### 代码格式化
4767

48-
```bash
49-
python test/infiniop/[operator].py [--cpu | --nvidia | --cambricon | --ascend]
68+
本项目使用 [`scripts/format.py`](/scripts/format.py) 脚本实现代码格式化检查和操作。
69+
70+
使用
71+
72+
```shell
73+
python scripts/format.py -h
74+
```
75+
76+
查看脚本帮助信息:
77+
78+
```plaintext
79+
usage: format.py [-h] [--ref REF] [--path [PATH ...]] [--check] [--c C] [--py PY]
80+
81+
options:
82+
-h, --help show this help message and exit
83+
--ref REF Git reference (commit hash) to compare against.
84+
--path [PATH ...] Files to format or check.
85+
--check Check files without modifying them.
86+
--c C C formatter (default: clang-format-16)
87+
--py PY Python formatter (default: black)
5088
```
89+
90+
参数中:
91+
92+
- `ref``path` 控制格式化的文件范围
93+
- 若 `ref``path` 都为空,格式化当前暂存(git added)的文件;
94+
- 否则
95+
- 若 `ref` 非空,将比较指定 commit 和当前代码的差异,只格式化修改过的文件;
96+
- 若 `path` 非空,可传入多个路径(`--path p0 p1 p2`),只格式化指定路径及其子目录中的文件;
97+
- 若设置 `--check`,将检查代码是否需要修改格式,不修改文件内容;
98+
- 通过 `--c` 指定 c/c++ 格式化器,默认为 `clang-format-16`
99+
- 通过 `--python` 指定 python 格式化器 `black`

include/infinicore.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
#define __INFINICORE_EXPORT_C__
77
#if defined(_WIN32)
88
#define __export __declspec(dllexport)
9-
#elif defined(__GNUC__) && \
10-
((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))
9+
#elif defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))
1110
#define __export __attribute__((visibility("default")))
1211
#else
1312
#define __export

include/infiniop/ops/causal_softmax.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ __C __export infiniopStatus_t infiniopCausalSoftmax(infiniopCausalSoftmaxDescrip
1919

2020
__C __export infiniopStatus_t infiniopDestroyCausalSoftmaxDescriptor(infiniopCausalSoftmaxDescriptor_t desc);
2121

22-
2322
#endif

include/infiniop/ops/conv.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ __C __export infiniopStatus_t infiniopConv(infiniopConvDescriptor_t desc, void *
2121

2222
__C __export infiniopStatus_t infiniopDestroyConvDescriptor(infiniopConvDescriptor_t desc);
2323

24-
2524
#endif

include/infiniop/ops/random_sample.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ __C __export infiniopStatus_t infiniopRandomSample(infiniopRandomSampleDescripto
2222

2323
__C __export infiniopStatus_t infiniopDestroyRandomSampleDescriptor(infiniopRandomSampleDescriptor_t desc);
2424

25-
2625
#endif

include/infiniop/tensor_descriptor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ __C __export infiniopStatus_t infiniopCreateTensorDescriptor(infiniopTensorDescr
2121

2222
__C __export infiniopStatus_t infiniopDestroyTensorDescriptor(infiniopTensorDescriptor_t desc);
2323

24-
#endif// __INFINIOP_TENSOR_DESCRIPTOR__
24+
#endif // __INFINIOP_TENSOR_DESCRIPTOR__

0 commit comments

Comments
 (0)