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_XLA_SERVICE_HLO_DOMAIN_VERIFIER_H_ 17 #define TENSORFLOW_COMPILER_XLA_SERVICE_HLO_DOMAIN_VERIFIER_H_ 18 19 #include <string> 20 #include <vector> 21 22 #include "tensorflow/compiler/xla/service/hlo_domain_map.h" 23 #include "tensorflow/compiler/xla/service/hlo_domain_metadata.h" 24 #include "tensorflow/compiler/xla/service/hlo_module.h" 25 #include "tensorflow/compiler/xla/service/hlo_pass_interface.h" 26 #include "tensorflow/core/lib/core/status.h" 27 28 namespace xla { 29 30 // Verifies that the domain instructions are consistent, and the each domain is 31 // surrounded by the same metadata. 32 class HloDomainVerifier : public HloModulePass { 33 public: HloDomainVerifier(std::vector<string> kinds)34 HloDomainVerifier(std::vector<string> kinds) : kinds_(std::move(kinds)) {} 35 name()36 absl::string_view name() const override { return "domain_verifier"; } 37 38 StatusOr<bool> Run(HloModule* module) override; 39 40 // Verify that the whole kDomain frontier bounding the instruction reach set, 41 // has matching metadata. 42 // A kDomain instruction has two sides of metadata, a user facing and an 43 // operand facing. 44 // A reachable instruction set can make contact with a kDomain instruction on 45 // a user facing side (the kDomain is operand of the instruction), or on a 46 // operand facing side (the kDomain is user of the instruction). 47 // And depending on the contact side, the proper metadata object 48 // (user_side_metadata() vs. operand_side_metadata()) needs to be used for 49 // consistency checks. 50 // Returns the DomainMetadata pointer which surrounds the domain, and 51 // represents the common metadata within such domain. If the returned 52 // DomainMetadata pointer is nullptr, the input domain had no kDomain 53 // boundary. 54 static StatusOr<const DomainMetadata*> VerifyDomain( 55 const DomainMetadata::Domain& domain); 56 57 private: 58 class RunContext; 59 60 std::vector<string> kinds_; 61 }; 62 63 } // namespace xla 64 65 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_HLO_DOMAIN_VERIFIER_H_ 66