Skip to content
This repository was archived by the owner on Jul 1, 2024. It is now read-only.

Commit 5c8f013

Browse files
cavusmustafabarykrgsspintel
authored
Applied clang formatting to the repo (#84)
* All repo clang formatting * Build flags added for atom cpu * Instructions for Atom build * Notification for Atom Processor and wording for paragraph and Table content Table paragraph wording in sync with README , notification and link for Atom processor added to index.html * Classification example fix for eager * update ocm commit * changed links for wheel packages and minor table content changes * TensorFlow naming fix in docs * Fixing link for Atom build instructions Co-authored-by: barykrg <[email protected]> Co-authored-by: Suryaprakash Shanmugam <[email protected]>
1 parent ddaf932 commit 5c8f013

File tree

117 files changed

+928
-893
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+928
-893
lines changed

build_ov.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def main():
6767

6868
print('\033[1;35mOpenVINO Build finished\033[0m')
6969

70-
print('When building Openvino_Tensorflow using this prebuilt OpenVINO, use:')
70+
print(
71+
'When building Openvino_Tensorflow using this prebuilt OpenVINO, use:')
7172
print('\033[3;34mpython3 build_ovtf.py --use_openvino_from_location ' +
7273
os.path.abspath(arguments.output_dir) + '/artifacts/openvino' +
7374
'\033[1;0m')

build_ovtf.py

Lines changed: 75 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,17 @@ def main():
6565
parser.add_argument(
6666
'--target_arch',
6767
help=
68-
"Architecture flag to use (e.g., haswell, core-avx2 etc. Default \'native\'\n")
68+
"Architecture flag to use (e.g., haswell, core-avx2 etc. Default \'native\'\n"
69+
)
6970

7071
parser.add_argument(
7172
'--build_tf_from_source',
7273
type=str,
73-
help="Build TensorFlow from source and use the specified version.\n"
74-
+ "If version isn't specified, TF version " + tf_version +
74+
help="Build TensorFlow from source and use the specified version.\n" +
75+
"If version isn't specified, TF version " + tf_version +
7576
" will be used.\n" +
76-
"Note: in this case C++ API, unit tests and examples will be build for " +
77-
"OpenVINO integration with TensorFlow",
77+
"Note: in this case C++ API, unit tests and examples will be build for "
78+
+ "OpenVINO integration with TensorFlow",
7879
const=tf_version,
7980
default='',
8081
nargs='?',
@@ -110,8 +111,7 @@ def main():
110111

111112
parser.add_argument(
112113
'--disable_packaging_openvino_libs',
113-
help=
114-
"Use this option to do build a standalone python package of " +
114+
help="Use this option to do build a standalone python package of " +
115115
"the OpenVINO integration with TensorFlow Library without OpenVINO libraries",
116116
action="store_true")
117117

@@ -122,27 +122,23 @@ def main():
122122

123123
parser.add_argument(
124124
'--cxx11_abi_version',
125-
help=
126-
"Desired version of ABI to be used while building Tensorflow, \n" +
125+
help="Desired version of ABI to be used while building Tensorflow, \n" +
127126
"OpenVINO integration with TensorFlow, and OpenVINO libraries",
128127
default='0')
129-
128+
130129
parser.add_argument(
131130
'--resource_usage_ratio',
132-
help=
133-
"Ratio of CPU / RAM resources to utilize during Tensorflow build",
131+
help="Ratio of CPU / RAM resources to utilize during Tensorflow build",
134132
default=0.5)
135133

136134
parser.add_argument(
137135
'--openvino_version',
138-
help=
139-
"Openvino version to be used for building from source",
136+
help="Openvino version to be used for building from source",
140137
default='2021.3')
141-
138+
142139
parser.add_argument(
143140
'--python_executable',
144-
help=
145-
"Use a specific python executable while building whl",
141+
help="Use a specific python executable while building whl",
146142
action="store",
147143
default='')
148144

@@ -166,23 +162,22 @@ def main():
166162

167163
assert not (
168164
arguments.use_tensorflow_from_location != '' and
169-
arguments.build_tf_from_source != ''
170-
), ("\"use_tensorflow_from_location\" and \"build_tf_from_source\" "
171-
"cannot be used together.")
165+
arguments.build_tf_from_source != ''), (
166+
"\"use_tensorflow_from_location\" and \"build_tf_from_source\" "
167+
"cannot be used together.")
172168

