forked from openvinotoolkit/openvino_tensorflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_ov.py
101 lines (89 loc) · 3.71 KB
/
build_ov.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
99
100
101
#!/usr/bin/env python3
# ==============================================================================
# Copyright (C) 2021 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
# ==============================================================================
from tools.build_utils import *
import os, shutil
import argparse
def main():
openvino_version = "2021.4.1"
build_dir = 'build_cmake'
cxx_abi = "1"
print("openVINO version: ", openvino_version)
# Command line parser options
parser = argparse.ArgumentParser(
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument(
'--output_dir',
type=str,
help="Location where OpenVINO 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")
parser.add_argument(
'--debug_build',
help="Builds a debug version of the components\n",
action="store_true")
arguments = parser.parse_args()
if not os.path.isdir(arguments.output_dir):
os.makedirs(arguments.output_dir)
if not os.path.exists(arguments.output_dir):
raise AssertionError("Path doesn't exist {0}".format(
arguments.output_dir))
os.chdir(arguments.output_dir)
if not os.path.exists(arguments.output_dir):
raise AssertionError("Directory doesn't exist {0}".format(
arguments.output_dir))
if not os.path.isdir(os.path.join(arguments.output_dir, "openvino")):
# Download OpenVINO
download_repo(
"openvino",
"https://github.com/openvinotoolkit/openvino",
openvino_version,
submodule_update=True)
else:
pwd = os.getcwd()
if not os.path.exists(arguments.output_dir):
raise AssertionError("Path doesn't exist {0}".format(
arguments.output_dir))
os.chdir(os.path.join(arguments.output_dir, "openvino"))
call(["git", "fetch"])
command_executor(["git", "checkout", openvino_version])
call(["git", "pull"])
if not os.path.exists(pwd):
raise AssertionError("Path doesn't exist {0}".format(pwd))
os.chdir(pwd)
if not os.path.exists(os.path.join(arguments.output_dir, "openvino")):
raise AssertionError("Path doesn't exist {0}/openvino".format(
arguments.output_dir))
openvino_src_dir = os.path.join(arguments.output_dir, "openvino")
print("OV_SRC_DIR: ", openvino_src_dir)
verbosity = False
artifacts_location = os.path.abspath(arguments.output_dir) + '/artifacts'
# Build OpenVINO
build_openvino(build_dir, openvino_src_dir, cxx_abi, arguments.target_arch,
artifacts_location, arguments.debug_build, verbosity)
print('\033[1;35mOpenVINO Build finished\033[0m')
print(
'When building Openvino_Tensorflow using this prebuilt OpenVINO, use:')
print('\033[3;34mpython3 build_ovtf.py --use_openvino_from_location ' +
os.path.abspath(arguments.output_dir) + '/artifacts/openvino' +
'\033[1;0m')
if __name__ == '__main__':
main()
# Usage
# Build OV once
# ./build_ov.py --output_dir /prebuilt/ov/dir
#
# Reuse OV in different openvino_tensorflow builds
# mkdir ovtf_1; cd ovtf_1
# git clone https://github.com/openvinotoolkit/openvino_tensorflow.git
# ./build_ovtf.py --use_openvino_from_location /prebuilt/ov/dir/artifacts/openvino
# cd ..; mkdir ovtf_2; cd ovtf_2
# git clone https://github.com/openvinotoolkit/openvino_tensorflow.git
# ./build_ovtf.py --use_openvino_from_location /prebuilt/ov/dir/artifacts/openvino