Build thew new EagerOperation. In case of error, the returned 'op' is guaranteed to be 'nullptr'.
| 233 | // Build thew new EagerOperation. In case of error, the returned 'op' is |
| 234 | // guaranteed to be 'nullptr'. |
| 235 | tensorflow::Status BuildEagerOp(tensorflow::EagerContext* eager_context) { |
| 236 | op_.reset(); |
| 237 | |
| 238 | const tensorflow::AttrTypeMap* attr_types; |
| 239 | bool is_function = false; |
| 240 | TF_RETURN_WITH_CONTEXT_IF_ERROR( |
| 241 | tensorflow::AttrTypeMapForOp(name_.c_str(), &attr_types, &is_function), |
| 242 | " (while processing attributes of '", name_, "')"); |
| 243 | if (is_function) { |
| 244 | return tensorflow::errors::NotFound( |
| 245 | "Operation '", name_, |
| 246 | "' is not registered. (while processing attributes of '", name_, |
| 247 | "')"); |
| 248 | } |
| 249 | |
| 250 | op_.reset(new tensorflow::EagerOperation(eager_context, name_.c_str(), |
| 251 | /*is_function=*/false, |
| 252 | attr_types)); |
| 253 | |
| 254 | op_->MutableAttrs()->NumInputs(inputs_.Size()); |
| 255 | for (const auto& attr : nodedef_.attr()) { |
| 256 | op_->MutableAttrs()->Set(attr.first, attr.second); |
| 257 | } |
| 258 | |
| 259 | // Precalculating a cache key saves about 10% of inference time for very |
| 260 | // small models. |
| 261 | tensorflow::Device* device = op_->Device(); |
| 262 | op_->MutableAttrs()->CacheKey(device == nullptr ? "unspecified" |
| 263 | : device->name()); |
| 264 | |
| 265 | return tensorflow::Status::OK(); |
| 266 | } |
| 267 | |
| 268 | void ClearEagerInputs() { |
| 269 | for (tensorflow::TensorHandle* h : *op_->MutableInputs()) { |
no test coverage detected