Files
hand-motion-pipeline/scripts/foundationpose_env.sh
T

46 lines
1.8 KiB
Bash

#!/usr/bin/env bash
# Source this file before building or running FoundationPose.
FP_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
fp_python="${HANDFLOW_PYTHON:-$FP_ROOT/.venv/bin/python}"
if [ ! -x "$fp_python" ]; then
echo "Main Python environment missing: $fp_python (see docs/SETUP_AND_WEIGHTS.md)" >&2
return 1
fi
if [ -z "${CUDA_HOME:-}" ]; then
if [ -x "$FP_ROOT/.cuda/usr/local/cuda-12.8/bin/nvcc" ]; then
CUDA_HOME="$FP_ROOT/.cuda/usr/local/cuda-12.8"
elif command -v nvcc >/dev/null 2>&1; then
CUDA_HOME="$(dirname -- "$(dirname -- "$(readlink -f -- "$(command -v nvcc)")")")"
else
echo "CUDA toolkit missing: install nvcc and set CUDA_HOME before sourcing this file." >&2
return 1
fi
fi
if [ ! -x "$CUDA_HOME/bin/nvcc" ]; then
echo "CUDA_HOME must contain bin/nvcc: $CUDA_HOME" >&2
return 1
fi
unset PYTHONPATH LD_LIBRARY_PATH
export CUDA_HOME
export PATH="$(dirname -- "$fp_python"):$CUDA_HOME/bin:$PATH"
# PyTorch detects the visible GPU by default; preserve explicit build settings.
export MAX_JOBS="${MAX_JOBS:-2}"
export PIP_CACHE_DIR="$FP_ROOT/.cache/pip"
export TORCH_EXTENSIONS_DIR="$FP_ROOT/.cache/torch_extensions"
export XDG_CACHE_HOME="$FP_ROOT/.cache"
export MPLCONFIGDIR="$FP_ROOT/.cache/matplotlib"
export CPATH="$CUDA_HOME/include${CPATH:+:$CPATH}"
fp_include_dirs="$("$fp_python" - <<'PY'
import site
from pathlib import Path
roots = [*site.getsitepackages(), site.getusersitepackages()]
for directory in sorted({p for root in roots for p in (Path(root) / 'nvidia').glob('*/include') if p.is_dir()}):
print(directory)
PY
)" || return 1
while IFS= read -r fp_inc; do
[ -z "$fp_inc" ] || export CPATH="$CPATH:$fp_inc"
done <<< "$fp_include_dirs"
unset fp_python fp_include_dirs fp_inc