mirror of
https://github.com/keylase/nvidia-patch.git
synced 2024-11-22 13:37:27 +00:00
some refactoring patch, added multi-version support, added patch for 396.24 driver
This commit is contained in:
parent
f223ab9315
commit
22203ca48d
50
README.md
50
README.md
@ -1,40 +1,50 @@
|
|||||||
# nvidia-patch
|
# nvidia-patch
|
||||||
|
|
||||||
requirements:
|
Requirements:
|
||||||
- ubuntu 14.04
|
- ubuntu (< 16.04 for 375.39 nvidia driver or kernel < 4.15)
|
||||||
- nvenc-compatible gpu
|
- nvenc-compatible gpu (https://developer.nvidia.com/video-encode-decode-gpu-support-matrix#Encoder)
|
||||||
- nvidia 375.39 driver
|
- nvidia driver (patch availible for 375.39 or 396.24)
|
||||||
|
|
||||||
# step-by-step :
|
Tested on Ubuntu 18.04 LTS (GNU/Linux 4.15.0-23-generic x86_64)
|
||||||
|
|
||||||
Download driver: https://yadi.sk/d/yahf1Y-D3PJnzd
|
## step-by-step :
|
||||||
|
|
||||||
|
### Download driver
|
||||||
|
http://us.download.nvidia.com/XFree86/Linux-x86_64/375.39/NVIDIA-Linux-x86_64-375.39.run
|
||||||
|
http://us.download.nvidia.com/XFree86/Linux-x86_64/396.24/NVIDIA-Linux-x86_64-396.24.run
|
||||||
|
|
||||||
|
### Install driver 396.24
|
||||||
```bash
|
```bash
|
||||||
|
mkdir /opt/nvidia && cd /opt/nvidia
|
||||||
|
wget http://us.download.nvidia.com/XFree86/Linux-x86_64/396.24/NVIDIA-Linux-x86_64-396.24.run
|
||||||
chmod +x ./NVIDIA-Linux-x86_64-375.39.run
|
chmod +x ./NVIDIA-Linux-x86_64-375.39.run
|
||||||
|
./NVIDIA-Linux-x86_64-396.24.run
|
||||||
./NVIDIA-Linux-x86_64-375.39.run
|
|
||||||
```
|
```
|
||||||
|
|
||||||
check driver:
|
### Check driver
|
||||||
```bash
|
```bash
|
||||||
nvidia-smi
|
nvidia-smi
|
||||||
|
```
|
||||||
|
|
||||||
mkdir ~/nvenc_backup
|
### Patch libnvidia-encode.so (with backup)
|
||||||
|
```bash
|
||||||
|
bash ./patch.sh
|
||||||
|
```
|
||||||
|
|
||||||
cd ~/nvenc_backup
|
### Silent patch libnvidia-encode.so
|
||||||
|
```bash
|
||||||
|
bash ./patch.sh -s
|
||||||
|
```
|
||||||
|
|
||||||
cp /usr/lib/x86_64-linux-gnu/libnvidia-encode.so.375.39 ~/nvenc_backup/
|
### Rollback libnvidia-encode.so (restore from backup)
|
||||||
|
```bash
|
||||||
wget https://raw.githubusercontent.com/keylase/nvidia-patch/master/patch.sh
|
bash ./patch.sh -r
|
||||||
|
|
||||||
chmod +x patch.sh
|
|
||||||
|
|
||||||
./patch.sh ~/nvenc_backup/libnvidia-encode.so.375.39 /usr/lib/x86_64-linux-gnu/libnvidia-encode.so.375.39
|
|
||||||
|
|
||||||
reboot
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## See also
|
## See also
|
||||||
|
|
||||||
|
https://habr.com/post/262563/
|
||||||
|
|
||||||
If you experience `CreateBitstreamBuffer failed: out of memory (10)`, then you have to lower buffers number used for every encoding session. If you are using `ffmpeg`, consider using this [patch](https://gist.github.com/Snawoot/70ae403716c698cb86ab015626d72bd4).
|
If you experience `CreateBitstreamBuffer failed: out of memory (10)`, then you have to lower buffers number used for every encoding session. If you are using `ffmpeg`, consider using this [patch](https://gist.github.com/Snawoot/70ae403716c698cb86ab015626d72bd4).
|
||||||
|
|
||||||
|
|
||||||
|
86
patch.sh
Normal file → Executable file
86
patch.sh
Normal file → Executable file
@ -1,9 +1,81 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
input=$1
|
|
||||||
output=$2
|
|
||||||
if [ -z $1 ]; then
|
|
||||||
echo "Require params - example: ./patch.sh <input file> <output file>"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
sed 's/\x85\xC0\x89\xC5\x75\x18/\x29\xC0\x89\xC5\x90\x90/g' $input > $output
|
|
||||||
|
|
||||||
|
backup_path="/opt/nvidia/libnvidia-encode-backup"
|
||||||
|
silent_flag=''
|
||||||
|
rollback_flag=''
|
||||||
|
|
||||||
|
print_usage() { printf '
|
||||||
|
SYNOPSIS
|
||||||
|
patch.sh [OPTION]...
|
||||||
|
|
||||||
|
DESCRIPTION
|
||||||
|
The patch for libnvidia-encode to increase encoder sessions
|
||||||
|
|
||||||
|
-s Silent mode (No output)
|
||||||
|
-r Rollback to original (Restore lib from backup)
|
||||||
|
|
||||||
|
'
|
||||||
|
}
|
||||||
|
|
||||||
|
while getopts 'rs' flag; do
|
||||||
|
case "${flag}" in
|
||||||
|
r) rollback_flag='true' ;;
|
||||||
|
s) silent_flag='true' ;;
|
||||||
|
*) print_usage
|
||||||
|
exit 1 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ $silent_flag ]]; then
|
||||||
|
exec 1> /dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
declare -A patch_list=(
|
||||||
|
["375.39"]='s/\x85\xC0\x89\xC5\x75\x18/\x29\xC0\x89\xC5\x90\x90/g'
|
||||||
|
["396.24"]='s/\x85\xC0\x89\xC5\x0F\x85\x96\x00\x00\x00/\x29\xC0\x89\xC5\x90\x90\x90\x90\x90\x90/g'
|
||||||
|
# break nvenc.c:236,layout asm,step-mode,step,break *0x00007fff89f9ba45
|
||||||
|
# libnvidia-encode.so @ 0x15a45; test->sub, jne->nop-nop-nop-nop-nop-nop
|
||||||
|
)
|
||||||
|
|
||||||
|
driver_version=$(/usr/bin/nvidia-smi --query-gpu=driver_version --format=csv,noheader,nounits)
|
||||||
|
if [[ ! $? -eq 0 ]]; then
|
||||||
|
echo 'Something went wrong. Check nvidia driver'
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Detected nvidia driver version: $driver_version"
|
||||||
|
|
||||||
|
patch=${patch_list[$driver_version]}
|
||||||
|
|
||||||
|
if [[ ! $patch ]]; then
|
||||||
|
echo "Patch for this ($driver_version) nvidia driver not found." 1>&2
|
||||||
|
echo "Available patches for: " 1>&2
|
||||||
|
for drv in "${!patch_list[@]}"; do
|
||||||
|
echo "$drv" 1>&2
|
||||||
|
done
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $rollback_flag ]]; then
|
||||||
|
if [[ -f $backup_path/libnvidia-encode.so.$driver_version ]]; then
|
||||||
|
cp $backup_path/libnvidia-encode.so.$driver_version \
|
||||||
|
/usr/lib/x86_64-linux-gnu/libnvidia-encode.so.$driver_version
|
||||||
|
echo "Restore from backup libnvidia-encode.so.$driver_version"
|
||||||
|
else
|
||||||
|
echo "Backup not found. Try to patch first."
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if [[ ! -f $backup_path/libnvidia-encode.so.$driver_version ]]; then
|
||||||
|
echo "Attention! Backup not found. Copy current libnvidia-encode to backup."
|
||||||
|
mkdir -p $backup_path
|
||||||
|
cp /usr/lib/x86_64-linux-gnu/libnvidia-encode.so.$driver_version \
|
||||||
|
$backup_path/libnvidia-encode.so.$driver_version
|
||||||
|
fi
|
||||||
|
sha1sum $backup_path/libnvidia-encode.so.$driver_version
|
||||||
|
sed "$patch" $backup_path/libnvidia-encode.so.$driver_version > \
|
||||||
|
/usr/lib/x86_64-linux-gnu/libnvidia-encode.so.$driver_version
|
||||||
|
sha1sum /usr/lib/x86_64-linux-gnu/libnvidia-encode.so.$driver_version
|
||||||
|
ldconfig
|
||||||
|
echo "Patched!"
|
||||||
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user