• 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/dfs_hlo_visitor.h"
17 
18 #include <string>
19 
20 #include "tensorflow/compiler/xla/service/hlo_instruction.h"
21 #include "tensorflow/compiler/xla/types.h"
22 #include "tensorflow/compiler/xla/util.h"
23 #include "tensorflow/core/platform/logging.h"
24 
25 namespace xla {
26 
27 template <typename HloInstructionPtr>
HandleElementwiseUnary(HloInstructionPtr hlo)28 Status DfsHloVisitorBase<HloInstructionPtr>::HandleElementwiseUnary(
29     HloInstructionPtr hlo) {
30   return Unimplemented("DfsHloVisitor::HandleElementwiseUnary: %s",
31                        HloOpcodeString(hlo->opcode()));
32 }
33 
34 template <typename HloInstructionPtr>
HandleElementwiseBinary(HloInstructionPtr hlo)35 Status DfsHloVisitorBase<HloInstructionPtr>::HandleElementwiseBinary(
36     HloInstructionPtr hlo) {
37   return Unimplemented("DfsHloVisitor::HandleElementwiseBinary: %s",
38                        HloOpcodeString(hlo->opcode()));
39 }
40 
41 template <typename HloInstructionPtr>
42 typename DfsHloVisitorBase<HloInstructionPtr>::VisitState
GetVisitState(const HloInstruction & instruction)43 DfsHloVisitorBase<HloInstructionPtr>::GetVisitState(
44     const HloInstruction& instruction) {
45   return GetVisitState(instruction.unique_id());
46 }
47 
48 template <typename HloInstructionPtr>
SetVisiting(const HloInstruction & instruction)49 void DfsHloVisitorBase<HloInstructionPtr>::SetVisiting(
50     const HloInstruction& instruction) {
51   VLOG(3) << "marking HLO " << &instruction << " as visiting: ";
52   DCHECK(NotVisited(instruction));
53   visit_state_[instruction.unique_id()] = VisitState::kVisiting;
54 }
55 
56 template <typename HloInstructionPtr>
SetVisited(const HloInstruction & instruction)57 void DfsHloVisitorBase<HloInstructionPtr>::SetVisited(
58     const HloInstruction& instruction) {
59   VLOG(3) << "marking HLO " << &instruction << " as visited: ";
60   DCHECK(NotVisited(instruction) || IsVisiting(instruction));
61   visit_state_[instruction.unique_id()] = VisitState::kVisited;
62 }
63 
64 template <typename HloInstructionPtr>
Preprocess(HloInstructionPtr)65 Status DfsHloVisitorBase<HloInstructionPtr>::Preprocess(HloInstructionPtr) {
66   return Status::OK();
67 }
68 
69 template <typename HloInstructionPtr>
Postprocess(HloInstructionPtr)70 Status DfsHloVisitorBase<HloInstructionPtr>::Postprocess(HloInstructionPtr) {
71   return Status::OK();
72 }
73 
74 // Explicit instantiations.
75 template class DfsHloVisitorBase<HloInstruction*>;
76 template class DfsHloVisitorBase<const HloInstruction*>;
77 
78 }  // namespace xla
79