173-
assert not (
174-
arguments.openvino_version != "2021.3" and
175-
arguments.openvino_version != "2021.2"
176-
), ("Only 2021.2 and 2021.3 are supported OpenVINO versions")
169+
assert not (arguments.openvino_version != "2021.3" and
170+
arguments.openvino_version != "2021.2"), (
171+
"Only 2021.2 and 2021.3 are supported OpenVINO versions")
177172

178173
if arguments.use_openvino_from_location != '':
179-
ver_file = arguments.use_openvino_from_location + \
180-
'/deployment_tools/inference_engine/version.txt'
181-
with open(ver_file) as f:
182-
line = f.readline()
183-
assert line.find(arguments.openvino_version) != -1, "OpenVINO version " + \
184-
arguments.openvino_version + \
185-
" does not match the version specified in use_openvino_from_location"
174+
ver_file = arguments.use_openvino_from_location + \
175+
'/deployment_tools/inference_engine/version.txt'
176+
with open(ver_file) as f:
177+
line = f.readline()
178+
assert line.find(arguments.openvino_version) != -1, "OpenVINO version " + \
179+
arguments.openvino_version + \
180+
" does not match the version specified in use_openvino_from_location"
186181

187182
version_check((arguments.build_tf_from_source == ''),
188183
(arguments.use_tensorflow_from_location != ''),
@@ -279,10 +274,9 @@ def main():
279274
command_executor(["pip", "install", "-U", tf_whl])
280275
tf_cxx_abi = get_tf_cxxabi()
281276

282-
assert (
283-
arguments.cxx11_abi_version == tf_cxx_abi
284-
), ("Desired ABI version and user built tensorflow library provided with "
285-
"use_tensorflow_from_location are incompatible")
277+
assert (arguments.cxx11_abi_version == tf_cxx_abi), (
278+
"Desired ABI version and user built tensorflow library provided with "
279+
"use_tensorflow_from_location are incompatible")
286280

287281
cwd = os.getcwd()
288282
os.chdir(tf_whl_loc)
@@ -301,31 +295,37 @@ def main():
301295
if arguments.build_tf_from_source == '':
302296
print("Using TensorFlow version", tf_version)
303297
print("Install TensorFlow")
304-
298+
305299
if arguments.cxx11_abi_version == "0":
306-
command_executor(["pip", "install", "tensorflow=="+tf_version])
300+
command_executor(
301+
["pip", "install", "tensorflow==" + tf_version])
307302
elif arguments.cxx11_abi_version == "1":
308303
tags = next(sys_tags())
309304

310305
if tags.interpreter == "cp36":
311-
command_executor(["pip", "install",
312-
"https://github.com/openvinotoolkit/openvino_tensorflow/releases/download/v0.5.0/tensorflow_abi1-2.4.1-cp36-cp36m-manylinux2010_x86_64.whl"])
306+
command_executor([
307+
"pip", "install",
308+
"https://github.com/openvinotoolkit/openvino_tensorflow/releases/download/v0.5.0/tensorflow_abi1-2.4.1-cp36-cp36m-manylinux2010_x86_64.whl"
309+
])
313310
if tags.interpreter == "cp37":
314-
command_executor(["pip", "install",
315-
"https://github.com/openvinotoolkit/openvino_tensorflow/releases/download/v0.5.0/tensorflow_abi1-2.4.1-cp37-cp37m-manylinux2010_x86_64.whl"])
311+
command_executor([
312+
"pip", "install",
313+
"https://github.com/openvinotoolkit/openvino_tensorflow/releases/download/v0.5.0/tensorflow_abi1-2.4.1-cp37-cp37m-manylinux2010_x86_64.whl"
314+
])
316315
if tags.interpreter == "cp38":
317-
command_executor(["pip", "install",
318-
"https://github.com/openvinotoolkit/openvino_tensorflow/releases/download/v0.5.0/tensorflow_abi1-2.4.1-cp38-cp38-manylinux2010_x86_64.whl"])
319-
316+
command_executor([
317+
"pip", "install",
318+
"https://github.com/openvinotoolkit/openvino_tensorflow/releases/download/v0.5.0/tensorflow_abi1-2.4.1-cp38-cp38-manylinux2010_x86_64.whl"
319+
])
320+
320321
# ABI 1 TF required latest numpy
321322
command_executor(["pip", "install", "-U numpy"])
322323

323324
tf_cxx_abi = get_tf_cxxabi()
324325

325-
assert (
326-
arguments.cxx11_abi_version == tf_cxx_abi
327-
), ("Desired ABI version and tensorflow library installed with "
328-
"pip are incompatible")
326+
assert (arguments.cxx11_abi_version == tf_cxx_abi), (
327+
"Desired ABI version and tensorflow library installed with "
328+
"pip are incompatible")
329329

330330
tf_src_dir = os.path.join(artifacts_location, "tensorflow")
331331
print("TF_SRC_DIR: ", tf_src_dir)
@@ -364,13 +364,20 @@ def main():
364364
print("TF_SRC_DIR: ", tf_src_dir)
365365

366366
# Build TensorFlow
367-
build_tensorflow(tf_version, "tensorflow", artifacts_location,
368-
target_arch, verbosity, use_intel_tf, arguments.cxx11_abi_version,
369-
resource_usage_ratio=float(arguments.resource_usage_ratio))
367+
build_tensorflow(
368+
tf_version,
369+
"tensorflow",
370+
artifacts_location,
371+
target_arch,
372+
verbosity,
373+
use_intel_tf,
374+
arguments.cxx11_abi_version,
375+
resource_usage_ratio=float(arguments.resource_usage_ratio))
370376

371377
# Now build the libtensorflow_cc.so - the C++ library
372378
build_tensorflow_cc(tf_version, tf_src_dir, artifacts_location,
373-
target_arch, verbosity, use_intel_tf, arguments.cxx11_abi_version)
379+
target_arch, verbosity, use_intel_tf,
380+
arguments.cxx11_abi_version)
374381

