Home | History | Annotate | Download | only in legacy_flags
      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 
     16 // Legacy flags for the XLA bridge's mark_for_compilation_pass module.
     17 
     18 #include <mutex>
     19 #include <vector>
     20 
     21 #include "tensorflow/compiler/jit/legacy_flags/mark_for_compilation_pass_flags.h"
     22 #include "tensorflow/compiler/xla/legacy_flags/parse_flags_from_env.h"
     23 #include "tensorflow/core/platform/types.h"
     24 #include "tensorflow/core/util/command_line_flags.h"
     25 
     26 namespace tensorflow {
     27 namespace legacy_flags {
     28 
     29 // Pointers to the parsed value of the flags and flag descriptors, initialized
     30 // via flags_init.
     31 static MarkForCompilationPassFlags* flags;
     32 static std::vector<Flag>* flag_list;
     33 static std::once_flag flags_init;
     34 
     35 // Allocate *flags.  Called via call_once(&flags_init,...).
     36 static void AllocateFlags() {
     37   flags = new MarkForCompilationPassFlags;
     38   flags->tf_xla_auto_jit = 0;
     39   flags->tf_xla_min_cluster_size = 2;
     40   flags->tf_xla_max_cluster_size = std::numeric_limits<int32>::max();
     41   flags->tf_xla_clustering_debug = false;
     42   flags->tf_xla_cpu_global_jit = false;
     43   flag_list = new std::vector<Flag>(
     44       {Flag("tf_xla_auto_jit", &flags->tf_xla_auto_jit,
     45             "Control compilation of operators into XLA computations on CPU and "
     46             "GPU devices.  0 = use ConfigProto setting; -1 = off; 1 = on for "
     47             "things very likely to be improved; 2 = on for everything.  "
     48             "Experimental."),
     49        Flag("tf_xla_min_cluster_size", &flags->tf_xla_min_cluster_size,
     50             "Minimum number of operators in an XLA compilation. Ignored for "
     51             "operators placed on an XLA device or operators explicitly marked "
     52             "for compilation."),
     53        Flag("tf_xla_max_cluster_size", &flags->tf_xla_max_cluster_size,
     54             "Maximum number of operators in an XLA compilation."),
     55        Flag("tf_xla_clustering_debug", &flags->tf_xla_clustering_debug,
     56             "Dump graphs during XLA compilation."),
     57        Flag("tf_xla_cpu_global_jit", &flags->tf_xla_cpu_global_jit,
     58             "Enables global JIT compilation for CPU via SessionOptions.")});
     59   xla::legacy_flags::ParseFlagsFromEnv(*flag_list);
     60 }
     61 
     62 // Append to *append_to flag definitions associated with the XLA bridge's
     63 // mark_for_compilation_pass module.
     64 void AppendMarkForCompilationPassFlags(std::vector<Flag>* append_to) {
     65   std::call_once(flags_init, &AllocateFlags);
     66   append_to->insert(append_to->end(), flag_list->begin(), flag_list->end());
     67 }
     68 
     69 // Return a pointer to the MarkForCompilationPassFlags struct;
     70 // repeated calls return the same pointer.
     71 // This should be called only after Flags::Parse() has returned.
     72 MarkForCompilationPassFlags* GetMarkForCompilationPassFlags() {
     73   std::call_once(flags_init, &AllocateFlags);
     74   return flags;
     75 }
     76 
     77 }  // namespace legacy_flags
     78 }  // namespace tensorflow
     79