Update build and setup scripts to support both CUDA and ROCm backends

- Setup script now creates both venv-cuda and venv-rocm by default
- Build script builds both CUDA and ROCm worker versions
- Start script reads configuration to launch appropriate backend workers
- Added pip3 detection and --break-system-packages support
- Windows batch files updated with pip3 detection
- Runtime can switch between CUDA/ROCm implementations based on config
parent a9ec4a6f
Pipeline #191 canceled with stages
...@@ -25,9 +25,27 @@ else ...@@ -25,9 +25,27 @@ else
IS_WINDOWS=0 IS_WINDOWS=0
fi fi
TARGET=${1:-cuda} # Default to cuda BUILD_TARGETS=()
echo "Building Video AI Analysis Tool for $TARGET on $(uname -s)..." # Parse arguments
for arg in "$@"; do
case $arg in
cuda)
BUILD_TARGETS+=("cuda")
;;
rocm)
BUILD_TARGETS+=("rocm")
;;
esac
done
# If no targets specified, build both
if [ ${#BUILD_TARGETS[@]} -eq 0 ]; then
BUILD_TARGETS=("cuda" "rocm")
echo "No target specified, building both CUDA and ROCm versions..."
fi
echo "Building Video AI Analysis Tool for targets: ${BUILD_TARGETS[*]} on $(uname -s)..."
# Check if pyinstaller is installed # Check if pyinstaller is installed
if ! command -v pyinstaller &> /dev/null; then if ! command -v pyinstaller &> /dev/null; then
...@@ -42,6 +60,9 @@ else ...@@ -42,6 +60,9 @@ else
PYINSTALLER_ARGS="--onefile" PYINSTALLER_ARGS="--onefile"
fi fi
# Build common components (backend and web)
echo "Building common components..."
# Build backend # Build backend
pyinstaller $PYINSTALLER_ARGS \ pyinstaller $PYINSTALLER_ARGS \
--name vidai-backend \ --name vidai-backend \
...@@ -67,24 +88,39 @@ else ...@@ -67,24 +88,39 @@ else
vidai/web.py vidai/web.py
fi fi
# Build analysis worker # Build workers for each target
pyinstaller $PYINSTALLER_ARGS \ for TARGET in "${BUILD_TARGETS[@]}"; do
--name vidai-analysis-$TARGET \ echo ""
--hidden-import torch \ echo "=== Building $TARGET workers ==="
--hidden-import transformers \
--hidden-import cv2 \
vidai/worker_analysis.py
# Build training worker # Build analysis worker
pyinstaller $PYINSTALLER_ARGS \ pyinstaller $PYINSTALLER_ARGS \
--name vidai-training-$TARGET \ --name vidai-analysis-$TARGET \
--hidden-import torch \ --hidden-import torch \
--hidden-import transformers \ --hidden-import transformers \
vidai/worker_training.py --hidden-import cv2 \
vidai/worker_analysis.py
# Build training worker
pyinstaller $PYINSTALLER_ARGS \
--name vidai-training-$TARGET \
--hidden-import torch \
--hidden-import transformers \
vidai/worker_training.py
echo "Built workers for $TARGET"
done
echo "Build complete for $TARGET!" echo ""
echo "Executables created in dist/:" echo "=== Build Summary ==="
echo "Common executables:"
echo " - vidai-backend" echo " - vidai-backend"
echo " - vidai-web" echo " - vidai-web"
echo " - vidai-analysis-$TARGET" echo ""
echo " - vidai-training-$TARGET" echo "Worker executables:"
\ No newline at end of file for TARGET in "${BUILD_TARGETS[@]}"; do
echo " - vidai-analysis-$TARGET"
echo " - vidai-training-$TARGET"
done
echo ""
echo "All executables created in dist/"
\ No newline at end of file
...@@ -18,6 +18,14 @@ REM along with this program. If not, see <https://www.gnu.org/licenses/>. ...@@ -18,6 +18,14 @@ REM along with this program. If not, see <https://www.gnu.org/licenses/>.
REM Cross-platform setup script for Video AI Analysis Tool REM Cross-platform setup script for Video AI Analysis Tool
REM Creates a virtual environment and installs dependencies REM Creates a virtual environment and installs dependencies
REM Check for pip3 availability
where pip3 >nul 2>nul
if %errorlevel% == 0 (
set PIP_CMD=pip3
) else (
set PIP_CMD=pip
)
REM Parse arguments REM Parse arguments
if "%1"=="cuda" ( if "%1"=="cuda" (
set TARGET=cuda set TARGET=cuda
...@@ -41,12 +49,12 @@ REM Activate virtual environment ...@@ -41,12 +49,12 @@ REM Activate virtual environment
call venv-%TARGET%\Scripts\activate.bat call venv-%TARGET%\Scripts\activate.bat
REM Upgrade pip REM Upgrade pip
python -m pip install --upgrade pip %PIP_CMD% install --upgrade pip
REM Install requirements based on target REM Install requirements based on target
if "%TARGET%"=="cuda" ( if "%TARGET%"=="cuda" (
if exist "requirements-cuda.txt" ( if exist "requirements-cuda.txt" (
pip install -r requirements-cuda.txt %PIP_CMD% install -r requirements-cuda.txt
echo Installed dependencies from requirements-cuda.txt echo Installed dependencies from requirements-cuda.txt
) else ( ) else (
echo requirements-cuda.txt not found echo requirements-cuda.txt not found
...@@ -54,7 +62,7 @@ if "%TARGET%"=="cuda" ( ...@@ -54,7 +62,7 @@ if "%TARGET%"=="cuda" (
) )
) else if "%TARGET%"=="rocm" ( ) else if "%TARGET%"=="rocm" (
if exist "requirements-rocm.txt" ( if exist "requirements-rocm.txt" (
pip install -r requirements-rocm.txt %PIP_CMD% install -r requirements-rocm.txt
echo Installed dependencies from requirements-rocm.txt echo Installed dependencies from requirements-rocm.txt
) else ( ) else (
echo requirements-rocm.txt not found echo requirements-rocm.txt not found
...@@ -62,7 +70,7 @@ if "%TARGET%"=="cuda" ( ...@@ -62,7 +70,7 @@ if "%TARGET%"=="cuda" (
) )
) else ( ) else (
if exist "requirements.txt" ( if exist "requirements.txt" (
pip install -r requirements.txt %PIP_CMD% install -r requirements.txt
echo Installed dependencies from requirements.txt echo Installed dependencies from requirements.txt
) else ( ) else (
echo requirements.txt not found echo requirements.txt not found
......
...@@ -23,65 +23,111 @@ if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then ...@@ -23,65 +23,111 @@ if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then
IS_WINDOWS=1 IS_WINDOWS=1
PYTHON_CMD="python" PYTHON_CMD="python"
ACTIVATE_CMD="venv-$TARGET/Scripts/activate" ACTIVATE_CMD="venv-$TARGET/Scripts/activate"
PIP_CMD="pip"
else else
IS_WINDOWS=0 IS_WINDOWS=0
PYTHON_CMD="python3" PYTHON_CMD="python3"
ACTIVATE_CMD="venv-$TARGET/bin/activate" ACTIVATE_CMD="venv-$TARGET/bin/activate"
PIP_CMD="pip3"
fi fi
# Parse arguments # Parse arguments
TARGET="cpu" SETUP_TARGETS=()
if [ "$1" = "cuda" ]; then BREAK_SYSTEM_PACKAGES=""
TARGET="cuda"
elif [ "$1" = "rocm" ]; then # Check for pip3 availability
TARGET="rocm" if command -v pip3 &> /dev/null; then
PIP_CMD="pip3"
else
PIP_CMD="pip"
fi fi
echo "Setting up Video AI Analysis Tool for $TARGET on $(uname -s)..." # Parse command line arguments
for arg in "$@"; do
case $arg in
cuda)
SETUP_TARGETS+=("cuda")
;;
rocm)
SETUP_TARGETS+=("rocm")
;;
--break-system-packages)
BREAK_SYSTEM_PACKAGES="--break-system-packages"
;;
esac
done
# Create virtual environment # If no targets specified, setup both CUDA and ROCm
if [ ! -d "venv-$TARGET" ]; then if [ ${#SETUP_TARGETS[@]} -eq 0 ]; then
$PYTHON_CMD -m venv venv-$TARGET SETUP_TARGETS=("cuda" "rocm")
echo "Created virtual environment in venv-$TARGET/" echo "No target specified, setting up both CUDA and ROCm implementations..."
else
echo "Virtual environment venv-$TARGET already exists"
fi fi
# Activate virtual environment echo "Setting up Video AI Analysis Tool on $(uname -s)..."
if [ $IS_WINDOWS -eq 1 ]; then echo "Using pip command: $PIP_CMD"
# On Windows, we need to use call for batch files if [ -n "$BREAK_SYSTEM_PACKAGES" ]; then
echo "To activate on Windows: venv-$TARGET\\Scripts\\activate.bat" echo "Using --break-system-packages flag"
source $ACTIVATE_CMD 2>/dev/null || call $ACTIVATE_CMD 2>/dev/null || true
else
source $ACTIVATE_CMD
fi fi
echo "Setting up targets: ${SETUP_TARGETS[*]}"
# Upgrade pip # Setup each target
$PIP_CMD install --upgrade pip for TARGET in "${SETUP_TARGETS[@]}"; do
echo ""
echo "=== Setting up $TARGET ==="
# Install requirements based on target # Create virtual environment
REQ_FILE="requirements.txt" if [ ! -d "venv-$TARGET" ]; then
if [ "$TARGET" = "cuda" ] && [ -f "requirements-cuda.txt" ]; then $PYTHON_CMD -m venv venv-$TARGET
REQ_FILE="requirements-cuda.txt" echo "Created virtual environment in venv-$TARGET/"
elif [ "$TARGET" = "rocm" ] && [ -f "requirements-rocm.txt" ]; then else
REQ_FILE="requirements-rocm.txt" echo "Virtual environment venv-$TARGET already exists"
fi fi
if [ -f "$REQ_FILE" ]; then # Activate virtual environment
$PIP_CMD install -r $REQ_FILE if [ $IS_WINDOWS -eq 1 ]; then
echo "Installed dependencies from $REQ_FILE" # On Windows, we need to use call for batch files
else ACTIVATE_CMD="venv-$TARGET/Scripts/activate"
echo "$REQ_FILE not found" echo "To activate on Windows: venv-$TARGET\\Scripts\\activate.bat"
exit 1 source $ACTIVATE_CMD 2>/dev/null || call $ACTIVATE_CMD 2>/dev/null || true
fi else
ACTIVATE_CMD="venv-$TARGET/bin/activate"
source $ACTIVATE_CMD
fi
# Upgrade pip
$PIP_CMD install --upgrade pip $BREAK_SYSTEM_PACKAGES
# Install requirements based on target
REQ_FILE="requirements.txt"
if [ "$TARGET" = "cuda" ] && [ -f "requirements-cuda.txt" ]; then
REQ_FILE="requirements-cuda.txt"
elif [ "$TARGET" = "rocm" ] && [ -f "requirements-rocm.txt" ]; then
REQ_FILE="requirements-rocm.txt"
fi
if [ -f "$REQ_FILE" ]; then
$PIP_CMD install -r $REQ_FILE $BREAK_SYSTEM_PACKAGES
echo "Installed dependencies from $REQ_FILE for $TARGET"
else
echo "$REQ_FILE not found for $TARGET"
exit 1
fi
echo "Setup complete for $TARGET!"
done
echo "Setup complete for $TARGET!" echo ""
echo "=== Setup Summary ==="
echo "Available virtual environments:"
for TARGET in "${SETUP_TARGETS[@]}"; do
if [ $IS_WINDOWS -eq 1 ]; then
echo " venv-$TARGET (activate: venv-$TARGET\\Scripts\\activate.bat)"
else
echo " venv-$TARGET (activate: source venv-$TARGET/bin/activate)"
fi
done
echo ""
echo "To run the application:"
if [ $IS_WINDOWS -eq 1 ]; then if [ $IS_WINDOWS -eq 1 ]; then
echo "To activate the environment: venv-$TARGET\\Scripts\\activate.bat" echo " python vidai.py --help"
echo "To run the application: python vidai.py --help"
else else
echo "To activate the environment: source venv-$TARGET/bin/activate" echo " python3 vidai.py --help"
echo "To run the application: python3 vidai.py --help"
fi fi
\ No newline at end of file
...@@ -29,9 +29,19 @@ else ...@@ -29,9 +29,19 @@ else
SLEEP_CMD="sleep" SLEEP_CMD="sleep"
fi fi
TARGET=${1:-cuda} # Default to cuda # Read configuration to determine which backends to use
if [ -f "vidai/config.py" ]; then
# Try to get config values, fallback to defaults
ANALYSIS_BACKEND=$($PYTHON_CMD -c "from vidai.config import get_analysis_backend; print(get_analysis_backend())" 2>/dev/null || echo "cuda")
TRAINING_BACKEND=$($PYTHON_CMD -c "from vidai.config import get_training_backend; print(get_training_backend())" 2>/dev/null || echo "cuda")
else
ANALYSIS_BACKEND="cuda"
TRAINING_BACKEND="cuda"
fi
echo "Starting Video AI Analysis Tool for $TARGET on $(uname -s)..." echo "Starting Video AI Analysis Tool on $(uname -s)..."
echo "Analysis backend: $ANALYSIS_BACKEND"
echo "Training backend: $TRAINING_BACKEND"
# Create result directory (cross-platform) # Create result directory (cross-platform)
if [ $IS_WINDOWS -eq 1 ]; then if [ $IS_WINDOWS -eq 1 ]; then
...@@ -64,9 +74,9 @@ start_process "backend" "$PYTHON_CMD -m vidai.backend" ...@@ -64,9 +74,9 @@ start_process "backend" "$PYTHON_CMD -m vidai.backend"
$SLEEP_CMD 2 $SLEEP_CMD 2
# Start workers # Start workers with configured backends
start_process "analysis_worker" "$PYTHON_CMD -m vidai.worker_analysis $TARGET" start_process "analysis_worker" "$PYTHON_CMD -c \"from vidai.worker_analysis import worker_process; worker_process('$ANALYSIS_BACKEND')\""
start_process "training_worker" "$PYTHON_CMD -m vidai.worker_training $TARGET" start_process "training_worker" "$PYTHON_CMD -c \"from vidai.worker_training import worker_process; worker_process('$TRAINING_BACKEND')\""
$SLEEP_CMD 2 $SLEEP_CMD 2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment