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 // The attribute that marks nodes in a cluster to be placed outside the xla 34 // compilation by the encapsulate subgraphs pass. 35 extern const char* const kXlaOutsideCompilationAttr; 36 37 // Marks a subset of nodes in the graph which are to be clustered 38 // with an attribute _XlaCluster=<cluster id> so they are picked up by the 39 // EncapsulateSubgraphsPass. 40 class MarkForCompilationPass : public GraphOptimizationPass { 41 public: 42 MarkForCompilationPass() = default; 43 44 Status Run(const GraphOptimizationPassOptions& options) override; 45 46 private: 47 Status RunForTest(const GraphOptimizationPassOptions& options, 48 bool disable_deadness_analysis); 49 50 friend class MarkForCompilationPassTestHelper; 51 }; 52 53 absl::flat_hash_map<string, std::vector<string>>* GetAllowlistTable(); 54 55 namespace testing { 56 // DO NOT USE IN PRODUCTION. 57 // 58 // Resets some internal state to let us write reliable unit tests. 59 void ResetClusterSequenceNumber(); 60 61 // Return a list of operation that we choose not to put into the allowlist. 62 absl::flat_hash_set<string> GetKnownXLAAllowlistOp(); 63 } // namespace testing 64 } // namespace tensorflow 65 66 #endif // TENSORFLOW_COMPILER_JIT_MARK_FOR_COMPILATION_PASS_H_ 67