Restored gtk-3 installation (#3472)
[platform/upstream/dldt.git] / scripts / install_dependencies / install_NEO_OCL_driver.sh
1 #!/bin/bash
2
3 # Copyright (c) 2018 - 2020 Intel Corporation
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 #
18 # Installs the Intel® Graphics Compute Runtime for OpenCL™ Driver on Linux.
19 #
20 # Usage: sudo -E ./install_NEO_OCL_driver.sh
21 #
22 # Supported platforms:
23 #     6th-11th generation Intel® Core™ processor with Intel(R)
24 #     Processor Graphics Technology not previously disabled by the BIOS
25 #     or motherboard settings
26 #
27 EXIT_FAILURE=1
28 PKGS=
29 CENTOS_MINOR=
30 UBUNTU_VERSION=
31 DISTRO=
32 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
33 INSTALL_DRIVER_VERSION='19.41.14441'
34 AVAILABLE_DRIVERS=("19.41.14441" "20.35.17767")
35
36
37 print_help()
38 {
39     # Display Help
40     usage="Usage: $(basename "$0") [OPTIONS]...
41 Download and installs the Intel® Graphics Compute Runtime for OpenCL™ Driver on Linux
42
43     Available options:
44     -y                      Replace the currently installed driver with the newer version.
45     -d, --install_driver    Manually select driver version to one of available to install drivers.
46                             Default value: $INSTALL_DRIVER_VERSION
47                             Available to install drivers: ${AVAILABLE_DRIVERS[*]}
48     -h, --help              display this help and exit" 
49     echo "$usage"
50 }
51
52 while [[ $# -gt 0 ]]
53 do
54     key="$1"
55     case $key in
56         -d|--install_driver)
57         user_chosen_driver="$2"
58         if [[ " ${AVAILABLE_DRIVERS[@]} " =~ " ${user_chosen_driver} " ]]; then
59             INSTALL_DRIVER_VERSION=$user_chosen_driver
60         else
61             echo "ERROR: unable to install the driver ${user_chosen_driver}."
62             echo "Available values: ${AVAILABLE_DRIVERS[*]}"
63             exit -1
64         fi
65         shift
66         shift
67     ;;
68         -y)
69         agreement=true
70         shift
71     ;;
72         -h|--help)
73         print_help
74         exit
75     ;;
76         *)
77         echo "$(basename "$0"): invalid option -- '${key}'"
78         echo "Try '$(basename "$0") --help' for more information."
79         exit -1
80     esac
81 done
82
83 _install_prerequisites_centos()
84 {
85     # yum doesn't accept timeout in seconds as parameter
86     echo
87     echo "Note: if yum becomes non-responsive, try aborting the script and run:"
88     echo "      sudo -E $0"
89     echo
90
91     CMDS=("yum -y install numactl-libs numactl ocl-icd ocl-icd-devel")
92
93     for cmd in "${CMDS[@]}"; do
94         echo "$cmd"
95         eval "$cmd"
96         if [[ $? -ne 0 ]]; then
97             echo "ERROR: failed to run $cmd" >&2
98             echo "Problem (or disk space)?" >&2
99             echo ". Verify that you have enough disk space, and run the script again." >&2
100             exit $EXIT_FAILURE
101         fi
102     done
103
104 }
105
106 _install_prerequisites_ubuntu()
107 {
108     CMDS=("apt-get -y update"
109           "apt-get -y install libnuma1 ocl-icd-libopencl1")
110
111     for cmd in "${CMDS[@]}"; do
112         echo "$cmd"
113         eval "$cmd"
114         if [[ $? -ne 0 ]]; then
115             echo "ERROR: failed to run $cmd" >&2
116             echo "Problem (or disk space)?" >&2
117             echo "                sudo -E $0" >&2
118             echo "2. Verify that you have enough disk space, and run the script again." >&2
119             exit $EXIT_FAILURE
120         fi
121     done
122 }
123
124 install_prerequisites()
125 {
126     if [[ $DISTRO == "centos" ]]; then
127         echo "Installing prerequisites..."
128         _install_prerequisites_centos
129     elif [[ $DISTRO == "ubuntu" ]]; then
130         echo "Installing prerequisites..."
131         _install_prerequisites_ubuntu
132     else
133         echo Unknown OS
134     fi
135 }
136
137 _deploy_rpm()
138 {
139     # On a CentOS 7.2 machine with Intel Parallel Composer XE 2017
140     # installed we got conflicts when trying to deploy these rpms.
141     # If that happens to you too, try again with:
142     # IGFX_RPM_FLAGS="--force" sudo -E ./install_NEO_OCL_driver.sh install
143     #
144     cmd="rpm $IGFX_RPM_FLAGS -ivh --nodeps --force $1"
145     echo "$cmd"
146     eval "$cmd"
147 }
148
149 _deploy_deb()
150 {
151     cmd="dpkg -i $1"
152     echo "$cmd"
153     eval "$cmd"
154 }
155
156 _install_user_mode_centos()
157 {
158     _deploy_rpm "intel*.rpm"
159     if [[ $? -ne 0 ]]; then
160         echo "ERROR: failed to install rpms $cmd error"  >&2
161         echo "Make sure you have enough disk space or fix the problem manually and try again." >&2
162         exit $EXIT_FAILURE
163     fi
164 }
165
166 _install_user_mode_ubuntu()
167 {
168     _deploy_deb "intel*.deb"
169     if [[ $? -ne 0 ]]; then
170         echo "ERROR: failed to install rpms $cmd error"  >&2
171         echo "Make sure you have enough disk space or fix the problem manually and try again." >&2
172         exit $EXIT_FAILURE
173     fi
174 }
175
176
177 install_user_mode()
178 {
179     echo "Installing user mode driver..."
180     
181     if [[ $DISTRO == "centos" ]]; then
182         _install_user_mode_centos
183     else
184         _install_user_mode_ubuntu
185     fi
186     # exit from $SCRIPT_DIR/neo folder
187     cd -
188     # clean it up
189     rm -rf "$SCRIPT_DIR/neo"
190 }
191
192 _uninstall_user_mode_centos()
193 {
194     echo Looking for previously installed user-mode driver...
195     PACKAGES=("intel-opencl"
196            "intel-ocloc"
197            "intel-gmmlib"
198            "intel-igc-core"
199            "intel-igc-opencl")
200     for package in "${PACKAGES[@]}"; do      
201         echo "rpm -qa | grep $package"
202         found_package=$(rpm -qa | grep "$package")
203         if [[ $? -eq 0 ]]; then
204             echo "Found installed user-mode driver, performing uninstall..."
205             cmd="rpm -e --nodeps ${found_package}"
206             echo "$cmd"
207             eval "$cmd"
208             if [[ $? -ne 0 ]]; then
209                 echo "ERROR: failed to uninstall existing user-mode driver." >&2
210                 echo "Please try again manually and run the script again." >&2
211                 exit $EXIT_FAILURE
212             fi
213         fi
214     done
215 }
216
217 _uninstall_user_mode_ubuntu()
218 {
219     echo Looking for previously installed user-mode driver...
220
221     PACKAGES=("intel-opencl"
222            "intel-ocloc"
223            "intel-gmmlib"
224            "intel-igc-core"
225            "intel-igc-opencl")
226
227     for package in "${PACKAGES[@]}"; do
228         found_package=$(dpkg-query -W -f='${binary:Package}\n' "${package}")
229         if [[ $? -eq 0 ]]; then
230             echo "Found installed user-mode driver, performing uninstall..."
231             cmd="apt-get autoremove -y $package"
232             echo "$cmd"
233             eval "$cmd"
234             if [[ $? -ne 0 ]]; then
235                 echo "ERROR: failed to uninstall existing user-mode driver." >&2
236                 echo "Please try again manually and run the script again." >&2
237                 exit $EXIT_FAILURE
238             fi
239         fi
240     done
241 }
242
243 uninstall_user_mode()
244 {
245     if [[ $DISTRO == "centos" ]]; then
246         _uninstall_user_mode_centos
247     else
248         _uninstall_user_mode_ubuntu
249     fi
250 }
251
252 _is_package_installed()
253 {
254     if [[ $DISTRO == "centos" ]]; then
255         cmd="rpm -qa | grep $1"
256     else
257         cmd="dpkg-query -W -f='${binary:Package}\n' $pkg"
258     fi
259     echo "$cmd"
260     eval "$cmd"
261 }
262
263
264 _download_packages_ubuntu()
265 {
266     case $INSTALL_DRIVER_VERSION in
267     "19.41.14441")
268         wget https://github.com/intel/compute-runtime/releases/download/19.41.14441/intel-gmmlib_19.3.2_amd64.deb
269         wget https://github.com/intel/compute-runtime/releases/download/19.41.14441/intel-igc-core_1.0.2597_amd64.deb
270         wget https://github.com/intel/compute-runtime/releases/download/19.41.14441/intel-igc-opencl_1.0.2597_amd64.deb
271         wget https://github.com/intel/compute-runtime/releases/download/19.41.14441/intel-opencl_19.41.14441_amd64.deb
272         wget https://github.com/intel/compute-runtime/releases/download/19.41.14441/intel-ocloc_19.41.14441_amd64.deb
273     ;;
274     "20.35.17767")
275         wget https://github.com/intel/compute-runtime/releases/download/20.35.17767/intel-gmmlib_20.2.4_amd64.deb
276         wget https://github.com/intel/compute-runtime/releases/download/20.35.17767/intel-igc-core_1.0.4756_amd64.deb
277         wget https://github.com/intel/compute-runtime/releases/download/20.35.17767/intel-igc-opencl_1.0.4756_amd64.deb
278         wget https://github.com/intel/compute-runtime/releases/download/20.35.17767/intel-opencl_20.35.17767_amd64.deb
279         wget https://github.com/intel/compute-runtime/releases/download/20.35.17767/intel-ocloc_20.35.17767_amd64.deb
280         wget https://github.com/intel/compute-runtime/releases/download/20.35.17767/intel-level-zero-gpu_1.0.17767_amd64.deb
281     ;;
282         *)
283         echo "ERROR: Unrecognized driver ${INSTALL_DRIVER_VERSION}."
284         echo "Available values: ${AVAILABLE_DRIVERS[@]}"
285         exit -1
286     esac
287 }
288
289 _download_packages_centos()
290 {
291
292     case $INSTALL_DRIVER_VERSION in
293     "19.41.14441")
294         wget -O intel-igc-core-1.0.2597-1.el7.x86_64.rpm https://sourceforge.net/projects/intel-compute-runtime/files/19.41.14441/centos-7/intel-igc-core-1.0.2597-1.el7.x86_64.rpm/download
295         wget -O intel-opencl-19.41.14441-1.el7.x86_64.rpm https://sourceforge.net/projects/intel-compute-runtime/files/19.41.14441/centos-7/intel-opencl-19.41.14441-1.el7.x86_64.rpm/download
296         wget -O intel-igc-opencl-devel-1.0.2597-1.el7.x86_64.rpm https://sourceforge.net/projects/intel-compute-runtime/files/19.41.14441/centos-7/intel-igc-opencl-devel-1.0.2597-1.el7.x86_64.rpm/download
297         wget -O intel-igc-opencl-1.0.2597-1.el7.x86_64.rpm https://sourceforge.net/projects/intel-compute-runtime/files/19.41.14441/centos-7/intel-igc-opencl-1.0.2597-1.el7.x86_64.rpm/download
298         wget -O intel-gmmlib-19.3.2-1.el7.x86_64.rpm https://sourceforge.net/projects/intel-compute-runtime/files/19.41.14441/centos-7/intel-gmmlib-19.3.2-1.el7.x86_64.rpm/download
299         wget -O intel-gmmlib-devel-19.3.2-1.el7.x86_64.rpm https://sourceforge.net/projects/intel-compute-runtime/files/19.41.14441/centos-7/intel-gmmlib-devel-19.3.2-1.el7.x86_64.rpm/download
300     ;;
301     "20.35.17767")
302         wget -O intel-opencl-20.35.17767-1.el7.x86_64.rpm https://sourceforge.net/projects/intel-compute-runtime/files/20.35.17767/centos-7/intel-opencl-20.35.17767-1.el7.x86_64.rpm/download
303         wget -O level-zero-1.0.0-1.el7.x86_64.rpm https://sourceforge.net/projects/intel-compute-runtime/files/20.35.17767/centos-7/level-zero-1.0.0-1.el7.x86_64.rpm/download
304         wget -O level-zero-devel-1.0.0-1.el7.x86_64.rpm https://sourceforge.net/projects/intel-compute-runtime/files/20.35.17767/centos-7/level-zero-devel-1.0.0-1.el7.x86_64.rpm/download
305         wget -O intel-igc-opencl-1.0.4756-1.el7.x86_64.rpm https://sourceforge.net/projects/intel-compute-runtime/files/20.35.17767/centos-7/intel-igc-opencl-1.0.4756-1.el7.x86_64.rpm/download
306         wget -O intel-igc-opencl-devel-1.0.4756-1.el7.x86_64.rpm https://sourceforge.net/projects/intel-compute-runtime/files/20.35.17767/centos-7/intel-igc-opencl-devel-1.0.4756-1.el7.x86_64.rpm/download
307         wget -O intel-igc-core-1.0.4756-1.el7.x86_64.rpm https://sourceforge.net/projects/intel-compute-runtime/files/20.35.17767/centos-7/intel-igc-core-1.0.4756-1.el7.x86_64.rpm/download
308         wget -O intel-gmmlib-20.2.4-1.el7.x86_64.rpm https://sourceforge.net/projects/intel-compute-runtime/files/20.35.17767/centos-7/intel-gmmlib-20.2.4-1.el7.x86_64.rpm/download
309         wget -O intel-gmmlib-devel-20.2.4-1.el7.x86_64.rpm https://sourceforge.net/projects/intel-compute-runtime/files/20.35.17767/centos-7/intel-gmmlib-devel-20.2.4-1.el7.x86_64.rpm/download
310     ;;
311         *)
312         echo "ERROR: Unrecognized driver ${INSTALL_DRIVER_VERSION}."
313         echo "Available values: ${AVAILABLE_DRIVERS[@]}"
314         exit -1
315     esac
316 }
317
318
319 _verify_checksum_ubuntu()
320 {
321     case $INSTALL_DRIVER_VERSION in
322     "19.41.14441")
323         wget https://github.com/intel/compute-runtime/releases/download/19.41.14441/ww41.sum
324         sha256sum -c ww41.sum
325     ;;
326     "20.35.17767")
327         wget https://github.com/intel/compute-runtime/releases/download/20.35.17767/ww35.sum
328         sha256sum -c ww35.sum
329     ;;
330         *)
331         echo "ERROR: Unrecognized driver ${INSTALL_DRIVER_VERSION}."
332         echo "Available values: ${AVAILABLE_DRIVERS[@]}"
333         exit -1
334     esac
335 }
336
337 _verify_checksum_centos()
338 {
339     case $INSTALL_DRIVER_VERSION in
340     "19.41.14441")
341         sha1sum -c "$SCRIPT_DIR/neo_centos_19.41.14441.sum"
342     ;;
343     "20.35.17767")
344         sha1sum -c "$SCRIPT_DIR/neo_centos_20.35.17767.sum"
345     ;;
346         *)
347         echo "ERROR: Unrecognized driver ${INSTALL_DRIVER_VERSION}."
348         echo "Available values: ${AVAILABLE_DRIVERS[@]}"
349         exit -1
350     esac    
351 }
352
353 verify_checksum()
354 {
355     if [[ $DISTRO == "centos" ]]; then
356         _verify_checksum_centos
357     else
358         _verify_checksum_ubuntu
359     fi
360 }
361
362 download_packages()
363 {
364     mkdir -p "$SCRIPT_DIR/neo"
365     cd "$SCRIPT_DIR/neo"
366     
367     if [[ $DISTRO == "centos" ]]; then
368         _download_packages_centos
369     else
370         _download_packages_ubuntu
371     fi
372     verify_checksum
373     if [[ $? -ne 0 ]]; then
374         echo "ERROR: checksums do not match for the downloaded packages"
375         echo "       Please verify your Internet connection and make sure you have enough disk space or fix the problem manually and try again. "
376         exit $EXIT_FAILURE
377     fi
378 }
379
380
381 version_gt() {
382     # check if first version is greater than second version
383     test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1";
384 }
385
386 summary()
387 {
388     echo
389     echo "Installation completed successfully."
390     echo
391     echo "Next steps:"
392     echo "Add OpenCL users to the video and render group: 'sudo usermod -a -G video,render USERNAME'"
393     echo "   e.g. if the user running OpenCL host applications is foo, run: sudo usermod -a -G video,render foo"
394     echo "   Current user has been already added to the video and render group"
395     echo
396
397     echo "If you use 8th Generation Intel® Core™ processor, add:"
398     echo "   i915.alpha_support=1"
399     echo "   to the 4.14 kernel command line, in order to enable OpenCL functionality for this platform."
400     echo
401  
402 }
403
404 check_root_access()
405 {
406     if [[ $EUID -ne 0 ]]; then
407         echo "ERROR: you must run this script as root." >&2
408         echo "Please try again with \"sudo -E $0\", or as root." >&2
409         exit $EXIT_FAILURE
410     fi
411 }
412
413 add_user_to_video_group()
414 {
415     local real_user=$(logname 2>/dev/null || echo "${SUDO_USER:-${USER}}")
416     echo
417     echo "Adding $real_user to the video group..."
418     usermod -a -G video "$real_user"
419     if [[ $? -ne 0 ]]; then
420         echo "WARNING: unable to add $real_user to the video group" >&2
421     fi
422     echo "Adding $real_user to the render group..."
423     usermod -a -G render "$real_user"
424     if [[ $? -ne 0 ]]; then
425         echo "WARNING: unable to add $real_user to the render group" >&2
426     fi
427 }
428
429 _check_distro_version()
430 {
431     if [[ $DISTRO == centos ]]; then
432         CENTOS_MINOR=$(sed 's/CentOS Linux release 7\.\([[:digit:]]\+\).\+/\1/' /etc/centos-release)
433         if [[ $? -ne 0 ]]; then
434             echo "ERROR: failed to obtain CentOS version minor." >&2
435             echo "This script is supported only on CentOS 7 and above." >&2
436             exit $EXIT_FAILURE
437         fi
438     elif [[ $DISTRO == ubuntu ]]; then
439         UBUNTU_VERSION=$(grep -m1 'VERSION_ID' /etc/os-release | grep -Eo "[0-9]{2}.[0-9]{2}") 
440         if [[ $UBUNTU_VERSION != '18.04' && $UBUNTU_VERSION != '20.04' ]]; then
441             echo "Warning: This runtime can be installed only on Ubuntu 18.04 or Ubuntu 20.04."
442             echo "More info https://github.com/intel/compute-runtime/releases" >&2
443             echo "Installation of Intel Compute Runtime interrupted"
444             exit $EXIT_FAILURE
445         fi
446     fi
447 }
448
449 distro_init()
450 {
451     if [[ -f /etc/centos-release ]]; then
452         DISTRO="centos"
453     elif [[ -f /etc/lsb-release ]]; then
454         DISTRO="ubuntu"
455     fi
456
457     _check_distro_version
458 }
459
460 check_agreement()
461 {
462     if [ "$agreement" == true ]; then
463         return 0
464     fi
465
466     echo "This script will download and install Intel(R) Graphics Compute Runtime $INSTALL_DRIVER_VERSION, "
467     echo "that was used to validate this OpenVINO™ package."
468     echo "In case if you already have the driver - script will try to remove it."
469     while true; do
470         read -p "Want to proceed? (y/n): " yn
471         case $yn in
472             [Yy]*) return 0  ;;
473             [Nn]*) exit 1 ;;
474         esac
475     done
476 }
477
478 check_specific_generation()
479 {
480     echo "Checking processor generation..."
481     specific_generation=$(grep -m1 'model name' /proc/cpuinfo | grep -E "i[357]-1[01][0-9]{2,4}N?G[147R]E?")
482     if [[ ! -z "$specific_generation" && "$INSTALL_DRIVER_VERSION" != '20.35.17767' ]]; then
483         echo "$(basename "$0"): Detected 10th generation Intel® Core™ processor (formerly Ice Lake) or 11th generation Intel® Core™ processor (formerly Tiger Lake)."
484         echo "Driver version 20.35.17767 is going to be installed to fully utilize hardware features and performance."
485         while true; do
486             read -p "You are still able to use the older version 19.41.14441. Use the older driver? (y/n) [n] " yn
487             yn=${yn:=n}
488             case $yn in
489                 [Yy]*) return 0 ;;
490                 [Nn]*) INSTALL_DRIVER_VERSION='20.35.17767' && return 0 ;;
491             esac
492         done        
493     fi
494 }
495
496 check_current_driver()
497 {   
498     echo "Checking current driver version..."
499     if [[ $DISTRO == centos ]]; then
500         gfx_version=$(yum info intel-opencl | grep Version)
501     elif [[ $DISTRO == ubuntu ]]; then
502         gfx_version=$(apt show intel-opencl | grep Version)
503     fi
504     
505     gfx_version="$(echo -e "${gfx_version}" | sed -e 's/^Version[[:space:]]*\:[[:space:]]*//')"
506     check_specific_generation
507     
508     # install NEO OCL driver if the current driver version < INSTALL_DRIVER_VERSION
509     if [[ ! -z $gfx_version && "$(printf '%s\n' "$INSTALL_DRIVER_VERSION" "$gfx_version" | sort -V | head -n 1)" = "$INSTALL_DRIVER_VERSION" ]]; then
510         echo "Intel® Graphics Compute Runtime for OpenCL™ Driver installation skipped because current version greater or equal to $INSTALL_DRIVER_VERSION" >&2
511         echo "Installation of Intel® Graphics Compute Runtime for OpenCL™ Driver interrupted." >&2
512         exit $EXIT_FAILURE
513     else
514         echo "Starting installation..."
515     fi
516 }
517
518 install()
519 {   
520     uninstall_user_mode
521     install_prerequisites
522     download_packages
523     install_user_mode
524     add_user_to_video_group
525 }
526
527 main()
528 {
529     echo "Intel® Graphics Compute Runtime for OpenCL™ Driver installer"
530     distro_init
531     check_root_access
532     check_current_driver
533     check_agreement
534     install
535     summary
536 }
537
538 [[ "$0" == "$BASH_SOURCE" ]] && main "$@"