| 154 | } |
| 155 | |
| 156 | NodeOps* BindOps(Node* node, const std::string& dev_name) |
| 157 | { |
| 158 | CustomKernelList* k_list = any_cast<CustomKernelList>(&node->GetAttr(ATTR_CUSTOM_KERNEL)); |
| 159 | |
| 160 | struct custom_kernel_ops* ops = k_list->GetKernel(dev_name.c_str()); |
| 161 | |
| 162 | if(ops == nullptr) |
| 163 | { |
| 164 | /* try if there is any device support setting */ |
| 165 | ops = k_list->GetKernel(ANY_DEVICE_NAME); |
| 166 | |
| 167 | if(ops == nullptr) |
| 168 | return nullptr; |
| 169 | } |
| 170 | |
| 171 | Operator* op = node->GetOp(); |
| 172 | |
| 173 | if(op->GetName() != "Generic" && (op->GetName() != ops->op)) |
| 174 | { |
| 175 | XLOG_WARN() << "unmatched op: custom " << ops->op << " real " << op->GetName() << "\n"; |
| 176 | return nullptr; |
| 177 | } |
| 178 | |
| 179 | /* check bind */ |
| 180 | if(ops->bind != nullptr && !CheckBind(node, ops)) |
| 181 | { |
| 182 | if(ops->force) |
| 183 | { |
| 184 | LOG_ERROR() << "bind custom kernel for node: " << node->GetName() << " failed, but force is set\n"; |
| 185 | |
| 186 | set_tengine_errno(ENOTRECOVERABLE); |
| 187 | } |
| 188 | |
| 189 | return nullptr; |
| 190 | } |
| 191 | |
| 192 | NodeOps* node_ops = CustomKernelNodeOps::NewOps(node, ops); |
| 193 | |
| 194 | return node_ops; |
| 195 | } |
| 196 | |
| 197 | } // namespace CustomKernelManager |
| 198 |
no test coverage detected