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 #ifndef TENSORFLOW_COMPILER_XLA_SERVICE_FUSION_QUEUE_H_ 16 #define TENSORFLOW_COMPILER_XLA_SERVICE_FUSION_QUEUE_H_ 17 18 #include <utility> 19 20 #include "tensorflow/compiler/xla/service/hlo_instruction.h" 21 22 namespace xla { 23 24 // A queue interface that allows implementations to choose fusion candidates in 25 // custom order. 26 class FusionQueue { 27 public: 28 FusionQueue() = default; 29 virtual ~FusionQueue() = default; 30 31 // Dequeues the next fusion candidates: a consumer and the list of producers 32 // as operand indices. 33 virtual std::pair<HloInstruction*, std::vector<int64>> 34 DequeueNextInstructionAndOperandsToFuseInOrder() = 0; 35 36 // A callback passed to the queue implementation right before the producer is 37 // fused into the consumer. PreFusion(HloInstruction * producer,HloInstruction * consumer)38 virtual void PreFusion(HloInstruction* producer, HloInstruction* consumer) {} 39 40 // A callback passed to the queue implementation right after the fusion is 41 // created. Note that original_producer could have been destroyed. OnFusingInstruction(HloInstruction * fusion,HloInstruction * original_producer,HloInstruction * original_consumer)42 virtual void OnFusingInstruction(HloInstruction* fusion, 43 HloInstruction* original_producer, 44 HloInstruction* original_consumer) {} 45 46 // A callback passed to the queue implementation to notify the removal of an 47 // instruction. 48 virtual void RemoveInstruction(HloInstruction* instruction) = 0; 49 }; 50 51 } // namespace xla 52 53 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_FUSION_QUEUE_H_ 54