375382
tf_cxx_abi = install_tensorflow(venv_dir, artifacts_location)
376383

@@ -391,27 +398,30 @@ def main():
391398
"NOTE: OpenVINO python module is not built when building from source."
392399
)
393400

394-
if(arguments.openvino_version == "2021.3"):
395-
openvino_branch = "releases/2021/3"
396-
elif(arguments.openvino_version == "2021.2"):
397-
openvino_branch = "releases/2021/2"
401+
if (arguments.openvino_version == "2021.3"):
402+
openvino_branch = "releases/2021/3"
403+
elif (arguments.openvino_version == "2021.2"):
404+
openvino_branch = "releases/2021/2"
398405

399406
# Download OpenVINO
400407
download_repo(
401408
"openvino",
402409
"https://github.com/openvinotoolkit/openvino",
403-
openvino_branch,
404-
submodule_update=True)
410+
openvino_branch,
411+
submodule_update=True)
405412
openvino_src_dir = os.path.join(os.getcwd(), "openvino")
406413
print("OV_SRC_DIR: ", openvino_src_dir)
407414

408415
build_openvino(build_dir, openvino_src_dir, cxx_abi, target_arch,
409416
artifacts_location, arguments.debug_build, verbosity)
410417

411418
# Next build CMAKE options for the bridge
419+
atom_flags = ""
420+
if (target_arch == "silvermont"):
421+
atom_flags = " -mcx16 -mssse3 -msse4.1 -msse4.2 -mpopcnt -mno-avx"
412422
openvino_tf_cmake_flags = [
413423
"-DOPENVINO_TF_INSTALL_PREFIX=" + artifacts_location,
414-
"-DCMAKE_CXX_FLAGS=-march=" + target_arch,
424+
"-DCMAKE_CXX_FLAGS=-march=" + target_arch + atom_flags,
415425
]
416426

