Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an automatically-generated "tensorflow.python.platform.build_info…
…" script. The motivation for this script is to provide better tools for diagnosing load-time errors (such as the ones that plague the Windows build due to DLL issues). Note that the script is intended to be self-contained, so that it is possible to import it without loading the entire TensorFlow runtime. This generated script currently contains a single symbol, `is_cuda_build`, which records whether the build has GPU support or not. PiperOrigin-RevId: 168471034
- Loading branch information
1 parent
c3b8634
commit 59bdf59
Showing
8 changed files
with
181 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright 2015 The TensorFlow Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
"""Test for the generated build_info script.""" | ||
|
||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
from tensorflow.python.platform import build_info | ||
from tensorflow.python.platform import test | ||
|
||
|
||
class BuildInfoTest(test.TestCase): | ||
|
||
def testBuildInfo(self): | ||
self.assertEqual(build_info.is_cuda_build, test.is_built_with_cuda()) | ||
|
||
|
||
if __name__ == '__main__': | ||
test.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Description: | ||
# Contains script to generate tensorflow/python/platform/build_info.py | ||
package(default_visibility = ["//tensorflow:internal"]) | ||
|
||
licenses(["notice"]) # Apache 2.0 | ||
|
||
exports_files( | ||
glob(["gen/*"]) + [ | ||
"gen_build_info.py", | ||
], | ||
) | ||
|
||
# ----------------------------------------------------------------------------- | ||
# Google-internal targets. These must be at the end for syncrepo. | ||
|
||
filegroup( | ||
name = "all_files", | ||
srcs = glob( | ||
["**/*"], | ||
exclude = [ | ||
"**/METADATA", | ||
"**/OWNERS", | ||
], | ||
), | ||
visibility = ["//tensorflow:__subpackages__"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env python | ||
# Copyright 2017 The TensorFlow Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
"""Generates a Python module containing information about the build.""" | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
import argparse | ||
|
||
|
||
def write_build_info(filename, build_config): | ||
"""Writes a Python that describes the build. | ||
Args: | ||
filename: filename to write to. | ||
build_config: A string containinggit_version: the result of a git describe. | ||
""" | ||
module_docstring = "\"\"\"Generates a Python module containing information " | ||
module_docstring += "about the build.\"\"\"" | ||
if build_config == "cuda": | ||
build_config_bool = "True" | ||
else: | ||
build_config_bool = "False" | ||
|
||
contents = """ | ||
# Copyright 2017 The TensorFlow Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
%s | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
is_cuda_build = %s | ||
""" % (module_docstring, build_config_bool) | ||
open(filename, "w").write(contents) | ||
|
||
|
||
parser = argparse.ArgumentParser( | ||
description="""Build info injection into the PIP package.""") | ||
|
||
parser.add_argument( | ||
"--build_config", | ||
type=str, | ||
help="Either 'cuda' for GPU builds or 'cpu' for CPU builds.") | ||
|
||
parser.add_argument("--raw_generate", type=str, help="Generate build_info.py") | ||
|
||
args = parser.parse_args() | ||
|
||
if args.raw_generate is not None and args.build_config is not None: | ||
write_build_info(args.raw_generate, args.build_config) | ||
else: | ||
raise RuntimeError("--raw_generate and --build_config must be used") |