AutoFuse Enabling Method
Prerequisites
- Install the software package. Specifically, prepare a hardware environment with the AI processor and install the driver, firmware, and CANN package. For details, see CANN Software Installation.
- GCC version: 9.5.0 (recommended) or later.
- CMake version: 3.20.0 (recommended) or later.
- After the installation is complete, set environment variables.
After the CANN software is installed, log in to the environment as the CANN operating user and run the source ${INSTALL_DIR}/set_env.sh command to set environment variables. Replace ${INSTALL_DIR} with the CANN component directory. For example, if the installation is performed by the root user, the default file storage path is /usr/local/Ascend/cann.
Enabling AutoFuse
The AutoFuse framework supports fusing four types of operators: Elemwise, Broadcast, Reduce, and Concat. The fusion capabilities of the Elemwise and Broadcast operators are complete and are enabled by default as long as automatic fusion is enabled. The fusion of Reduce and Concat operators are disabled by default and can be enabled by setting additional environment variables. In the TensorFlow graph mode, you can enable automatic fusion by setting environment variables. These variables control functions and DFX. For automatic fusion out-of-the-box, only function control needs to be enabled. DFX control is used for fault locating or optimization. The environment variable for function control is AUTOFUSE_FLAGS, and that for DFX control is AUTOFUSE_DFX_FLAGS. The environment variable value is configured in the format of "--key=value". Each key represents a control point. Use semicolons (;) to separate multiple control points. Below are configuration examples:
- Function control
export AUTOFUSE_FLAGS="--enable_autofuse=true;--autofuse_enable_pass=reduce,concat"
- DFX control
export AUTOFUSE_DFX_FLAGS="--att_accuracy_level=1;--att_profiling=true"
AUTOFUSE_FLAGS environment variable and its control points
AUTOFUSE_DFX_FLAGS environment variable and its control points
|
Key |
Control Point |
|---|---|
|
--codegen_compile_debug |
Controls whether to retain the intermediate files generated during fused operator generation. Value:
Configuration example: --codegen_compile_debug=true If this key is set to true, the kernel_meta_* folder is generated in the script execution directory, including the generated kernel source code, tiling source code, CMake project, and compilation result. Constraints: none |
|
--autofuse_att_algorithm |
Controls the auto tiling algorithm. Value:
Configuration example: --autofuse_att_algorithm=HighPerf Restrictions:
|
|
--att_accuracy_level |
Controls the accuracy of the auto tiling algorithm. Theoretically, the higher the accuracy, the better the kernel performance. Value:
By default, the low-accuracy solution is used to ensure that the tiling time is not extended. Configuration example: --att_accuracy_level=1 Restrictions:
|
|
--att_enable_multicore_ub_tradeoff |
Controls whether to enable the att_corenum_threshold and att_ub_threshold functions. Value:
Configuration example: --att_enable_multicore_ub_tradeoff=true Restrictions: If an invalid value is configured, the default value is used. |
|
--att_ub_threshold |
Controls the tiling strategies for Auto Tiling to ensure that the tiling solution result is combined with the operator implementation. The UB usage is not lower than the value of this control point. If the UB usage does not meet the specified threshold, the maximum UB usage that can be solved is used. This control point helps locate performance-related problems. Value: an integer ranging from 0 to 100. The default value is 20. Configuration example: --att_ub_threshold=20 Restrictions:
|
|
--att_corenum_threshold |
Controls the tiling strategies for Auto Tiling to ensure that the tiling solution result is combined with the operator implementation. The multi-core usage is not lower than the value set for this control point. If the multi-core usage does not meet the specified threshold, the maximum multi-core usage that can be solved is used. This control point helps locate performance-related problems. Value: an integer ranging from 0 to 100. The default value is 40. When --att_enable_multicore_ub_tradeoff is enabled, the default value is 40. Otherwise, no strategy is set. Configuration example: --att_corenum_threshold=40 Restrictions:
|
|
--att_profiling |
Controls whether to enable profiling for Auto Tiling. Value:
Configuration example: --att_profiling=true Restrictions:
|
|
--disable_lifting |
Controls whether to disable the lifting function. Automatic fusion is used to fuse operators into a new operator named AscBackend, while lifting is used to roll back the AscBackend operator that does not meet the requirements to the original operators. Value:
Configuration example: --disable_lifting=true Restrictions: This control point is used only to locate the analysis problems of the Ascbackend rollback structure. Enabling this control point may cause the ApplyAdamD operator precision to be abnormal. |
|
--autofuse_pgo_algo |
Controls the PGO algorithm. The tiling method varies depending on the algorithm. Value:
By default, the core control algorithm is used to ensure that the tiling time is not too long. Theoretically, the pruning algorithm may obtain a better tiling solution, but the tiling takes much longer. Configuration example: --autofuse_enable_pgo=true --autofuse_pgo_algo=core_select Restrictions:
|
|
--autofuse_pgo_step_max |
Controls the step of the PGO pruning algorithm. Value: a power of 2 ranging from 2 to 1024. The default value is 16. Configuration example: --autofuse_enable_pgo=true --autofuse_pgo_algo=pruning --autofuse_pgo_step_max=16 Restrictions:
A smaller step value may result in a better tiling solution, but requires a longer tiling execution time. It is reverse for a larger step value.
|
|
--autofuse_pgo_topn |
Controls the number of solutions involved in PGO static tuning. Value:
Configuration example: --autofuse_enable_pgo=true --autofuse_pgo_topn=5 Restrictions:
|
The automatic fusion function can be enabled in the static shape scenario of offline inference. The method is as follows:
- Set an environment variable to enable automatic fusion. For example:
export AUTOFUSE_FLAGS="--enable_autofuse=true
- Model loading and inference
Use the acl API to load the generated OM model and perform inference.
For details about how to use the ATC tool, see ATC.
For details about how to use the GE API, see Building a Graph into an Offline Model.
For details about the acl API, see Application Development (C&C++) > Model Inference.