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_SHARDING_BUILDER_H_ 17 #define TENSORFLOW_COMPILER_XLA_CLIENT_SHARDING_BUILDER_H_ 18 19 #include <vector> 20 21 #include "tensorflow/compiler/xla/array.h" 22 #include "tensorflow/compiler/xla/shape_tree.h" 23 #include "tensorflow/compiler/xla/shape_util.h" 24 #include "tensorflow/compiler/xla/types.h" 25 #include "tensorflow/compiler/xla/util.h" 26 #include "tensorflow/compiler/xla/xla_data.pb.h" 27 28 namespace xla { 29 namespace sharding_builder { 30 // A shaped array used to describe the assignment of tiles to devices. 31 using TileAssignment = Array<int64>; 32 33 // Creates a replicated sharding - replicate a tensor on every device. 34 OpSharding Replicate(); 35 36 // Creates a manual sharding - the partitioner will not change the shape. 37 OpSharding Manual(); 38 39 // Creates a sharding that assigns a tensor to just one device. 40 OpSharding AssignDevice(int device); 41 42 // Creates a tiled sharding with the given tile shape and assignment of tiles 43 // to devices. 44 // 45 // If tile_shape is not evenly divisible by the number of devices in 46 // tile_assignment, operations behave as if implicit padding had been inserted. 47 // The value of this padding is undefined. 48 OpSharding Tile(const Shape& tile_shape, const TileAssignment& tile_assignment); 49 50 // Creates a sharding in one dimension, with the given tile shape which must 51 // be rank 1 and using devices [0..num_tiles). 52 // 53 // This is simply a convenience wrapper for Tile(). 54 OpSharding Tile1D(const Shape& tile_shape, int64 num_tiles); 55 56 // Creates a tuple sharding from the given ShapeTree of element shardings. 57 OpSharding Tuple(const ShapeTree<OpSharding>& shardings); 58 59 } // namespace sharding_builder 60 } // namespace xla 61 62 #endif // TENSORFLOW_COMPILER_XLA_CLIENT_SHARDING_BUILDER_H_ 63