diff --git a/CMakeLists.txt b/CMakeLists.txt index 41f615d1..654842a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -239,7 +239,7 @@ if (NOT USE_PRE_BUILT_NGRAPH) ExternalProject_Add( ext_ngraph GIT_REPOSITORY https://github.com/NervanaSystems/ngraph - GIT_TAG v0.16.0-rc.3 + GIT_TAG v0.17.0-rc.1 CMAKE_ARGS -DNGRAPH_DISTRIBUTED_ENABLE=${NGRAPH_DISTRIBUTED_ENABLE} -DNGRAPH_INSTALL_PREFIX=${NGRAPH_ARTIFACTS_DIR} diff --git a/README.md b/README.md index 156d320f..530f39d7 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ + +[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/NervanaSystems/ngraph-tf/blob/master/LICENSE) +[![Build Status](https://badge.buildkite.com/f20db2a4be0e82e493faa08de85953d45b313b3be12abf4acf.svg)](https://buildkite.com/ngraph/ngtf-master-cpu) + + # Intel(R) nGraph(TM) Compiler and runtime for TensorFlow* This repository contains the code needed to enable Intel(R) nGraph(TM) Compiler and @@ -42,7 +47,7 @@ a variety of nGraph-enabled backends: CPU, GPU, and custom silicon like the This will produce something like this: TensorFlow version: 1.13.1 - nGraph bridge version: b'0.12.0-rc2' + nGraph bridge version: b'0.12.0-rc3' nGraph version used for this build: b'0.21.0-rc.0+b638705' TensorFlow version used for this build: v1.13.1-0-g6612da8951 @@ -84,7 +89,7 @@ The installation prerequisites are the same as described in the TensorFlow git clone https://github.com/NervanaSystems/ngraph-tf.git cd ngraph-tf - git checkout v0.12.0-rc2 + git checkout v0.12.0-rc3 2. Next run the following Python script to build TensorFlow, nGraph and the bridge. Please use Python 3.5: diff --git a/bazel/WORKSPACE b/bazel/WORKSPACE index b9d7749f..25234f00 100644 --- a/bazel/WORKSPACE +++ b/bazel/WORKSPACE @@ -25,11 +25,11 @@ tf_configure( http_archive( name = "ngraph", build_file = "//:bazel/ngraph.BUILD", - sha256 = "6c1a85cf58e22ad2392d57c98aeef5fd0fbe40122765a233d5efdeb1f94e227b", - strip_prefix = "ngraph-0.16.0-rc.2", + sha256 = "517f2430ab1434021c2c4e3daf6f52cc855e4134632ed7c517a2c9c4b2c28f6b", + strip_prefix = "ngraph-0.17.0-rc.1", urls = [ - "https://mirror.bazel.build/github.com/NervanaSystems/ngraph/archive/v0.16.0-rc.2.tar.gz", - "https://github.com/NervanaSystems/ngraph/archive/v0.16.0-rc.2.tar.gz", + "https://mirror.bazel.build/github.com/NervanaSystems/ngraph/archive/v0.17.0-rc.1.tar.gz", + "https://github.com/NervanaSystems/ngraph/archive/v0.17.0-rc.1.tar.gz", ], ) diff --git a/build_ngtf.py b/build_ngtf.py index b017dfff..a3178585 100755 --- a/build_ngtf.py +++ b/build_ngtf.py @@ -90,7 +90,7 @@ def main(): #------------------------------- # Component versions - ngraph_version = "v0.16.0-rc.3" + ngraph_version = "v0.17.0-rc.1" tf_version = "v1.13.1" # Default directories diff --git a/python/setup.in.py b/python/setup.in.py index c66f2485..68dafa0e 100644 --- a/python/setup.in.py +++ b/python/setup.in.py @@ -39,7 +39,7 @@ def get_tag(self): setup( name='ngraph_tensorflow_bridge', - version='0.12.0rc2', + version='0.12.0rc3', description='Intel nGraph compiler and runtime for TensorFlow', long_description=long_description, long_description_content_type="text/markdown", diff --git a/src/ngraph_builder.cc b/src/ngraph_builder.cc index cdfc0622..4737ede0 100644 --- a/src/ngraph_builder.cc +++ b/src/ngraph_builder.cc @@ -2522,9 +2522,10 @@ static Status TranslatePadOp(const Node* op, "elements"); } - ng::Shape padding_below(paddings.size() / 2); - ng::Shape padding_above(paddings.size() / 2); + ng::CoordinateDiff padding_below(paddings.size() / 2); + ng::CoordinateDiff padding_above(paddings.size() / 2); ng::Shape padding_interior(paddings.size() / 2); + auto pad_mode = ng::op::PadMode::CONSTANT; for (size_t i = 0; i < paddings.size() / 2; i++) { padding_below[i] = paddings[2 * i]; @@ -2539,9 +2540,8 @@ static Status TranslatePadOp(const Node* op, auto pad_val_op = ConstructNgNode( op->name(), ng_input->get_element_type(), ng::Shape{}, std::vector{"0"}); - auto pad_op = ConstructNgNode(op->name(), ng_input, pad_val_op, - padding_below, padding_above, - padding_interior); + auto pad_op = ConstructNgNode( + op->name(), ng_input, pad_val_op, padding_below, padding_above, pad_mode); SaveNgOp(ng_op_map, op->name(), pad_op); return Status::OK(); diff --git a/src/version.cc b/src/version.cc index aaddbfc7..f919491b 100644 --- a/src/version.cc +++ b/src/version.cc @@ -30,7 +30,7 @@ // candidate such as v0.7.0-rc0 // The code in master will always have the last released version number // with a suffix of '-master' -#define NG_TF_VERSION_SUFFIX "-rc2" +#define NG_TF_VERSION_SUFFIX "-rc3" #define VERSION_STR_HELPER(x) #x #define VERSION_STR(x) VERSION_STR_HELPER(x) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 56acce37..ff70abeb 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -81,21 +81,6 @@ if (APPLE) set(NGRAPH_TF_CXX11_ABI 0) endif() -# If pre-built tensorflow CC library is not provided, then build one. -# TODO: Remove this option once we migrate to build_ngtf.py -if (NOT UNIT_TEST_TF_CC_DIR) - add_custom_target( - build_tf_cc - COMMENT "Building TensorFlow C++ library" - COMMAND - ${CMAKE_CURRENT_SOURCE_DIR}/build_tf_cc.sh - ${TensorFlow_SRC_DIR} - ${NGRAPH_TF_CXX11_ABI} - ) - - add_dependencies(gtest_ngtf build_tf_cc) -endif() - target_link_libraries( gtest_ngtf ngraph_bridge @@ -107,3 +92,19 @@ target_link_libraries( ) add_subdirectory(python) + +if (DEFINED NGRAPH_TF_INSTALL_PREFIX) + set(CMAKE_INSTALL_PREFIX ${NGRAPH_TF_INSTALL_PREFIX}) +else() + set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/../install/") +endif() + +# First install the libngraph_bridge.so and headers +install(TARGETS gtest_ngtf DESTINATION ${CMAKE_INSTALL_PREFIX}/test) +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/test_axpy.pbtxt DESTINATION ${CMAKE_INSTALL_PREFIX}/test) +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/test_axpy_launchop.pbtxt DESTINATION ${CMAKE_INSTALL_PREFIX}/test) +install( + DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/python + DESTINATION ${CMAKE_INSTALL_PREFIX}/test + FILES_MATCHING PATTERN "*.py" +) diff --git a/test/build_tf_cc.sh b/test/build_tf_cc.sh deleted file mode 100755 index a3ebd338..00000000 --- a/test/build_tf_cc.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/bin/bash - -echo "TensorFlow Source directory 1: " $1 -echo "_GLIBCXX_USE_CXX11_ABI: " $2 -# If this script is not invoked with the TF source directory then return error -if [ $# -lt 2 ] -then - echo "Usage: $0 " - exit -1 -fi - -TF_ROOT=$1 -USE_CXX11_ABI=$2 - -if [ $2 -eq 0 ] -then - COPT=--copt='-D_GLIBCXX_USE_CXX11_ABI=0' -else - COPT=--copt='-D_GLIBCXX_USE_CXX11_ABI=1' -fi - -if [ ! -e $TF_ROOT ]; then - echo "TensorFlow installation directory not found: " $TF_ROOT - exit 1 -fi - -# Set the python directory. Must be inside a virtual env -export PYTHON_BIN_PATH=$VIRTUAL_ENV/bin/python - -# Declare the build options for TensorFlow -export CC_OPT_FLAGS="-march=native" -export USE_DEFAULT_PYTHON_LIB_PATH=1 - -export TF_NEED_NGRAPH=0 - -export TF_NEED_IGNITE=0 -export TF_NEED_ROCM=0 - -export TF_NEED_JEMALLOC=1 -export TF_NEED_AWS=0 -export TF_NEED_GCP=0 -export TF_NEED_HDFS=0 -export TF_NEED_KAFKA=0 -export TF_ENABLE_XLA=0 -export TF_NEED_GDR=0 -export TF_NEED_VERBS=0 -export TF_NEED_OPENCL_SYCL=0 -export TF_NEED_COMPUTECPP=0 -export TF_NEED_CUDA=0 -export TF_NEED_OPENCL=0 -export TF_NEED_MPI=0 -export TF_DOWNLOAD_CLANG=0 -export TF_SET_ANDROID_WORKSPACE=0 - -# Configure TF -pushd "${TF_ROOT}" -./configure - -# Build the TensorFlow C++ Library -bazel build --config=opt ${COPT} //tensorflow:libtensorflow_cc.so - -popd - diff --git a/test/ci/buildkite/test_runner.py b/test/ci/buildkite/test_runner.py new file mode 100755 index 00000000..965d72d1 --- /dev/null +++ b/test/ci/buildkite/test_runner.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python3 +# ============================================================================== +# Copyright 2018 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. +# ============================================================================== +import argparse +import errno +import os +from subprocess import check_output, call +import sys +import shutil +import glob +import platform +from distutils.sysconfig import get_python_lib + +#from tools.build_utils import load_venv, command_executor +from tools.test_utils import * + + +def main(): + ''' + Tests nGraph-TensorFlow Python 3. This script needs to be run after + running build_ngtf.py which builds the ngraph-tensorflow-bridge + and installs it to a virtual environment that would be used by this script. + ''' + parser = argparse.ArgumentParser() + parser.add_argument( + '--test_cpp', + help="Runs C++ tests (GTest based).\n", + action="store_true") + + parser.add_argument( + '--test_python', + help="Runs Python tests (Pytest based).\n", + action="store_true") + + parser.add_argument( + '--test_tf_python', + help="Runs TensorFlow Python tests (Pytest based).\n", + action="store_true") + + parser.add_argument( + '--test_resnet', + help="Runs TensorFlow Python tests (Pytest based).\n", + action="store_true") + + parser.add_argument( + '--artifacts_dir', + type=str, + help= + "Location of the artifacts that would be used for running the tests\n", + action="store") + + parser.add_argument( + '--backend', + type=str, + help="String indicating what backend to use (e.g., CPU, INTERPRETER)\n", + action="store") + + arguments = parser.parse_args() + + #------------------------------- + # Recipe + #------------------------------- + + root_pwd = os.getcwd() + + # Check for mandetary parameters + if not arguments.artifacts_dir: + raise Exception("Need to specify --artifacts_dir") + + # Set the backend if specified + if (arguments.backend): + os.environ['NGRAPH_TF_BACKEND'] = arguments.backend + + # Decide which tests to run + if (arguments.test_cpp): + run_ngtf_cpp_gtests(arguments.artifacts_dir, './', None) + elif (arguments.test_python): + run_ngtf_pytests_from_artifacts(arguments.artifacts_dir) + elif (arguments.test_tf_python): + raise Exception("TensorFlow Python tests are not yet supported") + elif (arguments.test_resnet): + run_resnet50_from_artifacts(arguments.artifacts_dir) + else: + raise Exception("No tests specified") + + os.chdir(root_pwd) + + +if __name__ == '__main__': + main() diff --git a/test/python/CMakeLists.txt b/test/python/CMakeLists.txt index b76943e7..e06281b5 100644 --- a/test/python/CMakeLists.txt +++ b/test/python/CMakeLists.txt @@ -22,3 +22,5 @@ foreach(file ${files}) ${CMAKE_CURRENT_BINARY_DIR}/${file} ) endforeach() + + diff --git a/test/python/tensorflow/python_tests_list.txt b/test/python/tensorflow/python_tests_list.txt index 3c60b0d6..007d6375 100644 --- a/test/python/tensorflow/python_tests_list.txt +++ b/test/python/tensorflow/python_tests_list.txt @@ -422,4 +422,3 @@ transpose_op_test.TransposeTest.testTranspose2DAuto #transpose_op_test.TransposeTest.testInt16 #transpose_op_test.TransposeTest.testInt8 transpose_op_test.TransposeTest.testError - diff --git a/test/test_array_ops.cpp b/test/test_array_ops.cpp index b14e86b0..7bdf5367 100644 --- a/test/test_array_ops.cpp +++ b/test/test_array_ops.cpp @@ -498,6 +498,29 @@ TEST(ArrayOps, OneHot3dNegAxis) { } // end of op OneHot +TEST(ArrayOps, Pad) { + Scope root = Scope::NewRootScope(); + + vector static_input_indexes = {1}; + + Tensor input(DT_INT32, TensorShape({2, 3})); + + Tensor paddings(DT_INT32, TensorShape({2, 2})); + + AssignInputValuesRandom(input, 1, 4); + AssignInputValuesRandom(paddings, 2, 5); + + auto R = ops::Pad(root, input, paddings); + vector output_datatypes = {DT_INT32}; + std::vector sess_run_fetchoutputs = {R}; + + OpExecuter opexecuter(root, "Pad", static_input_indexes, output_datatypes, + sess_run_fetchoutputs); + + opexecuter.RunTest(); + +} // end of op Pad + // Test op: PreventGradient TEST(ArrayOps, PreventGradient) { Scope scope_cpu = Scope::NewRootScope(); diff --git a/test_ngtf.py b/test_ngtf.py index b985e940..c4c1e045 100755 --- a/test_ngtf.py +++ b/test_ngtf.py @@ -24,223 +24,8 @@ import platform from distutils.sysconfig import get_python_lib -from tools.build_utils import load_venv, command_executor - - -def run_ngtf_gtests(build_dir, filters): - root_pwd = os.getcwd() - build_dir = os.path.abspath(build_dir) - - os.environ['GTEST_OUTPUT'] = 'xml:%s/xunit_gtest.xml' % build_dir - - if not os.path.isdir(build_dir): - raise Exception("build directory doesn't exist: " + build_dir) - - # First run the C++ gtests - os.chdir(os.path.join(build_dir, "test")) - if (filters != None): - gtest_filters = "--gtest_filter=" + filters - cmd = ['./gtest_ngtf', gtest_filters] - else: - cmd = ['./gtest_ngtf'] - - command_executor(cmd, verbose=True) - - os.chdir(root_pwd) - - -def run_ngtf_pytests(venv_dir, build_dir): - root_pwd = os.getcwd() - - build_dir = os.path.abspath(build_dir) - venv_dir = os.path.abspath(venv_dir) - - test_dir = os.path.join(build_dir, "test") - test_dir = os.path.join(test_dir, "python") - - if not os.path.isdir(test_dir): - raise Exception("test directory doesn't exist: " + test_dir) - - # Change the directory to the test_dir - os.chdir(test_dir) - - # Load venv - load_venv(venv_dir) - - # Next run the ngraph-tensorflow python tests - command_executor(["pip", "install", "-U", "pytest"]) - command_executor(["pip", "install", "-U", "psutil"]) - command_executor([ - "python", "-m", "pytest", - ('--junitxml=%s/xunit_pytest.xml' % build_dir) - ]) - - os.chdir(root_pwd) - - -def run_tensorflow_pytests(venv_dir, build_dir, ngraph_tf_src_dir, tf_src_dir): - root_pwd = os.getcwd() - - build_dir = os.path.abspath(build_dir) - venv_dir = os.path.abspath(venv_dir) - ngraph_tf_src_dir = os.path.abspath(ngraph_tf_src_dir) - - patch_file = os.path.abspath( - os.path.join(ngraph_tf_src_dir, - "test/python/tensorflow/tf_unittest_ngraph.patch")) - - # Load the virtual env - venv_dir_absolute = load_venv(venv_dir) - - # Next patch the TensorFlow so that the tests run using ngraph_bridge - pwd = os.getcwd() - - # Go to the site-packages - os.chdir(glob.glob(venv_dir_absolute + "/lib/py*/site-packages")[0]) - print("CURRENT DIR: " + os.getcwd()) - - print("Patching TensorFlow using: %s" % patch_file) - result = call(["patch", "-p1", "-N", "-i", patch_file]) - print("Patch result: %d" % result) - os.chdir(pwd) - - # Now run the TensorFlow python tests - test_src_dir = os.path.join(ngraph_tf_src_dir, "test/python/tensorflow") - test_script = os.path.join(test_src_dir, "tf_unittest_runner.py") - test_manifest_file = os.path.join(test_src_dir, "python_tests_list.txt") - test_xml_report = '%s/junit_tensorflow_tests.xml' % build_dir - - import psutil - num_cores = int(psutil.cpu_count(logical=False)) - print("OMP_NUM_THREADS: %s " % str(num_cores)) - os.environ['OMP_NUM_THREADS'] = str(num_cores) - os.environ['NGRAPH_TF_DISABLE_DEASSIGN_CLUSTERS'] = '1' - - command_executor([ - "python", test_script, "--tensorflow_path", tf_src_dir, - "--run_tests_from_file", test_manifest_file, "--xml_report", - test_xml_report - ]) - - os.chdir(root_pwd) - - -def run_resnet50(build_dir): - - root_pwd = os.getcwd() - build_dir = os.path.abspath(build_dir) - os.chdir(build_dir) - - call(['git', 'clone', 'https://github.com/tensorflow/benchmarks.git']) - os.chdir('benchmarks/scripts/tf_cnn_benchmarks/') - - call(['git', 'checkout', '4c7b09ad87bbfc4b1f89650bcee40b3fc5e7dfed']) - - junit_script = os.path.abspath('%s/test/ci/junit-wrap.sh' % root_pwd) - - # Update the script by adding `import ngraph_bridge` - with open('convnet_builder.py', 'a') as outfile: - call(['echo', 'import ngraph_bridge'], stdout=outfile) - - # Setup the env flags - import psutil - num_cores = int(psutil.cpu_count(logical=False)) - print("OMP_NUM_THREADS: %s " % str(num_cores)) - - os.environ['OMP_NUM_THREADS'] = str(num_cores) - os.environ["KMP_AFFINITY"] = 'granularity=fine,compact,1,0' - - # Delete the temporary model save directory - model_save_dir = os.getcwd() + '/modelsavepath' - if os.path.exists(model_save_dir) and os.path.isdir(model_save_dir): - shutil.rmtree(model_save_dir) - - os.environ['JUNIT_WRAP_FILE'] = "%s/junit_training_test.xml" % build_dir - os.environ['JUNIT_WRAP_SUITE'] = 'models' - os.environ['JUNIT_WRAP_TEST'] = 'resnet50-training' - - # Run training job - cmd = [ - junit_script, 'python', 'tf_cnn_benchmarks.py', '--data_format', - 'NCHW', '--num_inter_threads', '1', '--train_dir=' + model_save_dir, - '--num_batches', '10', '--model=resnet50', '--batch_size=128' - ] - command_executor(cmd) - - os.environ['JUNIT_WRAP_FILE'] = "%s/junit_inference_test.xml" % build_dir - os.environ['JUNIT_WRAP_SUITE'] = 'models' - os.environ['JUNIT_WRAP_TEST'] = 'resnet50-inference' - - # Run inference job - cmd = [ - junit_script, 'python', 'tf_cnn_benchmarks.py', '--data_format', - 'NCHW', '--num_inter_threads', '1', '--train_dir=' + model_save_dir, - '--model=resnet50', '--batch_size=128', '--num_batches', '10', '--eval' - ] - command_executor(cmd) - - os.chdir(root_pwd) - - -def run_cpp_example_test(build_dir): - - root_pwd = os.getcwd() - build_dir = os.path.abspath(build_dir) - os.chdir(build_dir) - - # Create the example workspace directory and chdir there - path = 'cpp_example' - try: - os.makedirs(path) - except OSError as exc: # Python >2.5 - if exc.errno == errno.EEXIST and os.path.isdir(path): - pass - os.chdir(path) - - # Copy the files - files = [ - '../../examples/tf_cpp_examples/hello_tf.cpp', - '../../examples/tf_cpp_examples/Makefile' - ] - command_executor(['cp', files[0], './']) - command_executor(['cp', files[1], './']) - - # Now execute Make - command_executor(['make']) - - # Now run the hello_tf example - # First setup the LD_LIB_PATH - if (platform.system() == 'Darwin'): - ld_path_name = 'DYLD_LIBRARY_PATH' - else: - ld_path_name = 'LD_LIBRARY_PATH' - - os.environ[ld_path_name] = '../artifacts/lib:../artifacts/tensorflow' - command_executor('./hello_tf') - - # Return to the original directory - os.chdir(root_pwd) - - -def run_bazel_build_test(venv_dir, build_dir): - # Load the virtual env - venv_dir_absolute = load_venv(venv_dir) - - # Next patch the TensorFlow so that the tests run using ngraph_bridge - root_pwd = os.getcwd() - - # Now run the configure - command_executor(['bash', 'configure_bazel.sh']) - - # Build the bridge - command_executor(['bazel', 'build', 'libngraph_bridge.so']) - - # Build the backend - command_executor(['bazel', 'build', '@ngraph//:libinterpreter_backend.so']) - - # Return to the original directory - os.chdir(root_pwd) - +#from tools.build_utils import load_venv, command_executor +from tools.test_utils import * def main(): ''' diff --git a/tools/test_utils.py b/tools/test_utils.py new file mode 100755 index 00000000..a7a8e20f --- /dev/null +++ b/tools/test_utils.py @@ -0,0 +1,396 @@ +#!/usr/bin/env python3 +# ============================================================================== +# Copyright 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. +# ============================================================================== + +import argparse +import errno +import os +from subprocess import check_output, call +import sys +import shutil +import glob +import platform +from distutils.sysconfig import get_python_lib + +from tools.build_utils import load_venv, command_executor + + +def get_os_type(): + if platform.system() == 'Darwin': + return 'Darwin' + + if platform.linux_distribution(): + return platform.linux_distribution()[0] + + +def install_ngraph_bridge(artifacts_dir): + # Determine the ngraph whl + ngtf_wheel_files = glob.glob(artifacts_dir + + "/ngraph_tensorflow_bridge-*.whl") + if (len(ngtf_wheel_files) != 1): + print("Multiple Python whl files exist. Please remove old wheels") + for whl in ngtf_wheel_files: + print("Existing Wheel: " + whl) + raise Exception("Error getting the ngraph-tf wheel file") + + # First ensure that we have nGraph installed + ng_whl = os.path.join(artifacts_dir, ngtf_wheel_files[0]) + command_executor(["pip", "install", "-U", ng_whl]) + + +#@depricated +def run_ngtf_gtests(build_dir, filters): + root_pwd = os.getcwd() + build_dir = os.path.abspath(build_dir) + + os.environ['GTEST_OUTPUT'] = 'xml:%s/xunit_gtest.xml' % build_dir + + if not os.path.isdir(build_dir): + raise Exception("build directory doesn't exist: " + build_dir) + + # First run the C++ gtests + os.chdir(os.path.join(build_dir, "test")) + if (filters != None): + gtest_filters = "--gtest_filter=" + filters + cmd = ['./gtest_ngtf', gtest_filters] + else: + cmd = ['./gtest_ngtf'] + + command_executor(cmd, verbose=True) + + os.chdir(root_pwd) + + +def run_ngtf_cpp_gtests(artifacts_dir, log_dir, filters): + root_pwd = os.getcwd() + artifacts_dir = os.path.abspath(artifacts_dir) + log_dir = os.path.abspath(log_dir) + + os.environ['GTEST_OUTPUT'] = 'xml:%s/xunit_gtest.xml' % log_dir + + if not os.path.isdir(artifacts_dir): + raise Exception("Artifacts directory doesn't exist: " + artifacts_dir) + + # First run the C++ gtests + lib_dir = 'lib' + if 'CentOS' in get_os_type(): + lib_dir = 'lib64' + + os.environ['LD_LIBRARY_PATH'] = os.path.join(artifacts_dir, lib_dir) + os.chdir(os.path.join(artifacts_dir, "test")) + if (filters != None): + gtest_filters = "--gtest_filter=" + filters + cmd = ['./gtest_ngtf', gtest_filters] + else: + cmd = ['./gtest_ngtf'] + + command_executor(cmd, verbose=True) + + os.chdir(root_pwd) + + +def run_ngtf_pytests(venv_dir, build_dir): + root_pwd = os.getcwd() + + build_dir = os.path.abspath(build_dir) + venv_dir = os.path.abspath(venv_dir) + + test_dir = os.path.join(build_dir, "test") + test_dir = os.path.join(test_dir, "python") + + if not os.path.isdir(test_dir): + raise Exception("test directory doesn't exist: " + test_dir) + + # Change the directory to the test_dir + os.chdir(test_dir) + + # Load venv + load_venv(venv_dir) + + # Next run the ngraph-tensorflow python tests + command_executor(["pip", "install", "-U", "pytest"]) + command_executor(["pip", "install", "-U", "psutil"]) + command_executor([ + "python", "-m", "pytest", ('--junitxml=%s/xunit_pytest.xml' % build_dir) + ], + verbose=True) + + os.chdir(root_pwd) + + +def run_ngtf_pytests_from_artifacts(artifacts_dir): + root_pwd = os.getcwd() + + artifacts_dir = os.path.abspath(artifacts_dir) + install_ngraph_bridge(artifacts_dir) + + test_dir = os.path.join(artifacts_dir, "test") + test_dir = os.path.join(test_dir, "python") + + if not os.path.isdir(test_dir): + raise Exception("test directory doesn't exist: " + test_dir) + + # Change the directory to the test_dir + os.chdir(test_dir) + + # Next run the ngraph-tensorflow python tests + command_executor(["pip", "install", "-U", "pytest"]) + command_executor(["pip", "install", "-U", "psutil"]) + command_executor([ + "python", "-m", "pytest", + ('--junitxml=%s/xunit_pytest.xml' % artifacts_dir) + ]) + + os.chdir(root_pwd) + + +def run_tensorflow_pytests(venv_dir, build_dir, ngraph_tf_src_dir, tf_src_dir): + root_pwd = os.getcwd() + + build_dir = os.path.abspath(build_dir) + venv_dir = os.path.abspath(venv_dir) + ngraph_tf_src_dir = os.path.abspath(ngraph_tf_src_dir) + + patch_file = os.path.abspath( + os.path.join(ngraph_tf_src_dir, + "test/python/tensorflow/tf_unittest_ngraph.patch")) + + # Load the virtual env + venv_dir_absolute = load_venv(venv_dir) + + # Next patch the TensorFlow so that the tests run using ngraph_bridge + pwd = os.getcwd() + + # Go to the site-packages + os.chdir(glob.glob(venv_dir_absolute + "/lib/py*/site-packages")[0]) + print("CURRENT DIR: " + os.getcwd()) + + print("Patching TensorFlow using: %s" % patch_file) + result = call(["patch", "-p1", "-N", "-i", patch_file]) + print("Patch result: %d" % result) + os.chdir(pwd) + + # Now run the TensorFlow python tests + test_src_dir = os.path.join(ngraph_tf_src_dir, "test/python/tensorflow") + test_script = os.path.join(test_src_dir, "tf_unittest_runner.py") + test_manifest_file = os.path.join(test_src_dir, "python_tests_list.txt") + test_xml_report = '%s/junit_tensorflow_tests.xml' % build_dir + + import psutil + num_cores = int(psutil.cpu_count(logical=False)) + print("OMP_NUM_THREADS: %s " % str(num_cores)) + os.environ['OMP_NUM_THREADS'] = str(num_cores) + os.environ['NGRAPH_TF_DISABLE_DEASSIGN_CLUSTERS'] = '1' + + command_executor([ + "python", test_script, "--tensorflow_path", tf_src_dir, + "--run_tests_from_file", test_manifest_file, "--xml_report", + test_xml_report + ]) + + os.chdir(root_pwd) + + +def run_resnet50(build_dir): + + root_pwd = os.getcwd() + build_dir = os.path.abspath(build_dir) + os.chdir(build_dir) + + call(['git', 'clone', 'https://github.com/tensorflow/benchmarks.git']) + os.chdir('benchmarks/scripts/tf_cnn_benchmarks/') + + call(['git', 'checkout', '4c7b09ad87bbfc4b1f89650bcee40b3fc5e7dfed']) + + junit_script = os.path.abspath('%s/test/ci/junit-wrap.sh' % root_pwd) + + # Update the script by adding `import ngraph_bridge` + with open('convnet_builder.py', 'a') as outfile: + call(['echo', 'import ngraph_bridge'], stdout=outfile) + + # Setup the env flags + import psutil + num_cores = int(psutil.cpu_count(logical=False)) + print("OMP_NUM_THREADS: %s " % str(num_cores)) + + os.environ['OMP_NUM_THREADS'] = str(num_cores) + os.environ["KMP_AFFINITY"] = 'granularity=fine,compact,1,0' + + # Delete the temporary model save directory + model_save_dir = os.getcwd() + '/modelsavepath' + if os.path.exists(model_save_dir) and os.path.isdir(model_save_dir): + shutil.rmtree(model_save_dir) + + os.environ['JUNIT_WRAP_FILE'] = "%s/junit_training_test.xml" % build_dir + os.environ['JUNIT_WRAP_SUITE'] = 'models' + os.environ['JUNIT_WRAP_TEST'] = 'resnet50-training' + + # Run training job + cmd = [ + junit_script, 'python', 'tf_cnn_benchmarks.py', '--data_format', 'NCHW', + '--num_inter_threads', '1', '--train_dir=' + model_save_dir, + '--num_batches', '10', '--model=resnet50', '--batch_size=128' + ] + command_executor(cmd) + + os.environ['JUNIT_WRAP_FILE'] = "%s/junit_inference_test.xml" % build_dir + os.environ['JUNIT_WRAP_SUITE'] = 'models' + os.environ['JUNIT_WRAP_TEST'] = 'resnet50-inference' + + # Run inference job + cmd = [ + junit_script, 'python', 'tf_cnn_benchmarks.py', '--data_format', 'NCHW', + '--num_inter_threads', '1', '--train_dir=' + model_save_dir, + '--model=resnet50', '--batch_size=128', '--num_batches', '10', '--eval' + ] + command_executor(cmd) + os.chdir(root_pwd) + + +def run_resnet50_from_artifacts(artifact_dir): + + root_pwd = os.getcwd() + artifact_dir = os.path.abspath(artifact_dir) + + install_ngraph_bridge(artifact_dir) + + # Now clone the repo and proceed + call(['git', 'clone', 'https://github.com/tensorflow/benchmarks.git']) + os.chdir('benchmarks/scripts/tf_cnn_benchmarks/') + + call(['git', 'checkout', '4c7b09ad87bbfc4b1f89650bcee40b3fc5e7dfed']) + + # junit_script = os.path.abspath('%s/test/ci/junit-wrap.sh' % root_pwd) + + # Update the script by adding `import ngraph_bridge` + with open('convnet_builder.py', 'a') as outfile: + call(['echo', 'import ngraph_bridge'], stdout=outfile) + + # Setup the env flags + import psutil + num_cores = int(psutil.cpu_count(logical=False)) + print("OMP_NUM_THREADS: %s " % str(num_cores)) + + os.environ['OMP_NUM_THREADS'] = str(num_cores) + os.environ["KMP_AFFINITY"] = 'granularity=fine,compact,1,0' + + # Delete the temporary model save directory + model_save_dir = os.getcwd() + '/modelsavepath' + if os.path.exists(model_save_dir) and os.path.isdir(model_save_dir): + shutil.rmtree(model_save_dir) + + eval_eventlog_dir = os.getcwd() + '/eval_eventlog_dir' + if os.path.exists(eval_eventlog_dir) and os.path.isdir(eval_eventlog_dir): + shutil.rmtree(eval_eventlog_dir) + + # os.environ['JUNIT_WRAP_FILE'] = "%s/junit_training_test.xml" % build_dir + # os.environ['JUNIT_WRAP_SUITE'] = 'models' + # os.environ['JUNIT_WRAP_TEST'] = 'resnet50-training' + + # Run training job + # cmd = [ + # junit_script, 'python', 'tf_cnn_benchmarks.py', '--data_format', + # 'NCHW', '--num_inter_threads', '1', '--train_dir=' + model_save_dir, + # '--num_batches', '10', '--model=resnet50', '--batch_size=128' + # ] + + cmd = [ + 'python', 'tf_cnn_benchmarks.py', '--data_format', 'NCHW', + '--num_inter_threads', '1', '--train_dir=' + model_save_dir, + '--num_batches', '10', '--model=resnet50', '--batch_size=128', + '--eval_dir=' + eval_eventlog_dir + ] + command_executor(cmd) + + # os.environ['JUNIT_WRAP_FILE'] = "%s/junit_inference_test.xml" % build_dir + # os.environ['JUNIT_WRAP_SUITE'] = 'models' + # os.environ['JUNIT_WRAP_TEST'] = 'resnet50-inference' + + # Run inference job + # cmd = [ + # junit_script, 'python', 'tf_cnn_benchmarks.py', '--data_format', + # 'NCHW', '--num_inter_threads', '1', '--train_dir=' + model_save_dir, + # '--model=resnet50', '--batch_size=128', '--num_batches', '10', '--eval' + # ] + cmd = [ + 'python', 'tf_cnn_benchmarks.py', '--data_format', 'NCHW', + '--num_inter_threads', '1', '--train_dir=' + model_save_dir, + '--model=resnet50', '--batch_size=128', '--num_batches', '10', '--eval', + '--eval_dir=' + eval_eventlog_dir + ] + command_executor(cmd) + + os.chdir(root_pwd) + + +def run_cpp_example_test(build_dir): + + root_pwd = os.getcwd() + build_dir = os.path.abspath(build_dir) + os.chdir(build_dir) + + # Create the example workspace directory and chdir there + path = 'cpp_example' + try: + os.makedirs(path) + except OSError as exc: # Python >2.5 + if exc.errno == errno.EEXIST and os.path.isdir(path): + pass + os.chdir(path) + + # Copy the files + files = [ + '../../examples/tf_cpp_examples/hello_tf.cpp', + '../../examples/tf_cpp_examples/Makefile' + ] + command_executor(['cp', files[0], './']) + command_executor(['cp', files[1], './']) + + # Now execute Make + command_executor(['make']) + + # Now run the hello_tf example + # First setup the LD_LIB_PATH + if (platform.system() == 'Darwin'): + ld_path_name = 'DYLD_LIBRARY_PATH' + else: + ld_path_name = 'LD_LIBRARY_PATH' + + os.environ[ld_path_name] = '../artifacts/lib:../artifacts/tensorflow' + command_executor('./hello_tf') + + # Return to the original directory + os.chdir(root_pwd) + + +def run_bazel_build_test(venv_dir, build_dir): + # Load the virtual env + venv_dir_absolute = load_venv(venv_dir) + + # Next patch the TensorFlow so that the tests run using ngraph_bridge + root_pwd = os.getcwd() + + # Now run the configure + command_executor(['bash', 'configure_bazel.sh']) + + # Build the bridge + command_executor(['bazel', 'build', 'libngraph_bridge.so']) + + # Build the backend + command_executor(['bazel', 'build', '@ngraph//:libinterpreter_backend.so']) + + # Return to the original directory + os.chdir(root_pwd)