Operator Compilation Porting Guide
During operator compilation, you need to be aware of different architectures and AI processor models.
- In the heterogeneous compilation scenario, if you use command lines or a CMake file for compilation, you need to manually change the NPU architecture version or AI processor model. For example, to change the NPU architecture version, modify the --npu-arch configuration in the compilation command line or the CMakeLists.txt file of the compilation project. The following is an example:
... target_compile_options(demo PRIVATE // Replace xxxx in dav-xxxx with the corresponding NPU architecture version. $<$<COMPILE_LANGUAGE:ASC>:--npu-arch=dav-xxxx> ) - For a standard custom operator project generated using the msOpGen tool, the compilation configuration file CMakePresets.json is automatically generated in the operator project directory and the ASCEND_COMPUTE_UNIT field is automatically filled in the file. When defining the operator prototype, you need to call the AddConfig API to register the AI processor models supported by the operator and related configurations. The prototype of the AddConfig API is as follows: The soc parameter indicates the AI processor model, and the aicore_config parameter indicates other configuration.
1 2
void AddConfig(const char *soc); void AddConfig(const char *soc, OpAICoreConfig &aicore_config);
The following is an example of registering the AI processor model through this API. For details about how to set ascendxxx, see the ASCEND_COMPUTE_UNIT field in the compilation configuration file CMakePresets.json in the operator project directory. The value of this field is automatically generated when msOpGen is used to create the project.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
... namespace ops { class AddCustom : public OpDef { public: AddCustom(const char* name) : OpDef(name) { ... // Replace ascendXXX with the corresponding chip version. this->AICore().AddConfig("ascendxxx"); } }; OP_ADD(AddCustom); } // namespace ops
Parent topic: 220x-to-351x Porting Guide