已合并
Update master branch with openEuler-24.03-LTS-Next at commit 0e655ee. #41
liuf9创建于 2025年2月7日
Update master branch with openEuler-24.03-LTS-Next at commit 0e655ee. #41
已合并
从refs/pull/41/head合入到master
共 5 个文件变更+17187-37
| @@ -0,0 +1,38 @@ | |||
| 1 | +From cce36baee7dc03d59355c1359e3653f4d695bc1a Mon Sep 17 00:00:00 2001 | ||
| 2 | +From: liuf9 <liufeiyang6@huawei.com> | ||
| 3 | +Date: Sun, 8 Dec 2024 15:14:25 +0800 | ||
| 4 | +Subject: [PATCH] Bugfix for undefined "np" symbol in ai4c-option-tuner. | ||
| 5 | + | ||
| 6 | +--- | ||
| 7 | + python/ai4c/option_tuner/xgboost_cost_model.py | 2 +- | ||
| 8 | + python/test/option_tuner/run_option_tuner.sh | 2 +- | ||
| 9 | + 2 files changed, 2 insertions(+), 2 deletions(-) | ||
| 10 | + | ||
| 11 | +diff --git a/python/ai4c/option_tuner/xgboost_cost_model.py b/python/ai4c/option_tuner/xgboost_cost_model.py | ||
| 12 | +index 06c3bea5..5f779c9d 100644 | ||
| 13 | +--- a/python/ai4c/option_tuner/xgboost_cost_model.py | ||
| 14 | ++++ b/python/ai4c/option_tuner/xgboost_cost_model.py | ||
| 15 | +@@ -25,7 +25,7 @@ class XGBoostCostModel(object): | ||
| 16 | + def predict(self, xs: List[List[int]]): | ||
| 17 | + ret = [] | ||
| 18 | + for x in xs: | ||
| 19 | +- ret.append(self.bst.predict(np.asarray([x]))[0]) | ||
| 20 | ++ ret.append(self.bst.predict(asarray([x]))[0]) | ||
| 21 | + return ret | ||
| 22 | + | ||
| 23 | + | ||
| 24 | +diff --git a/python/test/option_tuner/run_option_tuner.sh b/python/test/option_tuner/run_option_tuner.sh | ||
| 25 | +index baf00480..f36dcb5f 100644 | ||
| 26 | +--- a/python/test/option_tuner/run_option_tuner.sh | ||
| 27 | ++++ b/python/test/option_tuner/run_option_tuner.sh | ||
| 28 | +@@ -1,6 +1,6 @@ | ||
| 29 | + #!/bin/bash | ||
| 30 | + set -e | ||
| 31 | +-ai4c-option-tune --test_limit 3 -r run_test.sh | ||
| 32 | ++ai4c-option-tune --test_limit 20 -r run_test.sh | ||
| 33 | + | ||
| 34 | + ### clean intermediate files ### | ||
| 35 | + if [ "$1" = "clean" ]; then | ||
| 36 | +-- | ||
| 37 | +2.33.0 | ||
| 38 | + | ||
| @@ -0,0 +1,407 @@ | |||
| 1 | +From d4102f3e5d81aba360d55f734b6643e04dbc6132 Mon Sep 17 00:00:00 2001 | ||
| 2 | +From: liuf9 <liufeiyang6@huawei.com> | ||
| 3 | +Date: Mon, 9 Dec 2024 21:09:30 +0800 | ||
| 4 | +Subject: [PATCH] Update README.md. | ||
| 5 | + | ||
| 6 | +--- | ||
| 7 | + README.md | 376 ++++++++++++++++++++++++++++++++++++++++++++++++++---- | ||
| 8 | + 1 file changed, 352 insertions(+), 24 deletions(-) | ||
| 9 | + | ||
| 10 | +diff --git a/README.md b/README.md | ||
| 11 | +index a438086f..86fcf5f0 100644 | ||
| 12 | +--- a/README.md | ||
| 13 | ++++ b/README.md | ||
| 14 | +@@ -1,37 +1,365 @@ | ||
| 15 | + # AI4C | ||
| 16 | + | ||
| 17 | +-#### 介绍 | ||
| 18 | +-AI4C stands for AI for Compiler Kit, a framework which enables compilers to integrate ML-driven compiler optimizations. | ||
| 19 | ++## 1 AI4C 介绍 | ||
| 20 | + | ||
| 21 | +-#### 软件架构 | ||
| 22 | +-软件架构说明 | ||
| 23 | ++AI4C 代表 AI 辅助编译器的套件,是一个使编译器能够集成机器学习驱动编译优化的框架。 | ||
| 24 | + | ||
| 25 | ++## 2 软件架构说明 | ||
| 26 | + | ||
| 27 | +-#### 安装教程 | ||
| 28 | ++本框架包含以下几个模块,自动编译调优工具依赖 python 环境: | ||
| 29 | + | ||
| 30 | +-1. xxxx | ||
| 31 | +-2. xxxx | ||
| 32 | +-3. xxxx | ||
| 33 | ++* AI辅助编译优化的推理引擎,驱动编译器在优化 pass 内使用AI模型推理所获得的结果实现编译优化。 | ||
| 34 | ++ * 当前 GCC 内的 AI 使能优化 pass 基本通过编译器插件的形式实现,与编译器主版本解耦。 | ||
| 35 | ++* 自动编译调优工具,通过编译器外部的调优工具(OpenTuner)驱动编译器执行多层粒度的自动编译调优,当前支持 GCC 和 LLVM 编译器。 | ||
| 36 | ++ * 选项调优工具,用于应用级的编译选项调优。 | ||
| 37 | ++ * 编译调优工具,基于 [Autotuner](https://gitee.com/openeuler/BiSheng-Autotuner) 实现,可实现细粒度和粗粒度的编译调优。 | ||
| 38 | ++ * 细粒度调优,调优优化 pass 内的关键优化参数,例如,循环展开的次数(unroll count)。 | ||
| 39 | ++ * 粗粒度调优,调优函数级的编译选项。 | ||
| 40 | + | ||
| 41 | +-#### 使用说明 | ||
| 42 | ++未来规划方向: | ||
| 43 | + | ||
| 44 | +-1. xxxx | ||
| 45 | +-2. xxxx | ||
| 46 | +-3. xxxx | ||
| 47 | ++- [ ] 集成 [ACPO](https://gitee.com/src-openeuler/ACPO) 的 LLVM 编译优化模型,同时将 ACPO LLVM 侧的相关代码提取成插件,与 LLVM 主版本解耦。 | ||
| 48 | ++- [ ] AI4Compiler 框架支持更多的开源机器学习框架的推理(pytorch - LibTorch、tensorflow - LiteRT)。 | ||
| 49 | ++- [ ] 提供更多的 AI 辅助编译优化模型及相应的编译器插件。 | ||
| 50 | ++- [ ] 集成新的搜索算法(基于白盒信息)并优化参数搜索空间(热点函数调优)。 | ||
| 51 | ++- [ ] 支持 JDK 的编译参数调优。 | ||
| 52 | + | ||
| 53 | +-#### 参与贡献 | ||
| 54 | ++## 3 AI4C 的安装构建 | ||
| 55 | + | ||
| 56 | +-1. Fork 本仓库 | ||
| 57 | +-2. 新建 Feat_xxx 分支 | ||
| 58 | +-3. 提交代码 | ||
| 59 | +-4. 新建 Pull Request | ||
| 60 | ++### 3.1 直接安装AI4C | ||
| 61 | + | ||
| 62 | ++若用户使用最新的openEuler系统(24.03-LTS-SP1),同时只准备使用`AI4C`的现有特性,可以直接安装`AI4C`包。 | ||
| 63 | + | ||
| 64 | +-#### 特技 | ||
| 65 | ++```shell | ||
| 66 | ++yum install -y AI4C | ||
| 67 | ++``` | ||
| 68 | + | ||
| 69 | +-1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md | ||
| 70 | +-2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) | ||
| 71 | +-3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 | ||
| 72 | +-4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 | ||
| 73 | +-5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) | ||
| 74 | +-6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) | ||
| 75 | ++若用户使用其他版本的`AI4C`特性或在其他OS版本中安装`AI4C`,需重新构建`AI4C`,可以参考以下步骤。 | ||
| 76 | ++ | ||
| 77 | ++### 3.2 RPM包构建安装流程(推荐) | ||
| 78 | ++ | ||
| 79 | ++1. 使用 root 权限,安装 rpmbuild、rpmdevtools,具体命令如下: | ||
| 80 | ++ | ||
| 81 | ++ ```bash | ||
| 82 | ++ # 安装 rpmbuild | ||
| 83 | ++ yum install dnf-plugins-core rpm-build | ||
| 84 | ++ # 安装 rpmdevtools | ||
| 85 | ++ yum install rpmdevtools | ||
| 86 | ++ ``` | ||
| 87 | ++ | ||
| 88 | ++2. 在主目录`/root`下生成 rpmbuild 文件夹: | ||
| 89 | ++ | ||
| 90 | ++ ```bash | ||
| 91 | ++ rpmdev-setuptree | ||
| 92 | ++ # 检查自动生成的目录结构 | ||
| 93 | ++ ls ~/rpmbuild/ | ||
| 94 | ++ BUILD BUILDROOT RPMS SOURCES SPECS SRPMS | ||
| 95 | ++ ``` | ||
| 96 | ++ | ||
| 97 | ++3. 使用`git clone https://gitee.com/src-openeuler/AI4C.git`,从目标仓库的 `openEuler-24.03-LTS-SP1` 分支拉取代码,并把目标文件放入 rpmbuild 的相应文件夹下: | ||
| 98 | ++ | ||
| 99 | ++ ``` shell | ||
| 100 | ++ cp AI4C/AI4C-v%{version}-alpha.tar.gz ~/rpmbuild/SOURCES/ | ||
| 101 | ++ cp AI4C/*.patch ~/rpmbuild/SOURCES/ | ||
| 102 | ++ cp AI4C/AI4C.spec ~/rpmbuild/SPECS/ | ||
| 103 | ++ ``` | ||
| 104 | ++ | ||
| 105 | ++4. 用户可通过以下步骤生成 `AI4C` 的 RPM 包: | ||
| 106 | ++ | ||
| 107 | ++ ```shell | ||
| 108 | ++ # 安装 AI4C 所需依赖 | ||
| 109 | ++ yum-builddep ~/rpmbuild/SPECS/AI4C.spec | ||
| 110 | ++ # 构建 AI4C 依赖包 | ||
| 111 | ++ rpmbuild -ba ~/rpmbuild/SPECS/AI4C.spec | ||
| 112 | ++ # 安装 RPM 包 | ||
| 113 | ++ cd ~/rpmbuild/RPMS/ | ||
| 114 | ++ rpm -ivh AI4C-<version>-<release>.<arch>.rpm | ||
| 115 | ++ ``` | ||
| 116 | ++ | ||
| 117 | ++ 注意事项:若系统因存有旧版本的 RPM 安装包而导致文件冲突,可以通过以下方式解决: | ||
| 118 | ++ | ||
| 119 | ++ ```shell | ||
| 120 | ++ # 解决方案一:强制安装新版本 | ||
| 121 | ++ rpm -ivh AI4C-<version>-<release>.<arch>.rpm --force | ||
| 122 | ++ # 解决方案二:更新安装包 | ||
| 123 | ++ rpm -Uvh AI4C-<version>-<release>.<arch>.rpm | ||
| 124 | ++ ``` | ||
| 125 | ++ | ||
| 126 | ++ 安装完成后,系统内会存在以下文件: | ||
| 127 | ++ | ||
| 128 | ++ * `/usr/bin/ai4c-*`: AI 使能的编译器以及自动调优工具的 wrapper | ||
| 129 | ++ * `/usr/lib64/libonnxruntime.so`: ONNX Runtime 的推理框架动态库 | ||
| 130 | ++ * `/usr/lib64/AI4C/*.onnx`: AI 辅助编译优化模型(ONNX 格式) | ||
| 131 | ++ * `/usr/lib64/python<version>/site-packages/ai4c/lib/*.so`: | ||
| 132 | ++ * AI 辅助编译优化的推理引擎动态库 | ||
| 133 | ++ * AI 辅助编译优化与编译调优的编译器插件动态库 | ||
| 134 | ++ * `/usr/lib64/python<version>/site-packages/ai4c/autotuner/*`: 粗、细粒度调优工具的相关文件 | ||
| 135 | ++ * `/usr/lib64/python<version>/site-packages/ai4c/optimizer/*`: AI 辅助编译优化的相关文件 | ||
| 136 | ++ * `/usr/lib64/python<version>/site-packages/ai4c/option_tuner/*`: 应用级编译选项调优的相关文件 | ||
| 137 | ++ | ||
| 138 | ++### 3.3 源码构建安装流程 | ||
| 139 | ++ | ||
| 140 | ++#### 3.3.1 安装 ONNX Runtime 依赖 | ||
| 141 | ++ | ||
| 142 | ++方案一: | ||
| 143 | ++ | ||
| 144 | ++在 GitHub 下载 1.16.3 版本,并解压相应架构的 tgz 文件,地址:https://github.com/microsoft/onnxruntime/releases/tag/v1.16.3 | ||
| 145 | ++ | ||
| 146 | ++方案二: | ||
| 147 | ++ | ||
| 148 | ++保证以下 onnxruntime 的依赖包已安装: | ||
| 149 | ++ | ||
| 150 | ++```shell | ||
| 151 | ++yum install -y cmake make gcc gcc-c++ abseil-cpp-devel boost-devel bzip2 python3-devel python3-numpy python3-setuptools python3-pip | ||
| 152 | ++``` | ||
| 153 | ++ | ||
| 154 | ++使用 cmake 安装 onnxruntime: | ||
| 155 | ++ | ||
| 156 | ++```shell | ||
| 157 | ++cd path/to/your/AI4C/third_party/onnxruntime | ||
| 158 | ++cmake \ | ||
| 159 | ++ -DCMAKE_INSTALL_PREFIX=path/to/your/onnxruntime \ | ||
| 160 | ++ -Donnxruntime_BUILD_SHARED_LIB=ON \ | ||
| 161 | ++ -Donnxruntime_BUILD_UNIT_TESTS=ON \ | ||
| 162 | ++ -Donnxruntime_INSTALL_UNIT_TESTS=OFF \ | ||
| 163 | ++ -Donnxruntime_BUILD_BENCHMARKS=OFF \ | ||
| 164 | ++ -Donnxruntime_USE_FULL_PROTOBUF=ON \ | ||
| 165 | ++ -DPYTHON_VERSION=%{python3_version} \ | ||
| 166 | ++ -Donnxruntime_ENABLE_CPUINFO=ON \ | ||
| 167 | ++ -Donnxruntime_DISABLE_ABSEIL=ON \ | ||
| 168 | ++ -Donnxruntime_USE_NEURAL_SPEED=OFF \ | ||
| 169 | ++ -Donnxruntime_ENABLE_PYTHON=OFF \ | ||
| 170 | ++ -DCMAKE_BUILD_TYPE=Release \ | ||
| 171 | ++ -S cmake | ||
| 172 | ++make -j %{max_jobs} && make install | ||
| 173 | ++``` | ||
| 174 | ++ | ||
| 175 | ++#### 3.3.2 安装 AI4C 的其他构建依赖 | ||
| 176 | ++ | ||
| 177 | ++保证以下依赖包已安装: | ||
| 178 | ++ | ||
| 179 | ++```shell | ||
| 180 | ++yum install -y python3-wheel openssl openssl-devel yaml-cpp yaml-cpp-devel gcc-plugin-devel libstdc++-static | ||
| 181 | ++``` | ||
| 182 | ++ | ||
| 183 | ++#### 3.3.3 构建 AI4C 框架 | ||
| 184 | ++ | ||
| 185 | ++```shell | ||
| 186 | ++cd path/to/your/AI4C/python | ||
| 187 | ++python3 setup.py bdist_wheel \ | ||
| 188 | ++ -Donnxruntime_ROOTDIR=path/to/your/onnxruntime \ | ||
| 189 | ++ -DCMAKE_BUILD_TYPE=Release \ | ||
| 190 | ++ -DCMAKE_CXX_COMPILER=path/to/your/g++ \ | ||
| 191 | ++ -DCMAKE_C_COMPILER=path/to/your/gcc | ||
| 192 | ++pip3 install dist/ai4c-<version>-<python_version>-<python_version>-<os>_<arch>.whl --force-reinstall --no-deps | ||
| 193 | ++``` | ||
| 194 | ++ | ||
| 195 | ++安装完成后,系统内会存在以下文件: | ||
| 196 | ++ | ||
| 197 | ++* `~/.local/bin/ai4c-*`: AI 使能的编译器以及自动调优工具的 wrapper | ||
| 198 | ++* `path/to/your/onnxruntime/lib64/libonnxruntime.so`: ONNX Runtime 的推理框架动态库 | ||
| 199 | ++* `path/to/your/AI4C/models/*.onnx`: AI 辅助编译优化模型(ONNX 格式) | ||
| 200 | ++* `~/.local/python<version>/site-packages/ai4c/lib/*.so`: | ||
| 201 | ++ * AI 辅助编译优化的推理引擎动态库 | ||
| 202 | ++ * AI 辅助编译优化与编译调优的编译器插件动态库 | ||
| 203 | ++* `~/.local/python<version>/site-packages/ai4c/autotuner/*`: 粗、细粒度调优工具的相关文件 | ||
| 204 | ++* `~/.local/python<version>/site-packages/ai4c/optimizer/*`: AI 辅助编译优化的相关文件 | ||
| 205 | ++* `~/.local/python<version>/site-packages/ai4c/option_tuner/*`: 应用级编译选项调优的相关文件 | ||
| 206 | ++ | ||
| 207 | ++### 3.4 FAQ | ||
| 208 | ++ | ||
| 209 | ++#### 3.4.1 构建 onnxruntime 时,发现系统内的 cmake 版本较低,导致 onnxruntime 无法构建。 | ||
| 210 | ++ | ||
| 211 | ++解决方案:AI4C-v0.2.0-alpha 版本存有 cmake-3.28.5 版本的源码,可以从源码构建该版本的 cmake,用于构建 onnxruntime。 | ||
| 212 | ++ | ||
| 213 | ++ cmake 构建方式参考:https://gitee.com/src-openeuler/AI4C/blob/openEuler-22.03-LTS-SP4/AI4C.spec | ||
| 214 | ++ | ||
| 215 | ++ AI4C-v0.2.0-alpha 地址:https://gitee.com/openeuler/AI4C/releases/tag/v0.2.0-alpha | ||
| 216 | ++ | ||
| 217 | ++## 4 使用流程 | ||
| 218 | ++ | ||
| 219 | ++### 4.1 AI 辅助编译优化 | ||
| 220 | ++ | ||
| 221 | ++当前的 AI 辅助编译优化模块,主要由三部分输入组成: | ||
| 222 | ++ | ||
| 223 | ++- ONNX 模型,训练后的辅助编译优化模型。 | ||
| 224 | ++- 编译器插件(**当前仅支持 GCC 编译器**),用于运行 ONNX 模型推理并获取优化参数。 | ||
| 225 | ++- AI4Compiler 框架,提供 ONNX 推理引擎和 GCC 优化编译命令。 | ||
| 226 | ++ | ||
| 227 | ++用户事先根据开源机器学习框架训练一个 AI 模型,输出成 ONNX 格式。同时,针对该 AI 模型提供一个对应的编译器插件,插件内至少包含三个模块: | ||
| 228 | ++ | ||
| 229 | ++* 提取 AI 模型所需的编译器输入特征。 | ||
| 230 | ++* 驱动推理引擎调用 AI 模型执行推理。 | ||
| 231 | ++* 标注推理结果回编译器的数据结构。 | ||
| 232 | ++ | ||
| 233 | ++在下述测试例中,仅需要在每次编译目标二进制的编译命令中,增加三个与插件相关的编译选项:插件路径、插件对应的 AI 模型路径、推理引擎路径,即可在编译时使能 AI 辅助编译优化模型。 | ||
| 234 | ++ | ||
| 235 | ++```shell | ||
| 236 | ++# 若 onnxruntime 安装在非系统的文件夹下,注意设置环境变量 | ||
| 237 | ++# export LD_LIBRARY_PATH=path/to/your/onnxruntime/lib64/:$LD_LIBRARY_PATH | ||
| 238 | ++ | ||
| 239 | ++gcc_compiler=path/to/your/gcc | ||
| 240 | ++infer_engine_path=$(ai4c-gcc --inference-engine) | ||
| 241 | ++model_path=path/to/your/model.onnx | ||
| 242 | ++plugin_path=path/to/your/<model_plugin>.so | ||
| 243 | ++ | ||
| 244 | ++$gcc_compiler test.c -O2 -o test \ | ||
| 245 | ++ -fplugin=$plugin_path \ | ||
| 246 | ++ -fplugin-arg-<model_plugin>-model=$model_path \ | ||
| 247 | ++ -fplugin-arg-<model_plugin>-engine=$infer_engine_path | ||
| 248 | ++``` | ||
| 249 | ++ | ||
| 250 | ++当前已支持的插件存在于`$(ai4c-gcc --inference-engine)`的同目录下,已支持的模型存在于`path/to/your/AI4C/models`下。 | ||
| 251 | ++ | ||
| 252 | ++**注意事项:** | ||
| 253 | ++ | ||
| 254 | ++* 编译 AI 模型对应的编译器插件与编译目标优化应用的编译器需保证为同一个,否则会出现编译器版本不一致导致的编译报错。 | ||
| 255 | ++* 当前 AI4C 仅支持在 GCC 编译器 cc1 阶段实现的 AI 辅助编译优化 pass 使用插件形式。 | ||
| 256 | ++ | ||
| 257 | ++详细的编译器插件开发流程与使用流程可以参照 [AI 辅助编译优化手册](https://gitee.com/openeuler/AI4C/blob/master/python/docs/gcc-opt.md) 和 [测试例](https://gitee.com/openeuler/AI4C/tree/master/python/test/optimizer/block_correction) 进行。 | ||
| 258 | ++ | ||
| 259 | ++下面我们举两个位于不同编译阶段的 AI 辅助编译优化模型的使用例。**循环展开与函数内联模型**位于`cc1`编译优化阶段,使用 GCC 插件形式实现 AI 模型适配与推理;**BOLT 采样基本块精度修正模型**位于`BOLT`链接后优化阶段,模型适配层位于 [LLVM-BOLT](https://gitee.com/src-openeuler/llvm-bolt) 仓库。 | ||
| 260 | ++ | ||
| 261 | ++#### 4.1.1 循环展开与函数内联模型 | ||
| 262 | ++ | ||
| 263 | ++循环展开与函数内联模型对应的编译优化选项如下: | ||
| 264 | ++ | ||
| 265 | ++| 选项名 | 说明 | | ||
| 266 | ++| -------------------------------------------------- | ------------------------------------------------------------ | | ||
| 267 | ++| -fplugin | 指定循环展开与函数内联插件的**绝对路径**(`-fplugin=/path/to/ipa_inline_unroll_plugin.so`)。 | | ||
| 268 | ++| -fplugin-arg-ipa_inline_unroll_plugin-engine | 指定函数内联 ONNX 模型的推理引擎**绝对路径**(`-fplugin-arg-ipa_inline_unroll_plugin-inline_model=/path/to/inference_engine.so`),需要与`-fplugin`同时开启。`/path/to/inference_engine.so`的路径可通过`ai4c-gcc --inference-engine`获得。 | | ||
| 269 | ++| -fplugin-arg-ipa_inline_unroll_plugin-inline_model | 指定函数内联 ONNX 模型的**绝对路径**(`-fplugin-arg-ipa_inline_unroll_plugin-inline_model=/path/to/inline_model.onnx`),需要与`-fplugin`和`-fplugin-arg-ipa_inline_unroll_plugin-engine`同时开启。 | | ||
| 270 | ++| -fplugin-arg-ipa_inline_unroll_plugin-unroll_model | 指定循环展开 ONNX 模型的**绝对路径**(`-fplugin-arg-ipa_inline_unroll_plugin-unroll_model=/path/to/unroll_model.onnx`),需要与`-fplugin`和`-fplugin-arg-ipa_inline_unroll_plugin-engine`同时开启。 | | ||
| 271 | ++ | ||
| 272 | ++用户可同时启用一个 GCC 插件内的多个 AI 辅助编译优化模型,例如: | ||
| 273 | ++ | ||
| 274 | ++```shell | ||
| 275 | ++gxx_compiler=path/to/your/g++ | ||
| 276 | ++infer_engine_path=$(ai4c-gcc --inference-engine) | ||
| 277 | ++inline_model_path=path/to/your/inline_model.onnx | ||
| 278 | ++unroll_model_path=path/to/your/unroll_model.onnx | ||
| 279 | ++plugin_path=path/to/your/ipa_inline_unroll_plugin.so | ||
| 280 | ++ | ||
| 281 | ++$gxx_compiler test.cc -O3 -o test -funroll-loops \ | ||
| 282 | ++ -fplugin=$plugin_path \ | ||
| 283 | ++ -fplugin-arg-ipa_inline_unroll_plugin-engine=$infer_engine_path \ | ||
| 284 | ++ -fplugin-arg-ipa_inline_unroll_plugin-inline_model=$inline_model_path \ | ||
| 285 | ++ -fplugin-arg-ipa_inline_unroll_plugin-unroll_model=$unroll_model_path | ||
| 286 | ++``` | ||
| 287 | ++ | ||
| 288 | ++#### 4.1.2 BOLT 采样基本块精度修正模型 | ||
| 289 | ++ | ||
| 290 | ++BOLT 采样的基本块精度修正模型对应的 BOLT 优化选项如下: | ||
| 291 | ++ | ||
| 292 | ++| 选项名 | 说明 | | ||
| 293 | ++| ------------------- | ------------------------------------------------------------ | | ||
| 294 | ++| -block-correction | 开启 AI 优化 CFG BB Count 选项,需要与 `-model-path` 选项同时开启以指定 ONNX 模型。 | | ||
| 295 | ++| -model-path | 指定 ONNX 模型的**绝对路径**(`-model-path=/path/to/model.onnx`),需要与`-block-correction`同时开启。 | | ||
| 296 | ++| -annotate-threshold | 使用模型预测结果的置信度阈值,默认是 0.95。 | | ||
| 297 | ++ | ||
| 298 | ++BOLT 内自定义的优化选项可以通过 GCC 的`-fbolt-option`调用使能,例如: | ||
| 299 | ++ | ||
| 300 | ++```shell | ||
| 301 | ++g++ -fbolt-use=<gcov_file> -fbolt-target=<bin_file> -fbolt-option=\"-block-correction -model-path=path/to/your/block_correction_model.onnx\" | ||
| 302 | ++``` | ||
| 303 | ++ | ||
| 304 | ++### 4.2 细粒度调优 | ||
| 305 | ++ | ||
| 306 | ++此处我们以 GCC 内**循环展开**优化 pass 的细粒度调优为例,展开调优工具的使用流程。 | ||
| 307 | ++ | ||
| 308 | ++当前的细粒度调优模块,由两部分输入组成: | ||
| 309 | ++ | ||
| 310 | ++* 应用的调优配置文件(.ini):处理应用的编译流程、执行流程。 | ||
| 311 | ++* 搜参空间配置文件(YAML):Autotuner 阶段配置的选项调优搜参空间,可替换默认搜参空间。 | ||
| 312 | ++ | ||
| 313 | ++当前细粒度调优基于 [Autotuner](https://gitee.com/openeuler/BiSheng-Autotuner) 实现: | ||
| 314 | ++ | ||
| 315 | ++1. 在编译器的`generate`阶段,生成一组可调优的编译数据结构与可调优系数集合,保存在`opp/*.yaml`内。 | ||
| 316 | ++2. 根据额外提供的编译搜参空间(`search_space.yaml`)与可调优数据结构,Autotuner 通过调优算法针对每个可调优数据结构生成下一组调优系数,保存在`input.yaml`中。 | ||
| 317 | ++3. 在编译器的`autotune`阶段,根据`input.yaml`内数据结构的 hash 值,将调优系数标注到对应的数据结构里,完成调优。 | ||
| 318 | ++ | ||
| 319 | ++在开启细粒度调优前,需安装以下依赖包: | ||
| 320 | ++ | ||
| 321 | ++```shell | ||
| 322 | ++yum install -y BiSheng-Autotuner bisheng-opentuner | ||
| 323 | ++``` | ||
| 324 | ++ | ||
| 325 | ++**注意事项:** | ||
| 326 | ++ | ||
| 327 | ++* 当前默认支持程序运行时间作为性能值。 | ||
| 328 | ++ | ||
| 329 | ++详细使用信息,请参考[细粒度调优使用手册](https://gitee.com/openeuler/AI4C/blob/master/python/docs/autotuner.md) 与该测试例:https://gitee.com/openeuler/AI4C/tree/master/python/test/autotuner/loop_unroll | ||
| 330 | ++ | ||
| 331 | ++LLVM 编译器的细粒度调优请参考 [Autotuner](https://gitee.com/openeuler/BiSheng-Autotuner) 仓库的使用教程。 | ||
| 332 | ++ | ||
| 333 | ++### 4.3 函数级的粗粒度调优 | ||
| 334 | ++ | ||
| 335 | ++当前的函数级粗粒度调优模块,由三部分输入组成: | ||
| 336 | ++ | ||
| 337 | ++* 应用的调优配置文件(.ini):处理应用的编译流程、执行流程。 | ||
| 338 | ++* 搜参空间配置文件(YAML):Autotuner 阶段配置的选项调优搜参空间,可替换默认搜参空间。 | ||
| 339 | ++* 编译选项全集文件(YAML):预先设置的编译选项搜索空间全集,默认文件位于`path/to/your/python<version>/site-packages/ai4c/autotuner/yaml/coarse_options.yaml`。 | ||
| 340 | ++ | ||
| 341 | ++当前函数级粗粒度调优基于 [Autotuner](https://gitee.com/openeuler/BiSheng-Autotuner) 实现,可以帮助各函数使用不同的编译选项组合执行编译优化,其调优原理细粒度调优与一致。由于各函数可调优的编译选项众多,可预先对选项空间做裁剪。 | ||
| 342 | ++ | ||
| 343 | ++在开启函数级的粗粒度调优前,需安装以下依赖包: | ||
| 344 | ++ | ||
| 345 | ++```shell | ||
| 346 | ++yum install -y BiSheng-Autotuner bisheng-opentuner | ||
| 347 | ++``` | ||
| 348 | ++ | ||
| 349 | ++**注意事项:** | ||
| 350 | ++ | ||
| 351 | ++* 当前默认支持程序运行时间作为性能值。 | ||
| 352 | ++* 粗粒度调优暂不支持 dump 数据库内保存的历史数据。 | ||
| 353 | ++* 当前的粗粒度调优支持与当前版本的 GCC 版本(12.3.1)配套使用,其他编译器版本会出现部分编译选项不支持的问题。可在`path/to/your/AI4C/aiframe/include/option_utils.h`中注释编译器未识别的编译选项。 | ||
| 354 | ++ | ||
| 355 | ++详细使用信息,请参考该测试例:https://gitee.com/openeuler/AI4C/tree/master/python/test/autotuner/coarse_tuning | ||
| 356 | ++ | ||
| 357 | ++LLVM 编译器的粗粒度调优请参考 [Autotuner](https://gitee.com/openeuler/BiSheng-Autotuner) 仓库的使用教程。 | ||
| 358 | ++ | ||
| 359 | ++### 4.4 应用级选项调优 | ||
| 360 | ++ | ||
| 361 | ++当前的应用级选项调优模块,主要由三部分输入组成: | ||
| 362 | ++ | ||
| 363 | ++* 应用的编译与运行脚本(shell):处理应用的编译流程(并将生成的下一组选项替换进编译脚本内)、执行流程、和性能数据采集流程。 | ||
| 364 | ++* 编译选项与动态库选项的搜参空间配置文件(YAML):配置选项调优的搜参空间,可配置开关选项(编译优化/动态库)、编译参数、枚举选项。 | ||
| 365 | ++* 性能值的配置文件(YAML):配置多个性能项的权重,与目标优化方向(最大/最小值),需与“性能数据采集流程”所获取的性能值数量、顺序对应。 | ||
| 366 | ++ | ||
| 367 | ++应用级选项调优工具将不断收集应用的性能数据,更新性能模型,并生成一组模型预期收益较高的新编译选项组合。通过应用的编译与运行脚本将新的编译选项组合替换进编译脚本内,生成新的二进制文件并执行下一轮运行。反复调优,获取历史最优性能值。 | ||
| 368 | ++ | ||
| 369 | ++在开启应用级选项调优前,需安装以下依赖包: | ||
| 370 | ++ | ||
| 371 | ++```shell | ||
| 372 | ++pip install xgboost scikit-learn | ||
| 373 | ++yum install -y time | ||
| 374 | ++``` | ||
| 375 | ++ | ||
| 376 | ++默认的选项与性能值配置文件存在于以下路径:`path/to/your/python<version>/site-packages/ai4c/option_tuner/input/*.yaml` | ||
| 377 | ++ | ||
| 378 | ++* `options.yaml`:编译选项配置文件 | ||
| 379 | ++* `options_lib.yaml`:动态库选项配置文件 | ||
| 380 | ++* `config_measure.yaml`:性能值配置文件 | ||
| 381 | ++ | ||
| 382 | ++用户可根据需要修改编译选项与动态库选项配置文件,相关关键词为: | ||
| 383 | ++ | ||
| 384 | ++* `required_*`:必选调优项,将一直保留在调优中 | ||
| 385 | ++* `bool_*`:可选的编译优化开关选项 | ||
| 386 | ++* `interval_*`: 可选的编译参数(值选项,数据区间) | ||
| 387 | ++* `enum_*`: 可选的编译参数(枚举选项) | ||
| 388 | ++ | ||
| 389 | ++用户可根据需要修改性能值配置文件,相关关键词为: | ||
| 390 | ++ | ||
| 391 | ++* `weight`: 性能值权重 | ||
| 392 | ++* `optim`: 目标优化方向(最大/最小值) | ||
| 393 | ++ | ||
| 394 | ++调优完成后,历史与最佳调优数据将保留在`${parent_dir}/tuning/train.csv`和`${parent_dir}/tuning/result.txt`中。 | ||
| 395 | ++ | ||
| 396 | ++详细使用信息,请参考该测试例:https://gitee.com/openeuler/AI4C/tree/master/python/test/option_tuner | ||
| 397 | ++ | ||
| 398 | ++## 5 参与贡献 | ||
| 399 | ++ | ||
| 400 | ++1. Fork 本仓库 | ||
| 401 | ++2. 新建 Feat_xxx 分支 | ||
| 402 | ++3. 提交代码 | ||
| 403 | ++4. 新建 Pull Request | ||
| 404 | + | ||
| 405 | +-- | ||
| 406 | +2.33.0 | ||
| 407 | + | ||
此文件变更行数或变更字符数较多,你可以直接 查看源码
| @@ -5,23 +5,27 @@ | |||
| 5 | %global build_dir_frm %{build_dir}/aiframe/build | 5 | %global build_dir_frm %{build_dir}/aiframe/build |
| 6 | %global build_libdir %{build_dir_frm}/%{_lib} | 6 | %global build_libdir %{build_dir_frm}/%{_lib} |
| 7 | %global build_includedir %{build_dir_frm}/include | 7 | %global build_includedir %{build_dir_frm}/include |
| 8 | -%global build_dir_model %{build_libdir}/%{name} | ||
| 9 | 8 | ||
| 10 | %global install_libdir %{buildroot}%{_libdir} | 9 | %global install_libdir %{buildroot}%{_libdir} |
| 10 | +%global install_includedir %{buildroot}%{_includedir} | ||
| 11 | %global install_dir_model %{install_libdir}/%{name} | 11 | %global install_dir_model %{install_libdir}/%{name} |
| 12 | 12 | ||
| 13 | %global max_jobs 16 | 13 | %global max_jobs 16 |
| 14 | 14 | ||
| 15 | Summary: %{name} is a framework which enables compilers to integrate ML-driven compiler optimization. | 15 | Summary: %{name} is a framework which enables compilers to integrate ML-driven compiler optimization. |
| 16 | Name: AI4C | 16 | Name: AI4C |
| 17 | -Version: 0.2.0 | 17 | +Version: 1.0.4 |
| 18 | -Release: 3 | 18 | +Release: 5 |
| 19 | # Package onnxruntime and SafeInt have MIT License. | 19 | # Package onnxruntime and SafeInt have MIT License. |
| 20 | # Package onnx has Apache License 2.0. | 20 | # Package onnx has Apache License 2.0. |
| 21 | License: MIT and ASL 2.0 and Boost and BSD | 21 | License: MIT and ASL 2.0 and Boost and BSD |
| 22 | URL: https://gitee.com/openeuler/AI4C | 22 | URL: https://gitee.com/openeuler/AI4C |
| 23 | Source0: %{pkg_version}.tar.gz | 23 | Source0: %{pkg_version}.tar.gz |
| 24 | 24 | ||
| 25 | +Patch1: 0001-Bugfix-for-undefined-np-symbol-in-ai4c-option-tuner.patch | ||
| 26 | +Patch2: 0002-Update-README.md.patch | ||
| 27 | +Patch3: 0003-Bugfix-and-update-inline-and-unroll-model.patch | ||
| 28 | + | ||
| 25 | BuildRequires: cmake >= 3.13 | 29 | BuildRequires: cmake >= 3.13 |
| 26 | BuildRequires: make | 30 | BuildRequires: make |
| 27 | BuildRequires: gcc | 31 | BuildRequires: gcc |
| @@ -33,11 +37,15 @@ BuildRequires: python3-devel | |||
| 33 | BuildRequires: python3-numpy | 37 | BuildRequires: python3-numpy |
| 34 | BuildRequires: python3-setuptools | 38 | BuildRequires: python3-setuptools |
| 35 | BuildRequires: python3-pip | 39 | BuildRequires: python3-pip |
| 40 | +BuildRequires: python3-wheel | ||
| 36 | BuildRequires: openssl | 41 | BuildRequires: openssl |
| 37 | BuildRequires: openssl-devel | 42 | BuildRequires: openssl-devel |
| 43 | +BuildRequires: yaml-cpp | ||
| 44 | +BuildRequires: yaml-cpp-devel | ||
| 45 | +BuildRequires: gcc-plugin-devel | ||
| 46 | +BuildRequires: libstdc++-static | ||
| 38 | BuildRequires: git | 47 | BuildRequires: git |
| 39 | 48 | ||
| 40 | - | ||
| 41 | %description | 49 | %description |
| 42 | %{name} is a framework which enables compilers to integrate ML-driven compiler optimization. | 50 | %{name} is a framework which enables compilers to integrate ML-driven compiler optimization. |
| 43 | 51 | ||
| @@ -47,12 +55,6 @@ tar -xzf %{SOURCE0} -C . | |||
| 47 | %autosetup -S git -n %{pkg_version} | 55 | %autosetup -S git -n %{pkg_version} |
| 48 | 56 | ||
| 49 | %build | 57 | %build |
| 50 | -# Construct dependency package `cmake` | ||
| 51 | -cd %{build_dir_dep}/cmake | ||
| 52 | -mkdir -p build && cd build | ||
| 53 | -cmake .. -DCMAKE_INSTALL_PREFIX=./install | ||
| 54 | -make install -j %{max_jobs} | ||
| 55 | - | ||
| 56 | # Broken test in aarch64 architecture. | 58 | # Broken test in aarch64 architecture. |
| 57 | cd %{build_dir_dep}/onnxruntime | 59 | cd %{build_dir_dep}/onnxruntime |
| 58 | %ifarch aarch64 | 60 | %ifarch aarch64 |
| @@ -62,7 +64,7 @@ rm -v onnxruntime/test/optimizer/nhwc_transformer_test.cc | |||
| 62 | # Construct dependency package `onnxruntime`. | 64 | # Construct dependency package `onnxruntime`. |
| 63 | mkdir -p %{build_libdir} | 65 | mkdir -p %{build_libdir} |
| 64 | mkdir -p %{build_includedir} | 66 | mkdir -p %{build_includedir} |
| 65 | -%{build_dir_dep}/cmake/build/install/bin/cmake \ | 67 | +cmake \ |
| 66 | -DCMAKE_INSTALL_PREFIX=%{build_dir_frm} \ | 68 | -DCMAKE_INSTALL_PREFIX=%{build_dir_frm} \ |
| 67 | -DCMAKE_INSTALL_LIBDIR=%{build_libdir} \ | 69 | -DCMAKE_INSTALL_LIBDIR=%{build_libdir} \ |
| 68 | -DCMAKE_INSTALL_INCLUDEDIR=%{build_includedir} \ | 70 | -DCMAKE_INSTALL_INCLUDEDIR=%{build_includedir} \ |
| @@ -80,50 +82,58 @@ mkdir -p %{build_includedir} | |||
| 80 | -S cmake | 82 | -S cmake |
| 81 | make -j %{max_jobs} && make install | 83 | make -j %{max_jobs} && make install |
| 82 | 84 | ||
| 83 | -# Construct AI4C library `libONNXRunner.so`. | 85 | + |
| 84 | -cd %{build_dir_frm} | 86 | +pushd %{build_dir}/python |
| 85 | -cmake \ | 87 | +%{__python3} setup.py bdist_wheel \ |
| 86 | - -DCMAKE_INSTALL_PREFIX=%{build_dir_frm} \ | ||
| 87 | -Donnxruntime_ROOTDIR=%{build_dir_frm} \ | 88 | -Donnxruntime_ROOTDIR=%{build_dir_frm} \ |
| 88 | - -DCMAKE_BUILD_TYPE=RelWithDebInfo \ | 89 | + -DCMAKE_BUILD_TYPE=RelWithDebInfo |
| 89 | - ../ | ||
| 90 | -make -j %{max_jobs} && make install | ||
| 91 | 90 | ||
| 92 | %install | 91 | %install |
| 92 | +install -d %{install_includedir} | ||
| 93 | +install %{build_includedir}/onnxruntime/* -t %{install_includedir} | ||
| 93 | install -d %{install_dir_model} | 94 | install -d %{install_dir_model} |
| 94 | -install %{build_dir_model}/* -t %{install_dir_model} | 95 | +install %{build_dir}/models/* -t %{install_dir_model} |
| 95 | install %{build_libdir}/libonnxruntime.so* -t %{install_libdir} | 96 | install %{build_libdir}/libonnxruntime.so* -t %{install_libdir} |
| 96 | -install %{build_libdir}/libONNXRunner.so -t %{install_libdir} | ||
| 97 | pushd %{install_libdir} | 97 | pushd %{install_libdir} |
| 98 | ln -sf libonnxruntime.so.1.* libonnxruntime.so | 98 | ln -sf libonnxruntime.so.1.* libonnxruntime.so |
| 99 | popd | 99 | popd |
| 100 | 100 | ||
| 101 | +pushd %{build_dir}/python | ||
| 102 | +%py3_install | ||
| 101 | 103 | ||
| 102 | %files | 104 | %files |
| 103 | -%attr(0755,root,root) %{_libdir}/* | 105 | +%{_includedir}/* |
| 106 | +%{_libdir}/* | ||
| 107 | +%{python3_sitelib}/*egg-info | ||
| 108 | +%{python3_sitelib}/ai4c | ||
| 109 | +/usr/bin/ai4c-autotune | ||
| 110 | +/usr/bin/ai4c-g++ | ||
| 111 | +/usr/bin/ai4c-gcc | ||
| 112 | +/usr/bin/ai4c-option-tune | ||
| 113 | +/usr/bin/ai4c-tune | ||
| 104 | 114 | ||
| 105 | 115 | ||
| 106 | %changelog | 116 | %changelog |
| 107 | -* Wed Jan 15 2025 litian <dev11105@linx-info.com> - 0.2.0-3 | 117 | +* Wed Feb 05 2025 Feiyang Liu <liufeiyang6@huawei.com> - 1.0.4-5 |
| 108 | -- add build require git. | 118 | +- Add BuildRequires for git and fix description typo in spec file. |
| 109 | 119 | ||
| 110 | -* Thu Dec 12 2024 Yongkang Hou <houyongkang@inspur.com> - 0.2.0-2 | 120 | +* Tue Dec 31 2024 Chunfei Yu <yuchunfei@huawei.com> - 1.0.4-4 |
| 111 | -- Update description. | 121 | +- Bugfix and update inline and unroll model |
| 112 | 122 | ||
| 113 | -* Wed Aug 14 2024 Zhenyu Zhao <zhaozhenyu17@huawei.com> - 0.2.0-1 | 123 | +* Mon Dec 09 2024 Feiyang Liu <liufeiyang6@huawei.com> - 1.0.4-3 |
| 114 | -- Update AI4C from v0.1.0 to v0.2.0. | 124 | +- Update README.md. |
| 115 | 125 | ||
| 116 | -* Tue Aug 06 2024 Feiyang Liu <liufeiyang6@huawei.com> - 0.1.0-5 | 126 | +* Sun Dec 08 2024 Feiyang Liu <liufeiyang6@huawei.com> - 1.0.4-2 |
| 117 | -- Remove path dependencies for building AI4Compiler framework | 127 | +- Bugfix for undefined "np" symbol in ai4c-option-tuner. |
| 118 | 128 | ||
| 119 | -* Wed Jul 24 2024 Zhenyu Zhao <zhaozhenyu17@huawei.com> - 0.1.0-4 | 129 | +* Wed Dec 04 2024 Feiyang Liu <liufeiyang6@huawei.com> - 1.0.4-1 |
| 120 | -- Update-block-correction-model.patch | 130 | +- Update AI4C from v1.0.3 to v1.0.4. |
| 121 | 131 | ||
| 122 | -* Tue Jul 23 2024 Zhenyu Zhao <zhaozhenyu17@huawei.com> - 0.1.0-3 | 132 | +* Wed Nov 27 2024 Chenhui Zheng <zhengchenhui1@huawei.com> - 1.0.3-2 |
| 123 | -- Bugfix-for-tensor-formation-and-update-block-correct | 133 | +- Add inline_unroll plugin and models |
| 124 | 134 | ||
| 125 | -* Fri Jun 21 2024 Feiyang Liu <liufeiyang6@huawei.com> - 0.1.0-2 | 135 | +* Fri Nov 22 2024 Feiyang Liu <liufeiyang6@huawei.com> - 1.0.3-1 |
| 126 | -- Add batch inference feature and optimizer model | 136 | +- Update AI4C from v0.2.0 to v1.0.3. |
| 127 | 137 | ||
| 128 | -* Wed Jun 5 2024 Zhenyu Zhao <zhaozhenyu17@huawei.com> - 0.1.0-1 | 138 | +* Mon Nov 25 2024 Zhenyu Zhao <zhaozhenyu17@huawei.com> - 0.2.0-1 |
| 129 | -- Release 0.1.0 | 139 | +- Sync patch from 22.03 SP4. |