• 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 
40 xla::StatusOr<absl::optional<xla::OpSharding>> ParseShardingFromDevice(
41     const Node& node, int num_cores_per_replica);
42 
43 xla::StatusOr<absl::optional<xla::OpSharding>> ParseShardingFromDevice(
44     const NodeDef& node_def, int num_cores_per_replica);
45 
46 void SetShardingDeviceAssignmentFromNode(const Node& src, Node* dst);
47 
48 }  // namespace tensorflow
49 
50 #endif  // TENSORFLOW_COMPILER_TF2XLA_SHARDING_UTIL_H_
51