README.md 7.16 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
- CPU;
- CUDA
  - 英伟达 GPU;
  - 摩尔线程 GPU;
  - 天数智芯 GPU;
  - 沐曦 GPU;
22
  - 海光 DCU;
23
24
25
- 华为昇腾 NPU;
- 寒武纪 MLU;
- 昆仑芯 XPU;
Pan Zezhong's avatar
Pan Zezhong committed
26

PanZezhong's avatar
PanZezhong committed
27
28
API 定义以及使用方式详见 [`InfiniCore文档`](https://github.com/InfiniTensor/InfiniCore-Documentation)

29
30
31
32
33
34
35
36
## 项目依赖

- [Xmake](https://xmake.io/):跨平台自动构建工具,用于编译 InfiniCore 项目。
- [gcc-11](https://gcc.gnu.org/) 以上或者 [clang-16](https://clang.llvm.org/):基础编译器,需要支持 C++ 17 标准。
- [Python>=3.10](https://www.python.org/)
  - [PyTorch](https://pytorch.org/):可选,用于对比测试。
- 各个硬件平台的工具包:请参考各厂商官方文档(如英伟达平台需要安装 CUDA Toolkit)。

37
## 配置和使用
Pan Zezhong's avatar
Pan Zezhong committed
38

39
### 一、克隆项目
40
41
42
43
44
45
46
47
48
49
50
51
52

由于仓库中含有子模块,所以在克隆时请添加 `--recursive``--recurse-submodules`,如:

```shell
git clone --recursive https://github.com/InfiniTensor/InfiniCore.git
```

或者在普通克隆后进行更新:

```shell
git submodule update --init --recursive
```

53
54
55
56
57
58
59
配置`INFINI_ROOT``LD_LIBRARY_PATH` 环境变量。  
默认`INFINI_ROOT``$HOME/.infini`,可以使用以下命令自动配置:

```shell
source scripts/set_env_linux.sh
```

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
如果你需要在本地开发九齿算子(即需要对九齿算子库进行修改),推荐单独克隆[九齿算子库](https://github.com/InfiniTensor/ntops),并从本地安装:

```shell
git clone https://github.com/InfiniTensor/ntops.git
cd ntops
pip install -e .
```

### 二、编译安装

InfiniCore 项目主要包括:

1. 底层 C 库(InfiniOP/InfiniRT/InfiniCCL):[`一键安装`](#一键安装底层库)|[`手动安装`](#手动安装底层库)
2. InfiniCore C++ 库:[`安装指令`](#2-安装-c-库)
3. InfiniCore Python 包(依赖[九齿算子库](https://github.com/InfiniTensor/ntops)):[`安装指令`](#3-安装-python-包)

三者需要按照顺序进行编译安装。

#### 1. 安装底层库

##### 一键安装底层库
81

82
`script/` 目录中提供了 `install.py` 安装脚本。使用方式如下:
83
84
85
86

```shell
cd InfiniCore

87
python scripts/install.py [XMAKE_CONFIG_FLAGS]
88
89
```

YdrMaster's avatar
YdrMaster committed
90
91
参数 `XMAKE_CONFIG_FLAGS` 是 xmake 构建配置,可配置下列可选项:

92
93
94
95
96
97
98
99
| 选项                     | 功能                              | 默认值
|--------------------------|-----------------------------------|:-:
| `--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
100
| `--use-mc=[y\|n]`        | 是否沐曦 GPU 接口实现使用maca SDK | n
101
102
| `--moore-gpu=[y\|n]`     | 是否编译摩尔线程 GPU 接口实现     | n
| `--iluvatar-gpu=[y\|n]`  | 是否编译沐曦 GPU 接口实现         | n
103
| `--hygon-dcu=[y\|n]`     | 是否编译海光 DCU 接口实现         | n
104
| `--kunlun-xpu=[y\|n]`    | 是否编译昆仑 XPU 接口实现         | n
105
| `--ninetoothed=[y\|n]`   | 是否编译九齿实现                 | n
106
| `--ccl=[y\|n]`           | 是否编译 InfiniCCL 通信库接口实现 | n
YdrMaster's avatar
YdrMaster committed
107

108
##### 手动安装底层库
109

110
111
0. 生成九齿算子(可选)

112
113
114
115
116
117
118
   - 克隆并安装[九齿算子库](https://github.com/InfiniTensor/ntops)

   -`InfiniCore` 文件夹下运行以下命令 AOT 编译库中的九齿算子:

     ```shell
     PYTHONPATH=${PYTHONPATH}:src python scripts/build_ntops.py
     ```
119

120
1. 项目配置
Pan Zezhong's avatar
Pan Zezhong committed
121

122
   windows系统上,建议使用`xmake v2.8.9`编译项目。
123
   - 查看当前配置
Pan Zezhong's avatar
Pan Zezhong committed
124

125
126
127
     ```shell
     xmake f -v
     ```
Pan Zezhong's avatar
Pan Zezhong committed
128

129
   - 配置 CPU(默认配置)
Pan Zezhong's avatar
Pan Zezhong committed
130

131
132
133
     ```shell
     xmake f -cv
     ```
Pan Zezhong's avatar
Pan Zezhong committed
134

135
   - 配置加速卡
Pan Zezhong's avatar
Pan Zezhong committed
136

137
138
139
     ```shell
     # 英伟达
     # 可以指定 CUDA 路径, 一般环境变量为 `CUDA_HOME` 或者 `CUDA_ROOT`
140
141
     # window系统:--cuda="%CUDA_HOME%"
     # linux系统:--cuda=$CUDA_HOME
142
     xmake f --nv-gpu=true --cuda=$CUDA_HOME -cv
Pan Zezhong's avatar
Pan Zezhong committed
143

144
145
     # 寒武纪
     xmake f --cambricon-mlu=true -cv
Pan Zezhong's avatar
Pan Zezhong committed
146

147
148
149
     # 华为昇腾
     xmake f --ascend-npu=true -cv
     ```
Pan Zezhong's avatar
Pan Zezhong committed
150

151
152
153
154
155
156
157
158
2. 编译安装

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

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

159
#### 2. 安装 C++ 库
Pan Zezhong's avatar
Pan Zezhong committed
160

161
```shell
162
163
xmake build _infinicore
xmake install _infinicore
164
```
Pan Zezhong's avatar
Pan Zezhong committed
165

166
#### 3. 安装 Python 包
167

168
```shell
169
pip install .
170
171
```

172

173

174
```shell
175
pip install . -e
176
177
```

178
注:开发时建议加入 `-e` 选项(即 `pip install -e .`),这样对 `python/infinicore` 做的更改将会实时得到反映,同时对 C++ 层所做的修改也只需要运行 `xmake build _infinicore && xmake install _infinicore` 便可以生效。
179

180
### 三、运行测试
181

182
#### 运行 InfiniCore Python算子接口测试
183

184
```bash
185
# 测试单算子
186
python test/infinicore/ops/[operator].py [--bench | --debug | --verbose] [--cpu | --nvidia | --cambricon | --ascend | --iluvatar | --metax | --moore | --kunlun | --Hygon]
187
# 测试全部算子
188
python test/infinicore/run.py [--bench | --debug | --verbose] [--cpu | --nvidia | --cambricon | --ascend | --iluvatar | --metax | --moore | --kunlun]
189
190
```

191
使用 -h 查看更多参数。
192

193
#### 运行 InfiniOP 算子测试
194
195

```shell
196
# 测试单算子
197
python test/infiniop/[operator].py [--cpu | --nvidia | --cambricon | --ascend | --iluvatar | --metax | --moore | --kunlun | --Hygon]
198
# 测试全部算子
199
python scripts/python_test.py [--cpu | --nvidia | --cambricon | --ascend | --iluvatar | --metax | --moore | --kunlun | --Hygon]
200
201
```

202
#### 通信库(InfiniCCL)测试
203

204
编译(需要先安装底层库中的 InfiniCCL 库):
205
206

```shell
207
xmake build infiniccl-test
208
209
```

210
在英伟达平台运行测试(会自动使用所有可见的卡):
211
212

```shell
213
infiniccl-test --nvidia
214
215
```

PanZezhong's avatar
PanZezhong committed
216
## 如何开源贡献
YdrMaster's avatar
YdrMaster committed
217

PanZezhong's avatar
PanZezhong committed
218
[`InfiniCore开发者手册`](DEV.md)