Registerar::Registerar(const std::string&, const KERNEL_CREATOR_FUN&)

Description

Constructor of the AI CPU operator kernel register V1. Registerar 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 V1 registry creatorMap_ of CpuKernelRegister. This function is the underlying implementation of the REGISTER_CPU_KERNEL macro and the RegistCpuKernel API. It is used by operator developers to register their kernel classes with the framework factory.

Prototype

Registerar(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 V1 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

None

Example

class AddCpuKernel : public CpuKernel {
public:
    uint32_t Compute(CpuKernelContext& ctx) override { /* ... */ return 0; }
};
REGISTER_CPU_KERNEL("Add", AddCpuKernel);

// Equivalent macro expansion. The RegistCpuKernel internally constructs a Registerar object to complete the registration.
// CpuKernelRegister::Registerar AddRegisterar("Add", Creator_Add_Kernel);