README.md 2.83 KB
Newer Older
Pan Zezhong's avatar
Pan Zezhong committed
1
2
# InfiniCore

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

5
6
7
8
9
10
11
12
13
14
- CPU;
- CUDA
  - 英伟达 GPU;
  - 摩尔线程 GPU;
  - 天数智芯 GPU;
  - 沐曦 GPU;
  - 曙光 DCU;
- 华为昇腾 NPU;
- 寒武纪 MLU;
- 昆仑芯 XPU;
Pan Zezhong's avatar
Pan Zezhong committed
15

16
## 配置和使用
Pan Zezhong's avatar
Pan Zezhong committed
17

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
### 一键安装

`script/` 目录中分别提供了 `install.bat` windows安装脚本和 `install.sh` linux安装脚本。使用方式如下:

```shell
cd InfiniCore

# Windows
.\scripts\install.bat . --nv-gpu=true 

# Linux
source ./scripts/install.sh . --nv-gpu=true
```

### 手动安装

34
1. 项目配置
Pan Zezhong's avatar
Pan Zezhong committed
35

36
   - 查看当前配置
Pan Zezhong's avatar
Pan Zezhong committed
37

38
39
40
     ```shell
     xmake f -v
     ```
Pan Zezhong's avatar
Pan Zezhong committed
41

42
   - 配置 CPU(默认配置)
Pan Zezhong's avatar
Pan Zezhong committed
43

44
45
46
     ```shell
     xmake f -cv
     ```
Pan Zezhong's avatar
Pan Zezhong committed
47

48
   - 配置加速卡
Pan Zezhong's avatar
Pan Zezhong committed
49

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

55
56
     # 寒武纪
     xmake f --cambricon-mlu=true -cv
Pan Zezhong's avatar
Pan Zezhong committed
57

58
59
60
     # 华为昇腾
     xmake f --ascend-npu=true -cv
     ```
Pan Zezhong's avatar
Pan Zezhong committed
61

62
63
64
65
66
67
68
69
70
71
72
73
2. 编译安装

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

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

3. 设置环境变量

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

74
75
76
### 运行测试

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

78
79
80
   ```shell
   python test/infiniop/[operator].py [--cpu | --nvidia | --cambricon | --ascend]
   ```
Pan Zezhong's avatar
Pan Zezhong committed
81

82
83
84
85
#### 算子测试框架

详见 `test/infiniop-test` 目录

86
## 开发指南
Pan Zezhong's avatar
Pan Zezhong committed
87

88
### 代码格式化
Pan Zezhong's avatar
Pan Zezhong committed
89

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
本项目使用 [`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
110
```
111
112
113
114
115
116
117
118
119
120
121

参数中:

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