• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_TF2XLA_LIB_SCATTER_H_
17 #define TENSORFLOW_COMPILER_TF2XLA_LIB_SCATTER_H_
18 
19 #include <functional>
20 
21 #include "tensorflow/compiler/xla/client/xla_builder.h"
22 #include "tensorflow/compiler/xla/client/xla_computation.h"
23 #include "tensorflow/compiler/xla/statusor.h"
24 
25 namespace tensorflow {
26 
27 // Builds an XLA computation that performs a scatter operation on `buffer`,
28 // returning an updated buffer.
29 // For each i0, i1, ..., sets
30 // buffer[indices[i0, i1, ...], ...] := updates[i0, i1, ...]
31 //
32 // If `indices_are_vectors` is false, then each index in indices is a scalar,
33 // and the shape of `indices` must be a prefix of the shape of updates.
34 // Otherwise, `indices_are_vectors`, then indices are multidimensional and the
35 // minor dimension of `indices` represents a vector of indices.
36 //
37 // If `updates` is a scalar, then it will be broadcasted into the expected shape
38 // of updates.
39 //
40 // If any part of the update region is out-of-bounds, the corresponding update
41 // is discarded.
42 //
43 // If a `combiner` is provided, updates are combined with the existing values in
44 // the buffer using the combiner function. Otherwise, the updates replace the
45 // existing values. The order of updates is implementation-defined.
46 xla::StatusOr<xla::XlaOp> XlaScatter(
47     const xla::XlaOp& buffer, const xla::XlaOp& updates,
48     const xla::XlaOp& indices, bool indices_are_vectors,
49     const std::function<xla::XlaOp(xla::XlaOp, xla::XlaOp, xla::XlaBuilder*)>&
50         combiner,
51     xla::XlaBuilder* builder);
52 
53 }  // namespace tensorflow
54 
55 #endif  // TENSORFLOW_COMPILER_TF2XLA_LIB_SCATTER_H_
56