tf_1.8_xla_doc
algebraic_simplifier.h
Go to the documentation of this file.
1 
3 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7  http://www.apache.org/licenses/LICENSE-2.0
8 Unless required by applicable law or agreed to in writing, software
9 distributed under the License is distributed on an "AS IS" BASIS,
10 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 See the License for the specific language governing permissions and
12 limitations under the License.
13 ==============================================================================*/
14 #ifndef TENSORFLOW_COMPILER_XLA_SERVICE_ALGEBRAIC_SIMPLIFIER_H_
15 #define TENSORFLOW_COMPILER_XLA_SERVICE_ALGEBRAIC_SIMPLIFIER_H_
16 #include <utility>
18 #include "tensorflow/compiler/xla/service/hlo_pass_interface.h"
19 namespace xla {
23 class AlgebraicSimplifier : public HloPassInterface {
24  public:
25  // Given shapes 'from_shape' and 'to_shape', determines if it is valid to
26  // bitcast from 'from_shape' to 'to_shape' after considering platform
27  // dependent effects on layout like alignment restrictions. Precondition: the
28  // two shapes have layouts, the same number of elements and
29  // ShapeUtil::ReshapeIsBitcast returns true.
30  using ValidBitcastCallback =
31  std::function<bool(const Shape& from_shape, const Shape& to_shape)>;
32  // If is_layout_sensitive is true, then the simplifier preserves layout during
33  // transformation. Otherwise, layout is ignored. If valid_bitcast_callback
34  // returns true, then the pass will replace reshapes and transposes with
35  // bitcasts.
36  AlgebraicSimplifier(bool is_layout_sensitive,
37  ValidBitcastCallback valid_bitcast_callback,
38  bool enable_dot_strength_reduction = true,
39  bool enable_conv_simplification = true)
40  : is_layout_sensitive_(is_layout_sensitive),
41  valid_bitcast_callback_(std::move(valid_bitcast_callback)),
42  enable_dot_strength_reduction_(enable_dot_strength_reduction),
43  enable_conv_simplification_(enable_conv_simplification) {}
44  ~AlgebraicSimplifier() override = default;
45  tensorflow::StringPiece name() const override { return "algsimp"; }
46  // Run algebraic simplification on the given computation. Returns whether the
47  // computation was changed.
48  StatusOr<bool> Run(HloModule* module) override;
49  private:
50  bool is_layout_sensitive_;
51  ValidBitcastCallback valid_bitcast_callback_;
52  // Enable dot simplification on platforms where it is profitable.
53  bool enable_dot_strength_reduction_;
54  // Enable convolution simplification on platforms where it is profitable.
55  bool enable_conv_simplification_;
56 };
57 } // namespace xla
58 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_ALGEBRAIC_SIMPLIFIER_H_
59 
Definition: algebraic_simplifier.h:23
namespace for xla
Definition: client_library.cc:26
Definition: hlo_module.h:52