Home | History | Annotate | Download | only in c
      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/c/c_api_experimental.h"
     17 
     18 #include "tensorflow/c/c_api_internal.h"
     19 #include "tensorflow/compiler/jit/legacy_flags/mark_for_compilation_pass_flags.h"
     20 #include "tensorflow/core/protobuf/config.pb.h"
     21 
     22 void TF_EnableXLACompilation(TF_SessionOptions* options, unsigned char enable) {
     23   tensorflow::ConfigProto& config = options->options.config;
     24   auto* optimizer_options =
     25       config.mutable_graph_options()->mutable_optimizer_options();
     26   if (enable) {
     27     optimizer_options->set_global_jit_level(tensorflow::OptimizerOptions::ON_1);
     28 
     29     // These XLA flags are needed to trigger XLA properly from C (more generally
     30     // non-Python) clients. If this API is called again with `enable` set to
     31     // false, it is safe to keep these flag values as is.
     32     tensorflow::legacy_flags::MarkForCompilationPassFlags* flags =
     33         tensorflow::legacy_flags::GetMarkForCompilationPassFlags();
     34     flags->tf_xla_cpu_global_jit = true;
     35     flags->tf_xla_min_cluster_size = 1;
     36   } else {
     37     optimizer_options->set_global_jit_level(tensorflow::OptimizerOptions::OFF);
     38   }
     39 }
     40