| 924 | } // namespace |
| 925 | |
| 926 | Status FunctionLibraryRuntimeImpl::CreateItem(Item** item) { |
| 927 | const FunctionBody* fbody; |
| 928 | FunctionLibraryRuntime* flr; |
| 929 | string executor_type; |
| 930 | { |
| 931 | tf_shared_lock l(mu_); |
| 932 | fbody = (*item)->func_graph; |
| 933 | flr = (*item)->overlay_flr |
| 934 | ? static_cast<FunctionLibraryRuntime*>((*item)->overlay_flr) |
| 935 | : static_cast<FunctionLibraryRuntime*>(this); |
| 936 | executor_type = (*item)->executor_type; |
| 937 | } |
| 938 | const FunctionLibraryDefinition* lib_def = |
| 939 | flr->GetFunctionLibraryDefinition(); |
| 940 | std::unique_ptr<Graph> g(new Graph(lib_def)); |
| 941 | CopyGraph(*fbody->graph, g.get()); |
| 942 | |
| 943 | PruneFunctionBody(fbody->fdef, g.get()); |
| 944 | optimizer_.Optimize(this, env(), device(), &g, /*shape_map=*/nullptr); |
| 945 | TF_RETURN_IF_ERROR(EnsureMemoryTypes(DeviceType(device()->device_type()), |
| 946 | device()->name(), g.get())); |
| 947 | |
| 948 | // Creates an executor based on the g. This must be done without |
| 949 | // holding mu_ because create_kernel_ calls back into the library. |
| 950 | LocalExecutorParams params; |
| 951 | params.device = device_; |
| 952 | params.function_library = flr; |
| 953 | if (flr == this) { |
| 954 | params.create_kernel = create_kernel_; |
| 955 | } else { |
| 956 | params.create_kernel = [this, flr](const NodeDef& ndef, OpKernel** kernel) { |
| 957 | return CreateKernel(ndef, flr, kernel); |
| 958 | }; |
| 959 | } |
| 960 | params.delete_kernel = [](OpKernel* kernel) { |
| 961 | DeleteNonCachedKernel(kernel); |
| 962 | }; |
| 963 | params.rendezvous_factory = (*item)->rendezvous_factory; |
| 964 | params.session_metadata = session_metadata_; |
| 965 | Graph* graph = g.get(); |
| 966 | std::unique_ptr<Executor> exec; |
| 967 | TF_RETURN_IF_ERROR(NewExecutor(executor_type, params, std::move(g), &exec)); |
| 968 | { |
| 969 | // Guard item since it is already inserted in items_. |
| 970 | mutex_lock l(mu_); |
| 971 | if ((*item)->exec == nullptr) { |
| 972 | (*item)->graph = graph; |
| 973 | (*item)->exec = exec.release(); |
| 974 | } |
| 975 | } |
| 976 | return Status::OK(); |
| 977 | } |
| 978 | |
| 979 | Status FunctionLibraryRuntimeImpl::GetOrCreateItem(LocalHandle local_handle, |
| 980 | Item** item) { |
nothing calls this directly
no test coverage detected