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 #ifndef TENSORFLOW_COMPILER_XLA_CLIENT_EXECUTABLE_BUILD_OPTIONS_H_
     17 #define TENSORFLOW_COMPILER_XLA_CLIENT_EXECUTABLE_BUILD_OPTIONS_H_
     18 
     19 #include "tensorflow/compiler/xla/service/device_memory_allocator.h"
     20 #include "tensorflow/compiler/xla/xla_data.pb.h"
     21 #include "tensorflow/core/lib/gtl/optional.h"
     22 
     23 namespace xla {
     24 
     25 // Class containing options for building an LocalExecutable with
     26 // LocalClient::Compile.
     27 class ExecutableBuildOptions {
     28  public:
     29   // If set, this is the device to build the computation for. Valid
     30   // device_ordinal values are: 0 to # of devices - 1. These values are
     31   // identical to the device ordinal values used by StreamExecutor. The built
     32   // executable will be executable on any device equivalent to the specified
     33   // device as determined by Backend::devices_equivalent(). A value of -1
     34   // indicates this option has not been set.
     35   ExecutableBuildOptions& set_device_ordinal(int device_ordinal);
     36   int device_ordinal() const;
     37 
     38   // If set, this specifies the layout of the result of the computation. If not
     39   // set, the service will chose the layout of the result. A Shape is used to
     40   // store the layout to accommodate tuple result shapes. A value of nullptr
     41   // indicates the option has not been set.
     42   ExecutableBuildOptions& set_result_layout(const Shape& shape_with_layout);
     43   const Shape* result_layout() const;
     44 
     45   // If set, this specifies an allocator that can be used to allocate temporary
     46   // space on the device during compilation.  For example, the compiler might
     47   // want to run various algorithms on the device and pick the fastest one -- it
     48   // might allocate buffers for use by these algorithms using this allocator.
     49   //
     50   // This does not need to be the same as the DeviceMemoryAllocator passed when
     51   // running the executable.
     52   ExecutableBuildOptions& set_device_allocator(
     53       DeviceMemoryAllocator* allocator);
     54   DeviceMemoryAllocator* device_allocator() const;
     55 
     56   // If set, specifies a regexp of HLO graphs to dump (as in DebugOptions).
     57   ExecutableBuildOptions& set_generate_hlo_graph(string regex);
     58   const tensorflow::gtl::optional<string>& generate_hlo_graph() const;
     59 
     60   // Returns a string representation of the build options, suitable for
     61   // debugging.
     62   string ToString() const;
     63 
     64  private:
     65   int device_ordinal_ = -1;
     66   Shape result_layout_;
     67   bool result_layout_set_ = false;
     68   tensorflow::gtl::optional<string> generate_hlo_graph_;
     69   DeviceMemoryAllocator* device_allocator_ = nullptr;
     70 };
     71 
     72 }  // namespace xla
     73 
     74 #endif  // TENSORFLOW_COMPILER_XLA_CLIENT_EXECUTABLE_BUILD_OPTIONS_H_
     75