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 #ifndef TENSORFLOW_COMPILER_XLA_SERVICE_CPU_CONV_CANONICALIZATION_H_ 17 #define TENSORFLOW_COMPILER_XLA_SERVICE_CPU_CONV_CANONICALIZATION_H_ 18 19 #include "tensorflow/compiler/xla/service/cpu/target_machine_features.h" 20 #include "tensorflow/compiler/xla/service/hlo_module.h" 21 #include "tensorflow/compiler/xla/service/hlo_pass_interface.h" 22 23 namespace xla { 24 namespace cpu { 25 26 // An HLO pass that canonicalizes the dimension numbers of all top-level 27 // convolutions in the given module. 28 // 29 // In order to hit the fast path of using Eigen's convolution implementation, a 30 // convolution's dimension numbers need to satisfy certain constraints (so 31 // called canonical convolutions). This pass expands non-canonical convolutions 32 // into reshapes and canonical convolutions, so that these non-canonical 33 // convolutions can run faster. 34 class ConvCanonicalization : public HloModulePass { 35 public: ConvCanonicalization(const TargetMachineFeatures * target_machine_features)36 explicit ConvCanonicalization( 37 const TargetMachineFeatures* target_machine_features) 38 : target_machine_features_(*target_machine_features) {} 39 ~ConvCanonicalization()40 ~ConvCanonicalization() override {} name()41 absl::string_view name() const override { 42 return "convolution-canonicalization"; 43 } 44 45 StatusOr<bool> Run(HloModule* module) override; 46 47 private: 48 const TargetMachineFeatures& target_machine_features_; 49 }; 50 51 } // namespace cpu 52 } // namespace xla 53 54 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_CPU_CONV_CANONICALIZATION_H_ 55