Skip to content

Commit b3459c0

Browse files
authored
add dockerfiles (#2162)
1 parent 7bccc3f commit b3459c0

File tree

4 files changed

+368
-0
lines changed

4 files changed

+368
-0
lines changed

docker/Dockerfile.ipex-flex-xpu

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ============================================================================
14+
15+
ARG UBUNTU_VERSION
16+
17+
FROM ubuntu:${UBUNTU_VERSION}
18+
19+
ENV LANG=C.UTF-8
20+
21+
ARG DEBIAN_FRONTEND=noninteractive
22+
23+
HEALTHCHECK NONE
24+
RUN useradd -d /home/ipex -m -s /bin/bash ipex
25+
26+
RUN apt-get update && \
27+
apt-get install -y --no-install-recommends --fix-missing \
28+
apt-utils \
29+
build-essential \
30+
ca-certificates \
31+
clinfo \
32+
curl \
33+
git \
34+
gnupg2 \
35+
gpg-agent \
36+
rsync \
37+
sudo \
38+
unzip \
39+
wget && \
40+
apt-get clean && \
41+
rm -rf /var/lib/apt/lists/*
42+
43+
44+
RUN no_proxy=$no_proxy wget -qO - https://repositories.intel.com/graphics/intel-graphics.key | \
45+
gpg --dearmor --output /usr/share/keyrings/intel-graphics.gpg
46+
RUN echo 'deb [arch=amd64 signed-by=/usr/share/keyrings/intel-graphics.gpg] https://repositories.intel.com/graphics/ubuntu jammy flex' | \
47+
tee /etc/apt/sources.list.d/intel.gpu.jammy.list
48+
49+
ARG ICD_VER
50+
ARG LEVEL_ZERO_GPU_VER
51+
ARG LEVEL_ZERO_VER
52+
ARG LEVEL_ZERO_DEV_VER
53+
54+
RUN apt-get update && \
55+
apt-get install -y --no-install-recommends --fix-missing \
56+
intel-opencl-icd=${ICD_VER} \
57+
intel-level-zero-gpu=${LEVEL_ZERO_GPU_VER} \
58+
level-zero=${LEVEL_ZERO_VER} \
59+
level-zero-dev=${LEVEL_ZERO_DEV_VER} && \
60+
apt-get clean && \
61+
rm -rf /var/lib/apt/lists/*
62+
63+
RUN no_proxy=$no_proxy wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \
64+
| gpg --dearmor | tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null && \
65+
echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" \
66+
| tee /etc/apt/sources.list.d/oneAPI.list
67+
68+
ARG DPCPP_VER
69+
ARG MKL_VER
70+
71+
RUN apt-get update && \
72+
apt-get install -y --no-install-recommends --fix-missing \
73+
intel-oneapi-runtime-dpcpp-cpp=${DPCPP_VER} \
74+
intel-oneapi-runtime-mkl=${MKL_VER}
75+
76+
ARG PYTHON
77+
78+
RUN apt-get update && apt-get install software-properties-common -y && add-apt-repository ppa:deadsnakes/ppa
79+
80+
RUN apt-get update && apt-get install -y --no-install-recommends --fix-missing \
81+
${PYTHON} lib${PYTHON} python3-pip python3.9-distutils && \
82+
apt-get clean && \
83+
rm -rf /var/lib/apt/lists/*
84+
85+
RUN pip --no-cache-dir install --upgrade \
86+
pip \
87+
setuptools
88+
89+
RUN ln -sf $(which ${PYTHON}) /usr/local/bin/python && \
90+
ln -sf $(which ${PYTHON}) /usr/local/bin/python3 && \
91+
ln -sf $(which ${PYTHON}) /usr/bin/python && \
92+
ln -sf $(which ${PYTHON}) /usr/bin/python3
93+
94+
ARG TORCH_WHL_URL
95+
ARG TORCH_VERSION
96+
ARG IPEX_WHEEL_URL
97+
ARG IPEX_VERSION
98+
ARG TORCHVISION_VERSION
99+
ARG TORCHVISION_WHL_URL
100+
101+
RUN python -m pip install numpy
102+
103+
RUN python -m pip install torch==${TORCH_VERSION} -f ${TORCH_WHL_URL} && \
104+
python -m pip install intel_extension_for_pytorch==${IPEX_VERSION} -f ${IPEX_WHEEL_URL} && \
105+
python -m pip install torchvision==${TORCHVISION_VERSION} -f ${TORCHVISION_WHL_URL}

docker/Dockerfile.ipex-max-xpu

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ============================================================================
14+
15+
ARG UBUNTU_VERSION
16+
17+
FROM ubuntu:${UBUNTU_VERSION}
18+
19+
ENV LANG=C.UTF-8
20+
21+
ARG DEBIAN_FRONTEND=noninteractive
22+
23+
HEALTHCHECK NONE
24+
RUN useradd -d /home/ipex -m -s /bin/bash ipex
25+
26+
RUN apt-get update && \
27+
apt-get install -y --no-install-recommends --fix-missing \
28+
apt-utils \
29+
build-essential \
30+
ca-certificates \
31+
clinfo \
32+
curl \
33+
git \
34+
gnupg2 \
35+
gpg-agent \
36+
rsync \
37+
sudo \
38+
unzip \
39+
wget && \
40+
apt-get clean && \
41+
rm -rf /var/lib/apt/lists/*
42+
43+
44+
RUN no_proxy=$no_proxy wget -qO - https://repositories.intel.com/graphics/intel-graphics.key | \
45+
gpg --dearmor --output /usr/share/keyrings/intel-graphics.gpg
46+
RUN echo 'deb [arch=amd64 signed-by=/usr/share/keyrings/intel-graphics.gpg] https://repositories.intel.com/graphics/ubuntu jammy flex' | \
47+
tee /etc/apt/sources.list.d/intel.gpu.jammy.list
48+
49+
ARG ICD_VER
50+
ARG LEVEL_ZERO_GPU_VER
51+
ARG LEVEL_ZERO_VER
52+
ARG LEVEL_ZERO_DEV_VER
53+
54+
RUN apt-get update && \
55+
apt-get install -y --no-install-recommends --fix-missing \
56+
intel-opencl-icd=${ICD_VER} \
57+
intel-level-zero-gpu=${LEVEL_ZERO_GPU_VER} \
58+
level-zero=${LEVEL_ZERO_VER} \
59+
level-zero-dev=${LEVEL_ZERO_DEV_VER} && \
60+
apt-get clean && \
61+
rm -rf /var/lib/apt/lists/*
62+
63+
RUN no_proxy=$no_proxy wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \
64+
| gpg --dearmor | tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null && \
65+
echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" \
66+
| tee /etc/apt/sources.list.d/oneAPI.list
67+
68+
ARG DPCPP_VER
69+
ARG MKL_VER
70+
ARG CCL_VER
71+
72+
RUN apt-get update && \
73+
apt-get install -y --no-install-recommends --fix-missing \
74+
intel-oneapi-runtime-dpcpp-cpp=${DPCPP_VER} \
75+
intel-oneapi-runtime-mkl=${MKL_VER} \
76+
intel-oneapi-runtime-ccl=${CCL_VER}
77+
78+
ARG PYTHON
79+
80+
RUN apt-get update && apt-get install -y --no-install-recommends --fix-missing \
81+
${PYTHON} lib${PYTHON} python3-pip && \
82+
apt-get clean && \
83+
rm -rf /var/lib/apt/lists/*
84+
85+
RUN pip --no-cache-dir install --upgrade \
86+
pip \
87+
setuptools
88+
89+
RUN ln -sf $(which ${PYTHON}) /usr/local/bin/python && \
90+
ln -sf $(which ${PYTHON}) /usr/local/bin/python3 && \
91+
ln -sf $(which ${PYTHON}) /usr/bin/python && \
92+
ln -sf $(which ${PYTHON}) /usr/bin/python3
93+
94+
ARG TORCH_VERSION
95+
ARG TORCHVISION_VERSION
96+
ARG IPEX_VERSION
97+
ARG ONECCL_BIND_PT_VERSION
98+
ARG TORCH_WHL_URL
99+
ARG IPEX_WHL_URL
100+
ARG TORCHVISION_WHL_URL
101+
ARG ONECCL_BIND_PT_WHL_URL
102+
103+
RUN python -m pip install numpy
104+
105+
RUN python -m pip install torch==${TORCH_VERSION} -f ${TORCH_WHL_URL} && \
106+
python -m pip install intel_extension_for_pytorch==${IPEX_VERSION} -f ${IPEX_WHL_URL} && \
107+
python -m pip install torchvision==${TORCHVISION_VERSION} -f ${TORCHVISION_WHL_URL} && \
108+
python -m pip install oneccl_bind_pt==${ONECCL_BIND_PT_VERSION} -f ${ONECCL_BIND_PT_WHL_URL}
109+
110+
ENV LD_LIBRARY_PATH=/opt/intel/oneapi/lib:/opt/intel/oneapi/lib/intel64:$LD_LIBRARY_PATH
111+

docker/README.md

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Intel® Extension for PyTorch\* Container
2+
3+
## Description
4+
5+
This document has instruction for running Intel® Extension for PyTorch\* for
6+
GPU in a container.
7+
8+
Assumptions:
9+
* Host machine has the Intel® Data Center GPU
10+
* Host machine has the Intel® Data Center GPU Ubuntu driver
11+
* Host machine has Docker installed
12+
13+
## Docker
14+
15+
### Build the container:
16+
17+
`./build.sh` script has docker build command, update all the relevant build arguments and execute the script.
18+
19+
```bash
20+
./build.sh [xpu-flex/xpu-max]
21+
```
22+
23+
### Running container:
24+
25+
Run the following commands to start Intel® Extension for PyTorch\* GPU container. You can use `-v` option to mount your
26+
local directory into the container. The `-v` argument can be omitted if you do not need
27+
access to a local directory in the container. Pass the video and render groups to your
28+
docker container so that the GPU is accessible.
29+
30+
For Flex GPU:
31+
```
32+
IMAGE_NAME=intel-extension-for-pytorch:xpu-flex
33+
```
34+
For Max GPU:
35+
```
36+
IMAGE_NAME=intel-extension-for-pytorch:xpu-max
37+
```
38+
```bash
39+
40+
VIDEO=$(getent group video | sed -E 's,^video:[^:]*:([^:]*):.*$,\1,')
41+
RENDER=$(getent group render | sed -E 's,^render:[^:]*:([^:]*):.*$,\1,')
42+
43+
test -z "$RENDER" || RENDER_GROUP="--group-add ${RENDER}"
44+
45+
docker run --rm \
46+
-v <your-local-dir>:/workspace \
47+
--group-add ${VIDEO} \
48+
${RENDER_GROUP} \
49+
--device=/dev/dri \
50+
--ipc=host \
51+
-e http_proxy=$http_proxy \
52+
-e https_proxy=$https_proxy \
53+
-e no_proxy=$no_proxy \
54+
-it $IMAGE_NAME bash
55+
```
56+
57+
#### Verify if XPU is accessible from PyTorch:
58+
You are inside the container now. Run the following command to verify XPU is visible to PyTorch:
59+
```bash
60+
python -c "import torch;print(torch.device('xpu'))"
61+
```
62+
Sample output looks like below:
63+
```
64+
xpu
65+
```
66+
Then, verify that the XPU device is available to Intel® Extension for PyTorch\*:
67+
```bash
68+
python -c "import intel_extension_for_pytorch as ipex;print(ipex.xpu.is_available())"
69+
```
70+
Sample output looks like below:
71+
```
72+
True
73+
```
74+
Use the following command to check whether MKL is enabled as default:
75+
```bash
76+
python -c "import intel_extension_for_pytorch as ipex;print(ipex.xpu.has_onemkl())"
77+
```
78+
Sample output looks like below:
79+
```
80+
True
81+
```
82+
Finally, use the following command to show detailed info of detected device:
83+
```bash
84+
python -c "import torch; import intel_extension_for_pytorch as ipex; print(torch.__version__); print(ipex.__version__); [print(f'[{i}]: {ipex.xpu.get_device_properties(i)}') for i in range(ipex.xpu.device_count())];"
85+
```
86+
87+
Sample output looks like below:
88+
```
89+
1.13.0a0+gitb1dde16
90+
1.13.10+xpu
91+
[0]: _DeviceProperties(name='Intel(R) Graphics [0x0bd5]', platform_name='Intel(R) Level-Zero', dev_type='gpu, support_fp64=1, total_memory=62244MB, max_compute_units=512)
92+
[1]: _DeviceProperties(name='Intel(R) Graphics [0x0bd5]', platform_name='Intel(R) Level-Zero', dev_type='gpu, support_fp64=1, total_memory=62244MB, max_compute_units=512)
93+
```
94+
#### Running your own script
95+
96+
Now you are inside container with Python 3.10, PyTorch, and Intel® Extension for PyTorch\* preinstalled. You can run your own script
97+
to run on Intel GPU.

docker/build.sh

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
set -e
2+
IMAGE_TYPE=$1
3+
4+
if [ $IMAGE_TYPE == "xpu-flex" ];then
5+
6+
IMAGE_NAME=intel-extension-for-pytorch:xpu-flex
7+
8+
docker build --build-arg http_proxy=$http_proxy \
9+
--build-arg https_proxy=$https_proxy \
10+
--build-arg no_proxy=$no_proxy \
11+
--build-arg UBUNTU_VERSION=22.04 \
12+
--build-arg PYTHON=python3.10 \
13+
--build-arg ICD_VER=22.43.24595.35+i538~22.04 \
14+
--build-arg LEVEL_ZERO_GPU_VER=1.3.24595.35+i538~22.04 \
15+
--build-arg LEVEL_ZERO_VER=1.8.8+i524~u22.04 \
16+
--build-arg LEVEL_ZERO_DEV_VER=1.8.8+i524~u22.04 \
17+
--build-arg DPCPP_VER=2023.0.0-25370 \
18+
--build-arg MKL_VER=2023.0.0-25398 \
19+
--build-arg TORCH_VERSION==1.13.0a0+gitb1dde16 \
20+
--build-arg IPEX_VERSION=1.13.10+xpu \
21+
--build-arg TORCHVISION_VERSION=0.14.1a0+0504df5 \
22+
--build-arg TORCH_WHL_URL=https://developer.intel.com/ipex-whl-stable-xpu \
23+
--build-arg IPEX_WHEEL_URL=https://developer.intel.com/ipex-whl-stable-xpu \
24+
--build-arg TORCHVISION_WHL_URL=https://developer.intel.com/ipex-whl-stable-xpu \
25+
-t $IMAGE_NAME \
26+
-f Dockerfile.ipex-flex-xpu .
27+
fi
28+
29+
if [ ${IMAGE_TYPE} == "xpu-max" ];then
30+
31+
IMAGE_NAME=intel-extension-for-pytorch:xpu-max
32+
33+
docker build --build-arg http_proxy=$http_proxy \
34+
--build-arg https_proxy=$https_proxy \
35+
--build-arg no_proxy=$no_proxy \
36+
--build-arg UBUNTU_VERSION=22.04 \
37+
--build-arg PYTHON=python3.10 \
38+
--build-arg ICD_VER=22.43.24595.35+i538~22.04 \
39+
--build-arg LEVEL_ZERO_GPU_VER=1.3.24595.35+i538~22.04 \
40+
--build-arg LEVEL_ZERO_VER=1.8.8+i524~u22.04 \
41+
--build-arg LEVEL_ZERO_DEV_VER=1.8.8+i524~u22.04 \
42+
--build-arg DPCPP_VER=2023.0.0-25370 \
43+
--build-arg MKL_VER=2023.0.0-25398 \
44+
--build-arg CCL_VER=2021.8.0-25371 \
45+
--build-arg TORCH_VERSION=1.13.0a0+gitb1dde16 \
46+
--build-arg IPEX_VERSION=1.13.10+xpu \
47+
--build-arg TORCHVISION_VERSION=0.14.1a0+0504df5 \
48+
--build-arg ONECCL_BIND_PT_VERSION=1.13.100 \
49+
--build-arg TORCH_WHL_URL=https://developer.intel.com/ipex-whl-stable-xpu \
50+
--build-arg IPEX_WHL_URL=https://developer.intel.com/ipex-whl-stable-xpu \
51+
--build-arg TORCHVISION_WHL_URL=https://developer.intel.com/ipex-whl-stable-xpu \
52+
--build-arg ONECCL_BIND_PT_WHL_URL=https://developer.intel.com/ipex-whl-stable-xpu \
53+
-t $IMAGE_NAME \
54+
-f Dockerfile.ipex-max-xpu .
55+
fi

0 commit comments

Comments
 (0)