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

Function TEST

tensorflow/compiler/tf2xla/xla_jit_compiled_cpu_function_test.cc:86–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84}
85
86TEST(XlaJitCompiledCpuFunction, Sum) {
87 GraphDef graph_def = SumGraph();
88 tf2xla::Config config = SumConfig();
89
90 TF_ASSERT_OK_AND_ASSIGN(
91 std::unique_ptr<XlaJitCompiledCpuFunction> jit,
92 XlaJitCompiledCpuFunction::Compile(graph_def, config,
93 xla::ExecutableBuildOptions()));
94 XlaCompiledCpuFunction function(jit->StaticData());
95
96 // Run the function and check results.
97 *static_cast<int32*>(function.arg_data(0)) = 10;
98 *static_cast<int32*>(function.arg_data(1)) = 32;
99 EXPECT_TRUE(function.Run());
100 EXPECT_EQ(function.error_msg(), "");
101 EXPECT_EQ(*static_cast<int32*>(function.result_data(0)), 42);
102
103 // Run the function again.
104 *static_cast<int32*>(function.arg_data(0)) = 100;
105 *static_cast<int32*>(function.arg_data(1)) = 320;
106 EXPECT_TRUE(function.Run());
107 EXPECT_EQ(function.error_msg(), "");
108 EXPECT_EQ(*static_cast<int32*>(function.result_data(0)), 420);
109
110 // Check name to index lookups.
111 EXPECT_TRUE(function.HasNameIndices());
112
113 EXPECT_EQ(function.LookupArgIndex("x_name"), 0);
114 EXPECT_EQ(function.LookupArgIndex("y_name"), 1);
115 EXPECT_EQ(function.LookupArgIndex(""), -1);
116 EXPECT_EQ(function.LookupArgIndex("x"), -1);
117 EXPECT_EQ(function.LookupArgIndex("y"), -1);
118 EXPECT_EQ(function.LookupArgIndex("sum"), -1);
119 EXPECT_EQ(function.LookupArgIndex("sum_name"), -1);
120
121 EXPECT_EQ(function.LookupResultIndex("sum_name"), 0);
122 EXPECT_EQ(function.LookupResultIndex(""), -1);
123 EXPECT_EQ(function.LookupResultIndex("x"), -1);
124 EXPECT_EQ(function.LookupResultIndex("y"), -1);
125 EXPECT_EQ(function.LookupResultIndex("sum"), -1);
126 EXPECT_EQ(function.LookupResultIndex("x_name"), -1);
127 EXPECT_EQ(function.LookupResultIndex("y_name"), -1);
128
129 // Check program shape.
130 using xla::ShapeUtil;
131 const xla::Shape s32 = ShapeUtil::MakeShape(xla::S32, {});
132 ASSERT_TRUE(function.ProgramShape() != nullptr);
133 const xla::ProgramShape program_shape(*function.ProgramShape());
134 ASSERT_EQ(program_shape.parameters_size(), 2);
135 EXPECT_TRUE(ShapeUtil::Compatible(program_shape.parameters(0), s32));
136 EXPECT_TRUE(ShapeUtil::Compatible(program_shape.parameters(1), s32));
137
138 const xla::Shape& result = program_shape.result();
139 ASSERT_EQ(result.element_type(), xla::TUPLE);
140 ASSERT_EQ(ShapeUtil::TupleElementCount(result), 1);
141 const xla::Shape& result0 = ShapeUtil::GetTupleElementShape(result, 0);
142 EXPECT_TRUE(ShapeUtil::Compatible(result0, s32));
143}

Callers

nothing calls this directly

Calls 15

MakeShapeFunction · 0.85
CompatibleClass · 0.85
arg_dataMethod · 0.80
error_msgMethod · 0.80
result_dataMethod · 0.80
HasNameIndicesMethod · 0.80
LookupArgIndexMethod · 0.80
LookupResultIndexMethod · 0.80
parameters_sizeMethod · 0.80
SumGraphFunction · 0.70
SumConfigFunction · 0.70

Tested by

no test coverage detected