Skip to content

Commit

Permalink
Docker infra for Adreno target with CLML support
Browse files Browse the repository at this point in the history
New docker for Adreno that inherits gpu docker and amends android-sdk.

For CLML, we need to specify ADRENO_OPENCL via environment variable. CLML SDK can be downlaoded
from Qualcomm Developer Network by following
https://developer.qualcomm.com/blog/accelerate-your-models-our-opencl-ml-sdk
Adreno device is shared with host, hence networking is enabled for Adreno Docker.
  • Loading branch information
srkreddy1238 committed Sep 19, 2022
1 parent 60cf692 commit 0642d86
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 4 deletions.
28 changes: 28 additions & 0 deletions docker/Dockerfile.ci_adreno
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.

# CI docker GPU env
FROM tlcpack/ci-gpu:20220908-060034-62bdc91b1

COPY utils/apt-install-and-clear.sh /usr/local/bin/apt-install-and-clear

# Android SDK
COPY install/ubuntu_install_androidsdk.sh /install/ubuntu_install_androidsdk.sh
RUN bash /install/ubuntu_install_androidsdk.sh
ENV ANDROID_HOME=/opt/android-sdk-linux
ENV ANDROID_NDK_HOME=/opt/android-sdk-linux/ndk/21.3.6528147
ENV PATH /opt/android-sdk-linux/platform-tools:$PATH
6 changes: 6 additions & 0 deletions docker/bash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,12 @@ if [ -f "${REPO_DIR}/.git" ]; then
fi
fi

if [[ "${DOCKER_IMAGE_NAME}" == *"ci_adreno"* && ! -z "${ADRENO_OPENCL}" ]]; then
DOCKER_MOUNT+=( --volume ${ADRENO_OPENCL}:/adreno-opencl)
DOCKER_ENV+=( --env ADRENO_OPENCL=/adreno-opencl )
DOCKER_ENV+=( --net=host)
fi

# Print arguments.
echo "REPO_DIR: ${REPO_DIR}"
echo "DOCKER CONTAINER NAME: ${DOCKER_IMAGE_NAME}"
Expand Down
2 changes: 1 addition & 1 deletion docker/install/ubuntu_install_cmake_source.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ wget https://cmake.org/files/v${v}/cmake-${version}.tar.gz
tar xvf cmake-${version}.tar.gz
cd cmake-${version}
./bootstrap
make -j"$(nproc)"
make -j$(nproc)
make install
cd ..
rm -rf cmake-${version} cmake-${version}.tar.gz
4 changes: 2 additions & 2 deletions python/tvm/testing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,8 +899,8 @@ def _any_gpu_exists():
"OpenCL",
cmake_flag="USE_OPENCL",
target_kind_enabled="opencl",
target_kind_hardware="opencl",
parent_features="gpu",
target_kind_hardware="opencl" if "RPC_TARGET" not in os.environ else None,
parent_features="gpu" if "RPC_TARGET" not in os.environ else None,
)

# Mark a test as requiring the rocm runtime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,6 @@ def test_residual_block(target, dtype):
"global.texture-weight",
"global.texture",
"global.texture-weight",
"global",
"global.texture",
"global.texture-weight",
"",
Expand Down
14 changes: 14 additions & 0 deletions tests/scripts/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def docker(name: str, image: str, scripts: List[str], env: Dict[str, str], inter
"ci_arm",
"ci_hexagon",
"ci_riscv",
"ci_adreno",
}

if image in sccache_images and os.getenv("USE_SCCACHE", "1") == "1":
Expand Down Expand Up @@ -687,6 +688,19 @@ def add_subparser(
),
},
),
generate_command(
name="adreno",
help="Run Adreno build and test(s)",
post_build=["./tests/scripts/task_build_adreno_bins.sh"],
options={
"test": (
"run Adreno API/Python tests",
[
"./tests/scripts/task_python_adreno.sh " + os.environ.get('ANDROID_SERIAL', ""),
],
),
},
),
]


Expand Down
52 changes: 52 additions & 0 deletions tests/scripts/task_build_adreno_bins.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.

set -e
set -u

output_directory=$(realpath ${PWD}/build-adreno-target)
rm -rf ${output_directory}

mkdir -p ${output_directory}
cd ${output_directory}

cp ../cmake/config.cmake .

