diff --git a/.github/workflows/dev.opencl.yml b/.github/workflows/dev.opencl.yml index 777a3b8..e49ce54 100644 --- a/.github/workflows/dev.opencl.yml +++ b/.github/workflows/dev.opencl.yml @@ -27,8 +27,10 @@ jobs: include: - docker_file: Dockerfile.opencl.nvidia label: "dev-opencl-nvidia" - - docker_file: Dockerfile.opencl.amd - label: "dev-opencl-amd" + - docker_file: Dockerfile.opencl.amd.rusticl + label: "dev-opencl-amd-rusticl" + - docker_file: Dockerfile.opencl.amd.clover + label: "dev-opencl-amd-clover" steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/prod.opencl.yml b/.github/workflows/prod.opencl.yml index 8868c28..557164f 100644 --- a/.github/workflows/prod.opencl.yml +++ b/.github/workflows/prod.opencl.yml @@ -25,8 +25,10 @@ jobs: include: - docker_file: Dockerfile.opencl.nvidia label: "latest-opencl-nvidia" - - docker_file: Dockerfile.opencl.amd - label: "latest-opencl-amd" + - docker_file: Dockerfile.opencl.amd.rusticl + label: "latest-opencl-amd-rusticl" + - docker_file: Dockerfile.opencl.amd.clover + label: "latest-opencl-amd-clover" steps: - uses: actions/checkout@v4 diff --git a/Dockerfile.opencl.amd.clover b/Dockerfile.opencl.amd.clover new file mode 100644 index 0000000..c5e4fe0 --- /dev/null +++ b/Dockerfile.opencl.amd.clover @@ -0,0 +1,83 @@ +FROM ubuntu:noble + +ARG DEBIAN_FRONTEND=noninteractive + +USER root + +ARG PYTORCH_OCL_VERSION=0.2.0 +ARG TORCH_VERSION=2.4 +ARG PYTHON_VERSION=cp312 +ARG PLATFORM=linux_x86_64 + +ENV WHL_FILE=pytorch_ocl-${PYTORCH_OCL_VERSION}+torch${TORCH_VERSION}-${PYTHON_VERSION}-none-${PLATFORM}.whl +ENV WHL_URL=https://github.com/artyom-beilis/pytorch_dlprim/releases/download/${PYTORCH_OCL_VERSION}/${WHL_FILE} + +WORKDIR /app +COPY . /app + +RUN apt-get update && \ + apt install software-properties-common -y && \ + add-apt-repository ppa:kisak/kisak-mesa -y && \ + apt-get update -y && \ + apt dist-upgrade -y && \ + apt-get install -y \ + wget \ + software-properties-common \ + apt-transport-https \ + ca-certificates \ + curl \ + gpg && \ + rm -rf /var/lib/apt/lists/* + +# Install OpenCL dependencies +RUN apt-get update && apt-get install -y \ + ocl-icd-opencl-dev \ + opencl-headers \ + ocl-icd-libopencl1 \ + clinfo \ + mesa-opencl-icd \ + && rm -rf /var/lib/apt/lists/* + +# Install Python 3.12 +RUN add-apt-repository ppa:deadsnakes/ppa -y && \ + apt-get update && \ + apt-get install -y \ + python3.12 \ + python3.12-venv \ + python3.12-dev \ + python3-pip \ + && rm -rf /var/lib/apt/lists/* + +# Set up Python virtual environment +RUN python3.12 -m venv /app/venv +ENV PATH="/app/venv/bin:$PATH" +RUN pip install --upgrade pip + +# Configure OpenCL vendors +RUN mkdir -p /etc/OpenCL/vendors && \ + echo "libMesaOpenCL.so.1" > /etc/OpenCL/vendors/mesa.icd && \ + chmod 755 /etc/OpenCL/vendors + +RUN groupadd -f render && groupadd -f video +RUN usermod -a -G render,video root + +RUN mkdir -p /dev/dri && \ + touch /dev/dri/renderD128 && \ + chmod 666 /dev/dri/renderD128 + +RUN chmod 666 /dev/dri/render* || true +RUN chmod 666 /dev/dri/card* || true + +# Set environment variables for OpenCL +ENV OCL_ICD_VENDORS="/etc/OpenCL/vendors" +ENV OPENCL_VENDOR_PATH="/etc/OpenCL/vendors" + +COPY requirements.txt /app/requirements.txt +RUN /app/venv/bin/pip install --no-cache-dir -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu + +# Install OpenCL backend for PyTorch +RUN wget ${WHL_URL} && \ + /app/venv/bin/pip install ${WHL_FILE} && \ + rm ${WHL_FILE} + +CMD ["/app/venv/bin/python", "-m", "fastapi", "run", "main.py", "--proxy-headers", "--host", "0.0.0.0", "--port", "8000"] \ No newline at end of file diff --git a/Dockerfile.opencl.amd b/Dockerfile.opencl.amd.rusticl similarity index 100% rename from Dockerfile.opencl.amd rename to Dockerfile.opencl.amd.rusticl diff --git a/README.md b/README.md index 410286f..4e42249 100644 --- a/README.md +++ b/README.md @@ -86,13 +86,43 @@ services: ### **AMD GPU Support** > [!WARNING] -> Unless AMD starts to officially support older Cards again (e.g. gfx803), ROCm will not be available. +> Unless AMD starts to officially support older Cards again (e.g. gfx8), ROCm will not be available. -**OpenCL (AMD64):** +**OpenCL Rusticl (AMD64):** +> [!CAUTION] +> While Rusticl is compatible with Polaris, there are significant differences in inference performance, with Polaris cards running Clover showing higher accuracy. + +```yml +services: + image_video_classification_cuda: + image: ghcr.io/doppeltilde/image_video_classification:latest-opencl-amd-rusticl + ports: + - "8000:8000" + volumes: + - ./models:/root/.cache/huggingface/hub:rw + - /tmp/.X11-unix:/tmp/.X11-unix + environment: + - DEFAULT_MODEL_NAME + - BATCH_SIZE + - ACCESS_TOKEN + - DEFAULT_SCORE + - USE_API_KEYS + - API_KEYS + restart: unless-stopped + devices: + - /dev/kfd + - /dev/dri + security_opt: + - seccomp:unconfined + group_add: + - "video" + - "render" +``` +**OpenCL Clover (AMD64):** ```yml services: image_video_classification_cuda: - image: ghcr.io/doppeltilde/image_video_classification:latest-opencl-amd + image: ghcr.io/doppeltilde/image_video_classification:latest-opencl-amd-clover ports: - "8000:8000" volumes: diff --git a/docker-compose.dev.opencl.amd.yml b/docker-compose.dev.opencl.amd.yml index 1eeb517..cf45520 100644 --- a/docker-compose.dev.opencl.amd.yml +++ b/docker-compose.dev.opencl.amd.yml @@ -2,7 +2,7 @@ services: opencl_amd_dev: build: context: . - dockerfile: ./Dockerfile.opencl.amd + dockerfile: ./Dockerfile.opencl.amd.rusticl ports: - "8200:8000" environment: