Building and Installing a Custom Operator Package
AMCT depends on a custom operator package based on the ONNX Runtime, while building a custom operator package depends on the ONNX Runtime header files. You need to download the header files, and then build and install a custom operator package
- Decompress the custom operator package.
tar -zvxf amct_onnx_op.tar.gz
The directory structure after decompression is as follows:
amct_onnx_op # Custom operator package root directory ├── inc # Directory of the header files for custom operator package building ?? src # Source file for implementing the custom operator. For details, see the official ONNX Runtime API description. └── setup.py # Build script that builds custom operators and copies the generated dynamic libraries to the AMCT package
The compilation of ONNX Runtime-based custom operators depends on the header file provided by ONNX Runtime. The file needs to be downloaded from GitHub online. If the server where AMCT is located has Internet access and can visit GitHub, go to 2. Otherwise, manually download the following files and upload them to the amct_onnx_op/inc directory on the AMCT server:
- onnxruntime_cxx_api.h
- onnxruntime_cxx_inline.h
- onnxruntime_c_api.h
- onnxruntime_session_options_config_keys.h
- onnxruntime_float16.h
The version of the downloaded header file must be the same as that of the ONNX Runtime. If a segmentation fault occurs when amct_onnx is imported, you are advised to delete the header file, uninstall amct_onnx, download the header file of the correct version, and reinstall amct_onnx.
- Go to the amct_onnx_op directory and build and install an AMCT custom operator package.
cd amct_onnx_op && python3 setup.py build
You should see the following output if the custom operator package is successfully built and installed. If the building fails, fix the error by referring to What Do I Do If "AttributeError: module 'onnxruntime' has no attribute 'SessionOption'" Is Displayed When Compiling and Installing a Custom Operator Package?
1 2
[INFO] Build amct_onnx_op success! [INFO] Install amct_onnx_op success!