1# Copyright 2015 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"""System configuration library.""" 17from __future__ import absolute_import 18from __future__ import division 19from __future__ import print_function 20 21import os.path as _os_path 22import platform as _platform 23 24from tensorflow.python.framework.versions import CXX11_ABI_FLAG as _CXX11_ABI_FLAG 25from tensorflow.python.framework.versions import MONOLITHIC_BUILD as _MONOLITHIC_BUILD 26from tensorflow.python.framework.versions import VERSION as _VERSION 27from tensorflow.python.platform import build_info 28from tensorflow.python.util.tf_export import tf_export 29 30 31# pylint: disable=g-import-not-at-top 32@tf_export('sysconfig.get_include') 33def get_include(): 34 """Get the directory containing the TensorFlow C++ header files. 35 36 Returns: 37 The directory as string. 38 """ 39 # Import inside the function. 40 # sysconfig is imported from the tensorflow module, so having this 41 # import at the top would cause a circular import, resulting in 42 # the tensorflow module missing symbols that come after sysconfig. 43 import tensorflow as tf 44 return _os_path.join(_os_path.dirname(tf.__file__), 'include') 45 46 47@tf_export('sysconfig.get_lib') 48def get_lib(): 49 """Get the directory containing the TensorFlow framework library. 50 51 Returns: 52 The directory as string. 53 """ 54 import tensorflow as tf 55 return _os_path.join(_os_path.dirname(tf.__file__)) 56 57 58@tf_export('sysconfig.get_compile_flags') 59def get_compile_flags(): 60 """Get the compilation flags for custom operators. 61 62 Returns: 63 The compilation flags. 64 """ 65 flags = [] 66 flags.append('-I%s' % get_include()) 67 flags.append('-D_GLIBCXX_USE_CXX11_ABI=%d' % _CXX11_ABI_FLAG) 68 return flags 69 70 71@tf_export('sysconfig.get_link_flags') 72def get_link_flags(): 73 """Get the link flags for custom operators. 74 75 Returns: 76 The link flags. 77 """ 78 is_mac = _platform.system() == 'Darwin' 79 ver = _VERSION.split('.')[0] 80 flags = [] 81 if not _MONOLITHIC_BUILD: 82 flags.append('-L%s' % get_lib()) 83 if is_mac: 84 flags.append('-ltensorflow_framework.%s' % ver) 85 else: 86 flags.append('-l:libtensorflow_framework.so.%s' % ver) 87 return flags 88 89 90@tf_export('sysconfig.get_build_info') 91def get_build_info(): 92 """Get a dictionary describing TensorFlow's build environment. 93 94 Values are generated when TensorFlow is compiled, and are static for each 95 TensorFlow package. The return value is a dictionary with string keys such as: 96 97 - cuda_version 98 - cudnn_version 99 - is_cuda_build 100 - is_rocm_build 101 - msvcp_dll_names 102 - nvcuda_dll_name 103 - cudart_dll_name 104 - cudnn_dll_name 105 106 Note that the actual keys and values returned by this function is subject to 107 change across different versions of TensorFlow or across platforms. 108 109 Returns: 110 A Dictionary describing TensorFlow's build environment. 111 """ 112 return build_info.build_info 113