aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/compiler/xla/service/hlo_opcode_test.cc
blob: 6f3f83f63a05fafaa3f3ddcff8a7cac7cb7b06d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#include "tensorflow/compiler/xla/service/hlo_opcode.h"

#include "tensorflow/compiler/xla/test.h"
#include "tensorflow/compiler/xla/types.h"

namespace xla {
namespace {

// This test verifies that an example HloOpcode stringifies as expected.
TEST(HloOpcodeTest, StringifyMultiply) {
  ASSERT_EQ("multiply", HloOpcodeString(HloOpcode::kMultiply));
}

TEST(HloOpcodeTest, OpcodeProperties) {
  // Test counting macro.
#define SOME_LIST(X) \
  X(One)             \
  X(Two)             \
  X(Three)
  EXPECT_EQ(3, HLO_XLIST_LENGTH(SOME_LIST));
#undef SOME_LIST

  for (int i = 0; i < HloOpcodeCount(); ++i) {
    auto opcode = static_cast<HloOpcode>(i);
    // Test round-trip conversion to and from string.
    EXPECT_EQ(opcode, StringToHloOpcode(HloOpcodeString(opcode)).ValueOrDie());

    // Test some properties.
    switch (opcode) {
      case HloOpcode::kEq:
      case HloOpcode::kNe:
      case HloOpcode::kGt:
      case HloOpcode::kLt:
      case HloOpcode::kGe:
      case HloOpcode::kLe:
        EXPECT_TRUE(HloOpcodeIsComparison(opcode));
        break;
      default:
        EXPECT_FALSE(HloOpcodeIsComparison(opcode));
    }
    switch (opcode) {
      case HloOpcode::kCall:
      case HloOpcode::kConcatenate:
      case HloOpcode::kFusion:
      case HloOpcode::kMap:
      case HloOpcode::kAfterAll:
      case HloOpcode::kTuple:
        EXPECT_TRUE(HloOpcodeIsVariadic(opcode));
        break;
      default:
        EXPECT_FALSE(HloOpcodeIsVariadic(opcode));
    }
  }
}

}  // namespace
}  // namespace xla