Home | History | Annotate | Download | only in service
      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.
     25 TEST(HloOpcodeTest, StringifyMultiply) {
     26   ASSERT_EQ("multiply", HloOpcodeString(HloOpcode::kMultiply));
     27 }
     28 
     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::kEq:
     46       case HloOpcode::kNe:
     47       case HloOpcode::kGt:
     48       case HloOpcode::kLt:
     49       case HloOpcode::kGe:
     50       case HloOpcode::kLe:
     51         EXPECT_TRUE(HloOpcodeIsComparison(opcode));
     52         break;
     53       default:
     54         EXPECT_FALSE(HloOpcodeIsComparison(opcode));
     55     }
     56     switch (opcode) {
     57       case HloOpcode::kCall:
     58       case HloOpcode::kConcatenate:
     59       case HloOpcode::kFusion:
     60       case HloOpcode::kMap:
     61       case HloOpcode::kTuple:
     62         EXPECT_TRUE(HloOpcodeIsVariadic(opcode));
     63         break;
     64       default:
     65         EXPECT_FALSE(HloOpcodeIsVariadic(opcode));
     66     }
     67   }
     68 }
     69 
     70 }  // namespace
     71 }  // namespace xla
     72