Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 34 additions & 18 deletions build_ngtf.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ def load_venv(venv_dir):
return venv_dir


def setup_venv(venv_dir):
load_venv(venv_dir)
def setup_venv(venv_dir, system):
if not system:
load_venv(venv_dir)

print("PIP location")
call(['which', 'pip'])
Expand Down Expand Up @@ -245,10 +246,11 @@ def build_tensorflow(venv_dir, src_dir, artifacts_dir, target_arch, verbosity):
os.chdir(pwd)


def install_tensorflow(venv_dir, artifacts_dir):
def install_tensorflow(venv_dir, artifacts_dir, system):

# Load the virtual env
load_venv(venv_dir)
if not system:
# Load the virtual env
load_venv(venv_dir)

# Install tensorflow pip
tf_pip = os.path.join(os.path.abspath(artifacts_dir), "tensorflow")
Expand Down Expand Up @@ -279,11 +281,12 @@ def install_tensorflow(venv_dir, artifacts_dir):


def build_ngraph_tf(artifacts_location, ngtf_src_loc, venv_dir, cmake_flags,
verbose):
verbose, system):
pwd = os.getcwd()

# Load the virtual env
load_venv(venv_dir)
if not system:
# Load the virtual env
load_venv(venv_dir)

command_executor(["pip", "list"])

Expand Down Expand Up @@ -344,9 +347,10 @@ def build_ngraph_tf(artifacts_location, ngtf_src_loc, venv_dir, cmake_flags,
return output_wheel


def install_ngraph_tf(venv_dir, ngtf_pip_whl):
# Load the virtual env
load_venv(venv_dir)
def install_ngraph_tf(venv_dir, ngtf_pip_whl, system):
if not system:
# Load the virtual env
load_venv(venv_dir)

command_executor(["pip", "install", "-U", ngtf_pip_whl])

Expand Down Expand Up @@ -417,6 +421,12 @@ def main():
help="Builds a distributed version of the nGraph components\n",
action="store_true")

parser.add_argument(
'--system',
help="install on system (or current venv) python environment",
action="store_true"
)

arguments = parser.parse_args()

if (arguments.debug_build):
Expand All @@ -427,6 +437,11 @@ def main():
print("Building in with VERBOSE output messages\n")
verbosity = True

install_on_system = False
if arguments.system:
print("Install on current python environment")
install_on_system = True

#-------------------------------
# Recipe
#-------------------------------
Expand Down Expand Up @@ -459,16 +474,17 @@ def main():
artifacts_location = os.path.abspath(artifacts_location)
print("ARTIFACTS location: " + artifacts_location)

if not use_prebuilt_binaries:
if not use_prebuilt_binaries and not install_on_system:
#install virtualenv
install_virtual_env(venv_dir)

# Load the virtual env
load_venv(venv_dir)
if not install_on_system:
# Load the virtual env
load_venv(venv_dir)

if not use_prebuilt_binaries:
# Setup the virtual env
setup_venv(venv_dir)
setup_venv(venv_dir, install_on_system)

target_arch = 'native'
if (arguments.target_arch):
Expand All @@ -488,7 +504,7 @@ def main():
target_arch, verbosity)

# Install tensorflow
cxx_abi = install_tensorflow(venv_dir, artifacts_location)
cxx_abi = install_tensorflow(venv_dir, artifacts_location, install_on_system)
else:
print("Skipping the TensorFlow build")
import tensorflow as tf
Expand Down Expand Up @@ -549,12 +565,12 @@ def main():

# Now build the bridge
ng_tf_whl = build_ngraph_tf(artifacts_location, "../", venv_dir,
ngraph_tf_cmake_flags, verbosity)
ngraph_tf_cmake_flags, verbosity, install_on_system)

print("SUCCESSFULLY generated wheel: %s" % ng_tf_whl)

# Run a quick test
install_ngraph_tf(venv_dir, os.path.join(artifacts_location, ng_tf_whl))
install_ngraph_tf(venv_dir, os.path.join(artifacts_location, ng_tf_whl), install_on_system)

os.chdir(pwd)

Expand Down