[ci] Add docker and kokoro configuration for SwiftShader (#2628)
This commit adds a docker image to build Ubuntu 18.04 together
with the Vulkan SDK and SwiftShader ICD. With this docker image,
we should be able to build IREE itself and run all Vulkan tests.
diff --git a/build_tools/docker/build_and_update_gcr.py b/build_tools/docker/build_and_update_gcr.py
index 531088f..82fdb16 100755
--- a/build_tools/docker/build_and_update_gcr.py
+++ b/build_tools/docker/build_and_update_gcr.py
@@ -36,6 +36,8 @@
'cmake': [],
'cmake-android': ['cmake'],
'cmake-nvidia': ['cmake'],
+ 'cmake-vulkan': ['cmake'],
+ 'cmake-swiftshader': ['cmake-vulkan'],
'rbe-toolchain': [],
}
diff --git a/build_tools/docker/cmake_nvidia/Dockerfile b/build_tools/docker/cmake_nvidia/Dockerfile
index c25519f..1fdeaee 100644
--- a/build_tools/docker/cmake_nvidia/Dockerfile
+++ b/build_tools/docker/cmake_nvidia/Dockerfile
@@ -34,6 +34,7 @@
# does not support Ubuntu 18.04.
# This allows to share configuration with base CMake, but it also means we need
# to MATCH the driver version between the host machine and the docker image.
+# TODO: use cmake-vulkan as the base.
FROM gcr.io/iree-oss/cmake
# Additionally, we need to install the Vulkan SDK and the NVIDIA Vulkan driver.
diff --git a/build_tools/docker/cmake_swiftshader/Dockerfile b/build_tools/docker/cmake_swiftshader/Dockerfile
new file mode 100644
index 0000000..b92ce02
--- /dev/null
+++ b/build_tools/docker/cmake_swiftshader/Dockerfile
@@ -0,0 +1,60 @@
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+# An image for building IREE using CMake and testing IREE with SwiftShader
+# Vulkan implementation.
+
+# Build using:
+# docker build --tag gcr.io/iree-oss/cmake-swiftshader \
+# build_tools/docker/cmake_swiftshader/
+
+# Run interactively using the following, where IREE_WORKDIR is the path to your
+# local dev environment:
+# docker run -it --rm --entrypoint bash \
+# --volume "${IREE_WORKDIR?}:/usr/src/iree/" \
+# --gpus all \
+# gcr.io/iree-oss/cmake-swiftshader
+
+# Set up the image and working directory by inheriting the base
+# CMake configuration.
+FROM gcr.io/iree-oss/cmake-vulkan
+
+ARG SWIFTSHADER_COMMIT=6a8a74986c357b0c6fa0dfd2b4b9230af8d39d1a
+
+# zlib is needed for compiling SwiftShader.
+RUN apt-get update && apt-get install zlib1g-dev
+
+RUN git clone https://github.com/google/swiftshader \
+ && cd swiftshader && git checkout "${SWIFTSHADER_COMMIT?}" && cd .. \
+ # Only build SwiftShader Vulkan ICD.
+ && cmake -S swiftshader/ -B build-swiftshader/ \
+ -GNinja \
+ -DSWIFTSHADER_BUILD_VULKAN=ON \
+ -DSWIFTSHADER_BUILD_EGL=OFF \
+ -DSWIFTSHADER_BUILD_GLESv2=OFF \
+ -DSWIFTSHADER_BUILD_GLES_CM=OFF \
+ -DSWIFTSHADER_BUILD_PVR=OFF \
+ -DSWIFTSHADER_BUILD_TESTS=OFF \
+ && cmake --build build-swiftshader/ \
+ --config Release \
+ --target vk_swiftshader \
+ # Copy the ICD JSON and .so to a known place.
+ && cp -rf build-swiftshader/Linux /swiftshader \
+ # Keep track of the commit we are using.
+ && echo "${SWIFTSHADER_COMMIT?}" > /swiftshader/git-commit \
+ # Clean up everything.
+ && rm -rf swiftshader build-swiftshader
+
+# Set VK_ICD_FILENAMES so Vulkan loader can find the SwiftShader ICD.
+ENV VK_ICD_FILENAMES /swiftshader/vk_swiftshader_icd.json
diff --git a/build_tools/docker/cmake_vulkan/Dockerfile b/build_tools/docker/cmake_vulkan/Dockerfile
new file mode 100644
index 0000000..f2cdee6
--- /dev/null
+++ b/build_tools/docker/cmake_vulkan/Dockerfile
@@ -0,0 +1,47 @@
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+# An image with Vulkan SDK for building IREE using CMake.
+
+# Build using:
+# docker build --tag gcr.io/iree-oss/cmake-vulkan \
+# build_tools/docker/cmake_vulkan/
+
+# Run interactively using the following, where IREE_WORKDIR is the path to your
+# local dev environment:
+# docker run -it --rm --entrypoint bash \
+# --volume "${IREE_WORKDIR?}:/usr/src/iree/" \
+# --gpus all \
+# gcr.io/iree-oss/cmake-vulkan
+
+# Set up the image and working directory by inheriting the base
+# CMake configuration.
+FROM gcr.io/iree-oss/cmake
+
+# Additionally, we need to install the Vulkan SDK.
+
+ARG VULKAN_SDK_VERSION=1.2.141
+
+# Disable apt-key parse waring. If someone knows how to do whatever the "proper"
+# thing is then feel free. The warning complains about parsing apt-key output,
+# which we're not even doing.
+ARG APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1
+
+RUN wget -qO - http://packages.lunarg.com/lunarg-signing-key-pub.asc \
+ | apt-key add - \
+ && wget -qO \
+ "/etc/apt/sources.list.d/lunarg-vulkan-${VULKAN_SDK_VERSION?}-bionic.list" \
+ "http://packages.lunarg.com/vulkan/${VULKAN_SDK_VERSION?}/lunarg-vulkan-${VULKAN_SDK_VERSION?}-bionic.list" \
+ && apt-get update \
+ && apt-get install -y vulkan-sdk
diff --git a/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader/build.sh b/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader/build.sh
new file mode 100755
index 0000000..ddd5a74
--- /dev/null
+++ b/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader/build.sh
@@ -0,0 +1,57 @@
+#!/bin/bash
+
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+# Build the project with cmake using Kokoro.
+
+set -e
+set -x
+
+# Print the UTC time when set -x is on
+export PS4='[$(date -u "+%T %Z")] '
+
+# Check these exist and print the versions for later debugging
+export CMAKE_BIN="$(which cmake)"
+"$CMAKE_BIN" --version
+"$CC" --version
+"$CXX" --version
+python3 --version
+
+# For some reason the environment variable set in base `cmake` image cannot
+# reach the child `cmake-swiftshader` image. Given this environment variable
+# is just a temporary solution, duplicate it here instead of spending all
+# the effort trying to figure out why.
+# TODO(#2645): remove this once we have a better solution for AOT linker
+# discovery.
+export IREE_LLVMAOT_LINKER_PATH=/usr/bin/ld
+
+# Print Vulkan related information: SDK version and GPU ICD version
+vulkaninfo 2>/dev/null | grep "Vulkan Instance" || echo "Vulkan Instance not found!"
+vulkaninfo 2>/dev/null | grep -A7 "VkPhysicalDeviceProperties" || echo "VkPhysicalDeviceProperties not found!"
+
+# Print SwiftShader git commit
+cat /swiftshader/git-commit
+
+echo "Initializing submodules"
+./scripts/git/submodule_versions.py init
+
+# TODO(gcmn): It would be nice to be able to build and test as much as possible,
+# so a build failure only prevents building/testing things that depend on it and
+# we can still run the other tests.
+echo "Building with cmake"
+./build_tools/cmake/clean_build.sh
+
+echo "Testing with ctest"
+./build_tools/cmake/test.sh
diff --git a/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader/build_kokoro.sh b/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader/build_kokoro.sh
new file mode 100755
index 0000000..82426ec
--- /dev/null
+++ b/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader/build_kokoro.sh
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+# Build and test the project within the gcr.io/iree-oss/cmake-swiftshader image
+# using Kokoro.
+# Requires the environment variables KOKORO_ROOT and KOKORO_ARTIFACTS_DIR, which
+# are set by Kokoro.
+
+set -x
+set -e
+set -o pipefail
+
+# Print the UTC time when set -x is on
+export PS4='[$(date -u "+%T %Z")] '
+
+source "${KOKORO_ARTIFACTS_DIR?}/github/iree/build_tools/kokoro/gcp_ubuntu/docker_common.sh"
+
+# Sets DOCKER_RUN_ARGS
+docker_setup
+
+docker run "${DOCKER_RUN_ARGS[@]?}" \
+ --env IREE_VULKAN_DISABLE=0 \
+ gcr.io/iree-oss/cmake-swiftshader:prod \
+ build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader/build.sh
+
+# Kokoro will rsync this entire directory back to the executor orchestrating the
+# build which takes forever and is totally useless.
+rm -rf "${KOKORO_ARTIFACTS_DIR?}"/*
+
+# Print out artifacts dir contents after deleting them as a coherence check.
+ls -1a "${KOKORO_ARTIFACTS_DIR?}/"
diff --git a/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader/common.cfg b/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader/common.cfg
new file mode 100644
index 0000000..9f4a82c
--- /dev/null
+++ b/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader/common.cfg
@@ -0,0 +1,17 @@
+# Format: //devtools/kokoro/config/proto/build.proto
+
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+build_file: "iree/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader/build_kokoro.sh"
diff --git a/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader/continuous.cfg b/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader/continuous.cfg
new file mode 100644
index 0000000..e4cc270
--- /dev/null
+++ b/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader/continuous.cfg
@@ -0,0 +1,19 @@
+# Format: //devtools/kokoro/config/proto/build.proto
+
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+# Deliberately blank as everything necessary is configured in common files, but
+# file must still exist to match corresponding (Google internal) job
+# configurations that trigger the builds.
diff --git a/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader/google.cfg b/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader/google.cfg
new file mode 100644
index 0000000..e4cc270
--- /dev/null
+++ b/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader/google.cfg
@@ -0,0 +1,19 @@
+# Format: //devtools/kokoro/config/proto/build.proto
+
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+# Deliberately blank as everything necessary is configured in common files, but
+# file must still exist to match corresponding (Google internal) job
+# configurations that trigger the builds.
diff --git a/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader/main.cfg b/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader/main.cfg
new file mode 100644
index 0000000..e4cc270
--- /dev/null
+++ b/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader/main.cfg
@@ -0,0 +1,19 @@
+# Format: //devtools/kokoro/config/proto/build.proto
+
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+# Deliberately blank as everything necessary is configured in common files, but
+# file must still exist to match corresponding (Google internal) job
+# configurations that trigger the builds.
diff --git a/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader/presubmit.cfg b/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader/presubmit.cfg
new file mode 100644
index 0000000..e4cc270
--- /dev/null
+++ b/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader/presubmit.cfg
@@ -0,0 +1,19 @@
+# Format: //devtools/kokoro/config/proto/build.proto
+
+# Copyright 2020 Google LLC
+#
+# 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
+#
+# https://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.
+
+# Deliberately blank as everything necessary is configured in common files, but
+# file must still exist to match corresponding (Google internal) job
+# configurations that trigger the builds.