Skip to content

Instantly share code, notes, and snippets.

@kytulendu
Last active January 15, 2024 09:08
Show Gist options
  • Save kytulendu/3351b5d0b4f947e19df36b1ea3c95cbe to your computer and use it in GitHub Desktop.
Save kytulendu/3351b5d0b4f947e19df36b1ea3c95cbe to your computer and use it in GitHub Desktop.
A shell script to install AMDGPU-PRO OpenCL driver.
#!/bin/bash
# This script will install AMDGPU-PRO OpenCL and Vulkan support.
#
# For Ubuntu and it's flavor, just install the package using this command
# in extracted driver directory instread.
#
# ./amdgpu-pro-install --opencl=legacy,pal --headless --no-dkms
#
# For Arch Linux or Manjaro, use the opencl-amd or rocm-opencl-runtime on AUR instread.
#
# To use amdvlk driver, launch the program/game with this command :
#
# VK_ICD_FILENAMES="/opt/amdgpu-pro/etc/vulkan/icd.d/amd_icd64.json" game64
#
# If the program/game is 32bit, use this command :
#
# VK_ICD_FILENAMES="/opt/amdgpu-pro/etc/vulkan/icd.d/amd_icd32.json" game32
#
prefix='amdgpu-pro'
# amdgpu-pro package version
major='21'
minor='30'
build='1290604'
system='ubuntu-20.04'
# libdrm-amdgpu-amdgpu1 version
libdrmver='2.4.106'
libamd_comgrver='2.1.0'
libhsa_ver='1.3.0'
libamdhip_ver='4.2.21303'
shared32="/usr/lib32"
shared64="/usr/lib"
amd_shared32="/opt/amdgpu-pro/lib/i386-linux-gnu"
amd_shared64="/opt/amdgpu-pro/lib/x86_64-linux-gnu"
ids="/opt/amdgpu/share/libdrm"
vk_icd="/opt/amdgpu-pro/etc/vulkan/icd.d"
gcn_bitcode="/opt/amdgpu-pro/amdgcn/bitcode"
# make sure we’re running with root permissions.
if [ `whoami` != root ]; then
echo Please run this script using sudo
exit
fi
# check for 64-bit arch
if [ $(uname -m) != 'x86_64' ]; then
echo This install script support only 64-bit linux.
exit
fi
# download and extract drivers
rm -r ${prefix}-${major}.${minor}-${build}-${system} &>/dev/null
if [ ! -f ./${prefix}-${major}.${minor}-${build}-${system}.tar.xz ]; then
wget --referer https://www.amd.com/en/support/kb/release-notes/rn-amdgpu-unified-linux-21-30 https://drivers.amd.com/drivers/linux/${prefix}-${major}.${minor}-${build}-${system}.tar.xz
fi
tar xJf ${prefix}-${major}.${minor}-${build}-${system}.tar.xz
cd ${prefix}-${major}.${minor}-${build}-${system}
echo Extracting AMDGPU-PRO OpenCL driver files...
#ar x "../${prefix}-${major}.${minor}-${build}-${system}/clinfo-amdgpu-pro_${major}.${minor}-${build}_amd64.deb"
#tar xJf data.tar.xz
#ar x "../${prefix}-${major}.${minor}-${build}-${system}/clinfo-amdgpu-pro_${major}.${minor}-${build}_i386.deb"
#tar xJf data.tar.xz
ar x "../${prefix}-${major}.${minor}-${build}-${system}/comgr-amdgpu-pro_${libamd_comgrver}-${build}_amd64.deb"
tar xJf data.tar.xz
#ar x "../${prefix}-${major}.${minor}-${build}-${system}/comgr-amdgpu-pro-dev_${libamd_comgrver}-${build}_amd64.deb"
#tar xJf data.tar.xz
ar x "../${prefix}-${major}.${minor}-${build}-${system}/hip-rocr-amdgpu-pro_${major}.${minor}-${build}_amd64.deb"
tar xJf data.tar.xz
ar x "../${prefix}-${major}.${minor}-${build}-${system}/hsa-runtime-rocr-amdgpu_${libhsa_ver}-${build}_amd64.deb"
tar xJf data.tar.xz
#ar x "../${prefix}-${major}.${minor}-${build}-${system}/hsa-runtime-rocr-amdgpu-dev_${libhsa_ver}-${build}_amd64.deb"
#tar xJf data.tar.xz
ar x "../${prefix}-${major}.${minor}-${build}-${system}/hsakmt-roct-amdgpu_1.0.9-${build}_amd64.deb"
tar xJf data.tar.xz
#ar x "../${prefix}-${major}.${minor}-${build}-${system}/hsakmt-roct-amdgpu-dev_1.0.9-${build}_amd64.deb"
#tar xJf data.tar.xz
ar x "../${prefix}-${major}.${minor}-${build}-${system}/libdrm-amdgpu-amdgpu1_${libdrmver}-${build}_amd64.deb"
tar xJf data.tar.xz
ar x "../${prefix}-${major}.${minor}-${build}-${system}/libdrm-amdgpu-amdgpu1_${libdrmver}-${build}_i386.deb"
tar xJf data.tar.xz
ar x "../${prefix}-${major}.${minor}-${build}-${system}/libdrm-amdgpu-common_1.0.0-${build}_all.deb"
tar xJf data.tar.xz
ar x "../${prefix}-${major}.${minor}-${build}-${system}/opencl-orca-amdgpu-pro-icd_${major}.${minor}-${build}_amd64.deb"
tar xJf data.tar.xz
ar x "../${prefix}-${major}.${minor}-${build}-${system}/opencl-orca-amdgpu-pro-icd_${major}.${minor}-${build}_i386.deb"
tar xJf data.tar.xz
ar x "../${prefix}-${major}.${minor}-${build}-${system}/opencl-rocr-amdgpu-pro_${major}.${minor}-${build}_amd64.deb"
tar xJf data.tar.xz
#ar x "../${prefix}-${major}.${minor}-${build}-${system}/opencl-rocr-amdgpu-pro-dev_${major}.${minor}-${build}_amd64.deb"
#tar xJf data.tar.xz
ar x "../${prefix}-${major}.${minor}-${build}-${system}/rocm-device-libs-amdgpu-pro_1.0.0-${build}_amd64.deb"
tar xJf data.tar.xz
ar x "../${prefix}-${major}.${minor}-${build}-${system}/vulkan-amdgpu-pro_${major}.${minor}-${build}_amd64.deb"
tar xJf data.tar.xz
ar x "../${prefix}-${major}.${minor}-${build}-${system}/vulkan-amdgpu-pro_${major}.${minor}-${build}_i386.deb"
tar xJf data.tar.xz
# Remove target directory
echo Remove target directory.
rm -r /opt/amdgpu &>/dev/null
rm -r /opt/amdgpu-pro &>/dev/null
# Remove old version
rm ${shared32}/libdrm_amdpro.so.1
rm ${shared32}/libdrm_amdpro.so.1.0.0
rm ${shared32}/libamdocl-orca32.so
rm ${shared64}/libdrm_amdpro.so.1
rm ${shared64}/libdrm_amdpro.so.1.0.0
rm ${shared64}/libhsakmt.so.1
rm ${shared64}/libhsakmt.so.1.0.6
rm ${shared64}/libamdocl-orca64.so
rm ${shared64}/libamdocl64.so
rm ${shared64}/libamd_comgr.so
rm ${shared64}/libamd_comgr.so.2
rm ${shared64}/libamd_comgr.so.${libamd_comgrver}
rm ${shared64}/libamdhip64.so
rm ${shared64}/libamdhip64.so.4
rm ${shared64}/libamdhip64.so.${libamdhip_ver}-
rm ${shared64}/libhsa-runtime64.so.1
rm ${shared64}/libhsa-runtime64.so.${libhsa_ver}
# Create target directory
echo Create target directory.
mkdir -p ${ids}
mkdir -p ${amd_shared32}
mkdir -p ${amd_shared64}
mkdir -p ${vk_icd}
mkdir -p ${gcn_bitcode}
echo Patch and installing AMDGPU-PRO OpenCL driver...
rm /etc/OpenCL/vendors/amdocl-orca64.icd
rm /etc/OpenCL/vendors/amdocl-orca32.icd
rm /etc/OpenCL/vendors/amdocl64.icd
# For some reasons this directory is not exist on some system
if [ ! -f /etc/OpenCL/vendors ]; then
echo Directory /etc/OpenCL/vendors is not exist
echo Creating it...
mkdir -p /etc/OpenCL/vendors
fi
cp ./etc/OpenCL/vendors/*.icd /etc/OpenCL/vendors
cp ./opt/amdgpu-pro/etc/vulkan/icd.d/*.json ${vk_icd}
cp ./opt/amdgpu/share/libdrm/amdgpu.ids /opt/amdgpu/share/libdrm
cp ./opt/amdgpu-pro/amdgcn/bitcode/*.bc /opt/amdgpu-pro/amdgcn/bitcode
pushd ./opt/amdgpu/lib/i386-linux-gnu &>/dev/null
rm "libdrm_amdgpu.so.1"
mv "libdrm_amdgpu.so.1.0.0" "libdrm_amdpro.so.1.0.0"
ln -s "libdrm_amdpro.so.1.0.0" "libdrm_amdpro.so.1"
mv "libdrm_amdpro.so.1.0.0" "${shared32}"
mv "libdrm_amdpro.so.1" "${shared32}"
popd &>/dev/null
pushd ./opt/amdgpu/lib/x86_64-linux-gnu &>/dev/null
rm "libdrm_amdgpu.so.1"
mv "libdrm_amdgpu.so.1.0.0" "libdrm_amdpro.so.1.0.0"
ln -s "libdrm_amdpro.so.1.0.0" "libdrm_amdpro.so.1"
mv "libdrm_amdpro.so.1.0.0" "${shared64}"
mv "libdrm_amdpro.so.1" "${shared64}"
mv "libhsakmt.so.1.0.6" "${shared64}"
mv "libhsakmt.so.1" "${shared64}"
popd &>/dev/null
pushd ./opt/amdgpu-pro/lib/i386-linux-gnu &>/dev/null
sed -i "s|libdrm_amdgpu|libdrm_amdpro|g" libamdocl-orca32.so
mv "libamdocl-orca32.so" "${shared32}"
mv "amdvlk32.so.1.0" "${amd_shared32}"
mv "amdvlk32.so" "${amd_shared32}"
popd &>/dev/null
pushd ./opt/amdgpu-pro/lib/x86_64-linux-gnu &>/dev/null
sed -i "s|libdrm_amdgpu|libdrm_amdpro|g" libamdocl-orca64.so
mv "libamdocl-orca64.so" "${shared64}"
mv "libamdocl64.so" "${shared64}"
mv "libamd_comgr.so.${libamd_comgrver}" "${shared64}"
ln -s "libamd_comgr.so.2" "libamd_comgr.so"
mv "libamd_comgr.so.2" "${shared64}"
mv "libamd_comgr.so" "${shared64}"
mv "libcltrace.so" "${amd_shared64}"
mv "amdvlk64.so.1.0" "${amd_shared64}"
mv "amdvlk64.so" "${amd_shared64}"
mv "libamdhip64.so.${libamdhip_ver}-" "${shared64}"
mv "libamdhip64.so.4" "${shared64}"
mv "libamdhip64.so" "${shared64}"
mv "libhsa-runtime64.so.1" "${shared64}"
mv "libhsa-runtime64.so.${libhsa_ver}" "${shared64}"
mv "libhiprtc-builtins.so.4.2" "${amd_shared64}"
popd &>/dev/null
echo "Finished!"
cd ..
echo "Cleaning up"
rm -r ${prefix}-${major}.${minor}-${build}-${system}
echo Done.
@Etaash-mathamsetty
Copy link

nope not working
Error: AMD HSA Code Object loading failed: HSA_STATUS_ERROR_INVALID_CODE_OBJECT: The code object is invalid.

@debian-alain
Copy link

Hello to all.
there is a solution to install OpenCL on Debian .
provided by AMD :

download and unpack the latest version of amdgpu-pro
(currently, 21.30)
go to its folder.
and enter this command:

sudo ./amdgpu-install --opencl=legacy --headless --no-dkms

OpenCL is installed but, at this time (kernel 5.14.0-3), it is not functional.

to uninstall : sudo amdgpu-uninstall

to test : clinfo

thanks to the AMD staff .

@debian-alain
Copy link

debian-alain commented Oct 25, 2021

also kytulendu, you removed your thread from your main github page ?

now it is independent ?

@debian-alain
Copy link

debian-alain commented Dec 12, 2021

Hello kytulendu and thank you for your script.

today i tested it with kernel 5.15.6 (kernel.org) on my debian sid .

complete success .

apparently, indeed, you were right.
my kernel, until now, was not ready.

now blender recognizes openCL and my graphic card (also my cpu)

darktable also recognizes openCL.

in short, all is well in the best of worlds.

Thanks again.

I re-communicate below my clinfo .
attention, it is long.

alain@sid:~/Téléchargements/AMDGPU$ clinfo
Number of platforms 1
Platform Name AMD Accelerated Parallel Processing
Platform Vendor Advanced Micro Devices, Inc.
Platform Version OpenCL 2.0 AMD-APP (3314.0)
Platform Profile FULL_PROFILE
Platform Extensions cl_khr_icd cl_amd_event_callback
Platform Extensions function suffix AMD

Platform Name AMD Accelerated Parallel Processing
Number of devices 1
Device Name gfx1030
Device Vendor Advanced Micro Devices, Inc.
Device Vendor ID 0x1002
Device Version OpenCL 2.0
Driver Version 3314.0 (HSA1.1,LC)
Device OpenCL C Version OpenCL C 2.0
Device Type GPU
Device Board Name (AMD) Navi 21 [Radeon RX 6800/6800 XT / 6900 XT]
Device PCI-e ID (AMD) 0x73bf
Device Topology (AMD) PCI-E, 0000:0a:00.0
Device Profile FULL_PROFILE
Device Available Yes
Compiler Available Yes
Linker Available Yes
Max compute units 30
SIMD per compute unit (AMD) 4
SIMD width (AMD) 32
SIMD instruction width (AMD) 1
Max clock frequency 2475MHz
Graphics IP (AMD) 10.3
Device Partition (core)
Max number of sub-devices 30
Supported partition types None
Supported affinity domains (n/a)
Max work item dimensions 3
Max work item sizes 1024x1024x1024
Max work group size 256
Preferred work group size (AMD) 256
Max work group size (AMD) 1024
Preferred work group size multiple (kernel) 32
Wavefront width (AMD) 32
Preferred / native vector sizes
char 4 / 4
short 2 / 2
int 1 / 1
long 1 / 1
half 1 / 1 (cl_khr_fp16)
float 1 / 1
double 1 / 1 (cl_khr_fp64)
Half-precision Floating-point support (cl_khr_fp16)
Denormals No
Infinity and NANs No
Round to nearest No
Round to zero No
Round to infinity No
IEEE754-2008 fused multiply-add No
Support is emulated in software No
Single-precision Floating-point support (core)
Denormals Yes
Infinity and NANs Yes
Round to nearest Yes
Round to zero Yes
Round to infinity Yes
IEEE754-2008 fused multiply-add Yes
Support is emulated in software No
Correctly-rounded divide and sqrt operations Yes
Double-precision Floating-point support (cl_khr_fp64)
Denormals Yes
Infinity and NANs Yes
Round to nearest Yes
Round to zero Yes
Round to infinity Yes
IEEE754-2008 fused multiply-add Yes
Support is emulated in software No
Address bits 64, Little-Endian
Global memory size 17163091968 (15.98GiB)
Global free memory (AMD) 16760832 (15.98GiB) 16760832 (15.98GiB)
Global memory channels (AMD) 8
Global memory banks per channel (AMD) 4
Global memory bank width (AMD) 256 bytes
Error Correction support No
Max memory allocation 14588628168 (13.59GiB)
Unified memory for Host and Device No
Shared Virtual Memory (SVM) capabilities (core)
Coarse-grained buffer sharing Yes
Fine-grained buffer sharing Yes
Fine-grained system sharing No
Atomics No
Minimum alignment for any data type 128 bytes
Alignment of base address 1024 bits (128 bytes)
Preferred alignment for atomics
SVM 0 bytes
Global 0 bytes
Local 0 bytes
Max size for global variable 14588628168 (13.59GiB)
Preferred total size of global vars 17163091968 (15.98GiB)
Global Memory cache type Read/Write
Global Memory cache size 16384 (16KiB)
Global Memory cache line size 64 bytes
Image support Yes
Max number of samplers per kernel 29631
Max size for 1D images from buffer 134217728 pixels
Max 1D or 2D image array size 8192 images
Base address alignment for 2D image buffers 256 bytes
Pitch alignment for 2D image buffers 256 pixels
Max 2D image size 16384x16384 pixels
Max 3D image size 16384x16384x8192 pixels
Max number of read image args 128
Max number of write image args 8
Max number of read/write image args 64
Max number of pipe args 16
Max active pipe reservations 16
Max pipe packet size 1703726280 (1.587GiB)
Local memory type Local
Local memory size 65536 (64KiB)
Local memory size per CU (AMD) 65536 (64KiB)
Local memory banks (AMD) 32
Max number of constant args 8
Max constant buffer size 14588628168 (13.59GiB)
Preferred constant buffer size (AMD) 16384 (16KiB)
Max size of kernel argument 1024
Queue properties (on host)
Out-of-order execution No
Profiling Yes
Queue properties (on device)
Out-of-order execution Yes
Profiling Yes
Preferred size 262144 (256KiB)
Max size 8388608 (8MiB)
Max queues on device 1
Max events on device 1024
Prefer user sync for interop Yes
Number of P2P devices (AMD) 0
Profiling timer resolution 1ns
Profiling timer offset since Epoch (AMD) 0ns (Thu Jan 1 01:00:00 1970)
Execution capabilities
Run OpenCL kernels Yes
Run native kernels No
Thread trace supported (AMD) No
Number of async queues (AMD) 8
Max real-time compute queues (AMD) 8
Max real-time compute units (AMD) 30
printf() buffer size 4194304 (4MiB)
Built-in kernels (n/a)
Device Extensions cl_khr_fp64 cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_3d_image_writes cl_khr_byte_addressable_store cl_khr_fp16 cl_khr_gl_sharing cl_amd_device_attribute_query cl_amd_media_ops cl_amd_media_ops2 cl_khr_image2d_from_buffer cl_khr_subgroups cl_khr_depth_images cl_amd_copy_buffer_p2p cl_amd_assembly_program

NULL platform behavior
clGetPlatformInfo(NULL, CL_PLATFORM_NAME, ...) AMD Accelerated Parallel Processing
clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, ...) Success [AMD]
clCreateContext(NULL, ...) [default] Success [AMD]
clCreateContextFromType(NULL, CL_DEVICE_TYPE_DEFAULT) Success (1)
Platform Name AMD Accelerated Parallel Processing
Device Name gfx1030
clCreateContextFromType(NULL, CL_DEVICE_TYPE_CPU) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU) Success (1)
Platform Name AMD Accelerated Parallel Processing
Device Name gfx1030
clCreateContextFromType(NULL, CL_DEVICE_TYPE_ACCELERATOR) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_CUSTOM) No devices found in platform
clCreateContextFromType(NULL, CL_DEVICE_TYPE_ALL) Success (1)
Platform Name AMD Accelerated Parallel Processing
Device Name gfx1030

ICD loader properties
ICD loader Name OpenCL ICD Loader
ICD loader Vendor OCL Icd free software
ICD loader Version 2.2.14
ICD loader Profile OpenCL 3.0

@Jorgen-VikingGod
Copy link

found link to this script in a forum. Before I try on my system I wanted to ask, if someone already tried on Pop_OS! 21.10?

I'm using Pop_OS! 21.10 on a Ryzen 9 5900X system with an old AMD Radeon RX 580 GPU

But it is not recognized in Davinci Resolve Sudio 17

> clinfo
Number of platforms                               0
> uname -r
5.15.11-76051511-generic

Would be awesome if this script runs on my Pop too...

@DeeDeeRanged
Copy link

@Jorgen-VikingGod Your missing OpenCL. Install OpenCL for your card. Try installing it with the the amdgpu-pro-21.30 drivers unpack it cd into the directory and just run amdgpu-install --no-dkms --opencl=legacy (--headless). If it installed properly run /opt/amdgpu-pro/bin/clinfo and it should show the rx 580. For you --headless might not be needed. This way I have my rx 580 8gb running on Debian testing/bookworm and on Debian bullseye.

@Jorgen-VikingGod
Copy link

thx. @DeeDeeRanged I will try it today. But I could rmember that the amdgpu-pro script did not have any pop os support. Maybe I have to just add pop to the conditions (debian and ubuntu is there, as I remember).

Hopefully the script will work to install OpenCL for me.
I'll report if it worked or not. Thx 👍

@Jorgen-VikingGod
Copy link

Sorry for late reply...
Following result:

  • amdgpu pro seams not to build against newer linux kernel like 5.15 used by Pop!_OS 21.10
  • on Pop!_OS 20.04, my RX 580 is visible and works
  • didn't try to upgrade to 21.10 (once I done, I'll report if driver still there or not)
    Thank you all for the help 👍

@inteus707
Copy link

I'm running Pop!_OS 21.10 (PopOS was discontinuing support for 20.04 early). I run the Ubuntu command and it failed because it found pop as the os, but I changed that in the install script. However, when running ./amdgpu-pro-install --opencl=legacy,pal --headless --no-dkms it gives the following error:

ERROR: using --no-dkms with a pro install is invalid.
Did you want to run the following instead?
amdgpu-install --no-dkms

Does anyone have a solution for Pop!_OS 21.10?

Copy link

ghost commented Mar 5, 2022

How do I revert the changes made by this script? (I want to uninstall)

@Dany-Wilde
Copy link

hello ;) ;) ;)

ubuntu is now in 22.04 but I don't know what happened to the amdgpupro driver?

  • has it evolved?
  • is it still available?
  • in what form?
  • and open CL ?
  • what about the evolution of the sources driven by amd?

a lot of questions are asked but, until now, few answers,
few answers.

@yhilgjff
Copy link

yhilgjff commented Oct 20, 2022

a lot of questions are asked but, until now, few answers, few answers.

Dany,

Exactly my thought too and our posts are several months apart. So yes, still very relevant!

My real quest is this however: For 22.04.1 systems is it possible to simply adapt the versions of the script and have it fix OpenCL automagically?

For example, the script says:
major='21'
minor='30'
build='1290604'
system='ubuntu-20.04'

So if we base ourselves on the AMD driver reference which is currently pointing to v22.20 (no build) (https://www.amd.com/en/support/linux-drivers) that would then mean that the same lines would need to read:

major='22'
minor='20'
system='ubuntu-22.04.1'

Should that work on Ubuntu 22.04.1 systems or am I day dreaming here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment