RegisterarV2::RegisterarV2(const std::string&, const KERNEL_CREATOR_FUN&)
Description
Constructor of the AI CPU operator kernel register V2. RegisterarV2 is an internal class of CpuKernelRegister and uses the RAII mechanism. When an object is constructed, the specified operator type and the corresponding creator function are registered with the V2 registry creatorMapV2_ of CpuKernelRegister. This function is the underlying implementation of the REGISTER_CPU_KERNELV2 macro and the RegistCpuKernelV2 API.
Different from Registerar::Registerar(const std::string&, const KERNEL_CREATOR_FUN&), this function is registered with the V2 registry for V2 APIs such as GetCpuKernelV2, RunCpuKernelV2, and IsRegisteredV2 to use.
Prototype
RegisterarV2(const std::string& type, const KERNEL_CREATOR_FUN& fun)
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
type |
Input |
Operator type, which is used as the key of the V2 registry. |
fun |
Input |
Creator function of type KERNEL_CREATOR_FUN (std::function<std::shared_ptr<CpuKernel>()>), which is used to create the corresponding kernel instance. |
Returns
None
Restrictions
The copy constructor cannot be used.
Example
class AddCpuKernelV2 : public CpuKernel {
public:
uint32_t Compute(CpuKernelContext& ctx) override { /* ... */ return 0; }
};
REGISTER_CPU_KERNELV2("Add", AddCpuKernelV2);
// Equivalent macro expansion. The RegistCpuKernelV2 internally constructs a RegisterarV2 object to complete the registration.
// CpuKernelRegister::RegisterarV2 AddRegisterarV2("Add", Creator_Add_Kernel);