Commit bf2a5318 authored by Your Name's avatar Your Name

Add per-model backend selection and OpenCL support

- Add --image-backend, --audio-backend, --tts-backend CLI args
- Add opencl to backend choices
- Add OpenCL build target in build.sh
parent 4ce1f330
#!/bin/bash #!/bin/bash
# Build script for CoderAI - Supports NVIDIA (CUDA) and Vulkan backends # Build script for CoderAI - Supports NVIDIA (CUDA) and Vulkan backends
# Usage: ./build.sh [nvidia|vulkan|vulkan-nvidia] # Usage: ./build.sh [nvidia|vulkan|vulkan-nvidia|opencl]
# Default: nvidia # Default: nvidia
set -e set -e
...@@ -16,13 +16,14 @@ NC='\033[0m' # No Color ...@@ -16,13 +16,14 @@ NC='\033[0m' # No Color
BACKEND="${1:-nvidia}" BACKEND="${1:-nvidia}"
BACKEND=$(echo "$BACKEND" | tr '[:upper:]' '[:lower:]') BACKEND=$(echo "$BACKEND" | tr '[:upper:]' '[:lower:]')
if [[ "$BACKEND" != "nvidia" && "$BACKEND" != "vulkan" && "$BACKEND" != "vulkan-nvidia" && "$BACKEND" != "cuda" ]]; then if [[ "$BACKEND" != "nvidia" && "$BACKEND" != "vulkan" && "$BACKEND" != "vulkan-nvidia" && "$BACKEND" != "cuda" && "$BACKEND" != "opencl" ]]; then
echo -e "${RED}Error: Invalid backend '$BACKEND'${NC}" echo -e "${RED}Error: Invalid backend '$BACKEND'${NC}"
echo "Usage: ./build.sh [nvidia|vulkan|vulkan-nvidia|cuda]" echo "Usage: ./build.sh [nvidia|vulkan|vulkan-nvidia|cuda|opencl]"
echo " nvidia - Use PyTorch with CUDA for NVIDIA GPUs" echo " nvidia - Use PyTorch with CUDA for NVIDIA GPUs"
echo " vulkan - Use llama-cpp-python with Vulkan for AMD GPUs" echo " vulkan - Use llama-cpp-python with Vulkan for AMD GPUs"
echo " vulkan-nvidia - Use llama-cpp-python with Vulkan for NVIDIA GPU only" echo " vulkan-nvidia - Use llama-cpp-python with Vulkan for NVIDIA GPU only"
echo " cuda - Use llama-cpp-python with CUDA for NVIDIA GPUs" echo " cuda - Use llama-cpp-python with CUDA for NVIDIA GPUs"
echo " opencl - Use stable-diffusion-cpp-python with OpenCL"
exit 1 exit 1
fi fi
...@@ -52,6 +53,8 @@ elif [ "$BACKEND" = "vulkan-nvidia" ]; then ...@@ -52,6 +53,8 @@ elif [ "$BACKEND" = "vulkan-nvidia" ]; then
VENV_DIR="venv_vulkan_nvidia" VENV_DIR="venv_vulkan_nvidia"
elif [ "$BACKEND" = "cuda" ]; then elif [ "$BACKEND" = "cuda" ]; then
VENV_DIR="venv_cuda" VENV_DIR="venv_cuda"
elif [ "$BACKEND" = "opencl" ]; then
VENV_DIR="venv_opencl"
fi fi
# Create virtual environment if it doesn't exist # Create virtual environment if it doesn't exist
...@@ -321,6 +324,47 @@ elif [ "$BACKEND" = "cuda" ]; then ...@@ -321,6 +324,47 @@ elif [ "$BACKEND" = "cuda" ]; then
echo "" echo ""
echo "Note: With CUDA backend, llama-cpp-python will only use NVIDIA GPUs." echo "Note: With CUDA backend, llama-cpp-python will only use NVIDIA GPUs."
echo "" echo ""
elif [ "$BACKEND" = "opencl" ]; then
# stable-diffusion-cpp-python with OpenCL backend
echo -e "${YELLOW}Installing stable-diffusion-cpp-python with OpenCL support...${NC}"
# Check for OpenCL
if ! command -v clinfo &> /dev/null && ! ls /usr/lib/*/libOpenCL* &> /dev/null; then
echo -e "${YELLOW}Warning: OpenCL not found in system${NC}"
echo -e "${YELLOW}You may need to install OpenCL runtime:${NC}"
echo " Debian/Ubuntu: sudo apt install ocl-icd-opencl-dev"
echo " Fedora: sudo dnf install ocl-icd-devel"
else
echo -e "${GREEN}✓ Found OpenCL${NC}"
fi
# Install base requirements
echo -e "${YELLOW}Installing base requirements...${NC}"
pip install -r requirements.txt
# Install stable-diffusion-cpp-python with OpenCL
echo -e "${YELLOW}Installing stable-diffusion-cpp-python with OpenCL...${NC}"
pip install stable-diffusion-cpp-python || {
echo ""
echo -e "${YELLOW}Note: If stable-diffusion-cpp-python is not available with pip,${NC}"
echo -e "${YELLOW}you may need to build from source.${NC}"
}
# Install additional requirements for OpenCL
echo -e "${YELLOW}Installing additional requirements for OpenCL...${NC}"
pip install numpy pillow
echo ""
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN} OpenCL build complete!${NC}"
echo -e "${GREEN}========================================${NC}"
echo ""
echo "Usage:"
echo " source $VENV_DIR/bin/activate"
echo " python coderai --model <model> --image-backend opencl"
echo ""
echo "Note: With OpenCL backend, stable-diffusion-cpp-python can use various GPUs."
echo ""
fi fi
# Create .backend file to track which backend was used # Create .backend file to track which backend was used
......
...@@ -4198,9 +4198,30 @@ def parse_args(): ...@@ -4198,9 +4198,30 @@ def parse_args():
parser.add_argument( parser.add_argument(
"--backend", "--backend",
type=str, type=str,
choices=["auto", "nvidia", "vulkan"], choices=["auto", "nvidia", "vulkan", "opencl"],
default="auto", default="auto",
help="Backend to use: auto (detect), nvidia (CUDA), or vulkan (AMD GPUs)", help="Backend to use: auto (detect), nvidia (CUDA), vulkan (AMD), or opencl",
)
parser.add_argument(
"--image-backend",
type=str,
choices=["auto", "nvidia", "vulkan", "opencl"],
default="auto",
help="Image generation backend: auto, nvidia (CUDA), vulkan (AMD), or opencl",
)
parser.add_argument(
"--audio-backend",
type=str,
choices=["auto", "nvidia", "vulkan", "opencl"],
default="auto",
help="Audio transcription backend: auto, nvidia (CUDA), vulkan (AMD), or opencl",
)
parser.add_argument(
"--tts-backend",
type=str,
choices=["auto", "nvidia", "vulkan", "opencl"],
default="auto",
help="TTS backend: auto, nvidia (CUDA), vulkan (AMD), or opencl",
) )
parser.add_argument( parser.add_argument(
"--host", "--host",
......
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