Describes a tile used in tiling-based layout. Refer to g3doc/third_party/tensorflow/compiler/xla/g3doc/tiled_layout.md for details.
| 31 | // g3doc/third_party/tensorflow/compiler/xla/g3doc/tiled_layout.md for |
| 32 | // details. |
| 33 | class Tile { |
| 34 | public: |
| 35 | Tile() = default; |
| 36 | explicit Tile(absl::Span<const int64> dimensions) |
| 37 | : dimensions_(dimensions.begin(), dimensions.end()) {} |
| 38 | |
| 39 | // De/Serialize a Tile to and from a TileProto. |
| 40 | static Tile CreateFromProto(const TileProto& tile_proto) { |
| 41 | return Tile(AsInt64Slice(tile_proto.dimensions())); |
| 42 | } |
| 43 | TileProto ToProto() const; |
| 44 | |
| 45 | bool operator==(const Tile& other) const { |
| 46 | return dimensions() == other.dimensions(); |
| 47 | } |
| 48 | bool operator!=(const Tile& other) const { return !(*this == other); } |
| 49 | |
| 50 | string ToString() const; |
| 51 | |
| 52 | // Returns the bound of the tile in the given dimension index. |
| 53 | int64 dimension(int i) const { return dimensions_.at(i); } |
| 54 | |
| 55 | // Returns the dimensions of the tile. |
| 56 | absl::Span<const int64> dimensions() const { return dimensions_; } |
| 57 | |
| 58 | Tile& add_dimensions(int64 value) { |
| 59 | dimensions_.push_back(value); |
| 60 | return *this; |
| 61 | } |
| 62 | |
| 63 | Tile& clear_dimensions() { |
| 64 | dimensions_.clear(); |
| 65 | return *this; |
| 66 | } |
| 67 | |
| 68 | // This dimension size means the corresponding dimension in the shape is |
| 69 | // combined with the next minor dimension before tiling is applied. |
| 70 | static constexpr int64 kCombineDimension = std::numeric_limits<int64>::min(); |
| 71 | |
| 72 | template <typename H> |
| 73 | friend H AbslHashValue(H h, const Tile& t) { |
| 74 | return H::combine(std::move(h), t.dimensions_); |
| 75 | } |
| 76 | |
| 77 | private: |
| 78 | // The bounds of the tile. |
| 79 | absl::InlinedVector<int64, 2> dimensions_; |
| 80 | }; |
| 81 | |
| 82 | class Layout { |
| 83 | public: |