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