目录

Simulator

CAModel Performance Simulation

[h2]Function Description

Operator performance can be simulated on the simulator. Currently, the CAModel simulator is supported.

  • Due to the model accuracy issues, it is recommended that CAModel run only on a single core, which contributes to accurate simulation performance. If CAModel runs on multiple cores, it will lead to slow simulation performance and large error.

[h2]Procedure (CLI-based)

The key steps for performing performance simulation using the CLI are as follows:

  1. Set up the environment and prepare the input/golden data file.

  2. Run the following command to perform CAModel performance simulation. Only key parameters are provided. For details about other parameters, see Simulator Parameters.

    ascendebug kernel --backend simulator --repo-type customize --json-file ${op_config_json_file} --core-type ${core_type} --chip-version ${chip_version} --work-dir ${work_dir} --block-num 1 --timeout 1200 ... { Other parameters}

    Generally, CAModel simulation runs slowly. Usually, --timeout is set to 1200 seconds, and --block-num is set to 1. Set them as required.

  3. View the performance simulation result. For details, see Product Description.

[h2]Artifact Description

The CAModel simulation result is stored in the ${root}/${work_dir}/simulator directory. ${root} indicates the current operation path, ${work_dir} indicates the debugging workspace which defaults to the /debug_workspace/${op_type} directory, and ${op_type} indicates the operator name. The directory structure is as follows:

├ ${op_type} // Operator name
├── simulator
│   ├── build // Directory for storing the intermediate files generated after NPU compilation
│   │   ├── launch_args.so
│   │   └── run_Makefile_0.sh
│   ├── dump
│   │   ├── camodel
│   │   │   ├── log // Model execution log
│   │   └── dump_data
│   │       ├── 0 // Core ID
│   │       │   └── index_0 // Index is the unique identifier of the desc of the dump API.
│   │       └── index_dtype.json
│   ├── output // Directory for storing the output file after NPU compilation and running
│   │   ├── z.bin // Original data output by running
│   │   └── z.txt // Accuracy comparison result file
│   └── src // Directory for storing the temporary code files generated after NPU compilation
│       └── _gen_args_${op_type}.cpp

Model Simulation Dotting

[h2]Function Description

During CAModel operator simulation, dotting can be performed in any running phase of the operator, to analyze the pipeline chart of different instructions for further performance optimization.

Kirin 9020, Kirin 9030, and Kirin X90 do not support optimization using this method.

[h2]Usage

  1. Add TRACE_START and TRACE_STOP to the target instruction positions in the kernel code. The following is an example. For details about the start and stop APIs, see Trace API Description.

    TRACE_START(0x1);
    DataCopy(zGm, zLocal, this->totalLength);
    TRACE_STOP(0x1);
  2. Execute the operator simulation process by referring to the CLI method in How to Use (CLI).

  3. View the dotting result in the CAModel simulation result trace chart.

    As shown in the following figure, USER_DEFINE_1_DELAY indicates the duration from the time when the DataCopy instruction is delivered to the time when the instruction starts to be executed, and USER_DEFINE_1 indicates the time when the instruction is executed.

    Figure 1 Simulation breakpoints

[h2]Trace APIs

The description of the TRACE_START API is as follows:

The description of the TRACE_STOP API is as follows: