• 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/xla/service/hlo_opcode.h"
17 
18 #include "tensorflow/compiler/xla/test.h"
19 #include "tensorflow/compiler/xla/types.h"
20 
21 namespace xla {
22 namespace {
23 
24 // This test verifies that an example HloOpcode stringifies as expected.
TEST(HloOpcodeTest,StringifyMultiply)25 TEST(HloOpcodeTest, StringifyMultiply) {
26   ASSERT_EQ("multiply", HloOpcodeString(HloOpcode::kMultiply));
27 }
28 
TEST(HloOpcodeTest,OpcodeProperties)29 TEST(HloOpcodeTest, OpcodeProperties) {
30   // Test counting macro.
31 #define SOME_LIST(X) \
32   X(One)             \
33   X(Two)             \
34   X(Three)
35   EXPECT_EQ(3, HLO_XLIST_LENGTH(SOME_LIST));
36 #undef SOME_LIST
37 
38   for (int i = 0; i < HloOpcodeCount(); ++i) {
39     auto opcode = static_cast<HloOpcode>(i);
40     // Test round-trip conversion to and from string.
41     EXPECT_EQ(opcode, StringToHloOpcode(HloOpcodeString(opcode)).ValueOrDie());
42 
43     // Test some properties.
44     switch (opcode) {
45       case HloOpcode::kCompare:
46         EXPECT_TRUE(HloOpcodeIsComparison(opcode));
47         break;
48       default:
49         EXPECT_FALSE(HloOpcodeIsComparison(opcode));
50     }
51     switch (opcode) {
52       case HloOpcode::kAfterAll:
53       case HloOpcode::kAllReduce:
54       case HloOpcode::kAllToAll:
55       case HloOpcode::kCall:
56       case HloOpcode::kConcatenate:
57       case HloOpcode::kConditional:
58       case HloOpcode::kCustomCall:
59       case HloOpcode::kDynamicSlice:
60       case HloOpcode::kDynamicUpdateSlice:
61       case HloOpcode::kDynamicReshape:
62       case HloOpcode::kFusion:
63       case HloOpcode::kMap:
64       case HloOpcode::kReduce:
65       case HloOpcode::kRng:
66       case HloOpcode::kSort:
67       case HloOpcode::kTuple:
68       case HloOpcode::kReduceWindow:
69         EXPECT_TRUE(HloOpcodeIsVariadic(opcode));
70         break;
71       default:
72         EXPECT_FALSE(HloOpcodeIsVariadic(opcode));
73     }
74   }
75 }
76 
77 }  // namespace
78 }  // namespace xla
79