IsRegisteredV2
Description
Queries whether a specified operator type has been registered in V2. The kernel is not instantiated.
Lightweight query API: Only checks whether opType exists in creatorMapV2. The kernel is not constructed using the creator function. This API is used by the upper layer in the V2 routing scenario to avoid the overhead caused by repeated construction.
Prototype
bool IsRegisteredV2(const std::string &opType) const
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
opType |
Input |
Operator type. |
Returns
Bool type. true indicates that the operator type has been registered in V2. false indicates that the operator type has not been registered in V2.
Restrictions
- Only the V2 registry is queried. V1 is not involved.
- No kernel instance is constructed, and the performance overhead is low.
Example
std::string op_type = "add";
if (CpuKernelRegister::Instance().IsRegisteredV2(op_type)) {
std::shared_ptr<CpuKernel> kernel = CpuKernelRegister::Instance().GetCpuKernelV2(op_type);
// Use V2kernel for execution.
} else {
std::shared_ptr<CpuKernel> kernel = CpuKernelRegister::Instance().GetCpuKernel(op_type);
// Fall back to V1kernel for execution.
}
Parent topic: Class CpuKernelRegister