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