xref: /aosp_15_r20/external/tensorflow/tensorflow/compiler/jit/mark_for_compilation_pass.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
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 // An optimization passes that marks nodes that are to be compiled with
17 // attribute kXlaClusterAttr. Nodes with the same cluster ID will be compiled
18 // together.
19 
20 #ifndef TENSORFLOW_COMPILER_JIT_MARK_FOR_COMPILATION_PASS_H_
21 #define TENSORFLOW_COMPILER_JIT_MARK_FOR_COMPILATION_PASS_H_
22 
23 #include "absl/container/flat_hash_set.h"
24 #include "tensorflow/compiler/jit/compilability_check_util.h"
25 #include "tensorflow/core/common_runtime/optimization_registry.h"
26 
27 namespace tensorflow {
28 
29 // The attribute that marks nodes to be grouped into functions by the
30 // encapsulate subgraphs pass.
31 extern const char* const kXlaClusterAttr;
32 
33 // Marks a subset of nodes in the graph which are to be clustered
34 // with an attribute _XlaCluster=<cluster id> so they are picked up by the
35 // EncapsulateSubgraphsPass.
36 class MarkForCompilationPass : public GraphOptimizationPass {
37  public:
38   MarkForCompilationPass() = default;
39 
40   Status Run(const GraphOptimizationPassOptions& options) override;
41 
42  private:
43   Status RunForTest(const GraphOptimizationPassOptions& options,
44                     bool disable_deadness_analysis,
45                     bool deterministic_cluster_names);
46 
47   friend class MarkForCompilationPassTestHelper;
48 };
49 
50 absl::flat_hash_map<string, std::vector<string>>* GetAllowlistTable();
51 
52 namespace testing {
53 // DO NOT USE IN PRODUCTION.
54 //
55 // Resets some internal state to let us write reliable unit tests.
56 void ResetClusterSequenceNumber();
57 
58 // Return a list of operation that we choose not to put into the allowlist.
59 absl::flat_hash_set<string> GetKnownXLAAllowlistOp();
60 }  // namespace testing
61 }  // namespace tensorflow
62 
63 #endif  // TENSORFLOW_COMPILER_JIT_MARK_FOR_COMPILATION_PASS_H_
64