1 /* Copyright 2016 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 #ifndef TENSORFLOW_COMPILER_XLA_SERVICE_HLO_SCHEDULING_H_ 17 #define TENSORFLOW_COMPILER_XLA_SERVICE_HLO_SCHEDULING_H_ 18 19 #include <vector> 20 21 #include "tensorflow/compiler/xla/service/hlo_instruction.h" 22 #include "tensorflow/compiler/xla/service/hlo_module.h" 23 #include "tensorflow/compiler/xla/service/hlo_ordering.h" 24 #include "tensorflow/compiler/xla/service/logical_buffer.h" 25 #include "tensorflow/compiler/xla/statusor.h" 26 #include "tensorflow/compiler/xla/types.h" 27 28 namespace xla { 29 30 // Returns the minimum memory required to compute the given module sequence, 31 // assuming no fragmentation. 32 StatusOr<int64> MinimumMemoryForSequence( 33 const SequentialHloOrdering::HloModuleSequence& module_sequence, 34 const LogicalBuffer::SizeFunction& size_function); 35 36 enum class SchedulerAlgorithm { 37 kListSchedule, 38 kDfsSchedule, 39 40 // Selects the available scheduler algorithm that had the minimum memory in 41 // the resulting sequence (a la MinimumMemoryForSequence). 42 kAuto, 43 }; 44 45 // Returns an HloModuleSequence which seeks to minimize the memory required for 46 // the computation. size_function is the function returning the number of bytes 47 // required for a LogicalBuffer. 48 StatusOr<SequentialHloOrdering::HloModuleSequence> 49 CreateMemoryMinimizingSequence( 50 const HloModule& module, const LogicalBuffer::SizeFunction& size_function, 51 SchedulerAlgorithm algorithm = SchedulerAlgorithm::kAuto); 52 53 // Overload of above that computes the sequence for a single computation. 54 StatusOr<std::vector<const HloInstruction*>> CreateMemoryMinimizingSequence( 55 const HloComputation& computation, 56 const LogicalBuffer::SizeFunction& size_function, 57 SchedulerAlgorithm algorithm = SchedulerAlgorithm::kAuto); 58 59 } // namespace xla 60 61 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_HLO_SCHEDULING_H_ 62