Overview

Overview

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

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.

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:

  • 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.

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.

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

-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.

No

Supplementary Notes

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

Table 3 mi parameters

Parameter

Description

Remarks

mi

This parameter is used only on MindStudio.

Machine-machine interface, which can be ignored by users.

query

Stores all ops in the sheet when the JSON file is generated based on the prototype definition file.

Table 4 compile parameters

Parameter

Description

Description

compile

Used when compiling a TBE&AI CPU operator project.

For details, see "Operator Build and Deployment > Independent Build of Operator Deliverables" in TBE&AI CPU operator development guide .