Module API Reference
The Module is the base class for operators in esp-dl, and all operators inherit from this base class. This base class defines the basic interfaces for operators, enabling the model layer to automatically execute operators and manage memory planning.
Header File
Classes
-
class Module
Base class for module.
Public Functions
-
Module(const char *name = NULL, module_inplace_t inplace = MODULE_NON_INPLACE, quant_type_t quant_type = QUANT_TYPE_NONE)
Construct a new Module object.
- 参数
name – Name of module.
inplace – Inplace operation mode
quant_type – Quantization type
-
inline virtual std::vector<int> get_outputs_index()
Get the tensor index of this module’s outputs.
- 返回
Tensor index of model’s tensors
-
virtual std::vector<std::vector<int>> get_output_shape(std::vector<std::vector<int>> &input_shapes) = 0
Calculate output shape by input shape.
- 参数
input_shapes – Input shapes
- 返回
outputs shapes
-
virtual void forward(ModelContext *context, runtime_mode_t mode = RUNTIME_MODE_AUTO) = 0
Build the module, high-level inferface for Module layer.
- 参数
context – Model context including all inputs and outputs and other runtime information
mode – Runtime mode, default is RUNTIME_MODE_AUTO
-
inline virtual void forward_args(void *args)
Run the module, Low-level interface for base layer and multi-core processing.
- 参数
args – ArgsType, arithArgsType, resizeArgsType and so on
-
inline virtual void print()
print module information
-
inline virtual void set_preload_addr(void *addr, size_t size)
set preload RAM pointer
- 参数
addr – Internal RAM address, should be aligned to 16 bytes
size – The size of RAM address
-
inline virtual void preload()
Perform a preload operation.
警告
Not implemented
-
inline virtual void reset()
reset all state of module, include inputs, outputs and preload cache setting
-
virtual void run(TensorBase *input, TensorBase *output, runtime_mode_t mode = RUNTIME_MODE_AUTO)
Run the module with single input and single output.
- 参数
input – Input tensor
output – Output tensor
mode – Runtime mode
-
virtual void run(std::vector<dl::TensorBase*> inputs, std::vector<dl::TensorBase*> outputs, runtime_mode_t mode = RUNTIME_MODE_AUTO)
Run the module by inputs and outputs.
- 参数
inputs – Input tensors
outputs – Output tensors
mode – Runtime mode
Public Members
-
char *name
Name of module.
-
module_inplace_t inplace
Inplace type.
-
quant_type_t quant_type
Quantization type.
-
std::vector<int> m_inputs_index
Tensor index of model’s tensors that used for inputs.
-
std::vector<int> m_outputs_index
Tensor index of model’s tensors that used for outputs.
-
Module(const char *name = NULL, module_inplace_t inplace = MODULE_NON_INPLACE, quant_type_t quant_type = QUANT_TYPE_NONE)
Header File
Classes
-
class ModuleCreator
Singleton class for registering modules.
Public Types
Public Functions
-
inline void register_module(const std::string &op_type, Creator creator)
Register a module creator to the module creator map This function allows for the dynamic registration of new module types and their corresponding creator functions at runtime. By associating the module type name with the creator function, the system can flexibly create instances of various modules.
- 参数
op_type – The module type name, used as the key in the map
creator – The module creator function, used to create modules of a specific type
-
inline Module *create(fbs::FbsModel *fbs_model, const std::string &op_type, const std::string name)
Create module instance pointer.
-
inline void register_dl_modules()
Pre-register the already implemented modules.
-
inline void print()
Print all modules has been registered.
-
inline void clear()
Clear all modules has been registered.
Public Static Functions
-
static inline ModuleCreator *get_instance()
Get instance of ModuleCreator by this function. It is only safe method to get instance of ModuleCreator becase ModuleCreator is a singleton class.
- 返回
ModuleCreator instance pointer
-
inline void register_module(const std::string &op_type, Creator creator)