MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / HloSharding

Class HloSharding

tensorflow/compiler/xla/service/hlo_sharding.h:41–282  ·  view source on GitHub ↗

HLO shardings describe how an HLO instruction is split across multiple computations.

Source from the content-addressed store, hash-verified

39// HLO shardings describe how an HLO instruction is split across multiple
40// computations.
41class HloSharding {
42 public:
43 // Creates a trivial sharding that replicates a maximal tile across all
44 // devices.
45 static HloSharding Replicate() { return HloSharding(); }
46
47 // Creates a sharding that emulates device placement; a tile shape equal to
48 // the input shape (one tile) assigned to a single device.
49 static HloSharding AssignDevice(int64 device_id);
50
51 // Creates a new sharding which splits a shape into tiles amongst the devices
52 // specified by `tile_assignment`.
53 static HloSharding Tile(const Array<int64>& tile_assignment) {
54 return HloSharding(tile_assignment);
55 }
56
57 // Creates a new sharding which splits a one-dimensional input shape into
58 // `num_tiles` tiles.
59 static HloSharding Tile1D(const Shape& input_shape, int64 num_tiles);
60
61 // Creates a new sharding for a tuple type. The given ShapeTree must have
62 // elements for every leaf shape contained in the tuple.
63 static HloSharding Tuple(const ShapeTree<HloSharding>& sub_shardings);
64
65 // Creates a new sharding for a tuple type. The number of elements in
66 // shardings must match the number of leaf nodes in tuple_shape. For
67 // empty tuples, the shardings array must have one element.
68 static HloSharding Tuple(const Shape& tuple_shape,
69 absl::Span<const HloSharding> shardings);
70
71 // Creates a new sharding for a tuple type, with a single input sharding
72 // repeated on each leaf.
73 static HloSharding SingleTuple(const Shape& tuple_shape,
74 const HloSharding& sharding);
75
76 // If shape is an array, returns sharding, otherwise returns the tuple shaped
77 // sharding with all the leaf nodes having the same input sharding.
78 static HloSharding Single(const Shape& shape, const HloSharding& sharding);
79
80 // Create a new sharding from a protobuf OpSharding.
81 static StatusOr<HloSharding> FromProto(const OpSharding& proto);
82
83 // Checks whether device is a reserved device number. A reserved device number
84 // has usually a special meaning, with dedicated handling logic.
85 static bool IsReservedDevice(int64 device) { return device < 0; }
86
87 OpSharding ToProto() const;
88
89 // Note that this string canonically has outer curly braces, e.g.
90 // "{replicated}".
91 string ToString() const;
92
93 // Validate that this sharding can be applied to a tensor with shape `shape`.
94 Status Validate(const Shape& shape, int64 num_devices) const;
95
96 // Returns true if the sharding has tuple type.
97 bool IsTuple() const { return tuple_; }
98

Callers 7

ReplicateMethod · 0.85
TileMethod · 0.85
AssignDeviceMethod · 0.85
Tile1DMethod · 0.85
TupleMethod · 0.85
SingleTupleMethod · 0.85
FromProtoMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected