Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorflow/python/platform/sysconfig.py: 40%

50 statements  

« prev     ^ index     » next       coverage.py v7.4.0, created at 2024-01-03 07:57 +0000

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.""" 

17import os.path as _os_path 

18import platform as _platform 

19 

20from tensorflow.python.client import pywrap_tf_session 

21from tensorflow.python.framework.versions import CXX11_ABI_FLAG as _CXX11_ABI_FLAG 

22from tensorflow.python.framework.versions import CXX_VERSION as _CXX_VERSION 

23from tensorflow.python.framework.versions import MONOLITHIC_BUILD as _MONOLITHIC_BUILD 

24from tensorflow.python.framework.versions import VERSION as _VERSION 

25from tensorflow.python.platform import build_info 

26from tensorflow.python.util.tf_export import tf_export 

27 

28 

29# pylint: disable=g-import-not-at-top 

30@tf_export('sysconfig.get_include') 

31def get_include(): 

32 """Get the directory containing the TensorFlow C++ header files. 

33 

34 Returns: 

35 The directory as string. 

36 """ 

37 # Import inside the function. 

38 # sysconfig is imported from the tensorflow module, so having this 

39 # import at the top would cause a circular import, resulting in 

40 # the tensorflow module missing symbols that come after sysconfig. 

41 import tensorflow as tf 

42 return _os_path.join(_os_path.dirname(tf.__file__), 'include') 

43 

44 

45@tf_export('sysconfig.get_lib') 

46def get_lib(): 

47 """Get the directory containing the TensorFlow framework library. 

48 

49 Returns: 

50 The directory as string. 

51 """ 

52 import tensorflow as tf 

53 return _os_path.join(_os_path.dirname(tf.__file__)) 

54 

55 

56@tf_export('sysconfig.get_compile_flags') 

57def get_compile_flags(): 

58 """Returns the compilation flags for compiling with TensorFlow. 

59 

60 The returned list of arguments can be passed to the compiler for compiling 

61 against TensorFlow headers. The result is platform dependent. 

62 

63 For example, on a typical Linux system with Python 3.7 the following command 

64 prints `['-I/usr/local/lib/python3.7/dist-packages/tensorflow/include', 

65 '-D_GLIBCXX_USE_CXX11_ABI=1', '-DEIGEN_MAX_ALIGN_BYTES=64']` 

66 

67 >>> print(tf.sysconfig.get_compile_flags()) 

68 

69 Returns: 

70 A list of strings for the compiler flags. 

71 """ 

72 flags = [] 

73 flags.append('-I%s' % get_include()) 

74 flags.append('-D_GLIBCXX_USE_CXX11_ABI=%d' % _CXX11_ABI_FLAG) 

75 cxx_version_flag = None 

76 if _CXX_VERSION == 201103: 

77 cxx_version_flag = '--std=c++11' 

78 elif _CXX_VERSION == 201402: 

79 cxx_version_flag = '--std=c++14' 

80 elif _CXX_VERSION == 201703: 

81 cxx_version_flag = '--std=c++17' 

82 elif _CXX_VERSION == 202002: 

83 cxx_version_flag = '--std=c++20' 

84 if cxx_version_flag: 

85 flags.append(cxx_version_flag) 

86 flags.append('-DEIGEN_MAX_ALIGN_BYTES=%d' % 

87 pywrap_tf_session.get_eigen_max_align_bytes()) 

88 return flags 

89 

90 

91@tf_export('sysconfig.get_link_flags') 

92def get_link_flags(): 

93 """Returns the linker flags for linking with TensorFlow. 

94 

95 The returned list of arguments can be passed to the linker for linking against 

96 TensorFlow. The result is platform dependent. 

97 

98 For example, on a typical Linux system with Python 3.7 the following command 

99 prints `['-L/usr/local/lib/python3.7/dist-packages/tensorflow', 

100 '-l:libtensorflow_framework.so.2']` 

101 

102 >>> print(tf.sysconfig.get_link_flags()) 

103 

104 Returns: 

105 A list of strings for the linker flags. 

106 """ 

107 is_mac = _platform.system() == 'Darwin' 

108 ver = _VERSION.split('.')[0] 

109 flags = [] 

110 if not _MONOLITHIC_BUILD: 

111 flags.append('-L%s' % get_lib()) 

112 if is_mac: 

113 flags.append('-ltensorflow_framework.%s' % ver) 

114 else: 

115 flags.append('-l:libtensorflow_framework.so.%s' % ver) 

116 return flags 

117 

118 

119@tf_export('sysconfig.get_build_info') 

120def get_build_info(): 

121 """Get a dictionary describing TensorFlow's build environment. 

122 

123 Values are generated when TensorFlow is compiled, and are static for each 

124 TensorFlow package. The return value is a dictionary with string keys such as: 

125 

126 - cuda_version 

127 - cudnn_version 

128 - is_cuda_build 

129 - is_rocm_build 

130 - msvcp_dll_names 

131 - nvcuda_dll_name 

132 - cudart_dll_name 

133 - cudnn_dll_name 

134 

135 Note that the actual keys and values returned by this function is subject to 

136 change across different versions of TensorFlow or across platforms. 

137 

138 Returns: 

139 A Dictionary describing TensorFlow's build environment. 

140 """ 

141 return build_info.build_info