• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #include "tensorflow/compiler/tf2xla/test_util.h"
17 
18 #include "tensorflow/compiler/xla/status_macros.h"
19 #include "tensorflow/core/framework/node_def.pb.h"
20 
21 namespace tensorflow {
22 
InstantiateFunctionForTest(const string & name,const FunctionLibraryDefinition & library,InstantiationResultForTest * result)23 Status InstantiateFunctionForTest(const string& name,
24                                   const FunctionLibraryDefinition& library,
25                                   InstantiationResultForTest* result) {
26   const FunctionDef* fdef = library.Find(name);
27   TF_RET_CHECK(fdef != nullptr);
28 
29   auto get_func_sig = [&library](const string& op, const OpDef** sig) {
30     return library.LookUpOpDef(op, sig);
31   };
32   InstantiationResult inst;
33   TF_RETURN_IF_ERROR(
34       InstantiateFunction(*fdef, AttrSlice(), get_func_sig, &inst));
35   result->arg_types = inst.arg_types;
36   result->ret_types = inst.ret_types;
37   for (NodeDef& n : inst.nodes) {
38     *result->gdef.add_node() = std::move(n);
39   }
40   return OkStatus();
41 }
42 
43 }  // namespace tensorflow
44