Home | History | Annotate | Download | only in tf2xla
      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_TPU_UTIL_H_
     16 #define TENSORFLOW_COMPILER_TF2XLA_TPU_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<tensorflow::gtl::optional<xla::OpSharding>>
     37 ParseShardingFromDevice(const string& device_name, int num_cores_per_replica,
     38                         tensorflow::gtl::optional<xla::OpSharding>
     39                             explicit_sharding = tensorflow::gtl::nullopt);
     40 
     41 xla::StatusOr<tensorflow::gtl::optional<xla::OpSharding>>
     42 ParseShardingFromDevice(const Node& node, int num_cores_per_replica);
     43 
     44 xla::StatusOr<tensorflow::gtl::optional<xla::OpSharding>>
     45 ParseShardingFromDevice(const NodeDef& node_def, int num_cores_per_replica);
     46 
     47 void SetShardingDeviceAssignmentFromNode(const Node& src, Node* dst);
     48 
     49 }  // namespace tensorflow
     50 
     51 #endif  // TENSORFLOW_COMPILER_TF2XLA_TPU_UTIL_H_
     52