Rate This Document
Findability
Accuracy
Completeness
Readability

Application-level Option Tuning

The current application-level option tuning module consists of three parts:

  • Application compilation and execution script (shell): handles the application compilation process (including replacing the next set of generated options into the compile script), execution process, and performance data collection process.
  • Parameter search space configuration file (YAML) of the compilation options and dynamic library options: configures the parameter search space for option tuning, with configurable switch options (such as compilation optimization/dynamic library), compilation parameters, and enumeration options.
  • Performance value configuration file (YAML): configures the weights of multiple performance items and the target optimization direction (maximum/minimum value), which must correspond to the number and order of performance values obtained in the performance data collection process.

The application-level option tuning tool continuously collects performance data, updates the performance model, and generates a new set of compilation option combinations that are expected to yield higher performance. The new compilation option combinations are then inserted into the application's compile and run scripts, generating new binary files and executing the next round of runs. Iterative optimization is performed repeatedly to obtain the historical optimal performance.

Before enabling application-level tuning, install the following dependency package:

1
2
pip install xgboost scikit-learn
yum install -y time 

The following example will use different compilation option combinations to build and tune test.cc for three rounds. The compilation script and execution script of the application are as follows:

 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 

The default options and performance value configuration files are located at path/to/your/python<version>/site-packages/ai4c/option_tuner/input/*.yaml.

Users can modify the configuration files of compilation options and dynamic library options as needed. Relevant keywords include:

  • required_*: required tuning option, which will always be retained during tuning.
  • bool_*: optional compilation tuning option.
  • interval_*: optional compilation parameter (value option, data range).
  • enum_*: optional compilation parameter (enumerated option).
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

You can modify the performance value configuration file as needed. Relevant keywords include:

  • weight: performance value weight
  • optim: target optimization direction (maximum/minimum value)
1
2
3
4
config_measure:
- name: throughput
  weight: 1
  optim: maximize

After the tuning is complete, the historical and optimal tuning data will be reserved in ${parent_dir}/tuning/train.csv and ${parent_dir}/tuning/result.txt.