echo set\(USE_CLML ON\) >> config.cmake
echo set\(USE_CLML_GRAPH_EXECUTOR "${ADRENO_OPENCL}"\) >> config.cmake
echo set\(USE_RPC ON\) >> config.cmake
echo set\(USE_CPP_RPC ON\) >> config.cmake
echo set\(USE_GRAPH_EXECUTOR ON\) >> config.cmake
echo set\(USE_LIBBACKTRACE AUTO\) >> config.cmake

echo set\(ANDROID_ABI arm64-v8a\) >> config.cmake
echo set\(ANDROID_PLATFORM android-28\) >> config.cmake
echo set\(MACHINE_NAME aarch64-linux-gnu\) >> config.cmake

cmake -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake" \
-DANDROID_ABI=arm64-v8a \
-DANDROID_PLATFORM=android-28 \
-DCMAKE_SYSTEM_VERSION=1 \
-DCMAKE_FIND_ROOT_PATH="${ADRENO_OPENCL}" \
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
-DCMAKE_CXX_COMPILER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android28-clang++" \
-DCMAKE_C_COMPILER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android28-clang" \
-DMACHINE_NAME="aarch64-linux-gnu" ..

make -j$(nproc) tvm_rpc
31 changes: 31 additions & 0 deletions tests/scripts/task_config_build_adreno.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.

set -euxo pipefail

BUILD_DIR=$1
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
cp ../cmake/config.cmake .

echo set\(USE_OPENCL ON\) >> config.cmake
echo set\(USE_CLML ON\) >> config.cmake
echo set\(USE_RPC ON\) >> config.cmake
echo set\(USE_GRAPH_EXECUTOR ON\) >> config.cmake
echo set\(USE_LIBBACKTRACE AUTO\) >> config.cmake
echo set\(USE_LLVM ON\) >> config.cmake
62 changes: 62 additions & 0 deletions tests/scripts/task_python_adreno.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.

set -euxo pipefail

export TVM_TEST_TARGETS="opencl"
export TVM_RELAY_OPENCL_TEXTURE_TARGETS="opencl -device=adreno"

source tests/scripts/setup-pytest-env.sh
export PYTHONPATH=${PYTHONPATH}:${TVM_PATH}/apps/extension/python
export LD_LIBRARY_PATH="build:${LD_LIBRARY_PATH:-}"
export TVM_INTEGRATION_TESTSUITE_NAME=python-integration-adreno

export TVM_TRACKER_HOST=127.0.0.1
export TVM_TRACKER_PORT=$(((RANDOM % 100) + 9100))
export RPC_TARGET="adreno"
export TVM_NDK_CC="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android28-clang"

env PYTHONPATH=python python3 -m tvm.exec.rpc_tracker --host "${TVM_TRACKER_HOST}" --port "${TVM_TRACKER_PORT}" &
TRACKER_PID=$!
sleep 5 # Wait for tracker to bind

export ANDROID_SERIAL=$1

adb shell "mkdir -p /data/local/tmp/tvm_ci"
adb push build-adreno-target/tvm_rpc /data/local/tmp/tvm_ci
adb push build-adreno-target/libtvm_runtime.so /data/local/tmp/tvm_ci

adb reverse tcp:${TVM_TRACKER_PORT} tcp:${TVM_TRACKER_PORT}
adb forward tcp:5000 tcp:5000
adb forward tcp:5001 tcp:5001
adb forward tcp:5002 tcp:5002
env adb shell "cd /data/local/tmp/tvm_ci; killall -9 tvm_rpc; sleep 2; LD_LIBRARY_PATH=/data/local/tmp/tvm_ci/ ./tvm_rpc server --host=0.0.0.0 --port=5000 --port-end=5010 --tracker=127.0.0.1:${TVM_TRACKER_PORT} --key=android" &
DEVICE_PID=$!
sleep 5 # Wait for the device connections

# cleanup pycache
find . -type f -path "*.pyc" | xargs rm -f

# Test TVM
make cython3

# OpenCL texture test on Adreno
run_pytest ctypes ${TVM_INTEGRATION_TESTSUITE_NAME}-opencl-texture tests/python/relay/opencl_texture

kill ${TRACKER_PID}
kill ${DEVICE_PID}

0 comments on commit 0642d86

Please sign in to comment.