417427
openvino_artifacts_dir = ""
@@ -426,7 +436,7 @@ def main():
426436
["-DOPENVINO_ARTIFACTS_DIR=" + openvino_artifacts_dir])
427437

428438
openvino_tf_cmake_flags.extend(
429-
["-DOPENVINO_VERSION=" + arguments.openvino_version])
439+
["-DOPENVINO_VERSION=" + arguments.openvino_version])
430440

431441
if (arguments.debug_build):
432442
openvino_tf_cmake_flags.extend(["-DCMAKE_BUILD_TYPE=Debug"])
@@ -457,12 +467,13 @@ def main():
457467
if arguments.disable_packaging_openvino_libs:
458468
openvino_tf_cmake_flags.extend(["-DDISABLE_PACKAGING_OPENVINO_LIBS=1"])
459469
if arguments.python_executable != '':
460-
openvino_tf_cmake_flags.extend(["-DPYTHON_EXECUTABLE=%s"%arguments.python_executable])
470+
openvino_tf_cmake_flags.extend(
471+
["-DPYTHON_EXECUTABLE=%s" % arguments.python_executable])
461472

462473
# Now build the bridge
463474
ov_tf_whl = build_openvino_tf(build_dir, artifacts_location,
464-
openvino_tf_src_dir, venv_dir,
465-
openvino_tf_cmake_flags, verbosity)
475+
openvino_tf_src_dir, venv_dir,
476+
openvino_tf_cmake_flags, verbosity)
466477

467478
# Make sure that the openvino_tensorflow whl is present in the artfacts directory
468479
if not os.path.isfile(os.path.join(artifacts_location, ov_tf_whl)):
@@ -507,7 +518,7 @@ def main():
507518

508519
# Run a quick test
509520
install_openvino_tf(tf_version, venv_dir,
510-
os.path.join(artifacts_location, ov_tf_whl))
521+
os.path.join(artifacts_location, ov_tf_whl))
511522

512523
if builder_version > 0.50 and arguments.use_grappler_optimizer:
513524
import tensorflow as tf

build_tf.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22
# ==============================================================================
33
# Copyright (C) 2021 Intel Corporation
4-
4+
55
# SPDX-License-Identifier: Apache-2.0
66
# ==============================================================================
77

@@ -37,19 +37,17 @@ def main():
3737
action="store_true")
3838
parser.add_argument(
3939
'--cxx11_abi_version',
40-
help=
41-
"Desired version of ABI to be used while building Tensorflow",
40+
help="Desired version of ABI to be used while building Tensorflow",
4241
default='0')
4342
parser.add_argument(
4443
'--resource_usage_ratio',
45-
help=
46-
"Ratio of CPU / RAM resources to utilize during Tensorflow build",
44+
help="Ratio of CPU / RAM resources to utilize during Tensorflow build",
4745
default=0.5)
4846
arguments = parser.parse_args()
4947

5048
if not os.path.isdir(arguments.output_dir):
5149
os.makedirs(arguments.output_dir)
52-
50+
5351
assert os.path.isdir(arguments.output_dir), \
5452
"Did not find output directory: " + arguments.output_dir
5553

@@ -75,15 +73,20 @@ def main():
7573
os.chdir(pwd)
7674

7775
# Build TensorFlow
78-
build_tensorflow(arguments.tf_version, "tensorflow", 'artifacts',
79-
arguments.target_arch, False,
80-
arguments.use_intel_tensorflow, arguments.cxx11_abi_version,
81-
resource_usage_ratio=float(arguments.resource_usage_ratio))
76+
build_tensorflow(
77+
arguments.tf_version,
78+
"tensorflow",
79+
'artifacts',
80+
arguments.target_arch,
81+
False,
82+
arguments.use_intel_tensorflow,
83+
arguments.cxx11_abi_version,
84+
resource_usage_ratio=float(arguments.resource_usage_ratio))
8285

