MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TEST

Function TEST

tensorflow/compiler/jit/extract_outside_compilation_pass_test.cc:40–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38namespace tensorflow {
39
40TEST(RewriteOutsideCompilationSubgraphFnTest, Basic) {
41 // Build the graph:
42 // "add" = "arg0" + "arg1"
43 // "ret0" = "add"
44 // "ret1" = "arg1"
45 tensorflow::Scope s = tensorflow::Scope::NewRootScope();
46 Output arg0 = ops::_Arg(s.WithOpName("arg0"), DT_INT32, 0);
47 Output arg1 = ops::_Arg(s.WithOpName("arg1"), DT_FLOAT, 1);
48 Output arg2 = ops::_Arg(s.WithOpName("arg2"), DT_INT32, 2);
49 Output add = ops::Add(s.WithOpName("add"), arg0, arg0);
50 auto ret0 = ops::_Retval(s.WithOpName("ret0"), add, 0);
51 auto ret1 = ops::_Retval(s.WithOpName("ret1"), arg1, 1);
52 std::unique_ptr<Graph> g(new Graph(OpRegistry::Global()));
53 TF_CHECK_OK(s.ToGraph(g.get()));
54 auto node_name_image = g->BuildNodeNameIndex();
55 Node *add_node = node_name_image["add"];
56 EXPECT_NE(add_node, nullptr);
57 add_node->AddAttr(kXlaConnectedToXlaComputationAttrName, "cluster");
58 add_node->AddAttr(kXlaConnectedFromXlaComputationAttrName, "cluster");
59
60 RewriteOutsideCompilationSubgraphFn rewrite_fn("_xla", "_oc", "cluster", "");
61 std::vector<OutputTensor> arg_source_tensors;
62 NodeDef call_node_def;
63 call_node_def.set_op("0");
64 TF_CHECK_OK(
65 rewrite_fn(arg_source_tensors, &g, nullptr, nullptr, &call_node_def));
66 node_name_image = g->BuildNodeNameIndex();
67
68 // Verify step 1: add key placeholder node.
69 Node *key_placeholder = node_name_image["cluster_key_placeholder"];
70 EXPECT_NE(key_placeholder, nullptr);
71 // Verify step 2: replace _Arg nodes with XlaRecvAtHost.
72 for (Node *n : g->nodes()) {
73 EXPECT_NE(n->type_string(), "_Arg");
74 }
75 Node *recv_at_host = node_name_image["outside_compilation_cluster__0_recv"];
76 EXPECT_NE(recv_at_host, nullptr);
77 std::vector<DataType> recv_at_host_dtypes;
78 TF_CHECK_OK(
79 GetNodeAttr(recv_at_host->attrs(), "Toutputs", &recv_at_host_dtypes));
80 EXPECT_EQ(recv_at_host_dtypes.size(), 3);
81 EXPECT_EQ(recv_at_host_dtypes[0], DT_INT32);
82 EXPECT_EQ(recv_at_host_dtypes[1], DT_FLOAT);
83 EXPECT_EQ(recv_at_host_dtypes[2], DT_INT32);
84 // Verify step 3: replace _Retval nodes with XlaSendFromHost.
85 for (Node *n : g->nodes()) {
86 EXPECT_NE(n->type_string(), "_Retval");
87 }
88 Node *send_from_host = node_name_image["outside_compilation_cluster__0_send"];
89 EXPECT_NE(send_from_host, nullptr);
90 std::vector<DataType> send_from_host_dtypes;
91 TF_CHECK_OK(
92 GetNodeAttr(send_from_host->attrs(), "Tinputs", &send_from_host_dtypes));
93 EXPECT_EQ(send_from_host_dtypes.size(), 2);
94 EXPECT_EQ(send_from_host_dtypes[0], DT_INT32);
95 EXPECT_EQ(send_from_host_dtypes[1], DT_FLOAT);
96 // Verify step 4: nodes marked with XLA cluster and outside compilation attr.
97 add_node = node_name_image["add"];

Callers

nothing calls this directly

Calls 15

AttrSliceClass · 0.85
WithOpNameMethod · 0.80
ToGraphMethod · 0.80
BuildNodeNameIndexMethod · 0.80
AddAttrMethod · 0.80
set_opMethod · 0.80
attrMethod · 0.80
ConstFunction · 0.70
nameMethod · 0.65
AddClass · 0.50
GetNodeAttrFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected