Home | History | Annotate | Download | only in client
      1 /* Copyright 2018 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 
     16 #include "tensorflow/compiler/xla/client/executable_build_options.h"
     17 
     18 #include "absl/strings/str_format.h"
     19 #include "tensorflow/compiler/xla/debug_options_flags.h"
     20 #include "tensorflow/compiler/xla/shape_util.h"
     21 
     22 namespace xla {
     23 
     24 ExecutableBuildOptions& ExecutableBuildOptions::set_device_allocator(
     25     DeviceMemoryAllocator* allocator) {
     26   device_allocator_ = allocator;
     27   return *this;
     28 }
     29 
     30 DeviceMemoryAllocator* ExecutableBuildOptions::device_allocator() const {
     31   return device_allocator_;
     32 }
     33 
     34 ExecutableBuildOptions& ExecutableBuildOptions::set_device_ordinal(
     35     int device_ordinal) {
     36   CHECK_GE(device_ordinal, 0);
     37   device_ordinal_ = device_ordinal;
     38   return *this;
     39 }
     40 
     41 int ExecutableBuildOptions::device_ordinal() const { return device_ordinal_; }
     42 
     43 DebugOptions* ExecutableBuildOptions::mutable_debug_options() {
     44   if (!has_debug_options()) {
     45     debug_options_ = GetDebugOptionsFromFlags();
     46   }
     47   return &debug_options_.value();
     48 }
     49 
     50 ExecutableBuildOptions& ExecutableBuildOptions::set_result_layout(
     51     const Shape& shape_with_layout) {
     52   result_layout_set_ = true;
     53   result_layout_ = shape_with_layout;
     54   return *this;
     55 }
     56 
     57 const Shape* ExecutableBuildOptions::result_layout() const {
     58   return result_layout_set_ ? &result_layout_ : nullptr;
     59 }
     60 
     61 ExecutableBuildOptions& ExecutableBuildOptions::set_num_replicas(
     62     int num_replicas) {
     63   num_replicas_ = num_replicas;
     64   return *this;
     65 }
     66 
     67 string ExecutableBuildOptions::ToString() const {
     68   string result_layout = "nullopt";
     69   if (result_layout_set_) {
     70     result_layout = ShapeUtil::HumanStringWithLayout(result_layout_);
     71   }
     72   return absl::StrFormat(
     73       "ExecutableBuildOptions{device_ordinal=%d, result_layout=%s, "
     74       "num_replicas=%d}",
     75       device_ordinal_, result_layout, num_replicas_);
     76 }
     77 
     78 }  // namespace xla
     79