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 #include "tensorflow/compiler/xla/service/cpu/cpu_options.h" 17 18 #include "tensorflow/core/lib/strings/numbers.h" 19 20 namespace { 21 22 const char* const kXlaParallelCpuOption = "xla_cpu_parallel"; 23 const char* const kXlaOptimizeForSizeCpuOption = "xla_cpu_optimize_for_size"; 24 const char* const kXlaDisableVectorizedReduce = "xla_disable_vectorized_reduce"; 25 const char* const kLlvmIrDotTilingFactor = "xla_llvm_dot_tiling_factor"; 26 27 } // namespace 28 29 namespace xla { 30 namespace cpu { 31 namespace options { 32 33 bool CpuParallelBackendRequested(const HloModuleConfig& config) { 34 const auto& extra_options_map = 35 config.debug_options().xla_backend_extra_options(); 36 return extra_options_map.count(kXlaParallelCpuOption) > 0; 37 } 38 39 bool OptimizeForSizeRequested(const HloModuleConfig& config) { 40 const auto& extra_options_map = 41 config.debug_options().xla_backend_extra_options(); 42 return extra_options_map.count(kXlaOptimizeForSizeCpuOption) > 0; 43 } 44 45 bool VectorizedReduceDisabled(const HloModuleConfig& config) { 46 const auto& extra_options_map = 47 config.debug_options().xla_backend_extra_options(); 48 return extra_options_map.count(kXlaOptimizeForSizeCpuOption) > 0; 49 } 50 51 tensorflow::gtl::optional<int64> LlvmIrGemvTilingFactor( 52 const HloModuleConfig& config) { 53 const auto& extra_options_map = 54 config.debug_options().xla_backend_extra_options(); 55 auto it = extra_options_map.find(kLlvmIrDotTilingFactor); 56 int64 tiling_factor; 57 if (it != extra_options_map.end() && 58 tensorflow::strings::safe_strto64(it->second, &tiling_factor)) { 59 return tiling_factor; 60 } 61 return tensorflow::gtl::nullopt; 62 } 63 64 } // namespace options 65 } // namespace cpu 66 } // namespace xla 67