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 // This demonstrates how to use hlo_test_base to create textual IR based
17 // testcases.
18
19 #include <string>
20 #include <vector>
21
22 #include "absl/types/optional.h"
23 #include "tensorflow/compiler/xla/test.h"
24 #include "tensorflow/compiler/xla/tests/hlo_test_base.h"
25 #include "tensorflow/compiler/xla/tests/literal_test_util.h"
26 #include "tensorflow/compiler/xla/tests/test_macros.h"
27 #include "tensorflow/compiler/xla/types.h"
28 #include "tensorflow/core/platform/types.h"
29
30 namespace xla {
31 namespace {
32
33 using absl::nullopt;
34
35 class SampleTextTest : public HloTestBase {};
36
TEST_F(SampleTextTest,Axpy)37 TEST_F(SampleTextTest, Axpy) {
38 const string& hlo_string = R"(
39 HloModule axpy_module:
40 ENTRY %axpy.v5 (alpha: f32[], x: f32[2,4], y: f32[2,4]) -> f32[2,4] {
41 %alpha = f32[] parameter(0)
42 %broadcast = f32[2,4]{1,0} broadcast(f32[] %alpha), dimensions={}
43 %x = f32[2,4]{1,0} parameter(1)
44 %multiply = f32[2,4]{1,0} multiply(f32[2,4]{1,0} %broadcast, f32[2,4]{1,0} %x)
45 %y = f32[2,4]{1,0} parameter(2)
46 ROOT %add = f32[2,4]{1,0} add(f32[2,4]{1,0} %multiply, f32[2,4]{1,0} %y)
47 }
48 )";
49 EXPECT_TRUE(RunAndCompareNoHloPasses(hlo_string, ErrorSpec{0.0001}));
50 }
51
TEST_F(SampleTextTest,Tuple)52 TEST_F(SampleTextTest, Tuple) {
53 const string& hlo_string = R"(
54 HloModule TupleCreate_module:
55 ENTRY %TupleCreate.v4 (v1: f32[], v2: f32[3], v3: f32[2,3]) -> (f32[], f32[3], f32[2,3]) {
56 %v1 = f32[] parameter(0)
57 %v2 = f32[3]{0} parameter(1)
58 %v3 = f32[2,3]{1,0} parameter(2)
59 ROOT %tuple = (f32[], f32[3]{0}, f32[2,3]{1,0}) tuple(f32[] %v1, f32[3]{0} %v2, f32[2,3]{1,0} %v3)
60 }
61 )";
62 EXPECT_TRUE(RunAndCompare(hlo_string, nullopt));
63 }
64
65 } // namespace
66 } // namespace xla
67