-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_optimized.sh
More file actions
executable file
·130 lines (115 loc) · 4.66 KB
/
Copy pathinstall_optimized.sh
File metadata and controls
executable file
·130 lines (115 loc) · 4.66 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env bash
set -euo pipefail
# Optimized (non-portable) build helper.
# - Linux x86_64: native tuning enabled by default.
# - macOS: portable by default; opt into native tuning with --native-macos
# or ACTIONET_MACOS_NATIVE=1.
# OpenMP runtime is always required. Set ACTIONET_OPENMP_RUNTIME to
# GNU, INTEL, or LLVM to force a specific runtime; AUTO (default) lets
# CMake detect the compiler's preferred runtime.
#
# GPU support (Linux x86_64 + NVIDIA only):
# Pass --gpu or set LIBACTIONET_ENABLE_NVIDIA_GPU=ON to opt in.
# Optionally set CUDAToolkit_ROOT to a CUDA >= 12.2 install directory.
# Optionally set CMAKE_CUDA_ARCHITECTURES to override the default (80;86;89;90).
#
# Usage:
# ./install_optimized.sh [--native-macos] [--gpu] [--verbose] [pip args...]
# ACTIONET_MACOS_NATIVE=1 ./install_optimized.sh [pip args...]
# LIBACTIONET_ENABLE_NVIDIA_GPU=ON CUDAToolkit_ROOT=/usr/local/cuda ./install_optimized.sh [pip args...]
# Pass --verbose (or -v) to forward the verbose flag to pip.
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$here"
os="$(uname -s)"
arch="$(uname -m)"
runtime="${ACTIONET_OPENMP_RUNTIME:-AUTO}" # set to INTEL/GNU/LLVM to force, otherwise auto
enable_macos_native="${ACTIONET_MACOS_NATIVE:-0}"
enable_gpu="${LIBACTIONET_ENABLE_NVIDIA_GPU:-OFF}"
declare -a pip_args=()
for arg in "$@"; do
if [[ "$arg" == "--native-macos" ]]; then
enable_macos_native=1
continue
fi
if [[ "$arg" == "--gpu" ]]; then
enable_gpu="ON"
continue
fi
pip_args+=("$arg")
done
run_pip_install() {
python -m pip install . "${pip_args[@]}"
}
# Append GPU cmake flags to a cmake_args string (passed by name-ref).
append_gpu_args() {
local -n _ref=$1
if [[ "$enable_gpu" == "ON" ]]; then
_ref+=" -DLIBACTIONET_ENABLE_NVIDIA_GPU=ON"
if [[ -n "${CUDAToolkit_ROOT:-}" ]]; then
_ref+=" -DCUDAToolkit_ROOT=${CUDAToolkit_ROOT}"
fi
if [[ -n "${CMAKE_CUDA_ARCHITECTURES:-}" ]]; then
_ref+=" -DCMAKE_CUDA_ARCHITECTURES=${CMAKE_CUDA_ARCHITECTURES}"
fi
fi
}
if [[ "$os" == "Darwin" ]]; then
if [[ "$enable_macos_native" != "1" ]]; then
echo "[INFO] macOS detected; running portable build."
echo "[INFO] Use --native-macos (or ACTIONET_MACOS_NATIVE=1) to enable non-portable native CPU tuning."
cmake_args=""
if [[ "$runtime" != "AUTO" ]]; then
cmake_args+=" -DLIBACTIONET_OPENMP_RUNTIME=${runtime}"
fi
append_gpu_args cmake_args
if [[ -n "${cmake_args// }" ]]; then
export CMAKE_ARGS="${CMAKE_ARGS:-}${cmake_args}"
echo "[INFO] Using CMAKE_ARGS=${CMAKE_ARGS}"
fi
run_pip_install
exit 0
fi
macos_common_flags="-O3 -ffp-contract=fast -fno-strict-aliasing"
if [[ "$arch" == "arm64" || "$arch" == "aarch64" ]]; then
native_cxxflags="-mcpu=native ${macos_common_flags}"
elif [[ "$arch" == "x86_64" || "$arch" == "amd64" ]]; then
native_cxxflags="-march=native -mtune=native ${macos_common_flags}"
else
echo "[WARN] Unrecognized macOS arch ($arch); using generic optimization flags without native CPU target."
native_cxxflags="${macos_common_flags}"
fi
cmake_args="-DCMAKE_CXX_FLAGS='${native_cxxflags}' -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON"
if [[ "$runtime" != "AUTO" ]]; then
cmake_args+=" -DLIBACTIONET_OPENMP_RUNTIME=${runtime}"
fi
append_gpu_args cmake_args
export CMAKE_ARGS="${CMAKE_ARGS:-} ${cmake_args}"
echo "[INFO] Using CMAKE_ARGS=${CMAKE_ARGS}"
echo "[INFO] Invoking pip install with macOS native optimized flags..."
run_pip_install
exit 0
fi
if [[ "$arch" != "x86_64" && "$arch" != "amd64" ]]; then
echo "[WARN] Non-x86_64 architecture ($arch) detected; skipping native flags. Running portable build."
cmake_args=""
if [[ "$runtime" != "AUTO" ]]; then
cmake_args+=" -DLIBACTIONET_OPENMP_RUNTIME=${runtime}"
fi
append_gpu_args cmake_args
if [[ -n "${cmake_args// }" ]]; then
export CMAKE_ARGS="${CMAKE_ARGS:-}${cmake_args}"
echo "[INFO] Using CMAKE_ARGS=${CMAKE_ARGS}"
fi
run_pip_install
exit 0
fi
native_cxxflags="-march=native -mtune=native -O3 -ffp-contract=fast -funroll-loops -fomit-frame-pointer -fno-strict-aliasing"
cmake_args="-DCMAKE_CXX_FLAGS='${native_cxxflags}' -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON"
if [[ "$runtime" != "AUTO" ]]; then
cmake_args+=" -DLIBACTIONET_OPENMP_RUNTIME=${runtime}"
fi
append_gpu_args cmake_args
export CMAKE_ARGS="${CMAKE_ARGS:-} ${cmake_args}"
echo "[INFO] Using CMAKE_ARGS=${CMAKE_ARGS}"
echo "[INFO] Invoking pip install with optimized flags..."
run_pip_install