diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..04baa01b --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,33 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.0.0 + hooks: + - id: check-added-large-files + - id: check-case-conflict + - id: check-json + - id: check-merge-conflict + - id: check-symlinks + - id: check-yaml + - id: trailing-whitespace + - id: end-of-file-fixer + - repo: local + hooks: + - id: clang-format + name: clang-format + entry: clang-format + language: system + files: \.(c|cc|cxx|cpp|h|hpp|hxx|js|proto)$ + args: ["-i"] + - id: cpplint + name: cpplint + entry: cpplint + language: system + files: \.(c|cc|cxx|cpp|h|hpp|hxx)$ + args: + - --filter=-runtime/references,-readability/nolint,-build/c++11 + - id: yapf + name: yapf + entry: yapf + language: system + files: \.py$ + args: [-i] diff --git a/CONTRIB.md b/CONTRIB.md index 20b6043d..fab17727 100644 --- a/CONTRIB.md +++ b/CONTRIB.md @@ -36,4 +36,3 @@ merge conflicts. syntax level). The script has an exit code of `0` when code meets the standard and non-zero otherwise. This script does *not* modify the source code. - diff --git a/README.md b/README.md index 6a15d12c..7b8e8a45 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ The [examples](https://github.com/NervanaSystems/he-transformer/tree/master/exam ## Building HE Transformer ### Dependencies -- Operating system: Ubuntu 16.04, Ubuntu 18.04. +- Operating system: Ubuntu 18.04. - CMake >= 3.12 - Compiler: g++ version >= 6.0, clang >= 5.0 - OpenMP is strongly suggested, though not strictly necessary. You may experience slow runtimes without OpenMP diff --git a/contrib/docker/Dockerfile.he_transformer.centos74 b/contrib/docker/Dockerfile.he_transformer.centos74 deleted file mode 100644 index d1d13ee2..00000000 --- a/contrib/docker/Dockerfile.he_transformer.centos74 +++ /dev/null @@ -1,61 +0,0 @@ -# ****************************************************************************** -# Copyright 2018-2020 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. -# ****************************************************************************** - -# Environment to build and unit-test he-transformer on fedora27 -# with gcc 7.3.1 -# with cmake 3.13.5 -# with clang 5.0.1 -# with python version 3.6.8 - -FROM centos:7 - -RUN yum -y update && \ - yum -y --enablerepo=extras install epel-release && \ - yum -y install \ - gcc gcc-c++ \ - cmake3 make \ - git \ - wget patch diffutils zlib-devel ncurses-devel libtinfo-dev \ - python python-devel python-setuptools \ - python3 python36-devel python3-setuptools \ - which unzip - -RUN yum -y install centos-release-scl && \ - yum install -y devtoolset-7 llvm-toolset-7 - -# For ngraph-tf integration testing -RUN easy_install pip -RUN pip install --upgrade pip setuptools virtualenv==16.0.0 - -SHELL [ "/usr/bin/scl", "enable", "devtoolset-7", "llvm-toolset-7"] - -RUN ln -s /usr/bin/cmake3 /usr/bin/cmake - -RUN cmake --version -RUN make --version -RUN gcc --version -RUN c++ --version -RUN clang --version -RUN clang++ --version -RUN python3 --version -RUN virtualenv --version - -# Get bazel -RUN wget https://github.com/bazelbuild/bazel/releases/download/0.25.2/bazel-0.25.2-installer-linux-x86_64.sh -RUN chmod +x ./bazel-0.25.2-installer-linux-x86_64.sh -RUN bash ./bazel-0.25.2-installer-linux-x86_64.sh - -WORKDIR /home diff --git a/contrib/docker/Dockerfile.he_transformer.fedora28 b/contrib/docker/Dockerfile.he_transformer.fedora28 deleted file mode 100644 index f6617cca..00000000 --- a/contrib/docker/Dockerfile.he_transformer.fedora28 +++ /dev/null @@ -1,55 +0,0 @@ -# ****************************************************************************** -# Copyright 2018-2020 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. -# ****************************************************************************** - -# Environment to build and unit-test he-transformer on fedora27 -# with g++ 8.3.1 -# with python 3.6.8 -# with cmake 3.14.4 -# with clang 6.0.1 - -FROM fedora:28 - -RUN dnf -y update && \ - dnf -y install \ - gcc gcc-c++ \ - cmake3 make \ - git python3 python3-pip \ - python-setuptools \ - wget unzip \ - which redhat-rpm-config \ - python3-devel \ - patch - -# For ngraph-tf integration testing -RUN pip install virtualenv -RUN pip3 install --upgrade pip setuptools virtualenv==16.0.0 -RUN dnf install -y clang - -RUN cmake --version -RUN make --version -RUN gcc --version -RUN c++ --version -RUN clang --version -RUN python3 --version -RUN virtualenv --version - -# Get bazel -RUN wget https://github.com/bazelbuild/bazel/releases/download/0.25.2/bazel-0.25.2-installer-linux-x86_64.sh -RUN chmod +x ./bazel-0.25.2-installer-linux-x86_64.sh -RUN bash ./bazel-0.25.2-installer-linux-x86_64.sh - -RUN pip install python-config -WORKDIR /home diff --git a/contrib/docker/Dockerfile.he_transformer.ubuntu1604 b/contrib/docker/Dockerfile.he_transformer.ubuntu1604 deleted file mode 100644 index 5584e001..00000000 --- a/contrib/docker/Dockerfile.he_transformer.ubuntu1604 +++ /dev/null @@ -1,78 +0,0 @@ -# ****************************************************************************** -# Copyright 2018-2020 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. -# ****************************************************************************** - -# Environment to build and unit-test he-transformer - -FROM ubuntu:16.04 -# with g++ 7.4.0 -# with clang++ 6.0.1 -# with python 3.5.2 -# with cmake 3.14.4 - -RUN apt-get update && apt-get install -y \ - python3-pip virtualenv \ - python3-numpy python3-dev python3-wheel \ - git \ - unzip wget \ - sudo \ - bash-completion \ - build-essential cmake \ - software-properties-common \ - git \ - wget patch diffutils libtinfo-dev \ - autoconf libtool \ - doxygen graphviz \ - yapf3 python3-yapf - -# Install clang-6 -RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - -RUN apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-6.0 main" -RUN apt-get update -RUN apt-get install -y clang-6.0 - -RUN apt-get clean autoclean && \ - apt-get autoremove -y - -# For ngraph-tf integration testing -RUN pip3 install --upgrade pip setuptools virtualenv==16.1.0 - -# SEAL requires newer version of CMake -RUN pip3 install cmake --upgrade - -# Get g++-7 -RUN add-apt-repository ppa:ubuntu-toolchain-r/test \ - && apt update \ - && apt install g++-7 -y - -# Set g++-7 to default -RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 50 -RUN update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 50 -RUN update-alternatives --set g++ /usr/bin/g++-7 -RUN update-alternatives --set gcc /usr/bin/gcc-7 - -RUN cmake --version -RUN make --version -RUN gcc --version -RUN c++ --version -RUN clang++-6.0 --version -RUN python3 --version -RUN virtualenv --version - -# Get bazel for ng-tf -RUN wget https://github.com/bazelbuild/bazel/releases/download/0.25.2/bazel-0.25.2-installer-linux-x86_64.sh -RUN chmod +x ./bazel-0.25.2-installer-linux-x86_64.sh -RUN bash ./bazel-0.25.2-installer-linux-x86_64.sh -WORKDIR /home diff --git a/contrib/docker/Dockerfile.he_transformer.ubuntu1804 b/contrib/docker/Dockerfile.he_transformer.ubuntu1804 index e2aaab88..a5f19253 100644 --- a/contrib/docker/Dockerfile.he_transformer.ubuntu1804 +++ b/contrib/docker/Dockerfile.he_transformer.ubuntu1804 @@ -22,6 +22,7 @@ FROM ubuntu:18.04 + RUN apt-get update && apt-get install -y \ python3-pip virtualenv \ python3-numpy python3-dev python3-wheel \ @@ -34,8 +35,11 @@ RUN apt-get update && apt-get install -y \ git \ wget patch diffutils libtinfo-dev \ autoconf libtool \ - doxygen graphviz \ - yapf3 python3-yapf + doxygen graphviz + +# Install recent version of yapf3 +RUN add-apt-repository "deb http://ubuntu.osuosl.org/ubuntu/ eoan main universe" +RUN apt-get update && apt-get install -y yapf3=0.28.0-1 # Install clang-9 RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - diff --git a/contrib/docker/Makefile b/contrib/docker/Makefile index 8793d4c9..fea5f24a 100644 --- a/contrib/docker/Makefile +++ b/contrib/docker/Makefile @@ -72,26 +72,11 @@ endif DBUILD_DIR = ${DIR}/contrib/docker/.build-${DBUILD_VERSION}_${OS_ID} # Configuration for specific reference OS_ID in Dockerfiles -ifeq ("$(shell echo ${OS_ID} | grep centos)","centos74") - RUN_AS_USER_SCRIPT=${DOCKUSER_HOME}/he-transformer-test/contrib/docker/run_as_centOS_ID_user.sh - DOCKERFILE=Dockerfile.he_transformer.centOS_ID74 -endif - -ifeq ("$(shell echo ${OS_ID} | grep fedora)","fedora28") - RUN_AS_USER_SCRIPT=${DOCKUSER_HOME}/he-transformer-test/contrib/docker/run_as_fedora_user.sh - DOCKERFILE=Dockerfile.he_transformer.fedora28 -endif - ifeq ("$(shell echo ${OS_ID} | grep ubuntu)","ubuntu1804") RUN_AS_USER_SCRIPT=${DOCKUSER_HOME}/he-transformer-test/contrib/docker/run_as_ubuntu_user.sh DOCKERFILE=Dockerfile.he_transformer.ubuntu1804 endif -ifeq ("$(shell echo ${OS_ID} | grep ubuntu)","ubuntu1604") - RUN_AS_USER_SCRIPT=${DOCKUSER_HOME}/he-transformer-test/contrib/docker/run_as_ubuntu_user.sh - DOCKERFILE=Dockerfile.he_transformer.ubuntu1604 -endif - DOCKER_CMD_MESG=Building for CPU support only. DOCKER_CMD=docker diff --git a/contrib/docker/README.md b/contrib/docker/README.md index a5ccb20b..ae90f834 100644 --- a/contrib/docker/README.md +++ b/contrib/docker/README.md @@ -43,34 +43,13 @@ Note that all operations performed inside the docker image are run as a regular ## Examples/Hints -* To build an Ubuntu 16.04 docker container, compile with gcc 7.4, and run unit tests: - -``` -cd contrib/docker -make check_gcc -``` - -* To build an Ubuntu 16.04 docker container, compile with clang 6.0 , and run unit tests: - -``` -cd contrib/docker -make check_clang -``` - -* To build a Ubuntu 18.04 docker container, compile with gcc 7, and run unit tests: +* To build a Ubuntu 18.04 docker container, compile with gcc 7.4, and run unit tests: ``` cd contrib/docker make check_gcc OS=ubuntu1804 ``` -* To build an Ubuntu 16.04 docker container with persistent builds, compile with gcc 7.4, and run unit tests: - -``` -cd contrib/docker -make build_gcc RM_CONTAINER=false -``` - To launch the shell with the persistent docker image, run ```bash make shell @@ -100,11 +79,7 @@ A helper script to run as a normal user within the docker container. This is do #### `run_as_ubuntu_user.sh` -Same as `run_as_user.sh`, specifically called for _make_ targets with Ubuntu 16.04 docker containers. - -#### `run_as_centos_user.sh` - -A helper script to run as a normal user within a CentOS 7.4 docker container. +Same as `run_as_user.sh`, specifically called for _make_ targets with Ubuntu 18.04 docker containers. ## Notes @@ -114,15 +89,6 @@ A helper script to run as a normal user within a CentOS 7.4 docker container. * The _make_ targets have been tested with the following docker containers on an Ubuntu 16.04 host OS with docker installed and the docker daemon properly configured. Some adjustments may be needed to run these on other OSes. -#### Ubuntu 16.04 (default) - -``` -Dockerfile: Dockerfile.he-transformer.ubuntu1604 -Reference-OS: Ubuntu 16.04 -BUILD-GCC: gcc 7.4.0 -BUILD-CLANG: clang 6.0.1 -``` - #### Ubuntu 18.04 ``` diff --git a/contrib/docker/build-he-transformer-and-test.sh b/contrib/docker/build-he-transformer-and-test.sh index 01a5c58f..5f451344 100755 --- a/contrib/docker/build-he-transformer-and-test.sh +++ b/contrib/docker/build-he-transformer-and-test.sh @@ -7,7 +7,7 @@ set -o pipefail # Enable job control to allow scl enable command set -m -# Debugging to verify builds on Centos 7.4 and Ubuntu 16.04 +# Debugging to verify build OS if [ -f "/etc/centos-release" ]; then cat /etc/centos-release fi @@ -73,17 +73,7 @@ cd $HE_TRANSFORMER_REPO export CMAKE_OPTIONS_COMMON="-DCMAKE_BUILD_TYPE=RelWithDebInfo ${CMAKE_OPTIONS_EXTRA}" export CMAKE_OPTIONS_GCC="${CMAKE_OPTIONS_COMMON}" -# Centos 7.4 doesn't have clang6.0 yet -# https://www.centos.org/forums/viewtopic.php?t=70149 -if [ "${OS_ID}" == "centos74" ]; then - # - set +e - source scl_source enable devtoolset-7 llvm-toolset-7 - set -e - export CMAKE_OPTIONS_CLANG="$CMAKE_OPTIONS_COMMON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -Werror" -else - export CMAKE_OPTIONS_CLANG="$CMAKE_OPTIONS_COMMON -DCMAKE_CXX_COMPILER=clang++-6.0 -DCMAKE_C_COMPILER=clang-6.0 -Werror" -fi +export CMAKE_OPTIONS_CLANG="$CMAKE_OPTIONS_COMMON -DCMAKE_CXX_COMPILER=clang++-6.0 -DCMAKE_C_COMPILER=clang-6.0 -Werror" echo "CMD_TO_RUN=${CMD_TO_RUN}" diff --git a/contrib/docker/make_docker_image.sh b/contrib/docker/make_docker_image.sh index 95908c67..c4cb8cd5 100755 --- a/contrib/docker/make_docker_image.sh +++ b/contrib/docker/make_docker_image.sh @@ -12,7 +12,7 @@ if [ -z $DOCKER_IMAGE_NAME ]; then DOCKER_IMAGE_NAME=${DOCKER_TAG} fi -# Debugging to verify builds on CentOS 7.4 and Ubuntu 16.04 +# Debugging to verify build OS if [ -f "/etc/centos-release" ]; then cat /etc/centos-release fi diff --git a/contrib/docker/run_as_centos_user.sh b/contrib/docker/run_as_centos_user.sh deleted file mode 100755 index c651dc26..00000000 --- a/contrib/docker/run_as_centos_user.sh +++ /dev/null @@ -1,99 +0,0 @@ -#! /bin/bash - -# ****************************************************************************** -# Copyright 2018-2020 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. -# ****************************************************************************** - -# ****************************************************************************** -# This script is designed to simulate running as a user with a particular UID -# within a docker container. -# -# Normally a docker container runs as root, which can cause problems with file -# ownership when a host directory tree is mounted into the docker container. -# There are other problems with building and running software as root as -# well. Good practice when validating software builds in a docker container -# is to run as a normal user, since many (most?) end users will not be building -# and installing software as root. -# -# This script should be run using "docker run", with RUN_UID (set to the user -# you want to run as) passed into the docker container as an environment -# variable. The script will then add the UID as user "dockuser" to -# /etc/passwd (important for some software, like bazel), add the new dockuser -# to the sudo group (whether or not sudo is installed), and su to a new shell -# as the dockuser (passing in the existing environment, which is important). -# -# If the environment variable RUN_CMD is passed into the docker container, then -# this script will use RUN_CMD as a command to run when su'ing. If RUN_CMD is -# not defined, then /bin/bash will run, which effectively provides an -# interactive shell in the docker container, for debugging. -# ****************************************************************************** - -set -e # Make sure we exit on any command that returns non-zero -set -u # No unset variables - -if [ -z "$RUN_UID" ] ; then - - # >&2 redirects echo output to stderr. - # See: https://stackoverflow.com/questions/2990414/echo-that-outputs-to-stderr - ( >&2 echo 'ERROR: Environment variable RUN_UID was not set when run-as-user.sh was run' ) - ( >&2 echo ' Running as default user (root, in docker)' ) - ( >&2 echo ' ' ) - - exit 1 - -else - - # The username used in the docker container to map the caller UID to - # - # Note 'dockuser' is used in other scripts, notably Makefile. If you - # choose to change it here, then you need to change it in all other - # scripts, or else the builds will break. - # - DOCK_USER='dockuser' - - # We will be su'ing using a non-login shell or command, and preserving - # the environment. This is done so that env. variables passed in with - # "docker run --env ..." are honored. - # Therefore, we need to reset at least HOME=/root ... - # - # Note also that /home/dockuser is used in other scripts, notably - # Makefile. If you choose to change it here, then you need to change it - # in all other scripts, or else the builds will break. - # - export HOME="/home/${DOCK_USER}" - - # Make sure the home directory is owned by the new user - if [ -d "${HOME}" ] ; then - chown "${RUN_UID}" "${HOME}" - fi - - # Add a user with UID of person running docker (in ${RUN_UID}) - # If $HOME does not yet exist, then it will be created - adduser -c 'Docker-User' -u "${RUN_UID}" "${DOCK_USER}" - passwd -d "${DOCK_USER}" - # Add dockuser to the sudo group. Sudo *is* used for installing packages, - # so make sure dockuser can run sudo without requesting a password. - usermod -aG wheel "${DOCK_USER}" - echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers - - if [ -z "${RUN_CMD+x}" ] ; then # Launch a shell as dockuser - echo 'Running interactive shell (/bin/bash) as dockuser' - su -m "${DOCK_USER}" -c "/bin/bash" - else # Run command as dockuser - echo "Running command [${RUN_CMD}] as dockuser" - su -m "${DOCK_USER}" -c "${RUN_CMD}" - fi - -fi diff --git a/contrib/docker/run_as_fedora_user.sh b/contrib/docker/run_as_fedora_user.sh deleted file mode 100755 index 4f035c2c..00000000 --- a/contrib/docker/run_as_fedora_user.sh +++ /dev/null @@ -1,98 +0,0 @@ -#! /bin/bash - -# ****************************************************************************** -# Copyright 2018-2020 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. -# ****************************************************************************** - -# ****************************************************************************** -# This script is designed to simulate running as a user with a particular UID -# within a docker container. -# -# Normally a docker container runs as root, which can cause problems with file -# ownership when a host directory tree is mounted into the docker container. -# There are other problems with building and running software as root as -# well. Good practice when validating software builds in a docker container -# is to run as a normal user, since many (most?) end users will not be building -# and installing software as root. -# -# This script should be run using "docker run", with RUN_UID (set to the user -# you want to run as) passed into the docker container as an environment -# variable. The script will then add the UID as user "dockuser" to -# /etc/passwd (important for some software, like bazel), add the new dockuser -# to the sudo group (whether or not sudo is installed), and su to a new shell -# as the dockuser (passing in the existing environment, which is important). -# -# If the environment variable RUN_CMD is passed into the docker container, then -# this script will use RUN_CMD as a command to run when su'ing. If RUN_CMD is -# not defined, then /bin/bash will run, which effectively provides an -# interactive shell in the docker container, for debugging. -# ****************************************************************************** - -set -e # Make sure we exit on any command that returns non-zero -set -u # No unset variables - -if [ -z "$RUN_UID" ] ; then - - # >&2 redirects echo output to stderr. - # See: https://stackoverflow.com/questions/2990414/echo-that-outputs-to-stderr - ( >&2 echo 'ERROR: Environment variable RUN_UID was not set when run-as-user.sh was run' ) - ( >&2 echo ' Running as default user (root, in docker)' ) - ( >&2 echo ' ' ) - - exit 1 - -else - - # The username used in the docker container to map the caller UID to - # - # Note 'dockuser' is used in other scripts, notably Makefile. If you - # choose to change it here, then you need to change it in all other - # scripts, or else the builds will break. - # - DOCK_USER='dockuser' - - # We will be su'ing using a non-login shell or command, and preserving - # the environment. This is done so that env. variables passed in with - # "docker run --env ..." are honored. - # Therefore, we need to reset at least HOME=/root ... - # - # Note also that /home/dockuser is used in other scripts, notably - # Makefile. If you choose to change it here, then you need to change it - # in all other scripts, or else the builds will break. - # - export HOME="/home/${DOCK_USER}" - - # Make sure the home directory is owned by the new user - if [ -d "${HOME}" ] ; then - chown "${RUN_UID}" "${HOME}" - fi - - # Add a user with UID of person running docker (in ${RUN_UID}) - # If $HOME does not yet exist, then it will be created - adduser -c 'Docker-User' -u "${RUN_UID}" "${DOCK_USER}" - # Add dockuser to the sudo group. Sudo *is* used for installing packages, - # so make sure dockuser can run sudo without requesting a password. - usermod -aG wheel "${DOCK_USER}" - echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers - - if [ -z "${RUN_CMD+x}" ] ; then # Launch a shell as dockuser - echo 'Running interactive shell (/bin/bash) as dockuser' - su -m "${DOCK_USER}" -c "/bin/bash" - else # Run command as dockuser - echo "Running command [${RUN_CMD}] as dockuser" - su -m "${DOCK_USER}" -c "${RUN_CMD}" - fi - -fi diff --git a/examples/ImageNet/MobileNetV2/client.py b/examples/ImageNet/MobileNetV2/client.py index 0c0ad4f2..7cfe27f4 100644 --- a/examples/ImageNet/MobileNetV2/client.py +++ b/examples/ImageNet/MobileNetV2/client.py @@ -84,9 +84,8 @@ def main(FLAGS): x_test_flat = x_test.flatten(order="C") port = 34000 - client = pyhe_client.HESealClient(FLAGS.hostname, port, batch_size, { - "input": ("encrypt", x_test_flat) - }) + client = pyhe_client.HESealClient(FLAGS.hostname, port, batch_size, + {"input": ("encrypt", x_test_flat)}) results = client.get_results() @@ -116,11 +115,10 @@ def main(FLAGS): "Directory where cropped ImageNet data and ground truth labels are stored", ) parser.add_argument("--image_size", type=int, default=96, help="image size") - parser.add_argument( - "--save_images", - type=str2bool, - default=False, - help="save cropped images") + parser.add_argument("--save_images", + type=str2bool, + default=False, + help="save cropped images") parser.add_argument( "--load_cropped_images", type=str2bool, @@ -139,11 +137,15 @@ def main(FLAGS): default=256, help="crop to this size before resizing to image_size", ) - parser.add_argument( - "--hostname", type=str, default="localhost", help="server hostname") + parser.add_argument("--hostname", + type=str, + default="localhost", + help="server hostname") parser.add_argument("--batch_size", type=int, default=1, help="Batch size") - parser.add_argument( - "--start_batch", type=int, default=0, help="Test data start index") + parser.add_argument("--start_batch", + type=int, + default=0, + help="Test data start index") FLAGS, unparsed = parser.parse_known_args() if FLAGS.data_dir == None: diff --git a/examples/ImageNet/MobileNetV2/test.py b/examples/ImageNet/MobileNetV2/test.py index 9cdf5660..f082a72a 100644 --- a/examples/ImageNet/MobileNetV2/test.py +++ b/examples/ImageNet/MobileNetV2/test.py @@ -133,11 +133,10 @@ def main(FLAGS): help="Model to run inference with", ) parser.add_argument("--image_size", type=int, default=96, help="image size") - parser.add_argument( - "--save_images", - type=str2bool, - default=False, - help="save cropped images") + parser.add_argument("--save_images", + type=str2bool, + default=False, + help="save cropped images") parser.add_argument( "--load_cropped_images", type=str2bool, @@ -156,10 +155,14 @@ def main(FLAGS): default=256, help="crop to this size before resizing to image_size", ) - parser.add_argument( - "--ngraph", type=str2bool, default=False, help="use ngraph backend") - parser.add_argument( - "--start_batch", type=int, default=0, help="Test data start index") + parser.add_argument("--ngraph", + type=str2bool, + default=False, + help="use ngraph backend") + parser.add_argument("--start_batch", + type=int, + default=0, + help="Test data start index") FLAGS, unparsed = parser.parse_known_args() if FLAGS.data_dir == None: diff --git a/examples/ImageNet/MobileNetV2/util.py b/examples/ImageNet/MobileNetV2/util.py index 494510e5..b05d0c04 100644 --- a/examples/ImageNet/MobileNetV2/util.py +++ b/examples/ImageNet/MobileNetV2/util.py @@ -89,8 +89,8 @@ def center_crop2(im, new_size): # Resize such that shortest side has new_size width, height = im.size ratio = min(width / new_size, height / new_size) - im = im.resize( - (int(width / ratio), int(height / ratio)), resample=Image.LANCZOS) + im = im.resize((int(width / ratio), int(height / ratio)), + resample=Image.LANCZOS) # Center crop to new_size x new_size im = center_crop(im, new_size) @@ -140,8 +140,8 @@ def get_validation_image(i, FLAGS): stds = [0.229, 0.224, 0.225] # Subtract mean, then scale such that result is in (-1, 1) for channel in range(3): - im[:, :, channel] = (im[:, :, channel] - means[channel]) * ( - 1.0 / means[channel]) + im[:, :, channel] = (im[:, :, channel] - + means[channel]) * (1.0 / means[channel]) else: im = im / 128.0 - 1 im = np.expand_dims(im, axis=0) @@ -195,13 +195,14 @@ def accuracy(preds, truth): def server_argument_parser(): parser = argparse.ArgumentParser() parser.add_argument("--batch_size", type=int, default=1, help="Batch size") - parser.add_argument( - "--enable_client", - type=str2bool, - default=False, - help="Enable the client") - parser.add_argument( - "--backend", type=str, default="HE_SEAL", help="Name of backend to use") + parser.add_argument("--enable_client", + type=str2bool, + default=False, + help="Enable the client") + parser.add_argument("--backend", + type=str, + default="HE_SEAL", + help="Name of backend to use") parser.add_argument( "--encryption_parameters", type=str, @@ -216,11 +217,10 @@ def server_argument_parser(): help= "Encrypt server data (should not be used when enable_client is used)", ) - parser.add_argument( - "--pack_data", - type=str2bool, - default=True, - help="Use plaintext packing on data") + parser.add_argument("--pack_data", + type=str2bool, + default=True, + help="Use plaintext packing on data") return parser @@ -248,8 +248,7 @@ def server_config_from_flags(FLAGS, tensor_param_name): config = tf.compat.v1.ConfigProto() config.MergeFrom( - tf.compat.v1.ConfigProto( - graph_options=tf.compat.v1.GraphOptions( - rewrite_options=rewriter_options))) + tf.compat.v1.ConfigProto(graph_options=tf.compat.v1.GraphOptions( + rewrite_options=rewriter_options))) return config diff --git a/examples/MNIST/Cryptonets-Relu/train.py b/examples/MNIST/Cryptonets-Relu/train.py index 7ab9298c..1519f77a 100644 --- a/examples/MNIST/Cryptonets-Relu/train.py +++ b/examples/MNIST/Cryptonets-Relu/train.py @@ -76,13 +76,9 @@ def squash_layers(cryptonets_relu_model, sess): # Pass 0 to get bias squashed_bias = y.eval( session=sess, - feed_dict={ - "squashed_input:0": np.zeros((1, 14 * 14 * 5)) - }) + feed_dict={"squashed_input:0": np.zeros((1, 14 * 14 * 5))}) squashed_bias_plus_weights = y.eval( - session=sess, feed_dict={ - "squashed_input:0": np.eye(14 * 14 * 5) - }) + session=sess, feed_dict={"squashed_input:0": np.eye(14 * 14 * 5)}) squashed_weights = squashed_bias_plus_weights - squashed_bias print("squashed layers") @@ -100,33 +96,34 @@ def squash_layers(cryptonets_relu_model, sess): def main(FLAGS): (x_train, y_train, x_test, y_test) = mnist_util.load_mnist_data() - x = Input( - shape=( - 28, - 28, - 1, - ), name="input") + x = Input(shape=( + 28, + 28, + 1, + ), name="input") y = model.cryptonets_relu_model(x) cryptonets_relu_model = Model(inputs=x, outputs=y) print(cryptonets_relu_model.summary()) def loss(labels, logits): - return keras.losses.categorical_crossentropy( - labels, logits, from_logits=True) + return keras.losses.categorical_crossentropy(labels, + logits, + from_logits=True) optimizer = SGD(learning_rate=0.008, momentum=0.9) - cryptonets_relu_model.compile( - optimizer=optimizer, loss=loss, metrics=["accuracy"]) - - cryptonets_relu_model.fit( - x_train, - y_train, - epochs=FLAGS.epochs, - validation_data=(x_test, y_test), - batch_size=FLAGS.batch_size) - - test_loss, test_acc = cryptonets_relu_model.evaluate( - x_test, y_test, verbose=2) + cryptonets_relu_model.compile(optimizer=optimizer, + loss=loss, + metrics=["accuracy"]) + + cryptonets_relu_model.fit(x_train, + y_train, + epochs=FLAGS.epochs, + validation_data=(x_test, y_test), + batch_size=FLAGS.batch_size) + + test_loss, test_acc = cryptonets_relu_model.evaluate(x_test, + y_test, + verbose=2) print("Test accuracy:", test_acc) # Squash weights and save model @@ -137,12 +134,11 @@ def loss(labels, logits): tf.reset_default_graph() sess = tf.compat.v1.Session() - x = Input( - shape=( - 28, - 28, - 1, - ), name="input") + x = Input(shape=( + 28, + 28, + 1, + ), name="input") y = model.cryptonets_relu_model_squashed(x, conv1_weights, squashed_weights, fc2_weights) sess.run(tf.compat.v1.global_variables_initializer()) diff --git a/examples/MNIST/Cryptonets/train.py b/examples/MNIST/Cryptonets/train.py index d5967288..b8eee760 100644 --- a/examples/MNIST/Cryptonets/train.py +++ b/examples/MNIST/Cryptonets/train.py @@ -79,13 +79,9 @@ def squash_layers(cryptonets_model, sess): # Pass 0 to get bias squashed_bias = y.eval( session=sess, - feed_dict={ - "squashed_input:0": np.zeros((1, 14 * 14 * 5)) - }) + feed_dict={"squashed_input:0": np.zeros((1, 14 * 14 * 5))}) squashed_bias_plus_weights = y.eval( - session=sess, feed_dict={ - "squashed_input:0": np.eye(14 * 14 * 5) - }) + session=sess, feed_dict={"squashed_input:0": np.eye(14 * 14 * 5)}) squashed_weights = squashed_bias_plus_weights - squashed_bias print("squashed layers") @@ -103,32 +99,32 @@ def squash_layers(cryptonets_model, sess): def main(FLAGS): (x_train, y_train, x_test, y_test) = mnist_util.load_mnist_data() - x = Input( - shape=( - 28, - 28, - 1, - ), name="input") + x = Input(shape=( + 28, + 28, + 1, + ), name="input") y = model.cryptonets_model(x) cryptonets_model = Model(inputs=x, outputs=y) print(cryptonets_model.summary()) def loss(labels, logits): - return keras.losses.categorical_crossentropy( - labels, logits, from_logits=True) + return keras.losses.categorical_crossentropy(labels, + logits, + from_logits=True) optimizer = SGD(learning_rate=0.008, momentum=0.9) - cryptonets_model.compile( - optimizer=optimizer, loss=loss, metrics=["accuracy"]) + cryptonets_model.compile(optimizer=optimizer, + loss=loss, + metrics=["accuracy"]) - cryptonets_model.fit( - x_train, - y_train, - epochs=FLAGS.epochs, - batch_size=FLAGS.batch_size, - validation_data=(x_test, y_test), - verbose=1) + cryptonets_model.fit(x_train, + y_train, + epochs=FLAGS.epochs, + batch_size=FLAGS.batch_size, + validation_data=(x_test, y_test), + verbose=1) test_loss, test_acc = cryptonets_model.evaluate(x_test, y_test, verbose=1) print("Test accuracy:", test_acc) @@ -141,12 +137,11 @@ def loss(labels, logits): tf.reset_default_graph() sess = tf.compat.v1.Session() - x = Input( - shape=( - 28, - 28, - 1, - ), name="input") + x = Input(shape=( + 28, + 28, + 1, + ), name="input") y = model.cryptonets_model_squashed(x, conv1_weights, squashed_weights, fc2_weights) sess.run(tf.compat.v1.global_variables_initializer()) diff --git a/examples/MNIST/MLP/train.py b/examples/MNIST/MLP/train.py index 5ce9a801..f3a50549 100644 --- a/examples/MNIST/MLP/train.py +++ b/examples/MNIST/MLP/train.py @@ -33,12 +33,11 @@ def main(FLAGS): (x_train, y_train, x_test, y_test) = mnist_util.load_mnist_data() - x = Input( - shape=( - 28, - 28, - 1, - ), name="input") + x = Input(shape=( + 28, + 28, + 1, + ), name="input") y = model.mnist_mlp_model(x) mlp_model = Model(inputs=x, outputs=y) @@ -50,13 +49,12 @@ def loss(labels, logits): optimizer = SGD(learning_rate=0.008, momentum=0.9) mlp_model.compile(optimizer=optimizer, loss=loss, metrics=["accuracy"]) - mlp_model.fit( - x_train, - y_train, - epochs=FLAGS.epochs, - batch_size=FLAGS.batch_size, - validation_data=(x_test, y_test), - verbose=1) + mlp_model.fit(x_train, + y_train, + epochs=FLAGS.epochs, + batch_size=FLAGS.batch_size, + validation_data=(x_test, y_test), + verbose=1) test_loss, test_acc = mlp_model.evaluate(x_test, y_test, verbose=1) print("\nTest accuracy:", test_acc) diff --git a/examples/MNIST/mnist_util.py b/examples/MNIST/mnist_util.py index 6a719ddd..cf1983b9 100644 --- a/examples/MNIST/mnist_util.py +++ b/examples/MNIST/mnist_util.py @@ -105,8 +105,9 @@ def freeze_session(session, if clear_devices: for node in input_graph_def.node: node.device = "" - frozen_graph = convert_variables_to_constants( - session, input_graph_def, output_names, freeze_var_names) + frozen_graph = convert_variables_to_constants(session, input_graph_def, + output_names, + freeze_var_names) frozen_graph = remove_training_nodes(frozen_graph) return frozen_graph @@ -130,10 +131,14 @@ def str2bool(v): def train_argument_parser(): parser = argparse.ArgumentParser() - parser.add_argument( - "--epochs", type=int, default=10, help="Number of training epochs") - parser.add_argument( - "--batch_size", type=int, default=128, help="Batch Size") + parser.add_argument("--epochs", + type=int, + default=10, + help="Number of training epochs") + parser.add_argument("--batch_size", + type=int, + default=128, + help="Batch Size") return parser @@ -141,23 +146,28 @@ def train_argument_parser(): def client_argument_parser(): parser = argparse.ArgumentParser() parser.add_argument("--batch_size", type=int, default=1, help="Batch size") - parser.add_argument( - "--hostname", type=str, default="localhost", help="Hostname of server") - parser.add_argument( - "--port", type=int, default=34000, help="Port of server") + parser.add_argument("--hostname", + type=str, + default="localhost", + help="Hostname of server") + parser.add_argument("--port", + type=int, + default=34000, + help="Port of server") parser.add_argument( "--encrypt_data_str", type=str, default="encrypt", help='"encrypt" to encrypt client data, "plain" to not encrypt', ) - parser.add_argument( - "--tensor_name", - type=str, - default="import/input", - help="Input tensor name") - parser.add_argument( - "--start_batch", type=int, default=0, help="Test data start index") + parser.add_argument("--tensor_name", + type=str, + default="import/input", + help="Input tensor name") + parser.add_argument("--start_batch", + type=int, + default=0, + help="Test data start index") return parser @@ -165,16 +175,14 @@ def client_argument_parser(): def server_argument_parser(): parser = argparse.ArgumentParser() parser.add_argument("--batch_size", type=int, default=1, help="Batch size") - parser.add_argument( - "--enable_client", - type=str2bool, - default=False, - help="Enable the client") - parser.add_argument( - "--enable_gc", - type=str2bool, - default=False, - help="Enable garbled circuits") + parser.add_argument("--enable_client", + type=str2bool, + default=False, + help="Enable the client") + parser.add_argument("--enable_gc", + type=str2bool, + default=False, + help="Enable garbled circuits") parser.add_argument( "--mask_gc_inputs", type=str2bool, @@ -193,8 +201,10 @@ def server_argument_parser(): default=1, help="Number of threads to run garbled circuits with", ) - parser.add_argument( - "--backend", type=str, default="HE_SEAL", help="Name of backend to use") + parser.add_argument("--backend", + type=str, + default="HE_SEAL", + help="Name of backend to use") parser.add_argument( "--encryption_parameters", type=str, @@ -209,18 +219,18 @@ def server_argument_parser(): help= "Encrypt server data (should not be used when enable_client is used)", ) - parser.add_argument( - "--pack_data", - type=str2bool, - default=True, - help="Use plaintext packing on data") - parser.add_argument( - "--start_batch", type=int, default=0, help="Test data start index") - parser.add_argument( - "--model_file", - type=str, - default="", - help="Filename of saved protobuf model") + parser.add_argument("--pack_data", + type=str2bool, + default=True, + help="Use plaintext packing on data") + parser.add_argument("--start_batch", + type=int, + default=0, + help="Test data start index") + parser.add_argument("--model_file", + type=str, + default="", + help="Filename of saved protobuf model") parser.add_argument( "--input_node", type=str, @@ -267,8 +277,7 @@ def server_config_from_flags(FLAGS, tensor_param_name): config = tf.compat.v1.ConfigProto() config.MergeFrom( - tf.compat.v1.ConfigProto( - graph_options=tf.compat.v1.GraphOptions( - rewrite_options=rewriter_options))) + tf.compat.v1.ConfigProto(graph_options=tf.compat.v1.GraphOptions( + rewrite_options=rewriter_options))) return config diff --git a/examples/MNIST/pyclient_mnist.py b/examples/MNIST/pyclient_mnist.py index 38fd1c59..a0851731 100644 --- a/examples/MNIST/pyclient_mnist.py +++ b/examples/MNIST/pyclient_mnist.py @@ -25,8 +25,8 @@ def test_network(FLAGS): - (x_train, y_train, x_test, y_test) = load_mnist_data( - FLAGS.start_batch, FLAGS.batch_size) + (x_train, y_train, x_test, + y_test) = load_mnist_data(FLAGS.start_batch, FLAGS.batch_size) data = x_test.flatten("C") client = pyhe_client.HESealClient( diff --git a/examples/MNIST/test.py b/examples/MNIST/test.py index 544a5957..1ea0f550 100644 --- a/examples/MNIST/test.py +++ b/examples/MNIST/test.py @@ -31,8 +31,8 @@ def test_network(FLAGS): - (x_train, y_train, x_test, y_test) = load_mnist_data( - FLAGS.start_batch, FLAGS.batch_size) + (x_train, y_train, x_test, + y_test) = load_mnist_data(FLAGS.start_batch, FLAGS.batch_size) # Load saved model tf.import_graph_def(load_pb_file(FLAGS.model_file)) diff --git a/examples/ax.py b/examples/ax.py index 30d43d8e..dc66d84b 100644 --- a/examples/ax.py +++ b/examples/ax.py @@ -49,9 +49,8 @@ def server_config_from_flags(FLAGS, tensor_param_name): config = tf.compat.v1.ConfigProto() config.MergeFrom( - tf.compat.v1.ConfigProto( - graph_options=tf.compat.v1.GraphOptions( - rewrite_options=rewriter_options))) + tf.compat.v1.ConfigProto(graph_options=tf.compat.v1.GraphOptions( + rewrite_options=rewriter_options))) return config @@ -59,8 +58,9 @@ def server_config_from_flags(FLAGS, tensor_param_name): def main(FLAGS): a = tf.constant(np.array([[1, 2, 3, 4]]), dtype=np.float32) - b = tf.compat.v1.placeholder( - tf.float32, shape=(1, 4), name="client_parameter_name") + b = tf.compat.v1.placeholder(tf.float32, + shape=(1, 4), + name="client_parameter_name") c = tf.compat.v1.placeholder(tf.float32, shape=(1, 4)) f = c * (a + b) @@ -76,13 +76,14 @@ def main(FLAGS): if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--batch_size", type=int, default=1, help="Batch size") - parser.add_argument( - "--enable_client", - type=str2bool, - default=False, - help="Enable the client") - parser.add_argument( - "--backend", type=str, default="HE_SEAL", help="Name of backend to use") + parser.add_argument("--enable_client", + type=str2bool, + default=False, + help="Enable the client") + parser.add_argument("--backend", + type=str, + default="HE_SEAL", + help="Name of backend to use") parser.add_argument( "--encryption_parameters", type=str, diff --git a/examples/pyclient.py b/examples/pyclient.py index 9b40c11d..2b69fa3c 100644 --- a/examples/pyclient.py +++ b/examples/pyclient.py @@ -25,9 +25,9 @@ def main(FLAGS): port = 34000 batch_size = 1 - client = pyhe_client.HESealClient(FLAGS.hostname, port, batch_size, { - "client_parameter_name": ("encrypt", data) - }) + client = pyhe_client.HESealClient( + FLAGS.hostname, port, batch_size, + {"client_parameter_name": ("encrypt", data)}) results = client.get_results() print("results", results) @@ -35,8 +35,10 @@ def main(FLAGS): if __name__ == "__main__": parser = argparse.ArgumentParser() - parser.add_argument( - "--hostname", type=str, default="localhost", help="Hostname of server") + parser.add_argument("--hostname", + type=str, + default="localhost", + help="Hostname of server") FLAGS, unparsed = parser.parse_known_args() diff --git a/maint/bash_lib.sh b/maint/bash_lib.sh index d84c1e15..3f284147 100755 --- a/maint/bash_lib.sh +++ b/maint/bash_lib.sh @@ -88,4 +88,3 @@ if bash_lib_am_sudo_or_root; then else bash_lib_MAYBE_SUDO='sudo --set-home' fi - diff --git a/maint/clang_format_lib.sh b/maint/clang_format_lib.sh index d669b6d4..aad8b81a 100755 --- a/maint/clang_format_lib.sh +++ b/maint/clang_format_lib.sh @@ -71,4 +71,3 @@ clang_format_lib_verify_version() { return 1 fi } - diff --git a/maint/yapf_lib.sh b/maint/yapf_lib.sh index 8a2ff880..3d70c23e 100755 --- a/maint/yapf_lib.sh +++ b/maint/yapf_lib.sh @@ -71,4 +71,3 @@ yapf_lib_verify_version() { return 1 fi } - diff --git a/python/pyhe_client/pyhe_client.cpp b/python/pyhe_client/pyhe_client.cpp index 82244315..55b878ad 100644 --- a/python/pyhe_client/pyhe_client.cpp +++ b/python/pyhe_client/pyhe_client.cpp @@ -17,11 +17,11 @@ #include #include -#include #include #include #include +#include "boost/asio.hpp" #include "he_seal_client.hpp" #include "pyhe_client/he_seal_client.hpp" #include "seal/he_seal_client.hpp" diff --git a/src/protos/message.proto b/src/protos/message.proto index 83526ba7..6bca1bea 100644 --- a/src/protos/message.proto +++ b/src/protos/message.proto @@ -5,7 +5,11 @@ package ngraph.runtime.he.pb; /// \brief Represents a message between the server and client. message TCPMessage { - enum Type { UNKNOWN = 0; REQUEST = 1; RESPONSE = 2; } + enum Type { + UNKNOWN = 0; + REQUEST = 1; + RESPONSE = 2; + } Type type = 1; Function function = 2; EncryptionParameters encryption_parameters = 3; @@ -14,19 +18,32 @@ message TCPMessage { repeated HETensor he_tensors = 6; } -message EncryptionParameters { bytes encryption_parameters = 1; } +message EncryptionParameters { + bytes encryption_parameters = 1; +} -message EvaluationKey { bytes eval_key = 1; } +message EvaluationKey { + bytes eval_key = 1; +} -message PublicKey { bytes public_key = 1; } +message PublicKey { + bytes public_key = 1; +} -message Function { string function = 1; } +message Function { + string function = 1; +} message HETensor { string name = 1; repeated uint64 shape = 2; enum ElementType { - UNDEFINED = 0; DYNAMIC = 1; BOOLEAN = 2; BF16 = 3; F16 = 4; F32 = 5; + UNDEFINED = 0; + DYNAMIC = 1; + BOOLEAN = 2; + BF16 = 3; + F16 = 4; + F32 = 5; F64 = 6; I8 = 7; I16 = 8; diff --git a/src/seal/opset_he_seal_tbl.hpp b/src/seal/opset_he_seal_tbl.hpp index b654c61a..143e9b26 100644 --- a/src/seal/opset_he_seal_tbl.hpp +++ b/src/seal/opset_he_seal_tbl.hpp @@ -14,6 +14,8 @@ // limitations under the License. //***************************************************************************** +#pragma once + #define ID_SUFFIX(NAME) NAME #include "ngraph/opsets/opset0_tbl.hpp" NGRAPH_OP(BoundedRelu, op) diff --git a/test/test_add.in.cpp b/test/test_add.in.cpp index b6df29d5..719a09f6 100644 --- a/test/test_add.in.cpp +++ b/test/test_add.in.cpp @@ -24,7 +24,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_avg_pool.in.cpp b/test/test_avg_pool.in.cpp index 3710a6c2..92abc685 100644 --- a/test/test_avg_pool.in.cpp +++ b/test/test_avg_pool.in.cpp @@ -23,7 +23,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_basics.in.cpp b/test/test_basics.in.cpp index 19f22b17..9e8dbcea 100644 --- a/test/test_basics.in.cpp +++ b/test/test_basics.in.cpp @@ -26,7 +26,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_batch_norm_inference.in.cpp b/test/test_batch_norm_inference.in.cpp index 58493e13..e5b4d8fe 100644 --- a/test/test_batch_norm_inference.in.cpp +++ b/test/test_batch_norm_inference.in.cpp @@ -26,7 +26,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_broadcast.in.cpp b/test/test_broadcast.in.cpp index 22086a1d..73960257 100644 --- a/test/test_broadcast.in.cpp +++ b/test/test_broadcast.in.cpp @@ -23,7 +23,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_concat.in.cpp b/test/test_concat.in.cpp index 4c2d0661..11a54a91 100644 --- a/test/test_concat.in.cpp +++ b/test/test_concat.in.cpp @@ -23,7 +23,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_constant.in.cpp b/test/test_constant.in.cpp index 9726bf66..70c2f245 100644 --- a/test/test_constant.in.cpp +++ b/test/test_constant.in.cpp @@ -23,7 +23,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_convolution.in.cpp b/test/test_convolution.in.cpp index e68142b5..31884687 100644 --- a/test/test_convolution.in.cpp +++ b/test/test_convolution.in.cpp @@ -23,7 +23,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_divide.in.cpp b/test/test_divide.in.cpp index f2533ace..22888dd3 100644 --- a/test/test_divide.in.cpp +++ b/test/test_divide.in.cpp @@ -23,7 +23,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_dot.in.cpp b/test/test_dot.in.cpp index f3c4aaae..4f4ebc0d 100644 --- a/test/test_dot.in.cpp +++ b/test/test_dot.in.cpp @@ -23,7 +23,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_exp.in.cpp b/test/test_exp.in.cpp index 135ba053..fc1fd9ae 100644 --- a/test/test_exp.in.cpp +++ b/test/test_exp.in.cpp @@ -23,7 +23,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_layers.in.cpp b/test/test_layers.in.cpp index dec717cc..bbae23f8 100644 --- a/test/test_layers.in.cpp +++ b/test/test_layers.in.cpp @@ -24,7 +24,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_max.in.cpp b/test/test_max.in.cpp index cf7e6176..0126ad86 100644 --- a/test/test_max.in.cpp +++ b/test/test_max.in.cpp @@ -23,7 +23,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_maxpool.in.cpp b/test/test_maxpool.in.cpp index 21bb8cbb..f216eb3a 100644 --- a/test/test_maxpool.in.cpp +++ b/test/test_maxpool.in.cpp @@ -23,7 +23,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_minimum.in.cpp b/test/test_minimum.in.cpp index 594e89fc..57a0d761 100644 --- a/test/test_minimum.in.cpp +++ b/test/test_minimum.in.cpp @@ -23,7 +23,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_multiply.in.cpp b/test/test_multiply.in.cpp index 3adce30e..2e3d2314 100644 --- a/test/test_multiply.in.cpp +++ b/test/test_multiply.in.cpp @@ -24,7 +24,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_negate.in.cpp b/test/test_negate.in.cpp index d59aab89..4133c4b7 100644 --- a/test/test_negate.in.cpp +++ b/test/test_negate.in.cpp @@ -23,7 +23,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_pad.in.cpp b/test/test_pad.in.cpp index bbbedd65..cad6b839 100644 --- a/test/test_pad.in.cpp +++ b/test/test_pad.in.cpp @@ -24,7 +24,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_perf_micro.cpp b/test/test_perf_micro.cpp index 380c4751..a667825f 100644 --- a/test/test_perf_micro.cpp +++ b/test/test_perf_micro.cpp @@ -110,7 +110,8 @@ TEST(perf_micro, encode) { auto he_capacity = sizeof(uint64_t) * he_plain.size(); NGRAPH_INFO << "he plaintext capacity " << he_capacity; NGRAPH_INFO << "Memmory improvement: " - << seal_plain_capacity / float(he_capacity) << "\n"; + << seal_plain_capacity / static_cast(he_capacity) + << "\n"; } } @@ -183,7 +184,9 @@ TEST(perf_micro, encode) { NGRAPH_INFO << "time_seal_encode_avg (ns) " << time_seal_encode_avg; NGRAPH_INFO << "time_he_encode_avg (ns) " << time_he_encode_avg; NGRAPH_INFO << "Runtime improvement: " - << (time_seal_encode_avg / float(time_he_encode_avg)) << "\n"; + << (time_seal_encode_avg / + static_cast(time_he_encode_avg)) + << "\n"; NGRAPH_INFO << "time_seal_multiply_plain_avg (ns) " << time_seal_multiply_plain_avg; @@ -191,13 +194,14 @@ TEST(perf_micro, encode) { << time_he_multiply_plain_avg; NGRAPH_INFO << "Runtime improvement: " << (time_seal_multiply_plain_avg / - float(time_he_multiply_plain_avg)) + static_cast(time_he_multiply_plain_avg)) << "\n"; NGRAPH_INFO << "time_seal_add_plain_avg (ns) " << time_seal_add_plain_avg; NGRAPH_INFO << "time_he_add_plain_avg (ns) " << time_he_add_plain_avg; NGRAPH_INFO << "Runtime improvement: " - << (time_seal_add_plain_avg / float(time_he_add_plain_avg)) + << (time_seal_add_plain_avg / + static_cast(time_he_add_plain_avg)) << "\n"; }; diff --git a/test/test_power.in.cpp b/test/test_power.in.cpp index 195a97ed..302a860e 100644 --- a/test/test_power.in.cpp +++ b/test/test_power.in.cpp @@ -23,7 +23,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_read_write.in.cpp b/test/test_read_write.in.cpp index b2598bdb..080f9c92 100644 --- a/test/test_read_write.in.cpp +++ b/test/test_read_write.in.cpp @@ -24,7 +24,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_relu.in.cpp b/test/test_relu.in.cpp index fd9d0af9..7f19a6fa 100644 --- a/test/test_relu.in.cpp +++ b/test/test_relu.in.cpp @@ -23,7 +23,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_rescale.in.cpp b/test/test_rescale.in.cpp index e39e22d4..016e774e 100644 --- a/test/test_rescale.in.cpp +++ b/test/test_rescale.in.cpp @@ -23,7 +23,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_reshape.in.cpp b/test/test_reshape.in.cpp index 6426220e..5c52e455 100644 --- a/test/test_reshape.in.cpp +++ b/test/test_reshape.in.cpp @@ -23,7 +23,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { @@ -229,7 +229,7 @@ NGRAPH_TEST(${BACKEND_NAME}, reshape_m2m_dim_change_transpose) { NGRAPH_TEST(${BACKEND_NAME}, reshape_6d) { std::vector a_data(2 * 2 * 3 * 3 * 2 * 4); for (int i = 0; i < 2 * 2 * 3 * 3 * 2 * 4; i++) { - a_data[i] = float(i + 1); + a_data[i] = static_cast(i + 1); } for (bool arg1_encrypted : std::vector{false, true}) { diff --git a/test/test_result.in.cpp b/test/test_result.in.cpp index c85d3522..70aa81a9 100644 --- a/test/test_result.in.cpp +++ b/test/test_result.in.cpp @@ -23,7 +23,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_reverse.in.cpp b/test/test_reverse.in.cpp index f8c2141d..99033626 100644 --- a/test/test_reverse.in.cpp +++ b/test/test_reverse.in.cpp @@ -23,7 +23,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_server_client.in.cpp b/test/test_server_client.in.cpp index 1eab36eb..84e6e9ce 100644 --- a/test/test_server_client.in.cpp +++ b/test/test_server_client.in.cpp @@ -32,7 +32,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_server_client_gc.in.cpp b/test/test_server_client_gc.in.cpp index 6c01d7f1..6965d76c 100644 --- a/test/test_server_client_gc.in.cpp +++ b/test/test_server_client_gc.in.cpp @@ -31,9 +31,9 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; -static std::string gc_param_real_str = R"( +static const char* gc_param_real_str = R"( { "scheme_name" : "HE_SEAL", "poly_modulus_degree" : 2048, @@ -43,7 +43,7 @@ static std::string gc_param_real_str = R"( "complex_packing": false })"; -static std::string gc_param_complex_str = R"( +static const char* gc_param_complex_str = R"( { "scheme_name" : "HE_SEAL", "poly_modulus_degree" : 2048, diff --git a/test/test_slice.in.cpp b/test/test_slice.in.cpp index 1da825e9..c0e02e4c 100644 --- a/test/test_slice.in.cpp +++ b/test/test_slice.in.cpp @@ -23,7 +23,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_softmax.in.cpp b/test/test_softmax.in.cpp index c934facd..95a57180 100644 --- a/test/test_softmax.in.cpp +++ b/test/test_softmax.in.cpp @@ -23,7 +23,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_subtract.in.cpp b/test/test_subtract.in.cpp index bb2b24a4..cfab9029 100644 --- a/test/test_subtract.in.cpp +++ b/test/test_subtract.in.cpp @@ -23,7 +23,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_sum.in.cpp b/test/test_sum.in.cpp index ce5de9ad..24827783 100644 --- a/test/test_sum.in.cpp +++ b/test/test_sum.in.cpp @@ -24,7 +24,7 @@ #include "util/test_control.hpp" #include "util/test_tools.hpp" -static std::string s_manifest = "${MANIFEST}"; +static const char* s_manifest = "${MANIFEST}"; namespace ngraph::runtime::he { diff --git a/test/test_util.hpp b/test/test_util.hpp index 09d8d59a..6d7f2c60 100644 --- a/test/test_util.hpp +++ b/test/test_util.hpp @@ -17,6 +17,7 @@ #pragma once #include +#include #include #include @@ -63,7 +64,7 @@ bool all_close(const std::vector& a, const std::vector& b, inline std::shared_ptr annotation_from_flags( const bool from_client, const bool encrypted, const bool packed) { return std::make_shared(from_client, encrypted, packed); -}; +} inline std::string config_from_annotation(const HEOpAnnotations& annotation) { std::vector configs; @@ -101,6 +102,6 @@ inline std::shared_ptr tensor_from_flags( return he_seal_backend.create_plain_tensor(element::f32, shape); } throw ngraph_error("Logic error"); -}; +} } // namespace ngraph::runtime::he::test