Skip to content

Instantly share code, notes, and snippets.

@haxpor
Created March 27, 2021 23:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haxpor/15893127a2011c4a0c0f29a246189743 to your computer and use it in GitHub Desktop.
Save haxpor/15893127a2011c4a0c0f29a246189743 to your computer and use it in GitHub Desktop.
Script updated to make it work withROCm 4.1.x for Ubuntu 20.04 (tested with kernel 5.8.0-48). See context for older version at https://www.youtube.com/watch?v=CcaNLC1IIw8
#/bin/bash
# Original by tuxutku (https://gist.github.com/tuxutku/79daa2edca131c1525a136b650cdbe0a)
# Modified by haxpor (based also on older version tha work with ROcm 3.3 at https://gist.github.com/haxpor/8533fde401853615f4b2e4510048a319)
# This version with following changes
# - support ROCm 4.1.x for Ubuntu 20.04 (tested with kernel 5.8.0-48-generic)
# - improved to not re-download a driver package again unncessary
# - early exit with error if found error
# - refactor misc code
prefix='amdgpu-pro-'
postfix='-ubuntu-20.04'
major='20.50'
minor='1234664'
shared="opt/amdgpu-pro/lib/x86_64-linux-gnu"
extracted_dir="${prefix}${major}-${minor}${postfix}"
target_file="${extracted_dir}.tar.xz"
srcdir="$(pwd)"
# check if file is already downloaded, then skip re-download
if [ ! -f "${target_file}" ]; then
# AMD website check whether you're from the donwloading page in order to successfully download a target driver file
echo "Downloading archive and extracting"
# download a package then save into a file (file is quite large, better download and save it locally before proceeding
# with extraction later.
wget --header="Referer: https://www.amd.com/en/support/kb/release-notes/rn-amdgpu-unified-linux" --header="Host: drivers.amd.com" --header="User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0" --header="Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" --header="Accept-Encoding: gzip, deflate, br" -N "https://drivers.amd.com/drivers/linux/${target_file}"
if [[ "$?" -ne 0 ]]; then
echo "Error downloading amdgpu-pro driver package file"
exit 1
fi
fi
# extract the file
tar xJf ${target_file}
if [[ "$?" -ne 0 ]]; then
echo "Error extracting ${target_file}"
exit 1
else
echo "Extraction complete, creating the files"
fi
mkdir -p "opencl"
cd "opencl"
ar x "${srcdir}/${extracted_dir}/ocl-icd-libopencl1-amdgpu-pro_${major}-${minor}_amd64.deb"
tar xJf data.tar.xz
ar x "${srcdir}/${extracted_dir}/opencl-orca-amdgpu-pro-icd_${major}-${minor}_amd64.deb"
tar xJf data.tar.xz
cd "${shared}"
mkdir -p "${srcdir}/libdrm"
cd "${srcdir}/libdrm"
ar x "${srcdir}/${extracted_dir}/libdrm-amdgpu-amdgpu1_2.4.100-${minor}_amd64.deb"
tar xJf data.tar.xz
# create 'pkgdir'
pkgdir="${srcdir}/pkgdir"
mkdir -p "${pkgdir}"
# prep content inside pkgdir directory
mv "${srcdir}/opencl/etc" "${pkgdir}/"
mkdir -p ${pkgdir}/usr/lib
mv "${srcdir}/opencl/${shared}/libamdocl12cl64.so" "${pkgdir}/usr/lib/"
mv "${srcdir}/opencl/${shared}/libamdocl-orca64.so" "${pkgdir}/usr/lib/"
mv "${srcdir}/libdrm/opt/amdgpu/lib/x86_64-linux-gnu/libdrm_amdgpu.so.1.0.0" "${pkgdir}/usr/lib/"
mv "${srcdir}/libdrm/opt/amdgpu/lib/x86_64-linux-gnu/libdrm_amdgpu.so.1" "${pkgdir}/usr/lib/"
mkdir -p "${pkgdir}/opt/amdgpu/share/libdrm"
cd "${pkgdir}/opt/amdgpu/share/libdrm"
ln -s /usr/share/libdrm/amdgpu.ids amdgpu.ids
rm -r "${srcdir}/opencl"
rm -r "${srcdir}/libdrm"
cd "${pkgdir}"
echo "Done"
echo "Creating files complete, copying files to root. Enter sudo password when asked"
sudo cp -Rv * / # might need to use rsync instead if your /opt directory is symlinked
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment