#!/bin/bash
# ComfyUI Launch for BC-250 APU — unified memory, no lowvram
cd /home/fabian/ComfyUI
source venv/bin/activate

export HSA_OVERRIDE_GFX_VERSION=10.1.0
export HSA_ENABLE_SDMA=0
export HIP_VISIBLE_DEVICES=0
export ROCM_PATH=/opt/rocm
export OMP_NUM_THREADS=12
export MKL_NUM_THREADS=12
export NUMEXPR_NUM_THREADS=12
export PYTORCH_HIP_ALLOC_CONF="expandable_segments:False"

# Unset harmful vars
unset GPU_MAX_HW_QUEUES 2>/dev/null || true
unset HIP_LAUNCH_BLOCKING 2>/dev/null || true

echo "Starting ComfyUI (APU mode - no lowvram)..."

# --force-fp32: required for gfx1010 (no native fp16 support in some ops)
# NO --lowvram: APU has unified memory, offloading is counterproductive
# --gpu-only: keep everything in VRAM (which IS the system RAM on APU)
python main.py \
    --listen 0.0.0.0 \
    --port 8188 \
    --force-fp32 \
    --gpu-only
