├── LICENSE ├── Makefile ├── Dockerfile └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | image ?= opencl_$(USER) 3 | IMAGE ?= $(image) 4 | 5 | # Intel OpenCL 2.0 6 | #INTEL_DRIVER=SRB5.0_linux64.zip 7 | #INTEL_DRIVER_URL=http://registrationcenter-download.intel.com/akdlm/irc_nas/11396 8 | 9 | # Intel OpenCL 1.2 16.1.2 10 | #INTEL_DRIVER=opencl_runtime_16.1.2_x64_rh_6.4.0.37.tgz 11 | #INTEL_DRIVER_URL=http://registrationcenter-download.intel.com/akdlm/irc_nas/12556 12 | 13 | # Intel OpenCL 1.2 16.1.1 14 | INTEL_DRIVER=opencl_runtime_16.1.1_x64_ubuntu_6.4.0.25.tgz 15 | INTEL_DRIVER_URL=http://registrationcenter-download.intel.com/akdlm/irc_nas/9019 16 | 17 | # AMDGPU-PRO 18 | # TODO: this should be replaced by the ROCm drivers... 19 | #AMD_DRIVER = amdgpu-pro-17.40-492261.tar.xz 20 | AMD_DRIVER=amdgpu-pro-18.10-572953.tar.xz 21 | AMD_DRIVER_URL=https://www2.ati.com/drivers/linux/ubuntu 22 | 23 | # Specify the type of gpu (amd, nvidia, intel). 24 | # This defines the run options needed for the docker container to access the 25 | # GPU resources on the (Linux) host. The nvidia container needs a special 26 | # nvidia runtime installed, which depends on the docker-ce package from docker 27 | # rather than the base docker package in debian/ubuntu. 28 | # Note: Intel beignet gets confused by multiple cards... may need relabel 29 | # the card and renderer as shown in the comment below. This option can be 30 | # specified using RUN_OPTS="..." on the call to Make. 31 | NVIDIA_OPTS = --runtime=nvidia 32 | #AMD_OPTS = --device=/dev/kfd --device=/dev/dri --group-add video 33 | AMD_OPTS = --device=/dev/dri 34 | INTEL_OPTS = --device=/dev/dri 35 | #INTEL_OPTS = --device=/dev/dri/card1:/dev/dri/card0 --device=/dev/dri/renderD129:/dev/dri/renderD128 36 | gpu ?= none 37 | ifeq ($(gpu), amd) 38 | RUN_OPTS = $(AMD_OPTS) 39 | else ifeq ($(gpu), nvidia) 40 | RUN_OPTS = $(NVIDIA_OPTS) 41 | else ifeq ($(gpu), intel) 42 | RUN_OPTS = $(INTEL_OPTS) 43 | endif 44 | 45 | .PHONY: stop build run clean fetch 46 | 47 | all: build run 48 | 49 | stop: 50 | # Stop the container if it is running 51 | -docker container ls | grep -q $(IMAGE) && docker stop -t 0 $(IMAGE) 52 | # Remove the container if it exists 53 | -docker container ls -a | grep -q $(IMAGE) && docker container rm $(IMAGE) 54 | 55 | clean: stop 56 | # Remove the image if it exists 57 | -docker image ls | grep -q $(IMAGE) && docker image rm $(IMAGE) 58 | 59 | # Make build depend on fetch if you want to cache the drivers locally; need 60 | # to update the docker file appropriately. 61 | #build: fetch 62 | build: 63 | # Build or update the image ("make clean build" to build without cache) 64 | docker build . -t $(IMAGE) \ 65 | --build-arg INTEL_DRIVER_URL=$(INTEL_DRIVER_URL) \ 66 | --build-arg AMD_DRIVER_URL=$(AMD_DRIVER_URL) \ 67 | --build-arg INTEL_DRIVER=$(INTEL_DRIVER) \ 68 | --build-arg AMD_DRIVER=$(AMD_DRIVER) 69 | 70 | run: stop 71 | # Run the container 72 | docker run $(RUN_OPTS) --name $(IMAGE) $(IMAGE) 73 | 74 | bash: stop 75 | # Run the container interactive 76 | docker run $(RUN_OPTS) --interactive --tty --name $(IMAGE) $(IMAGE) bash 77 | 78 | attach: 79 | # Attach to running container 80 | docker exec --interactive --tty $(IMAGE) bash 81 | 82 | fetch: $(AMD_DRIVER) $(INTEL_DRIVER) 83 | 84 | $(AMD_DRIVER): 85 | # AMD requires referer to be ati.com in order to download 86 | #wget --referer https://www2.ati.com $(AMD_DRIVER_URL) 87 | curl --referer https://www2.ati.com -O $(AMD_DRIVER_URL)/$(AMD_DRIVER) 88 | 89 | $(INTEL_DRIVER): 90 | #wget $(INTEL_DRIVER_URL) 91 | curl -O $(INTEL_DRIVER_URL)/$(INTEL_DRIVER) 92 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Using the latest long-term-support Ubuntu OS 2 | FROM ubuntu:16.04 3 | 4 | RUN apt-get update && apt-get install -y \ 5 | apt-utils \ 6 | unzip \ 7 | tar \ 8 | curl \ 9 | xz-utils \ 10 | alien \ 11 | clinfo \ 12 | ; 13 | 14 | # Install Intel OpenCL drivers 15 | # Based on the Intel OpenCL installation instructions and the Intel docker file 16 | # in https://github.com/chihchun/opencl-docker 17 | # This seems to work for the CPU only. 18 | ARG INTEL_DRIVER=opencl_runtime_16.1.1_x64_ubuntu_6.4.0.25.tgz 19 | ARG INTEL_DRIVER_URL=http://registrationcenter-download.intel.com/akdlm/irc_nas/9019 20 | 21 | #ADD http://registrationcenter-download.intel.com/akdlm/irc_nas/11396/SRB5.0_linux64.zip /tmp/intel-opencl-driver 22 | RUN mkdir -p /tmp/opencl-driver-intel 23 | WORKDIR /tmp/opencl-driver-intel 24 | #COPY $INTEL_DRIVER /tmp/opencl-driver-intel/$INTEL_DRIVER 25 | #RUN curl -O $INTEL_DRIVER_URL/$INTEL_DRIVER 26 | # SRB 5 uses a zip file; older drivers use .tgz 27 | RUN echo INTEL_DRIVER is $INTEL_DRIVER; \ 28 | curl -O $INTEL_DRIVER_URL/$INTEL_DRIVER; \ 29 | if echo $INTEL_DRIVER | grep -q "[.]zip$"; then \ 30 | unzip $INTEL_DRIVER; \ 31 | mkdir fakeroot; \ 32 | for f in intel-opencl-*.tar.xz; do tar -C fakeroot -Jxvf $f; done; \ 33 | cp -R fakeroot/* /; \ 34 | ldconfig; \ 35 | else \ 36 | tar -xzf $INTEL_DRIVER; \ 37 | for i in $(basename $INTEL_DRIVER .tgz)/rpm/*.rpm; do alien --to-deb $i; done; \ 38 | dpkg -i *.deb; \ 39 | rm -rf $INTEL_DRIVER $(basename $INTEL_DRIVER .tgz) *.deb; \ 40 | mkdir -p /etc/OpenCL/vendors; \ 41 | echo /opt/intel/*/lib64/libintelocl.so > /etc/OpenCL/vendors/intel.icd; \ 42 | fi; \ 43 | rm -rf /tmp/opencl-driver-intel; 44 | 45 | # For an intel GPU you can use apt-get to install the beignet-opencl-icd driver. 46 | # To see the HD device you also need to add "--device=/dev/dri" to the docker 47 | # run command. With two GPUs beignet was confused and needed: 48 | # --device=/dev/dri/card1:/dev/dri/card0 49 | # --device=/dev/dri/renderD129:/dev/dri/renderD128 50 | # Since beignet causes problems with the other drivers, this has been 51 | # suppressed from the current docker build. 52 | # The chihchun/intel-beignet container from dockerhub will work in this case. 53 | #RUN apt-get update && apt-get install -y beignet-opencl-icd 54 | 55 | # Install AMD Radeon drivers 56 | # sonm/opencl is much smaller since it "pre-installs" the AMD libraries rather 57 | # going through the vendor installer (100 MB vs 800 MB). Similarly, installing 58 | # alien, etc. so the intel installer can work adds 300+ MB. Leave it this way 59 | # for now since it should be easier to bump driver versions; also, it should 60 | # be more trustworthy since the docker build relies on vendor binaries rather 61 | # than unsigned object files from an unknown user. 62 | # Docker run command needs --device=/dev/dri (and maybe --device=/dev/kfd) 63 | ARG AMD_DRIVER=amdgpu-pro-18.10-572953.tar.xz 64 | ARG AMD_DRIVER_URL=https://www2.ati.com/drivers/linux/ubuntu 65 | RUN mkdir -p /tmp/opencl-driver-amd 66 | WORKDIR /tmp/opencl-driver-amd 67 | #COPY $AMD_DRIVER /tmp/opencl-driver-amd/$AMD_DRIVER 68 | #RUN curl --referer $AMD_DRIVER_URL -O $AMD_DRIVER_URL/$AMD_DRIVER 69 | RUN echo AMD_DRIVER is $AMD_DRIVER; \ 70 | curl --referer $AMD_DRIVER_URL -O $AMD_DRIVER_URL/$AMD_DRIVER; \ 71 | tar -Jxvf $AMD_DRIVER; \ 72 | cd amdgpu-pro-*; \ 73 | ./amdgpu-install; \ 74 | apt-get install opencl-amdgpu-pro -y; \ 75 | rm -rf /tmp/opencl-driver-amd; 76 | 77 | #RUN apt-get install -y alien 78 | 79 | # Install NVidia OpenCL drivers 80 | # In order to run against nvidia GPU need the docker-ce package: 81 | # https://docs.docker.com/install/linux/docker-ce/ubuntu/#install-docker-ce 82 | # then the nvidia-docker2 package: 83 | # https://github.com/NVIDIA/nvidia-docker 84 | # The commands to compose the nvidia opencl configuration come from 85 | # the nvidia docker containers in opencl/runtime/Dockerfile at: 86 | # https://gitlab.com/nvidia/opencl 87 | # These are also hosted on docker hub and can be used as the base container: 88 | # https://hub.docker.com/r/nvidia/opencl/ 89 | # Docker run command needs "--runtime=nvidia" 90 | RUN mkdir -p /etc/OpenCL/vendors && \ 91 | echo "libnvidia-opencl.so.1" > /etc/OpenCL/vendors/nvidia.icd 92 | ENV NVIDIA_VISIBLE_DEVICES all 93 | ENV NVIDIA_DRIVER_CAPABILITIES compute,utility 94 | 95 | RUN rm -f /etc/OpenCL/vendors/mesa.icd 96 | 97 | CMD clinfo 98 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # opencl_docker 2 | Yet another OpenCL docker container, this for AMD, NVidia, and Intel CPU 3 | 4 | The intel driver will work directly. AMD and NVidia are Linux only and 5 | require special docker startup procedures to make the GPU devices available. 6 | 7 | The requirement for a Linux host is a limitation of the docker implementation 8 | (); maybe it can be made to work later. 9 | 10 | **Docker Install** 11 | 12 | If you are using the NVidia drivers you will need the official docker-ce 13 | package and the NVidia runtime package. The AMD and Intel drivers can use 14 | the version of docker that comes with your system. 15 | 16 | **Docker Configure** 17 | 18 | On linux systems DNS lookup was failing, so you may need to find 19 | the DNS IP addresses with: 20 | 21 | $ nmcli dev show | grep 'IP4.DNS' 22 | 23 | and add them to docker using the following in /etc/docker/daemon.json: 24 | 25 | { 26 | "dns": ["first ip", "second ip"], 27 | ... 28 | } 29 | 30 | You may need to force a docker daemon restart before this works: 31 | 32 | $ sudo pkill docker 33 | 34 | Note that the nvidia runtime configuration is also in /etc/docker/daemon.json 35 | so you may need some fiddling after installing it. 36 | 37 | **NVidia** 38 | 39 | In order to get a working NVidia container you need to install the nvidia 40 | runtime into your host docker configuration. This can be done using 41 | the nvidia-docker2 package from the NVidia PPA (perosnal package archive). 42 | See the following for details: 43 | 44 | https://github.com/NVIDIA/nvidia-docker 45 | 46 | As of this writing the nvidia-docker2 package depends on the docker-ce package 47 | from the docker PPA, so you may need to install that as well: 48 | 49 | https://docs.docker.com/install/linux/docker-ce/ubuntu/#install-docker-ce 50 | 51 | The docker run command reuires and additional argument "--runtime=nvidia" to 52 | connect the container to the hardware. 53 | 54 | The Dockerfile for NVidia is relatively simple; presumably the bulk of the 55 | configuration work is hidden in the NVidia runtime. 56 | 57 | Note: probably need to set up the NVidia drivers on the host before any other 58 | step, and probably needs to be done using the propriety drivers from NVidia. 59 | The test machine was already set up so the specifics are not included here. 60 | 61 | Test with: 62 | 63 | docker run --runtime=nvidia pkienzle/opencl_docker clinfo 64 | 65 | You may need to add the user to video group as part of your installation 66 | if your container is not running as root. 67 | 68 | **AMD Radeon** 69 | 70 | The AMD drivers may need to be installed on the host in order to run GPGPU 71 | from a docker container. This container hasn't been tested without. 72 | 73 | The open source ROCm drivers did not work from the container as of this 74 | writing, so the amdgpu-pro drivers were used instead. 75 | 76 | The AMD drivers need some startup options for the container to see the GPU: 77 | 78 | docker run --device=/dev/dri pkienzle/opencl clinfo 79 | 80 | For your application, you may need to add the user to video group as part 81 | of your installation if your container is not running as root. (Note: may 82 | also need --device=/dev/kfd but works fine without it on an R9 Nano). 83 | 84 | **Intel** 85 | 86 | The intel drivers are included in the container. The CPU device shows up on 87 | a machine with Intel CPU. 88 | 89 | docker run pkienzle/opencl_docker clinfo 90 | 91 | The official Intel drivers do not recognize the Intel GPU from within the 92 | container. The open source beignet driver on Ubuntu is able to see it if 93 | the /dev/dri device is forwarded to the docker container. It is not 94 | included in this container because it interferes with the other drivers 95 | on the system. There are intel-beignet containers on docker hub that work, 96 | such as: 97 | 98 | docker run --device=/dev/dri chihchun/intel-beignet clinfo 99 | 100 | Beignet was having trouble with two different GPUs on the same system, 101 | and needed to remap the Intel device to the first position: 102 | 103 | docker run \ 104 | --device=/dev/dri/card1:/dev/dri/card0 \ 105 | --device=/dev/dri/renderD129:/dev/dri/renderD128 \ 106 | chihchun/intel-beignet clinfo 107 | 108 | You may need to add the user to video group as part of your installation 109 | if your container is not running as root. 110 | --------------------------------------------------------------------------------