"docs/gmock_cook_book.md" did not exist on "c4b68b91f87436b5fc57f7ce2aaebd5b40de9575"
README.md 5.65 KB
Newer Older
Pan Zezhong's avatar
Pan Zezhong committed
1
2
# InfiniCore

YdrMaster's avatar
YdrMaster committed
3
4
5
6
7
8
9
10
11
12
13
[![Doc](https://img.shields.io/badge/Document-ready-blue)](https://github.com/InfiniTensor/InfiniCore-Documentation)
[![CI](https://github.com/InfiniTensor/InfiniCore/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/InfiniTensor/InfiniCore/actions)
[![license](https://img.shields.io/github/license/InfiniTensor/InfiniCore)](https://mit-license.org/)
![GitHub repo size](https://img.shields.io/github/repo-size/InfiniTensor/InfiniCore)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/InfiniTensor/InfiniCore)

[![GitHub Issues](https://img.shields.io/github/issues/InfiniTensor/InfiniCore)](https://github.com/InfiniTensor/InfiniCore/issues)
[![GitHub Pull Requests](https://img.shields.io/github/issues-pr/InfiniTensor/InfiniCore)](https://github.com/InfiniTensor/InfiniCore/pulls)
![GitHub contributors](https://img.shields.io/github/contributors/InfiniTensor/InfiniCore)
![GitHub commit activity](https://img.shields.io/github/commit-activity/m/InfiniTensor/InfiniCore)

14
InfiniCore 是一个跨平台统一编程工具集,为不同芯片平台的功能(包括计算、运行时、通信等)提供统一 C 语言接口。目前支持的硬件和后端包括:
Pan Zezhong's avatar
Pan Zezhong committed
15

16
17
18
19
20
21
22
23
24
25
- CPU;
- CUDA
  - 英伟达 GPU;
  - 摩尔线程 GPU;
  - 天数智芯 GPU;
  - 沐曦 GPU;
  - 曙光 DCU;
- 华为昇腾 NPU;
- 寒武纪 MLU;
- 昆仑芯 XPU;
Pan Zezhong's avatar
Pan Zezhong committed
26

27
## 配置和使用
Pan Zezhong's avatar
Pan Zezhong committed
28

29
30
### 一键安装

31
`script/` 目录中提供了 `install.py` 安装脚本。使用方式如下:
32
33
34
35

```shell
cd InfiniCore

36
python scripts/install.py [XMAKE_CONFIG_FLAGS]
37
38
```

YdrMaster's avatar
YdrMaster committed
39
40
41
42
43
44
45
46
47
48
49
50
51
参数 `XMAKE_CONFIG_FLAGS` 是 xmake 构建配置,可配置下列可选项:

| 选项                     | 功能                          | 默认值
|--------------------------|-------------------------------|:-:
| `--omp=[y\|n]`           | 是否使用 OpenMP               | y
| `--cpu=[y\|n]`           | 是否编译 CPU 接口实现         | y
| `--nv-gpu=[y\|n]`        | 是否编译英伟达 GPU 接口实现   | n
| `--ascend-npu=[y\|n]`    | 是否编译昇腾 NPU 接口实现     | n
| `--cambricon-mlu=[y\|n]` | 是否编译寒武纪 MLU 接口实现   | n
| `--metax-gpu=[y\|n]`     | 是否编译沐曦 GPU 接口实现     | n
| `--moore-gpu=[y\|n]`     | 是否编译摩尔线程 GPU 接口实现 | n
| `--sugon-dcu=[y\|n]`     | 是否编译曙光 DCU 接口实现     | n
| `--kunlun-xpu=[y\|n]`    | 是否编译昆仑 XPU 接口实现     | n
52
| `--ccl=[y\|n]`           | 是否编译 InfiniCCL 通信库接口实现     | n
YdrMaster's avatar
YdrMaster committed
53

54
55
### 手动安装

56
1. 项目配置
Pan Zezhong's avatar
Pan Zezhong committed
57

58
   - 查看当前配置
Pan Zezhong's avatar
Pan Zezhong committed
59

60
61
62
     ```shell
     xmake f -v
     ```
Pan Zezhong's avatar
Pan Zezhong committed
63

64
   - 配置 CPU(默认配置)
Pan Zezhong's avatar
Pan Zezhong committed
65

66
67
68
     ```shell
     xmake f -cv
     ```
Pan Zezhong's avatar
Pan Zezhong committed
69

70
   - 配置加速卡
Pan Zezhong's avatar
Pan Zezhong committed
71

72
73
74
75
     ```shell
     # 英伟达
     # 可以指定 CUDA 路径, 一般环境变量为 `CUDA_HOME` 或者 `CUDA_ROOT`
     xmake f --nv-gpu=true --cuda=$CUDA_HOME -cv
Pan Zezhong's avatar
Pan Zezhong committed
76

77
78
     # 寒武纪
     xmake f --cambricon-mlu=true -cv
Pan Zezhong's avatar
Pan Zezhong committed
79

80
81
82
     # 华为昇腾
     xmake f --ascend-npu=true -cv
     ```
Pan Zezhong's avatar
Pan Zezhong committed
83

84
85
86
87
88
89
90
91
92
93
94
95
2. 编译安装

   默认安装路径为 `$HOME/.infini`

   ```shell
   xmake build && xmake install
   ```

3. 设置环境变量

   按输出提示设置 `INFINI_ROOT``LD_LIBRARY_PATH` 环境变量。

96
97
98
### 运行测试

#### 运行Python算子测试
Pan Zezhong's avatar
Pan Zezhong committed
99

100
101
102
103
104
105
106
107
108
```shell
python test/infiniop/[operator].py [--cpu | --nvidia | --cambricon | --ascend]
```

#### 一键运行所有Python算子测试

```shell
python scripts/python_test.py [--cpu | --nvidia | --cambricon | --ascend]
```
Pan Zezhong's avatar
Pan Zezhong committed
109

110
111
112
113
#### 算子测试框架

详见 `test/infiniop-test` 目录

114
115
116
117
118
119
120
121
122
123
124
125
#### 通信库(InfiniCCL)测试

编译(需要先安装InfiniCCL):
```shell
xmake build infiniccl-test
```

在英伟达平台运行测试(会自动使用所有可见的卡):
```shell
infiniccl-test --nvidia
```

126
## 开发指南
Pan Zezhong's avatar
Pan Zezhong committed
127

128
### 代码格式化
Pan Zezhong's avatar
Pan Zezhong committed
129

130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
本项目使用 [`scripts/format.py`](/scripts/format.py) 脚本实现代码格式化检查和操作。

使用

```shell
python scripts/format.py -h
```

查看脚本帮助信息:

```plaintext
usage: format.py [-h] [--ref REF] [--path [PATH ...]] [--check] [--c C] [--py PY]

options:
  -h, --help         show this help message and exit
  --ref REF          Git reference (commit hash) to compare against.
  --path [PATH ...]  Files to format or check.
  --check            Check files without modifying them.
  --c C              C formatter (default: clang-format-16)
  --py PY            Python formatter (default: black)
Pan Zezhong's avatar
Pan Zezhong committed
150
```
151
152
153
154
155
156
157
158
159
160
161

参数中:

- `ref``path` 控制格式化的文件范围
  -`ref``path` 都为空,格式化当前暂存(git added)的文件;
  - 否则
    -`ref` 非空,将比较指定 commit 和当前代码的差异,只格式化修改过的文件;
    -`path` 非空,可传入多个路径(`--path p0 p1 p2`),只格式化指定路径及其子目录中的文件;
- 若设置 `--check`,将检查代码是否需要修改格式,不修改文件内容;
- 通过 `--c` 指定 c/c++ 格式化器,默认为 `clang-format-16`
- 通过 `--python` 指定 python 格式化器 `black`
YdrMaster's avatar
YdrMaster committed
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177

### vscode 开发配置

基本配置见 [xmake 官方文档](https://xmake.io/#/zh-cn/plugin/more_plugins?id=%e9%85%8d%e7%bd%ae-intellsence)

- TL;DR
  - clangd

    打开 *xmake.lua*,保存一次以触发编译命令生成,将在工作路径下自动生成 *.vscode/compile_commands.json* 文件。然后在这个文件夹下创建 *settings.json*,填入:

    > .vscode/settings.json

    ```json
    {
        "clangd.arguments": [
            "--compile-commands-dir=.vscode"
178
179
180
181
182
        ],
        "xmake.additionalConfigArguments": [
            // 在这里配置 XMAKE_CONFIG_FLAGS
            "--nv-gpu=y"
        ],
YdrMaster's avatar
YdrMaster committed
183
184
    }
    ```