GetCpuKernelV2

Description

Obtains the Compute function of the AI CPU operator kernel (V2 version).

V2 search accesses only creatorMapV2. If no match is found, nullptr is returned and the search does not fall back to V1. This function does not print "unregistered" logs. The caller outputs more informative logs (for example, which .so file is matched) based on the matching status.

Prototype

std::shared_ptr<CpuKernel> GetCpuKernelV2(const std::string &opType)

Parameters

Parameter

Input/Output

Description

opType

Input

Operator type.

Returns

std::shared_ptr <CpuKernel> type. If the V2 registry is matched, the corresponding kernel pointer is returned. If the V2 registry is not matched, nullptr is returned.

Restrictions

  • Search is performed only in the V2 registry. Fallback to V1 is not supported.
  • The "unregistered" log is not printed when the kernel is constructed using the creator function. The caller needs to handle the mismatching scenario.

Example

std::string op_type = "add";
std::shared_ptr<CpuKernel> kernel = CpuKernelRegister::Instance().GetCpuKernelV2(op_type);
if (kernel == nullptr) {
    // If no match is found in V2, fallback to V1 is allowed or more detailed information can be output.
    kernel = CpuKernelRegister::Instance().GetCpuKernel(op_type);
}