This repository has been archived by the owner on Mar 2, 2024. It is now read-only.
forked from tensorflow/ngraph-bridge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_tf.py
executable file
·98 lines (82 loc) · 3.31 KB
/
build_tf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python3
# ==============================================================================
# Copyright 2018-2019 Intel Corporation
#
# 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.
# ==============================================================================
from tools.build_utils import *
import os, shutil
import argparse
def main():
# Command line parser options
parser = argparse.ArgumentParser(
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument(
'--tf_version',
type=str,
help="TensorFlow tag/branch/SHA\n",
action="store",
required=True)
parser.add_argument(
'--output_dir',
type=str,
help="Location where TensorFlow build will happen\n",
action="store",
required=True)
parser.add_argument(
'--target_arch',
help=
"Architecture flag to use (e.g., haswell, core-avx2 etc. Default \'native\'\n",
default="native")
arguments = parser.parse_args()
assert not os.path.isdir(
arguments.output_dir), arguments.output_dir + " already exists"
os.makedirs(arguments.output_dir)
os.chdir(arguments.output_dir)
assert not is_venv(
), "Please deactivate virtual environment before running this script"
assert not is_venv(
), "Please deactivate virtual environment before running this script"
venv_dir = './venv3/'
install_virtual_env(venv_dir)
load_venv(venv_dir)
setup_venv(venv_dir)
# Download TensorFlow
download_repo("tensorflow", "https://github.com/tensorflow/tensorflow.git",
arguments.tf_version)
# Build TensorFlow
build_tensorflow(venv_dir, "tensorflow", 'artifacts', arguments.target_arch,
False)
# Build TensorFlow C++ Library
build_tensorflow_cc("tensorflow", 'artifacts', arguments.target_arch, False)
pwd = os.getcwd()
artifacts_dir = os.path.join(pwd, 'artifacts/tensorflow')
os.chdir("tensorflow")
copy_tf_to_artifacts(artifacts_dir, None)
print('\033[1;35mTensorFlow Build finished\033[0m')
print('When building ngraph-bridge using this prebuilt tensorflow, use:')
print('\033[3;34mpython3 build_ngtf.py --use_tensorflow_from_location ' +
os.path.abspath(arguments.output_dir) + '\033[1;0m')
if __name__ == '__main__':
main()
# Usage
# Build TF once
# ./build_tf.py --tf_version v1.14.0-rc0 --output_dir /prebuilt/tf/dir
#
# Reuse TF in different ngraph-bridge builds
# mkdir ngtf_1; cd ngtf_1
# git clone https://github.com/tensorflow/ngraph-bridge.git
# ./build_ngtf.py --use_tensorflow_from_location /prebuilt/tf/dir
# cd ..; mkdir ngtf_2; cd ngtf_2
# git clone https://github.com/tensorflow/ngraph-bridge.git
# ./build_ngtf.py --use_tensorflow_from_location /prebuilt/tf/dir