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 // A collection of utilities on the HLO graph. 17 18 #ifndef TENSORFLOW_COMPILER_XLA_SERVICE_LIVENESS_UTIL_H_ 19 #define TENSORFLOW_COMPILER_XLA_SERVICE_LIVENESS_UTIL_H_ 20 21 #include "tensorflow/compiler/xla/service/hlo_dataflow_analysis.h" 22 #include "tensorflow/compiler/xla/service/hlo_instruction.h" 23 #include "tensorflow/compiler/xla/service/tuple_points_to_analysis.h" 24 #include "tensorflow/compiler/xla/shape_util.h" 25 #include "tensorflow/compiler/xla/types.h" 26 27 namespace xla { 28 29 // Returns true if 'user' cannot possibly use the buffer at 'index' in 30 // 'operand'. Returns false otherwise. 31 // 32 // REQUIRES: 'operand' is an operand of 'user'. 33 // 34 // TODO(b/65835246): Remove TuplePointsToAnalysis overload when all users have 35 // moved over to the dataflow overload. 36 bool DoesNotUseOperandBuffer(const HloInstruction* operand, 37 const ShapeIndex& index, 38 const HloInstruction* user, 39 const TuplePointsToAnalysis& points_to_analysis); 40 bool DoesNotUseOperandBuffer(const HloInstruction* operand, 41 const ShapeIndex& index, 42 const HloInstruction* user, 43 const HloDataflowAnalysis& dataflow); 44 45 // Returns true if 'user' (at 'user_index') can share a buffer with its operand 46 // 'operand' (at 'operand_index'). Returns false otherwise. 47 // 48 // REQUIRES: 'operand' is an operand of 'user'. 49 // 50 // TODO(b/65835246): Remove TuplePointsToAnalysis overload when all users have 51 // moved over to the dataflow overload. 52 bool CanShareOperandBufferWithUser( 53 HloInstruction* operand, const ShapeIndex& operand_index, 54 HloInstruction* user, const ShapeIndex& user_index, 55 const TuplePointsToAnalysis& points_to_analysis); 56 bool CanShareOperandBufferWithUser(HloInstruction* operand, 57 const ShapeIndex& operand_index, 58 HloInstruction* user, 59 const ShapeIndex& user_index, 60 const HloDataflowAnalysis& dataflow); 61 62 } // namespace xla 63 64 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_LIVENESS_UTIL_H_ 65