aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/compiler/xla/client/executable_build_options.cc
blob: 0f1745366b7c33e573aff2e66d85431b01488c49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#include "tensorflow/compiler/xla/client/executable_build_options.h"

#include "absl/strings/str_format.h"
#include "tensorflow/compiler/xla/shape_util.h"

namespace xla {

ExecutableBuildOptions& ExecutableBuildOptions::set_device_allocator(
    DeviceMemoryAllocator* allocator) {
  device_allocator_ = allocator;
  return *this;
}

DeviceMemoryAllocator* ExecutableBuildOptions::device_allocator() const {
  return device_allocator_;
}

ExecutableBuildOptions& ExecutableBuildOptions::set_device_ordinal(
    int device_ordinal) {
  CHECK_GE(device_ordinal, 0);
  device_ordinal_ = device_ordinal;
  return *this;
}

int ExecutableBuildOptions::device_ordinal() const { return device_ordinal_; }

ExecutableBuildOptions& ExecutableBuildOptions::set_result_layout(
    const Shape& shape_with_layout) {
  result_layout_set_ = true;
  result_layout_ = shape_with_layout;
  return *this;
}

const Shape* ExecutableBuildOptions::result_layout() const {
  return result_layout_set_ ? &result_layout_ : nullptr;
}

string ExecutableBuildOptions::ToString() const {
  string result_layout = "nullopt";
  if (result_layout_set_) {
    result_layout = ShapeUtil::HumanStringWithLayout(result_layout_);
  }
  string generate_hlo_graph = "nullopt";
  if (generate_hlo_graph_.has_value()) {
    generate_hlo_graph = generate_hlo_graph_.value();
  }
  return absl::StrFormat(
      "ExecutableBuildOptions{device_ordinal=%d, result_layout=%s, "
      "generate_hlo_graph=%s}",
      device_ordinal_, result_layout, generate_hlo_graph);
}

ExecutableBuildOptions& ExecutableBuildOptions::set_generate_hlo_graph(
    string regex) {
  generate_hlo_graph_ = std::move(regex);
  return *this;
}

const absl::optional<string>& ExecutableBuildOptions::generate_hlo_graph()
    const {
  return generate_hlo_graph_;
}

ExecutableBuildOptions& ExecutableBuildOptions::set_dump_optimized_hlo_proto_to(
    absl::string_view dirpath) {
  dump_optimized_hlo_proto_to_ = string(dirpath);
  return *this;
}

const absl::optional<string>&
ExecutableBuildOptions::dump_optimized_hlo_proto_to() const {
  return dump_optimized_hlo_proto_to_;
}

ExecutableBuildOptions&
ExecutableBuildOptions::set_dump_unoptimized_hlo_proto_to(
    absl::string_view dirpath) {
  dump_unoptimized_hlo_proto_to_ = string(dirpath);
  return *this;
}

const absl::optional<string>&
ExecutableBuildOptions::dump_unoptimized_hlo_proto_to() const {
  return dump_unoptimized_hlo_proto_to_;
}

ExecutableBuildOptions& ExecutableBuildOptions::set_dump_per_pass_hlo_proto_to(
    absl::string_view dirpath) {
  dump_per_pass_hlo_proto_to_ = string(dirpath);
  return *this;
}

const absl::optional<string>&
ExecutableBuildOptions::dump_per_pass_hlo_proto_to() const {
  return dump_per_pass_hlo_proto_to_;
}

ExecutableBuildOptions& ExecutableBuildOptions::set_hlo_profile(bool enabled) {
  hlo_profile_ = enabled;
  return *this;
}

absl::optional<bool> ExecutableBuildOptions::hlo_profile() const {
  return hlo_profile_;
}

}  // namespace xla