• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CLIENT_LIB_ARITHMETIC_H_
17 #define TENSORFLOW_COMPILER_XLA_CLIENT_LIB_ARITHMETIC_H_
18 
19 #include <memory>
20 
21 #include "tensorflow/compiler/xla/client/xla_builder.h"
22 #include "tensorflow/compiler/xla/client/xla_computation.h"
23 #include "tensorflow/compiler/xla/xla_data.pb.h"
24 
25 namespace xla {
26 
27 using XlaOpGenerator = std::function<XlaOp(XlaOp, XlaOp)>;
28 
29 // Creates a scalar computation based on a lambda and returns it.
30 XlaComputation CreateScalarComputation(const string& name, PrimitiveType type,
31                                        XlaBuilder* builder,
32                                        XlaOpGenerator generator);
33 
34 // Creates a scalar add computation and returns it.
35 XlaComputation CreateScalarAddComputation(PrimitiveType type,
36                                           XlaBuilder* builder);
37 
38 // Creates a scalar multiply computation and returns it.
39 XlaComputation CreateScalarMultiplyComputation(PrimitiveType type,
40                                                XlaBuilder* builder);
41 
42 // Creates a scalar ge computation and returns it.
43 XlaComputation CreateScalarGeComputation(PrimitiveType type,
44                                          XlaBuilder* builder);
45 
46 // Creates a scalar max computation and returns it.
47 XlaComputation CreateScalarMaxComputation(PrimitiveType type,
48                                           XlaBuilder* builder);
49 
50 // Creates a scalar min computation and returns it.
51 XlaComputation CreateScalarMinComputation(PrimitiveType type,
52                                           XlaBuilder* builder);
53 
54 // Creates a scalar logical AND computation and returns it.
55 XlaComputation CreateScalarAndComputation(PrimitiveType type,
56                                           XlaBuilder* builder);
57 
58 // Creates a scalar logical OR computation and returns it.
59 XlaComputation CreateScalarOrComputation(PrimitiveType type,
60                                          XlaBuilder* builder);
61 
62 // This is to be used for general purpose "identity" like reductions with zero
63 // for any type (ie. boolean operations for PRED and Add for real numbers).
64 // As an example, this operation can be used for a situation of:
65 // x_type = type(x)
66 // op = CreateScalarIdentityWithZeroComputation(x_type)
67 // ASSERT_TRUE(op(x, 0) == x)
68 //
69 // This functionality is used for operations that are similar to a slice,
70 // gather, or broadcast, but are created through a reduction.
71 XlaComputation CreateScalarIdentityWithZeroComputation(PrimitiveType type,
72                                                        XlaBuilder* builder);
73 
74 // Returns whether any predicate in "predicates" is set.
75 //
76 // Note: if predicates is zero-sized, Any() vacuously returns false.
77 XlaOp Any(XlaOp predicates);
78 
79 // Returns the argmax of `input` along `axis`. `output_type` is the type to
80 // use for the output. The `tie_low` argument drives the index selection is case
81 // of same values. If `true` (default behavior) the lowest index will be
82 // returned, otherwise the higher. The tie_low argument only applies if `stable`
83 // is true or using the ArgMaxTwoPass.
84 XlaOp ArgMax(XlaOp input, PrimitiveType output_type, int axis,
85              bool stable = false, bool tie_low = true);
86 XlaOp ArgMaxTwoPass(XlaOp input, PrimitiveType output_type, int axis,
87                     bool tie_low = true);
88 
89 // Returns the argmin of `input` along `axis`. `output_type` is the type to
90 // use for the output. The `tie_low` argument drives the index selection is case
91 // of same values. If `true` (default behavior) the lowest index will be
92 // returned, otherwise the higher. The tie_low argument only applies if `stable`
93 // is true or using the ArgMinTwoPass.
94 XlaOp ArgMin(XlaOp input, PrimitiveType output_type, int axis,
95              bool stable = false, bool tie_low = true);
96 XlaOp ArgMinTwoPass(XlaOp input, PrimitiveType output_type, int axis,
97                     bool tie_low = true);
98 
99 }  // namespace xla
100 
101 #endif  // TENSORFLOW_COMPILER_XLA_CLIENT_LIB_ARITHMETIC_H_
102