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