• 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 #ifndef TENSORFLOW_COMPILER_TF2XLA_SHARDING_UTIL_H_
16 #define TENSORFLOW_COMPILER_TF2XLA_SHARDING_UTIL_H_
17 
18 #include <string>
19 
20 #include "tensorflow/compiler/xla/client/sharding_builder.h"
21 #include "tensorflow/compiler/xla/status_macros.h"
22 #include "tensorflow/core/graph/graph.h"
23 #include "tensorflow/core/lib/core/status.h"
24 
25 namespace tensorflow {
26 
27 // Parses the op sharding from the 'replicated core' device_name <device_name>.
28 // Returns an error:
29 // - if the device name is invalid.
30 // - the core is parsed and is out of the range [0, num_cores_per_replica).
31 //
32 // Otherwise, returns either:
33 // - explicit_sharding if explicit_sharding.has_value()
34 // - a non-value if there is no assigned core or
35 // - a sharding set as per xla::sharding_builder::AssignDevice.
36 xla::StatusOr<absl::optional<xla::OpSharding>> ParseShardingFromDevice(
37     const string& device_name, int num_cores_per_replica,
38     absl::optional<xla::OpSharding> explicit_sharding = absl::nullopt,
39     absl::optional<xla::OpMetadata> metadata = absl::nullopt);
40 
41 xla::StatusOr<absl::optional<xla::OpSharding>> ParseShardingFromDevice(
42     const Node& node, int num_cores_per_replica, bool add_metadata);
43 
44 xla::StatusOr<absl::optional<xla::OpSharding>> ParseShardingFromDevice(
45     const NodeDef& node_def, int num_cores_per_replica, bool add_metadata);
46 
47 xla::StatusOr<absl::optional<xla::OpSharding>> ParseShardingFromEdgeSource(
48     const Edge& edge, int num_cores_per_replica, bool add_metadata);
49 
50 void SetShardingDeviceAssignmentFromNode(const Node& src, Node* dst);
51 
52 // Get sharding inforamtion from node.
53 xla::StatusOr<absl::optional<xla::OpSharding>> GetShardingFromNodeDef(
54     const NodeDef& node_def, bool add_metadata);
55 
56 }  // namespace tensorflow
57 
58 #endif  // TENSORFLOW_COMPILER_TF2XLA_SHARDING_UTIL_H_
59