-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch_benchmark_android.sh
More file actions
executable file
·84 lines (71 loc) · 2.64 KB
/
launch_benchmark_android.sh
File metadata and controls
executable file
·84 lines (71 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
set -e
# ---------------------------------------------------------------------------
# Defaults (override via environment or flags)
# ---------------------------------------------------------------------------
ABI="${ANDROID_ABI:-arm64-v8a}"
PLATFORM="${ANDROID_PLATFORM:-android-21}"
DEVICE_DIR="/data/local/tmp"
BINARY_NAME="vector_math_benchmark"
# ---------------------------------------------------------------------------
# Locate Android NDK
# ---------------------------------------------------------------------------
if [ -z "$NDK" ]; then
SDK_ROOT="${ANDROID_HOME:-$HOME/Library/Android/sdk}"
NDK_BASE="$SDK_ROOT/ndk"
if [ ! -d "$NDK_BASE" ]; then
echo "error: NDK directory not found at $NDK_BASE"
echo " Set NDK=/path/to/ndk or ANDROID_HOME=/path/to/sdk"
exit 1
fi
# Pick the newest installed NDK version
NDK=$(ls -d "$NDK_BASE"/*/ 2>/dev/null | sort -V | tail -1)
NDK="${NDK%/}"
fi
if [ -z "$NDK" ] || [ ! -d "$NDK" ]; then
echo "error: could not locate Android NDK. Set NDK=/path/to/ndk"
exit 1
fi
TOOLCHAIN="$NDK/build/cmake/android.toolchain.cmake"
if [ ! -f "$TOOLCHAIN" ]; then
echo "error: toolchain file not found: $TOOLCHAIN"
exit 1
fi
echo "NDK: $NDK"
echo "ABI: $ABI"
echo "Platform: $PLATFORM"
echo ""
# ---------------------------------------------------------------------------
# Build
# ---------------------------------------------------------------------------
BUILD_DIR="build/android-benchmark-$ABI"
cmake -B "$BUILD_DIR" -S . \
-DVECTOR_MATH_BUILD_BENCHMARK=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN" \
-DANDROID_ABI="$ABI" \
-DANDROID_PLATFORM="$PLATFORM"
make -C "$BUILD_DIR"
# ---------------------------------------------------------------------------
# Verify adb and device
# ---------------------------------------------------------------------------
if ! command -v adb &>/dev/null; then
echo "error: adb not found. Add Android SDK platform-tools to PATH."
exit 1
fi
DEVICE_COUNT=$(adb devices | grep -c "device$" || true)
if [ "$DEVICE_COUNT" -eq 0 ]; then
echo "error: no adb device/emulator detected. Start an emulator or connect a device."
exit 1
fi
# ---------------------------------------------------------------------------
# Deploy and run
# ---------------------------------------------------------------------------
BINARY_PATH="$BUILD_DIR/$BINARY_NAME"
echo ""
echo "Pushing $BINARY_NAME to $DEVICE_DIR ..."
adb push "$BINARY_PATH" "$DEVICE_DIR/$BINARY_NAME"
adb shell chmod +x "$DEVICE_DIR/$BINARY_NAME"
echo "Running benchmark on device..."
echo ""
adb shell "$DEVICE_DIR/$BINARY_NAME"