The hierarchy of the model abstraction in MGX is shown as below:
flowchart LR
A[program] --> B[modules]
B --> C[instructions]
C --> D[op]
When reading a ONNX (or other formats) model, MGX will try to parse and represent it with the abstraction.
MGX will first try to finalize all operations in a program (i.e., all of its modules and all instructions in the modules), then invoke the compute function defined in each operation to evaluate the model.
When specifying a target (CPU, GPU or FPGA), MGX will obtain all its necessary passes via std::vector<pass> target::get_passes (e.g., from src/targets/gpu/target.cpp).
It returns all registered and supported optimization passes based on environment variables and device types.
After applying the optimization passes, the program will be finalized (determining what kernels to be used to achieve the semantic of operation).
Meanwhile, the operator parameters inferred at compile time will also be dumped to the saved .mxr model file, e.g., the MIOpen solution ID obtained from compile time tuning.
Many data structures in MGX follows the type erasure design pattern to hide the type information and expose the unified interfaces to outside.
Usually, the xxx struct contains the xxx_impl unique pointer with the real data member stored.
shape is described as dimension sizes and optional stride sizes.
In additional to fixed shape tensors, MGX also supports shapes with dynamic dimensions (with min and max values alongside the dimension).
argument is the structure to place the substantial data described by shape.