8386
# Build TensorFlow C++ Library
84-
build_tensorflow_cc(arguments.tf_version, "tensorflow", 'artifacts',
85-
arguments.target_arch, False,
86-
arguments.use_intel_tensorflow, arguments.cxx11_abi_version)
87+
build_tensorflow_cc(
88+
arguments.tf_version, "tensorflow", 'artifacts', arguments.target_arch,
89+
False, arguments.use_intel_tensorflow, arguments.cxx11_abi_version)
8790

8891
pwd = os.getcwd()
8992
artifacts_dir = os.path.join(pwd, 'artifacts/tensorflow')
@@ -94,7 +97,9 @@ def main():
9497

9598
print('\033[1;35mTensorFlow Build finished\033[0m')
9699

97-
print('When building openvino_tensorflow using this prebuilt tensorflow, use:')
100+
print(
101+
'When building openvino_tensorflow using this prebuilt tensorflow, use:'
102+
)
98103
print('\033[3;34mpython3 build_ovtf.py --use_tensorflow_from_location ' +
99104
os.path.abspath(arguments.output_dir) + '\033[1;0m')
100105

docs/BUILD.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ This **OpenVINO™ integration with TensorFlow** package is currently compatible
3333

3434
You can build TensorFlow from source with -D_GLIBCXX_USE_CXX11_ABI=1 or use the following TensorFlow package:
3535

36-
1. Ensure the following pip version is being used:
36+
1. Ensure the following versions are being used for pip and numpy:
3737

3838
pip3 install --upgrade pip==21.0.1
39+
pip3 install numpy==1.20.2
3940

4041
2. Install `TensorFlow`. Based on your Python version, use the appropriate package below:
4142

@@ -113,11 +114,11 @@ Use one of the following build options based on the requirements
113114

114115
python3 build_ovtf.py --build_tf_from_source --use_openvino_from_location=/opt/intel/openvino_2021.3.394/ --cxx11_abi_version=1
115116

116-
5. Uses pre-built TF from the given location ([refer the Tensorflow build instructions](#tensorflow)). Pulls and builds OpenVINO™ from source. Use this if you need to build **OpenVINO™ integration with TensorFlow** frequently without building TF from source everytime.
117+
5. Uses pre-built TF from the given location ([refer the TensorFlow build instructions](#tensorflow)). Pulls and builds OpenVINO™ from source. Use this if you need to build **OpenVINO™ integration with TensorFlow** frequently without building TF from source everytime.
117118

118119
python3 build_ovtf.py --use_tensorflow_from_location=/path/to/tensorflow/build/
119120

120-
6. Uses prebuilt TF from the given location ([refer the Tensorflow build instructions](#tensorflow)). Uses OpenVINO™ binary. **This is only compatible with ABI1 built TF**.
121+
6. Uses prebuilt TF from the given location ([refer the TensorFlow build instructions](#tensorflow)). Uses OpenVINO™ binary. **This is only compatible with ABI1 built TF**.
121122

122123
python3 build_ovtf.py --use_tensorflow_from_location=/path/to/tensorflow/build/ --use_openvino_from_location=/opt/intel/openvino_2021/ --cxx11_abi_version=1
123124

@@ -155,6 +156,11 @@ Test the installation:
155156

156157
This command runs all C++ and Python unit tests from the `openvino_tensorflow` source tree. It also runs various TensorFlow Python tests using OpenVINO™.
157158

159+
### Build Instructions for Intel Atom® Processor
160+
In order to build **OpenVINO™ integration with TensorFlow** to use on Intel Atom® processor, we recommend building TF from source. The command below will build TF and OpenVINO™ from source for Intel Atom® processors.
161+
162+
python3 build_ovtf.py --build_tf_from_source --cxx11_abi_version=1 --target_arch silvermont
163+
158164
## TensorFlow
159165

160166
TensorFlow can be built from source using `build_tf.py`. The build artifacts can be found under ${PATH_TO_TF_BUILD}/artifacts/

0 commit comments

Comments
 (0)