VENV ?= .venv PY := $(VENV)/bin/python PIP := $(PY) -m pip UV := uv CONFIG ?= config.toml # detect uv, fallback to pip HAS_UV := $(shell command -v $(UV) >/dev/null 2>&1 && echo 1 || echo 0) ifeq ($(HAS_UV),1) VENV_CREATE = $(UV) venv $(VENV) --python 3.11 2>/dev/null || $(UV) venv $(VENV) PIP_INSTALL = $(UV) pip install --python $(PY) else VENV_CREATE = python3 -m venv $(VENV) PIP_INSTALL = $(PIP) install endif .PHONY: install install-cpu install-rocm install-cuda extract ast clean help help: @echo "Targets:" @echo " make install # auto-detect GPU (ROCm>CUDA>CPU) via rocm-smi/nvidia-smi/torch, create venv, install deps" @echo " make install-cpu # force CPU torch" @echo " make install-rocm # force ROCm torch (RX 7900 XTX gfx1100)" @echo " make install-cuda # force CUDA torch" @echo " make extract # run extract.py (uses config.toml if present)" @echo " make ast # run sync_audio_test.py (audio_sync_test, PyQtGraph GUI)" @echo " make clean" install: @if [ ! -d $(VENV) ]; then echo "=> creating venv $(VENV)"; $(VENV_CREATE); else echo "=> venv exists $(VENV)"; fi @echo "=> detecting GPU..." @HAS_ROCM=0; HAS_CUDA=0; \ if command -v rocm-smi >/dev/null 2>&1 && [ -c /dev/kfd ] && lspci 2>/dev/null | grep -qi amd; then HAS_ROCM=1; fi; \ if command -v nvidia-smi >/dev/null 2>&1; then HAS_CUDA=1; fi; \ if [ $$HAS_ROCM -eq 1 ]; then \ echo " ROCm detected (AMD) -> torch rocm6.2"; \ $(PIP_INSTALL) --upgrade pip; \ $(PIP_INSTALL) torch torchaudio --index-url https://download.pytorch.org/whl/rocm6.2; \ elif [ $$HAS_CUDA -eq 1 ]; then \ echo " CUDA detected (NVIDIA) -> torch cu121"; \ $(PIP_INSTALL) --upgrade pip; \ $(PIP_INSTALL) torch torchaudio --index-url https://download.pytorch.org/whl/cu121; \ else \ echo " No GPU -> torch cpu"; \ $(PIP_INSTALL) --upgrade pip; \ $(PIP_INSTALL) torch torchaudio --index-url https://download.pytorch.org/whl/cpu; \ fi @echo "=> installing common deps..." @$(PIP_INSTALL) soundfile scipy numpy pyqtgraph PyQt6 @echo "=> optional sounddevice (audio playback, volume slider)..." @$(PIP_INSTALL) sounddevice || echo " sounddevice optional failed (PortAudio missing) -> playback disabled" @$(PY) -c "import torch, sys; print(f'torch {torch.__version__} cuda_available={torch.cuda.is_available()}', end=''); print(f' device={torch.cuda.get_device_name(0)}' if torch.cuda.is_available() else ' (cpu)')" @echo "=> done. Activate: source $(VENV)/bin/activate" install-cpu: @if [ ! -d $(VENV) ]; then $(VENV_CREATE); fi $(PIP_INSTALL) --upgrade pip $(PIP_INSTALL) torch torchaudio --index-url https://download.pytorch.org/whl/cpu $(PIP_INSTALL) soundfile scipy numpy pyqtgraph PyQt6 sounddevice || true $(PY) -c "import torch; print(torch.__version__, torch.cuda.is_available())" install-rocm: @if [ ! -d $(VENV) ]; then $(VENV_CREATE); fi $(PIP_INSTALL) --upgrade pip $(PIP_INSTALL) torch torchaudio --index-url https://download.pytorch.org/whl/rocm6.2 $(PIP_INSTALL) soundfile scipy numpy pyqtgraph PyQt6 sounddevice || true $(PY) -c "import torch; print(torch.__version__, torch.cuda.is_available(), torch.cuda.get_device_name(0) if torch.cuda.is_available() else '')" install-cuda: @if [ ! -d $(VENV) ]; then $(VENV_CREATE); fi $(PIP_INSTALL) --upgrade pip $(PIP_INSTALL) torch torchaudio --index-url https://download.pytorch.org/whl/cu121 $(PIP_INSTALL) soundfile scipy numpy pyqtgraph PyQt6 sounddevice || true $(PY) -c "import torch; print(torch.__version__, torch.cuda.is_available(), torch.cuda.get_device_name(0) if torch.cuda.is_available() else '')" extract: @if [ -x $(PY) ]; then $(PY) extract.py; else python3 extract.py; fi ast: @if [ -x $(PY) ]; then $(PY) sync_audio_test.py --config $(CONFIG); else python3 sync_audio_test.py --config $(CONFIG); fi clean: rm -rf $(VENV) __pycache__ .pytest_cache