Overview

Overview

After analyzing an operator and defining the prototype, you can use MindStudio Ops Generator (msOpGen) to generate a custom operator project, compile the project, and deploy it. For details about the process, see Figure 1.

In TBE and AI CPU operator development scenarios, for details about how to use the msOpGen tool, see Creating an Operator Project Based on the msOpGen Tool and Compiling and Deploying Operators. The TBE/TIK operator development method is no longer used. Therefore, the TBE/TIK samples will be brought offline in the next MindStudio version.

It provides the following functions:

  • Outputs operator projects based on the operator prototype definition.
  • Outputs the operator simulation pipeline file based on the dump data file generated in the performance simulation environment.
Figure 1 Process of using the msOpGen tool

Features

msOpGen supports the following features: operator project generation, operator implementation (on both host and kernel), operator project compilation and deployment, and operator simulation pipeline file parsing.

Table 1 msOpGen functions

Function

Link

Operator project generation

Creating an Operator Project

Operator implementation (on both host and kernel)

Developing Operators

Operator project compilation and deployment

Compiling and Deploying Operators

Operator simulation pipeline file parsing

Viewing the Operator Simulation Pipeline

Commands

Run the following command. For details about the parameters, see Table 2.

After an operator template is generated based on the input configuration parameters, you are advised to check the security of the operator project code before running the template.

msopgen gen -i {*.json} -f {framework type} -c {Compute Resource} -lan cpp -out {Output Path}
Table 2 Parameters for generating an operator project

Parameter

Description

Required

gen

Generates operator deliverables.

Yes

-i, --input

Path of the operator prototype definition file (.json). The value can be an absolute path or a relative path. The user who executes the tool must have the read permission on the path.

Yes

-f, --framework

Framework type.

  • The default framework is TensorFlow. The default value is tf or tensorflow.
  • caffe: Caffe
    NOTE:

    Custom Ascend C operators do not support the Caffe framework.

  • pytorch: PyTorch
  • ms or mindspore: MindSpore
  • onnx: ONNX
NOTE:
  • The arguments are case-insensitive.
  • TBE and TIK do not support single-operator API call. By default, the TensorFlow framework is generated.
  • Ascend C operator projects support the TensorFlow framework, PyTorch framework, and single-operator API call. By default, the TensorFlow framework is generated.
  • When -f aclnn is used, a simple Ascend C operator project is generated. Otherwise, the original function is retained.

No

-lan, --language

Operator coding language.

  • cpp: Use C/C++ for operator development based on the Ascend C framework.
  • py: Use Python for operator development based on the DSL and TIK frameworks.

Defaults to py.

NOTE:

cpp applies only to Ascend C operator development.

No

-c, --compute_unit

  • Compute resources used by the operator.

    Configuration format: ai_core-{soc_version}. A hyphen (-) is used to connect ai_core and {soc_version}.

    Select the version according to the Ascend AI Processor in use.

NOTE:

The AI processor model <soc_version> can be obtained in the following ways:

  • Products except for Atlas A3 training products / Atlas A3 inference products : Run the npu-smi info command on the server where the Ascend AI Processor is installed to obtain the Chip Name information. The actual value is AscendChip Name. For example, if Chip Name is xxxyy, the actual value is Ascendxxxyy. If Ascendxxxyy is the code sample path, you need to set ascendxxxyy.
  • Atlas A3 training products / Atlas A3 inference products : Run the npu-smi info -t board -i id -c chip_id command on the server where the Ascend AI Processor is installed to obtain Chip Name and NPU Name. The actual value is Chip Name_NPU Name. For example, if the value of Chip Name is Ascendxxx and the value of NPU Name is 1234, the actual value is Ascendxxx_1234. If Ascendxxx_1234 is the code sample path, you need to set ascendxxx_1234.

    Note that:

    • id: device ID, which is the NPU ID obtained by running the npu-smi info -l command.
    • chip_id: chip ID, which is obtained by running the npu-smi info -m command.

Basic functions (operator development, compilation, and deployment based on the project) are applicable across operator projects created based on the same AI processor series.

  • For an AI CPU operator, set it to aicpu.
    NOTE:

    In the Atlas A3 training products / Atlas A3 inference products scenario, do not use the following compilation options. Otherwise, the machine will be abnormal.

    • -march=armv8-a+lse
    • -march=armv8.1-a
    • -march=armv8.2-a
    • -march=armv8.3-a

Yes

-out, --output

Sets the output path. The path can be either absolute or relative. The user who runs the tool must have the read and write permissions on the path.

If this option is not specified, the outputs are generated to the current path where the command is executed.

NOTE:

If a file with the same name as the template project exists in the specified output directory, the file in the output directory will be overwritten by the file in the template project.

No

-m, --mode

Sets the deliverable generation mode.

  • 0: generates the deliverables to a new operator project. If an operator project exists in the specified path, an error is reported and the tool exits.
  • 1: generates the deliverables to an existing operator project.

Defaults to 0.

No

-op, --operator

Operator type, for example, Conv2DTik.

If it is not set, the tool prompts you to select an operator when there are multiple operators in the operator prototype definition file.

No

-h, --help

Outputs the help information.

No

Supplementary Notes

For details about other parameters of the msOpGen tool, see Table 3.

Table 3 Parameters

Parameter

Description

Remarks

compile

Used when compiling a TBE&AI CPU operator project.

For details, see Independent Building of Operator Deliverables.