| 229 | ~CaseOp() override {} |
| 230 | |
| 231 | void ComputeAsync(OpKernelContext* ctx, DoneCallback done) override { |
| 232 | auto lib = ctx->function_library(); |
| 233 | OP_REQUIRES_ASYNC(ctx, lib != nullptr, |
| 234 | errors::Internal("No function library"), done); |
| 235 | |
| 236 | // TODO(b/37549631): Because this op has `SetIsStateful()` in its op |
| 237 | // registration, this kernel may be shared by multiple subgraphs, which have |
| 238 | // different associated `FunctionLibraryRuntime` objects and hence different |
| 239 | // `FHandle` namespaces. So we must call Instantiate() to make sure we get |
| 240 | // the correct function handles with respect to `lib`. Note the underlying |
| 241 | // `lib->Instantiate()` caches the created function handles, so calling |
| 242 | // `Instantiate()` repeatedly on the same `lib` and function is cheap. |
| 243 | std::vector<FHandle> branch_handles(branch_funcs_.size()); |
| 244 | for (int i = 0; i < branch_funcs_.size(); i++) { |
| 245 | OP_REQUIRES_OK_ASYNC( |
| 246 | ctx, Instantiate(lib, branch_funcs_[i], &branch_handles[i]), done); |
| 247 | } |
| 248 | |
| 249 | const Tensor& branch_index = ctx->input(0); |
| 250 | OP_REQUIRES_ASYNC(ctx, TensorShapeUtils::IsScalar(branch_index.shape()), |
| 251 | errors::InvalidArgument("branch_index must be scalar"), |
| 252 | done); |
| 253 | int32 branch = branch_index.scalar<int32>()(); |
| 254 | (new State(this, ctx, branch, branch_handles, done))->Start(); |
| 255 | } |
| 256 | |
| 257 | private: |
| 258 | std::vector<NameAttrList> branch_funcs_; |
nothing calls this directly
no test coverage detected