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_REMOVER_H_ 17 #define TENSORFLOW_COMPILER_XLA_SERVICE_HLO_DOMAIN_REMOVER_H_ 18 19 #include "tensorflow/compiler/xla/service/hlo_domain_metadata.h" 20 #include "tensorflow/compiler/xla/service/hlo_module.h" 21 #include "tensorflow/compiler/xla/service/hlo_pass_interface.h" 22 #include "tensorflow/core/lib/core/status.h" 23 24 namespace xla { 25 26 // Removes all the kDomain instructions of a given kind from the input module, 27 // and calls the normalizer to propagate the properties on the possibly new born 28 // instructions. 29 class HloDomainRemover : public HloModulePass { 30 public: 31 // Creates a new HloDomainRemover object tasked at removing all the kDomain 32 // instructions of a given kind. 33 // In case a reachable set (the set of instructions within a computation, 34 // which are mutually reachable via operand/user pathways) has all the 35 // instructions in it with the same attributes (ie, sharding), a normalizer 36 // function is tasked at applying attribute normalization on the instructions 37 // within such domain. HloDomainRemover(absl::string_view kind,std::function<Status (const DomainMetadata::Domain &,const DomainMetadata * metadata)> normalizer)38 HloDomainRemover(absl::string_view kind, 39 std::function<Status(const DomainMetadata::Domain&, 40 const DomainMetadata* metadata)> 41 normalizer) 42 : kind_(kind), normalizer_(std::move(normalizer)) {} 43 name()44 absl::string_view name() const override { return "domain_remover"; } 45 46 StatusOr<bool> Run(HloModule* module) override; 47 48 private: 49 class RunContext; 50 51 string kind_; 52 std::function<Status(const DomainMetadata::Domain&, 53 const DomainMetadata* metadata)> 54 normalizer_; 55 }; 56 57 } // namespace xla 58 59 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_HLO_DOMAIN_REMOVER_H_ 60