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_HLO_ELEMENT_TYPE_CONVERTER_H_ 17 #define TENSORFLOW_COMPILER_XLA_SERVICE_HLO_ELEMENT_TYPE_CONVERTER_H_ 18 19 #include "tensorflow/compiler/xla/service/hlo_module.h" 20 #include "tensorflow/compiler/xla/service/hlo_pass_interface.h" 21 22 namespace xla { 23 24 // A pass that eliminates certain element types as the input or output of ops by 25 // inserting Convert ops. This allows a backend to support an element type while 26 // only actually implementing the Convert op for that element type. This is 27 // generally not the fastest approach, but it works. 28 class HloElementTypeConverter : public HloPassInterface { 29 public: 30 // eliminate_type is the type to eliminate as the input or output of ops, 31 // using Convert ops to replace it with replace_with_type. 32 HloElementTypeConverter(PrimitiveType eliminate_type, 33 PrimitiveType replace_with_type); 34 35 tensorflow::StringPiece name() const override { 36 return "element_type_converter"; 37 } 38 39 // Returns the pass on the module and returns whether the module was modified. 40 StatusOr<bool> Run(HloModule* module) override; 41 42 private: 43 PrimitiveType eliminate_type_; 44 PrimitiveType replace_with_type_; 45 }; 46 47 } // namespace xla 48 49 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_HLO_ELEMENT_TYPE_CONVERTER_H_ 50