Skip to content

Commit

Permalink
feat: OpenCL AMD GPUs
Browse files Browse the repository at this point in the history
  • Loading branch information
jonafeucht committed Nov 8, 2024
1 parent 5794ef0 commit 7837260
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dev.opencl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ 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
label: "dev-opencl-amd"

steps:
- uses: actions/checkout@v4
Expand Down
50 changes: 34 additions & 16 deletions Dockerfile.opencl.amd
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
FROM ubuntu:22.04
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
Expand All @@ -13,34 +15,29 @@ ENV WHL_URL=https://github.com/artyom-beilis/pytorch_dlprim/releases/download/${
WORKDIR /app
COPY . /app

RUN apt-get update && apt-get install -y \
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 \
gpg && \
rm -rf /var/lib/apt/lists/*

# Add AMD GPU repository and install drivers
RUN apt update && \
wget https://repo.radeon.com/amdgpu-install/6.2.3/ubuntu/jammy/amdgpu-install_6.2.60203-1_all.deb && \
apt install ./amdgpu-install_6.2.60203-1_all.deb -y && \
amdgpu-install --usecase=graphics,opencl --opencl=rocr,legacy --accept-eula --no-32 -y && \
rm ./amdgpu-install_6.2.60203-1_all.deb

# 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/*

# Configure OpenCL vendors
RUN mkdir -p /etc/OpenCL/vendors && \
echo "libamdocl64.so" > /etc/OpenCL/vendors/amdocl64.icd

# Install Python 3.12
RUN add-apt-repository ppa:deadsnakes/ppa -y && \
apt-get update && \
Expand All @@ -56,11 +53,32 @@ RUN python3.12 -m venv /app/venv
ENV PATH="/app/venv/bin:$PATH"
RUN pip install --upgrade pip

# Add render and video groups
# Install AMD GPU drivers
RUN apt update -y && \
wget https://repo.radeon.com/amdgpu-install/6.2.3/ubuntu/noble/amdgpu-install_6.2.60203-1_all.deb && \
apt install ./amdgpu-install_6.2.60203-1_all.deb -y && \
rm -rf ./amdgpu-install_6.2.60203-1_all.deb

# Configure OpenCL vendors
RUN mkdir -p /etc/OpenCL/vendors && \
dpkg-divert --divert '/etc/OpenCL/vendors/mesa.icd.disabled' --rename '/etc/OpenCL/vendors/mesa.icd' && \
echo "libamdocl64.so" > /etc/OpenCL/vendors/amdocl64.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 OCL_ICD_VENDORS="/etc/OpenCL/vendors"
ENV OPENCL_VENDOR_PATH="/etc/OpenCL/vendors"
ENV RUSTICL_ENABLE=radeonsi

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
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

- For ease of use it's recommended to use the provided [docker-compose.yml](https://github.com/doppeltilde/image_video_classification/blob/main/docker-compose.yml).

### **CPU Support**
### **CPU Support (AMD64 & ARM64)**
Use the `latest` tag.
```yml
services:
Expand All @@ -30,7 +30,9 @@ services:
```
### **NVIDIA GPU Support**
**CUDA:**
> [!IMPORTANT]
> Nvidia driver >=560 needs to be installed on the host machine.
**CUDA (AMD64 & ARM64):**
```yml
services:
image_video_classification_cuda:
Expand All @@ -55,7 +57,7 @@ services:
count: all
capabilities: [ gpu ]
```
**OpenCL:**
**OpenCL (AMD64):**
```yml
services:
image_video_classification_opencl:
Expand All @@ -82,7 +84,9 @@ services:
```
### **AMD GPU Support**
**OpenCL:**
> [!WARNING]
> Unless AMD starts to support older Cards again (e.g. gfx803), ROCm will not be available.
**OpenCL (AMD64):**
```yml
services:
image_video_classification_cuda:
Expand Down Expand Up @@ -110,6 +114,7 @@ services:
- "109"
```
## Environment Variables
- Create a `.env` file and set the preferred values.
```sh
DEFAULT_MODEL_NAME=Falconsai/nsfw_image_detection
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.dev.opencl.amd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ services:
security_opt:
- seccomp:unconfined
group_add:
- "39"
- "109"
- "video"
- "render"
volumes:
- ./models:/root/.cache/huggingface/hub:rw
- /tmp/.X11-unix:/tmp/.X11-unix
Expand Down

0 comments on commit 7837260

Please sign in to comment.