xref: /aosp_15_r20/external/tensorflow/tensorflow/compiler/jit/mark_for_compilation_pass_test_helper.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2018 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_JIT_MARK_FOR_COMPILATION_PASS_TEST_HELPER_H_
17 #define TENSORFLOW_COMPILER_JIT_MARK_FOR_COMPILATION_PASS_TEST_HELPER_H_
18 
19 #include "tensorflow/compiler/jit/mark_for_compilation_pass.h"
20 
21 namespace tensorflow {
22 class MarkForCompilationPassTestHelper {
23  public:
24   struct Options {
25     bool enable_global_jit;
26     bool disable_deadness_analysis;
27     bool enable_cluster_scoping;
28     bool deterministic_cluster_names;
29 
OptionsOptions30     Options()
31         : enable_global_jit(true),
32           disable_deadness_analysis(true),
33           enable_cluster_scoping(true),
34           deterministic_cluster_names(false) {}
35 
WithNoGlobalJitOptions36     Options WithNoGlobalJit() {
37       Options copy = *this;
38       copy.enable_global_jit = false;
39       return copy;
40     }
41 
WithDeadnessAnalysisOptions42     Options WithDeadnessAnalysis() {
43       Options copy = *this;
44       copy.disable_deadness_analysis = false;
45       return copy;
46     }
47 
WithNoClusterScopingOptions48     Options WithNoClusterScoping() {
49       Options copy = *this;
50       copy.enable_cluster_scoping = false;
51       return copy;
52     }
53 
WithDeterministicClusterNamesOptions54     Options WithDeterministicClusterNames() {
55       Options copy = *this;
56       copy.deterministic_cluster_names = true;
57       return copy;
58     }
59   };
60 
61   // Runs the MarkForCompilation pass on `graph` after assigning all nodes in
62   // `graph` to the CPU device.  To make testing easier, ignores device
63   // registration and  _XlaCompile attributes.
64   static Status MarkForCompilation(std::unique_ptr<Graph>* graph,
65                                    FunctionLibraryDefinition* flib_def,
66                                    Options options = Options());
67 
68   // Like `MarkForCompilation` but creates `flib_def` from the op registry.
69   static Status MarkForCompilation(std::unique_ptr<Graph>* graph,
70                                    Options options = Options());
71 };
72 }  // namespace tensorflow
73 
74 #endif  // TENSORFLOW_COMPILER_JIT_MARK_FOR_COMPILATION_PASS_TEST_HELPER_H_
75