应用级选项调优
当前的应用级选项调优模块,主要由三部分输入组成:
- 应用的编译与运行脚本(shell):处理应用的编译流程(并将生成的下一组选项替换进编译脚本内)、执行流程、和性能数据采集流程。
- 编译选项与动态库选项的搜参空间配置文件(YAML):配置选项调优的搜参空间,可配置开关选项(编译优化/动态库)、编译参数、枚举选项。
- 性能值的配置文件(YAML):配置多个性能项的权重,与目标优化方向(最大/最小值),需与“性能数据采集流程”所获取的性能值数量、顺序对应。
应用级选项调优工具将不断收集应用的性能数据,更新性能模型,并生成一组模型预期收益较高的新编译选项组合。通过应用的编译与运行脚本将新的编译选项组合替换进编译脚本内,生成新的二进制文件并执行下一轮运行。反复调优,获取历史最优性能值。
在开启应用级选项调优前,需安装以下依赖包:
1 | pip install xgboost scikit-learn yum install -y time |
以下用例将使用不同的编译选项组合构建并调优test.cc 3 轮。应用的编译与运行脚本如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # ---------- run_test.sh ---------- # parent_dir=$1 # path for intermediate tuning files config=$(cat ${parent_dir}/tuning/config.txt) # current compiler configuration file performance_file="${parent_dir}/tuning/performance.txt" # current performance data file measure_raw_file="time.txt" compiler=g++ compile_command="${compiler} test.cc -O2 -o test_opt_tuner" eval "${compile_command} ${config}" # program compilation, appending tuning options run_command="time -p -o ${measure_raw_file} ./test_opt_tuner 3" eval "${run_command}" # program execution info_collect_command="grep real ${measure_raw_file} | awk '{printf \"1 1 %s\", \$2}' > ${performance_file}" eval "${info_collect_command}" # program performance collection # ---------- run_option_tuner.sh ---------- # ai4c-option-tune --test_limit 3 --runfile run_test.sh # --optionfile path/to/your/python<version>/site-packages/ai4c/option_tuner/input/options.yaml \ # --libfile path/to/your/python<version>/site-packages/ai4c/option_tuner/input/options_lib.yaml \ # --measurefile path/to/your/python<version>/site-packages/ai4c/option_tuner/input/config_measure.yaml |
其中默认的选项与性能值配置文件存在于以下路径:path/to/your/python<version>/site-packages/ai4c/option_tuner/input/*.yaml
用户可根据需要修改编译选项与动态库选项配置文件,相关关键词为:
- required_*:必选调优项,将一直保留在调优中
- bool_*:可选的编译优化开关选项
- interval_*: 可选的编译参数(值选项,数据区间)
- enum_*: 可选的编译参数(枚举选项)
例如,
1 2 3 4 5 6 7 8 9 | required_config: - -O2 bool_config: - -funroll-loops interval_config: - name: --param max-inline-insns-auto default: 15 min: 10 max: 190 |
用户可根据需要修改性能值配置文件,相关关键词为:
- weight: 性能值权重
- optim: 目标优化方向(最大/最小值)
例如,
1 2 3 4 | config_measure: - name: throughput weight: 1 optim: maximize |
调优完成后,历史与最佳调优数据将保留在${parent_dir}/tuning/train.csv和${parent_dir}/tuning/result.txt中。
父主题: 使用方式